@sanity/cli 6.0.0-alpha.3 → 6.0.0-alpha.4
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/actions/auth/login/{index.js → login.js} +1 -1
- package/dist/actions/auth/login/{index.js.map → login.js.map} +1 -1
- package/dist/actions/organizations/getOrganizationChoices.d.ts +6 -0
- package/dist/actions/organizations/getOrganizationChoices.js +23 -0
- package/dist/actions/organizations/getOrganizationChoices.js.map +1 -0
- package/dist/actions/organizations/getOrganizationsWithAttachGrantInfo.d.ts +2 -0
- package/dist/actions/organizations/getOrganizationsWithAttachGrantInfo.js +9 -0
- package/dist/actions/organizations/getOrganizationsWithAttachGrantInfo.js.map +1 -0
- package/dist/actions/organizations/hasProjectAttachGrant.d.ts +1 -0
- package/dist/actions/organizations/hasProjectAttachGrant.js +24 -0
- package/dist/actions/organizations/hasProjectAttachGrant.js.map +1 -0
- package/dist/actions/schema/utils/schemaStoreValidation.js +2 -2
- package/dist/actions/schema/utils/schemaStoreValidation.js.map +1 -1
- package/dist/commands/__tests__/init/init.authentication.test.js +60 -0
- package/dist/commands/__tests__/init/init.authentication.test.js.map +1 -0
- package/dist/commands/__tests__/init/init.create-new-project.test.js +196 -0
- package/dist/commands/__tests__/init/init.create-new-project.test.js.map +1 -0
- package/dist/commands/__tests__/init/init.plan.test.js +220 -0
- package/dist/commands/__tests__/init/init.plan.test.js.map +1 -0
- package/dist/commands/__tests__/init/init.setup.test.js +279 -0
- package/dist/commands/__tests__/init/init.setup.test.js.map +1 -0
- package/dist/commands/__tests__/migration.test.js +119 -0
- package/dist/commands/__tests__/migration.test.js.map +1 -0
- package/dist/commands/backup/__tests__/download.test.js +3 -3
- package/dist/commands/backup/__tests__/download.test.js.map +1 -1
- package/dist/commands/dataset/__tests__/import.test.js +2 -2
- package/dist/commands/dataset/__tests__/import.test.js.map +1 -1
- package/dist/commands/documents/__tests__/query.test.js +3 -3
- package/dist/commands/documents/__tests__/query.test.js.map +1 -1
- package/dist/commands/init.d.ts +4 -0
- package/dist/commands/init.js +151 -18
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/login.js +1 -1
- package/dist/commands/login.js.map +1 -1
- package/dist/services/organizations.d.ts +40 -0
- package/dist/services/organizations.js +41 -0
- package/dist/services/organizations.js.map +1 -0
- package/dist/services/projects.d.ts +20 -0
- package/dist/services/projects.js +30 -1
- package/dist/services/projects.js.map +1 -1
- package/dist/services/user.d.ts +2 -0
- package/dist/services/user.js +11 -0
- package/dist/services/user.js.map +1 -0
- package/oclif.config.js +6 -1
- package/oclif.manifest.json +33 -184
- package/package.json +7 -7
- package/dist/actions/migration/getMigrationRootDirectory.d.ts +0 -2
- package/dist/actions/migration/getMigrationRootDirectory.js +0 -14
- package/dist/actions/migration/getMigrationRootDirectory.js.map +0 -1
- package/dist/actions/migration/resolveMigrations.d.ts +0 -19
- package/dist/actions/migration/resolveMigrations.js +0 -43
- package/dist/actions/migration/resolveMigrations.js.map +0 -1
- package/dist/actions/migration/templates/__tests__/minimalAdvanced.test.js +0 -65
- package/dist/actions/migration/templates/__tests__/minimalAdvanced.test.js.map +0 -1
- package/dist/actions/migration/templates/__tests__/minimalSimple.test.js +0 -145
- package/dist/actions/migration/templates/__tests__/minimalSimple.test.js.map +0 -1
- package/dist/actions/migration/templates/__tests__/renameField.test.js +0 -63
- package/dist/actions/migration/templates/__tests__/renameField.test.js.map +0 -1
- package/dist/actions/migration/templates/__tests__/renameType.test.js +0 -61
- package/dist/actions/migration/templates/__tests__/renameType.test.js.map +0 -1
- package/dist/actions/migration/templates/__tests__/stringToPTE.test.js +0 -87
- package/dist/actions/migration/templates/__tests__/stringToPTE.test.js.map +0 -1
- package/dist/actions/migration/templates/index.d.ts +0 -5
- package/dist/actions/migration/templates/index.js +0 -7
- package/dist/actions/migration/templates/index.js.map +0 -1
- package/dist/actions/migration/templates/minimalAdvanced.d.ts +0 -4
- package/dist/actions/migration/templates/minimalAdvanced.js +0 -21
- package/dist/actions/migration/templates/minimalAdvanced.js.map +0 -1
- package/dist/actions/migration/templates/minimalSimple.d.ts +0 -4
- package/dist/actions/migration/templates/minimalSimple.js +0 -61
- package/dist/actions/migration/templates/minimalSimple.js.map +0 -1
- package/dist/actions/migration/templates/renameField.d.ts +0 -4
- package/dist/actions/migration/templates/renameField.js +0 -20
- package/dist/actions/migration/templates/renameField.js.map +0 -1
- package/dist/actions/migration/templates/renameType.d.ts +0 -4
- package/dist/actions/migration/templates/renameType.js +0 -19
- package/dist/actions/migration/templates/renameType.js.map +0 -1
- package/dist/actions/migration/templates/stringToPTE.d.ts +0 -4
- package/dist/actions/migration/templates/stringToPTE.js +0 -32
- package/dist/actions/migration/templates/stringToPTE.js.map +0 -1
- package/dist/commands/__tests__/init.test.js +0 -411
- package/dist/commands/__tests__/init.test.js.map +0 -1
- package/dist/commands/migration/__tests__/create.test.js +0 -296
- package/dist/commands/migration/__tests__/create.test.js.map +0 -1
- package/dist/commands/migration/__tests__/list.test.js +0 -166
- package/dist/commands/migration/__tests__/list.test.js.map +0 -1
- package/dist/commands/migration/__tests__/run.test.js +0 -481
- package/dist/commands/migration/__tests__/run.test.js.map +0 -1
- package/dist/commands/migration/create.d.ts +0 -17
- package/dist/commands/migration/create.js +0 -143
- package/dist/commands/migration/create.js.map +0 -1
- package/dist/commands/migration/list.d.ts +0 -9
- package/dist/commands/migration/list.js +0 -61
- package/dist/commands/migration/list.js.map +0 -1
- package/dist/commands/migration/run.d.ts +0 -26
- package/dist/commands/migration/run.js +0 -271
- package/dist/commands/migration/run.js.map +0 -1
- package/dist/util/migration/constants.d.ts +0 -3
- package/dist/util/migration/constants.js +0 -10
- package/dist/util/migration/constants.js.map +0 -1
- package/dist/util/migration/ensureApiVersionFormat.d.ts +0 -9
- package/dist/util/migration/ensureApiVersionFormat.js +0 -16
- package/dist/util/migration/ensureApiVersionFormat.js.map +0 -1
- package/dist/util/migration/prettyMutationFormatter.d.ts +0 -8
- package/dist/util/migration/prettyMutationFormatter.js +0 -141
- package/dist/util/migration/prettyMutationFormatter.js.map +0 -1
- package/dist/utils/migration/resolveMigrationScript.d.ts +0 -44
- package/dist/utils/migration/resolveMigrationScript.js +0 -74
- package/dist/utils/migration/resolveMigrationScript.js.map +0 -1
- /package/dist/actions/auth/login/{index.d.ts → login.d.ts} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/util/migration/ensureApiVersionFormat.ts"],"sourcesContent":["import {type APIConfig} from '@sanity/migrate'\n\ntype ApiVersion = APIConfig['apiVersion']\n\nconst VERSION_PATTERN = /^v\\d+-\\d+-\\d+$|^vX$/ // Matches version strings like vYYYY-MM-DD or vX\n\n/**\n * Ensures that the provided API version string is in the correct format.\n * If the version does not start with 'v', it will be prefixed with 'v'.\n * If the version does not match the expected pattern, an error will be thrown.\n */\nexport function ensureApiVersionFormat(version: string): ApiVersion {\n const normalizedVersion = version.startsWith('v') ? version : `v${version}`\n\n // Check if the version matches the expected pattern\n if (!VERSION_PATTERN.test(normalizedVersion)) {\n throw new Error(\n `Invalid API version format: ${normalizedVersion}. Expected format: vYYYY-MM-DD or vX`,\n )\n }\n\n return normalizedVersion as ApiVersion\n}\n"],"names":["VERSION_PATTERN","ensureApiVersionFormat","version","normalizedVersion","startsWith","test","Error"],"mappings":"AAIA,MAAMA,kBAAkB,sBAAsB,iDAAiD;;AAE/F;;;;CAIC,GACD,OAAO,SAASC,uBAAuBC,OAAe;IACpD,MAAMC,oBAAoBD,QAAQE,UAAU,CAAC,OAAOF,UAAU,CAAC,CAAC,EAAEA,SAAS;IAE3E,oDAAoD;IACpD,IAAI,CAACF,gBAAgBK,IAAI,CAACF,oBAAoB;QAC5C,MAAM,IAAIG,MACR,CAAC,4BAA4B,EAAEH,kBAAkB,oCAAoC,CAAC;IAE1F;IAEA,OAAOA;AACT"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type Migration, type Mutation, type Transaction } from '@sanity/migrate';
|
|
2
|
-
interface FormatterOptions<Subject> {
|
|
3
|
-
migration: Migration;
|
|
4
|
-
subject: Subject;
|
|
5
|
-
indentSize?: number;
|
|
6
|
-
}
|
|
7
|
-
export declare function prettyFormat({ indentSize, migration, subject, }: FormatterOptions<(Mutation | Transaction)[] | Mutation | Transaction>): string;
|
|
8
|
-
export {};
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { isatty } from 'node:tty';
|
|
2
|
-
import { convertToTree, formatTree, maxKeyLength } from '@sanity/cli-core/tree';
|
|
3
|
-
import { chalk } from '@sanity/cli-core/ux';
|
|
4
|
-
const isTty = isatty(1);
|
|
5
|
-
export function prettyFormat({ indentSize = 0, migration, subject }) {
|
|
6
|
-
return (Array.isArray(subject) ? subject : [
|
|
7
|
-
subject
|
|
8
|
-
]).map((subjectEntry)=>{
|
|
9
|
-
if (subjectEntry.type === 'transaction') {
|
|
10
|
-
return [
|
|
11
|
-
[
|
|
12
|
-
badge('transaction', 'info'),
|
|
13
|
-
subjectEntry.id === undefined ? null : chalk.underline(subjectEntry.id)
|
|
14
|
-
].filter(Boolean).join(' '),
|
|
15
|
-
indent(prettyFormat({
|
|
16
|
-
indentSize: indentSize,
|
|
17
|
-
migration,
|
|
18
|
-
subject: subjectEntry.mutations
|
|
19
|
-
}))
|
|
20
|
-
].join('\n\n');
|
|
21
|
-
}
|
|
22
|
-
return prettyFormatMutation({
|
|
23
|
-
indentSize,
|
|
24
|
-
migration,
|
|
25
|
-
subject: subjectEntry
|
|
26
|
-
});
|
|
27
|
-
}).join('\n\n');
|
|
28
|
-
}
|
|
29
|
-
function encodeItemRef(ref) {
|
|
30
|
-
return typeof ref === 'number' ? ref : ref._key;
|
|
31
|
-
}
|
|
32
|
-
function badgeStyle(variant) {
|
|
33
|
-
const styles = {
|
|
34
|
-
destructive: chalk.bgRed.black.bold,
|
|
35
|
-
incremental: chalk.bgGreen.black.bold,
|
|
36
|
-
info: chalk.bgWhite.black,
|
|
37
|
-
maybeDestructive: chalk.bgYellow.black.bold
|
|
38
|
-
};
|
|
39
|
-
return styles[variant];
|
|
40
|
-
}
|
|
41
|
-
function badge(label, variant) {
|
|
42
|
-
if (!isTty) {
|
|
43
|
-
return `[${label}]`;
|
|
44
|
-
}
|
|
45
|
-
return badgeStyle(variant)(` ${label} `);
|
|
46
|
-
}
|
|
47
|
-
const mutationImpact = {
|
|
48
|
-
create: 'incremental',
|
|
49
|
-
createIfNotExists: 'incremental',
|
|
50
|
-
createOrReplace: 'maybeDestructive',
|
|
51
|
-
delete: 'destructive',
|
|
52
|
-
patch: 'maybeDestructive'
|
|
53
|
-
};
|
|
54
|
-
function documentId(mutation) {
|
|
55
|
-
if ('id' in mutation) {
|
|
56
|
-
return mutation.id;
|
|
57
|
-
}
|
|
58
|
-
if ('document' in mutation) {
|
|
59
|
-
return mutation.document._id;
|
|
60
|
-
}
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
const listFormatter = new Intl.ListFormat('en-US', {
|
|
64
|
-
type: 'disjunction'
|
|
65
|
-
});
|
|
66
|
-
function mutationHeader(mutation, migration) {
|
|
67
|
-
const mutationType = badge(mutation.type, mutationImpact[mutation.type]);
|
|
68
|
-
const documentType = 'document' in mutation || migration.documentTypes ? badge('document' in mutation ? mutation.document._type : listFormatter.format(migration.documentTypes ?? []), 'info') : null;
|
|
69
|
-
// TODO: Should we list documentType when a mutation can be yielded for any document type?
|
|
70
|
-
return [
|
|
71
|
-
mutationType,
|
|
72
|
-
documentType,
|
|
73
|
-
chalk.underline(documentId(mutation))
|
|
74
|
-
].filter(Boolean).join(' ');
|
|
75
|
-
}
|
|
76
|
-
function prettyFormatMutation({ indentSize = 0, migration, subject }) {
|
|
77
|
-
const lock = 'options' in subject ? chalk.cyan(`(if revision==${subject.options?.ifRevision})`) : '';
|
|
78
|
-
const header = [
|
|
79
|
-
mutationHeader(subject, migration),
|
|
80
|
-
lock
|
|
81
|
-
].join(' ');
|
|
82
|
-
const padding = ' '.repeat(indentSize);
|
|
83
|
-
if (subject.type === 'create' || subject.type === 'createIfNotExists' || subject.type === 'createOrReplace') {
|
|
84
|
-
return [
|
|
85
|
-
header,
|
|
86
|
-
'\n',
|
|
87
|
-
indent(JSON.stringify(subject.document, null, 2), indentSize)
|
|
88
|
-
].join('');
|
|
89
|
-
}
|
|
90
|
-
if (subject.type === 'patch') {
|
|
91
|
-
const tree = convertToTree(subject.patches.flat());
|
|
92
|
-
const paddingLength = Math.max(maxKeyLength(tree.children) + 2, 30);
|
|
93
|
-
return [
|
|
94
|
-
header,
|
|
95
|
-
'\n',
|
|
96
|
-
formatTree({
|
|
97
|
-
getMessage: (patch)=>formatPatchMutation(patch),
|
|
98
|
-
indent: padding,
|
|
99
|
-
node: tree.children,
|
|
100
|
-
paddingLength
|
|
101
|
-
})
|
|
102
|
-
].join('');
|
|
103
|
-
}
|
|
104
|
-
return header;
|
|
105
|
-
}
|
|
106
|
-
function formatPatchMutation(patch) {
|
|
107
|
-
const { op } = patch;
|
|
108
|
-
const formattedType = chalk.bold(op.type);
|
|
109
|
-
if (op.type === 'unset') {
|
|
110
|
-
return `${chalk.red(formattedType)}()`;
|
|
111
|
-
}
|
|
112
|
-
if (op.type === 'diffMatchPatch') {
|
|
113
|
-
return `${chalk.yellow(formattedType)}(${op.value})`;
|
|
114
|
-
}
|
|
115
|
-
if (op.type === 'inc' || op.type === 'dec') {
|
|
116
|
-
return `${chalk.yellow(formattedType)}(${op.amount})`;
|
|
117
|
-
}
|
|
118
|
-
if (op.type === 'set') {
|
|
119
|
-
return `${chalk.yellow(formattedType)}(${JSON.stringify(op.value)})`;
|
|
120
|
-
}
|
|
121
|
-
if (op.type === 'setIfMissing') {
|
|
122
|
-
return `${chalk.green(formattedType)}(${JSON.stringify(op.value)})`;
|
|
123
|
-
}
|
|
124
|
-
if (op.type === 'insert') {
|
|
125
|
-
return `${chalk.green(formattedType)}(${op.position}, ${encodeItemRef(op.referenceItem)}, ${JSON.stringify(op.items)})`;
|
|
126
|
-
}
|
|
127
|
-
if (op.type === 'replace') {
|
|
128
|
-
return `${chalk.yellow(formattedType)}(${encodeItemRef(op.referenceItem)}, ${JSON.stringify(op.items)})`;
|
|
129
|
-
}
|
|
130
|
-
if (op.type === 'truncate') {
|
|
131
|
-
return `${chalk.red(formattedType)}(${op.startIndex}, ${op.endIndex})`;
|
|
132
|
-
}
|
|
133
|
-
// @ts-expect-error all cases are covered
|
|
134
|
-
throw new Error(`Invalid operation type: ${op.type}`);
|
|
135
|
-
}
|
|
136
|
-
function indent(subject, size = 2) {
|
|
137
|
-
const padding = ' '.repeat(size);
|
|
138
|
-
return subject.split('\n').map((line)=>padding + line).join('\n');
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
//# sourceMappingURL=prettyMutationFormatter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/util/migration/prettyMutationFormatter.ts"],"sourcesContent":["import {isatty} from 'node:tty'\n\nimport {convertToTree, formatTree, maxKeyLength} from '@sanity/cli-core/tree'\nimport {chalk} from '@sanity/cli-core/ux'\nimport {type Migration, type Mutation, type NodePatch, type Transaction} from '@sanity/migrate'\nimport {type KeyedSegment} from '@sanity/types'\n\ntype ItemRef = number | string\ntype Impact = 'destructive' | 'incremental' | 'maybeDestructive'\ntype Variant = 'info' | Impact\n\nconst isTty = isatty(1)\n\ninterface FormatterOptions<Subject> {\n migration: Migration\n subject: Subject\n\n indentSize?: number\n}\n\nexport function prettyFormat({\n indentSize = 0,\n migration,\n subject,\n}: FormatterOptions<(Mutation | Transaction)[] | Mutation | Transaction>): string {\n return (Array.isArray(subject) ? subject : [subject])\n .map((subjectEntry) => {\n if (subjectEntry.type === 'transaction') {\n return [\n [\n badge('transaction', 'info'),\n subjectEntry.id === undefined ? null : chalk.underline(subjectEntry.id),\n ]\n .filter(Boolean)\n .join(' '),\n indent(\n prettyFormat({\n indentSize: indentSize,\n migration,\n subject: subjectEntry.mutations,\n }),\n ),\n ].join('\\n\\n')\n }\n return prettyFormatMutation({\n indentSize,\n migration,\n subject: subjectEntry,\n })\n })\n .join('\\n\\n')\n}\n\nfunction encodeItemRef(ref: KeyedSegment | number): ItemRef {\n return typeof ref === 'number' ? ref : ref._key\n}\n\nfunction badgeStyle(variant: Variant): typeof chalk {\n const styles: Record<Variant, typeof chalk> = {\n destructive: chalk.bgRed.black.bold,\n incremental: chalk.bgGreen.black.bold,\n info: chalk.bgWhite.black,\n maybeDestructive: chalk.bgYellow.black.bold,\n }\n\n return styles[variant]\n}\n\nfunction badge(label: string, variant: Variant): string {\n if (!isTty) {\n return `[${label}]`\n }\n\n return badgeStyle(variant)(` ${label} `)\n}\n\nconst mutationImpact: Record<Mutation['type'], Impact> = {\n create: 'incremental',\n createIfNotExists: 'incremental',\n createOrReplace: 'maybeDestructive',\n delete: 'destructive',\n patch: 'maybeDestructive',\n}\n\nfunction documentId(mutation: Mutation): string | undefined {\n if ('id' in mutation) {\n return mutation.id\n }\n\n if ('document' in mutation) {\n return mutation.document._id\n }\n\n return undefined\n}\n\nconst listFormatter = new Intl.ListFormat('en-US', {\n type: 'disjunction',\n})\n\nfunction mutationHeader(mutation: Mutation, migration: Migration): string {\n const mutationType = badge(mutation.type, mutationImpact[mutation.type])\n\n const documentType =\n 'document' in mutation || migration.documentTypes\n ? badge(\n 'document' in mutation\n ? mutation.document._type\n : listFormatter.format(migration.documentTypes ?? []),\n 'info',\n )\n : null\n\n // TODO: Should we list documentType when a mutation can be yielded for any document type?\n return [mutationType, documentType, chalk.underline(documentId(mutation))]\n .filter(Boolean)\n .join(' ')\n}\n\nfunction prettyFormatMutation({\n indentSize = 0,\n migration,\n subject,\n}: FormatterOptions<Mutation>): string {\n const lock =\n 'options' in subject ? chalk.cyan(`(if revision==${subject.options?.ifRevision})`) : ''\n const header = [mutationHeader(subject, migration), lock].join(' ')\n const padding = ' '.repeat(indentSize)\n\n if (\n subject.type === 'create' ||\n subject.type === 'createIfNotExists' ||\n subject.type === 'createOrReplace'\n ) {\n return [header, '\\n', indent(JSON.stringify(subject.document, null, 2), indentSize)].join('')\n }\n\n if (subject.type === 'patch') {\n const tree = convertToTree<NodePatch>(subject.patches.flat())\n const paddingLength = Math.max(maxKeyLength(tree.children) + 2, 30)\n\n return [\n header,\n '\\n',\n formatTree<NodePatch>({\n getMessage: (patch) => formatPatchMutation(patch),\n indent: padding,\n node: tree.children,\n paddingLength,\n }),\n ].join('')\n }\n\n return header\n}\n\nfunction formatPatchMutation(patch: NodePatch): string {\n const {op} = patch\n const formattedType = chalk.bold(op.type)\n if (op.type === 'unset') {\n return `${chalk.red(formattedType)}()`\n }\n if (op.type === 'diffMatchPatch') {\n return `${chalk.yellow(formattedType)}(${op.value})`\n }\n if (op.type === 'inc' || op.type === 'dec') {\n return `${chalk.yellow(formattedType)}(${op.amount})`\n }\n if (op.type === 'set') {\n return `${chalk.yellow(formattedType)}(${JSON.stringify(op.value)})`\n }\n if (op.type === 'setIfMissing') {\n return `${chalk.green(formattedType)}(${JSON.stringify(op.value)})`\n }\n if (op.type === 'insert') {\n return `${chalk.green(formattedType)}(${op.position}, ${encodeItemRef(\n op.referenceItem,\n )}, ${JSON.stringify(op.items)})`\n }\n if (op.type === 'replace') {\n return `${chalk.yellow(formattedType)}(${encodeItemRef(op.referenceItem)}, ${JSON.stringify(\n op.items,\n )})`\n }\n if (op.type === 'truncate') {\n return `${chalk.red(formattedType)}(${op.startIndex}, ${op.endIndex})`\n }\n // @ts-expect-error all cases are covered\n throw new Error(`Invalid operation type: ${op.type}`)\n}\n\nfunction indent(subject: string, size = 2): string {\n const padding = ' '.repeat(size)\n\n return subject\n .split('\\n')\n .map((line) => padding + line)\n .join('\\n')\n}\n"],"names":["isatty","convertToTree","formatTree","maxKeyLength","chalk","isTty","prettyFormat","indentSize","migration","subject","Array","isArray","map","subjectEntry","type","badge","id","undefined","underline","filter","Boolean","join","indent","mutations","prettyFormatMutation","encodeItemRef","ref","_key","badgeStyle","variant","styles","destructive","bgRed","black","bold","incremental","bgGreen","info","bgWhite","maybeDestructive","bgYellow","label","mutationImpact","create","createIfNotExists","createOrReplace","delete","patch","documentId","mutation","document","_id","listFormatter","Intl","ListFormat","mutationHeader","mutationType","documentType","documentTypes","_type","format","lock","cyan","options","ifRevision","header","padding","repeat","JSON","stringify","tree","patches","flat","paddingLength","Math","max","children","getMessage","formatPatchMutation","node","op","formattedType","red","yellow","value","amount","green","position","referenceItem","items","startIndex","endIndex","Error","size","split","line"],"mappings":"AAAA,SAAQA,MAAM,QAAO,WAAU;AAE/B,SAAQC,aAAa,EAAEC,UAAU,EAAEC,YAAY,QAAO,wBAAuB;AAC7E,SAAQC,KAAK,QAAO,sBAAqB;AAQzC,MAAMC,QAAQL,OAAO;AASrB,OAAO,SAASM,aAAa,EAC3BC,aAAa,CAAC,EACdC,SAAS,EACTC,OAAO,EAC+D;IACtE,OAAO,AAACC,CAAAA,MAAMC,OAAO,CAACF,WAAWA,UAAU;QAACA;KAAQ,AAAD,EAChDG,GAAG,CAAC,CAACC;QACJ,IAAIA,aAAaC,IAAI,KAAK,eAAe;YACvC,OAAO;gBACL;oBACEC,MAAM,eAAe;oBACrBF,aAAaG,EAAE,KAAKC,YAAY,OAAOb,MAAMc,SAAS,CAACL,aAAaG,EAAE;iBACvE,CACEG,MAAM,CAACC,SACPC,IAAI,CAAC;gBACRC,OACEhB,aAAa;oBACXC,YAAYA;oBACZC;oBACAC,SAASI,aAAaU,SAAS;gBACjC;aAEH,CAACF,IAAI,CAAC;QACT;QACA,OAAOG,qBAAqB;YAC1BjB;YACAC;YACAC,SAASI;QACX;IACF,GACCQ,IAAI,CAAC;AACV;AAEA,SAASI,cAAcC,GAA0B;IAC/C,OAAO,OAAOA,QAAQ,WAAWA,MAAMA,IAAIC,IAAI;AACjD;AAEA,SAASC,WAAWC,OAAgB;IAClC,MAAMC,SAAwC;QAC5CC,aAAa3B,MAAM4B,KAAK,CAACC,KAAK,CAACC,IAAI;QACnCC,aAAa/B,MAAMgC,OAAO,CAACH,KAAK,CAACC,IAAI;QACrC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ACmF,OAAS7B,UAAU6B,MACxB1E,IAAI,CAAC;AACV"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { type Migration } from '@sanity/migrate';
|
|
2
|
-
interface ResolvedMigrationScript {
|
|
3
|
-
/**
|
|
4
|
-
* Absolute path to the migration script
|
|
5
|
-
*/
|
|
6
|
-
absolutePath: string;
|
|
7
|
-
/**
|
|
8
|
-
* Relative path from the working directory to the migration script
|
|
9
|
-
*/
|
|
10
|
-
relativePath: string;
|
|
11
|
-
/**
|
|
12
|
-
* The migration module, if it could be resolved - otherwise `undefined`
|
|
13
|
-
*/
|
|
14
|
-
mod?: {
|
|
15
|
-
default: Migration;
|
|
16
|
-
down?: unknown;
|
|
17
|
-
up?: unknown;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Resolves the potential paths to a migration script.
|
|
22
|
-
* Considers the following paths (where `<ext>` is 'mjs', 'js', 'ts' or 'cjs'):
|
|
23
|
-
*
|
|
24
|
-
* - `<migrationsDir>/<migrationName>.<ext>`
|
|
25
|
-
* - `<migrationsDir>/<migrationName>/index.<ext>`
|
|
26
|
-
*
|
|
27
|
-
* Note that all possible paths are returned, even if the files do not exist.
|
|
28
|
-
* Check the `mod` property to see if a module could actually be loaded.
|
|
29
|
-
*
|
|
30
|
-
* @param workDir - Working directory of the studio
|
|
31
|
-
* @param migrationName - The name of the migration directory to resolve
|
|
32
|
-
* @returns An array of potential migration scripts
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
|
-
export declare function resolveMigrationScript(workDir: string, migrationName: string): Promise<ResolvedMigrationScript[]>;
|
|
36
|
-
/**
|
|
37
|
-
* Checks whether or not the passed resolved migration script is actually loadable (eg has a default export)
|
|
38
|
-
*
|
|
39
|
-
* @param script - The resolved migration script to check
|
|
40
|
-
* @returns `true` if the script is loadable, `false` otherwise
|
|
41
|
-
* @internal
|
|
42
|
-
*/
|
|
43
|
-
export declare function isLoadableMigrationScript(script: ResolvedMigrationScript): script is Required<ResolvedMigrationScript>;
|
|
44
|
-
export {};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { fileExists } from '@sanity/cli-core';
|
|
3
|
-
import { getTsconfig } from 'get-tsconfig';
|
|
4
|
-
import { isPlainObject } from 'lodash-es';
|
|
5
|
-
import { tsImport } from 'tsx/esm/api';
|
|
6
|
-
import { MIGRATION_SCRIPT_EXTENSIONS, MIGRATIONS_DIRECTORY } from '../../util/migration/constants.js';
|
|
7
|
-
/**
|
|
8
|
-
* Resolves the potential paths to a migration script.
|
|
9
|
-
* Considers the following paths (where `<ext>` is 'mjs', 'js', 'ts' or 'cjs'):
|
|
10
|
-
*
|
|
11
|
-
* - `<migrationsDir>/<migrationName>.<ext>`
|
|
12
|
-
* - `<migrationsDir>/<migrationName>/index.<ext>`
|
|
13
|
-
*
|
|
14
|
-
* Note that all possible paths are returned, even if the files do not exist.
|
|
15
|
-
* Check the `mod` property to see if a module could actually be loaded.
|
|
16
|
-
*
|
|
17
|
-
* @param workDir - Working directory of the studio
|
|
18
|
-
* @param migrationName - The name of the migration directory to resolve
|
|
19
|
-
* @returns An array of potential migration scripts
|
|
20
|
-
* @internal
|
|
21
|
-
*/ export async function resolveMigrationScript(workDir, migrationName) {
|
|
22
|
-
const tsconfig = getTsconfig(workDir);
|
|
23
|
-
const locations = [
|
|
24
|
-
migrationName,
|
|
25
|
-
path.join(migrationName, 'index')
|
|
26
|
-
];
|
|
27
|
-
const results = [];
|
|
28
|
-
for (const location of locations){
|
|
29
|
-
for (const ext of MIGRATION_SCRIPT_EXTENSIONS){
|
|
30
|
-
const relativePath = path.join(MIGRATIONS_DIRECTORY, `${location}.${ext}`);
|
|
31
|
-
const absolutePath = path.resolve(workDir, relativePath);
|
|
32
|
-
let mod;
|
|
33
|
-
// Check if the file exists before trying to import it
|
|
34
|
-
const exists = await fileExists(absolutePath);
|
|
35
|
-
if (!exists) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
const imported = await tsImport(absolutePath, {
|
|
40
|
-
parentURL: import.meta.url,
|
|
41
|
-
tsconfig: tsconfig?.path
|
|
42
|
-
});
|
|
43
|
-
// Handle both ESM and CJS default exports
|
|
44
|
-
mod = imported;
|
|
45
|
-
} catch (err) {
|
|
46
|
-
// Ignore MODULE_NOT_FOUND errors, but throw others
|
|
47
|
-
if (err.code !== 'MODULE_NOT_FOUND' && err.code !== 'ERR_MODULE_NOT_FOUND') {
|
|
48
|
-
throw new Error(`Error loading migration: ${err.message}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
results.push({
|
|
52
|
-
absolutePath,
|
|
53
|
-
mod,
|
|
54
|
-
relativePath
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return results;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Checks whether or not the passed resolved migration script is actually loadable (eg has a default export)
|
|
62
|
-
*
|
|
63
|
-
* @param script - The resolved migration script to check
|
|
64
|
-
* @returns `true` if the script is loadable, `false` otherwise
|
|
65
|
-
* @internal
|
|
66
|
-
*/ export function isLoadableMigrationScript(script) {
|
|
67
|
-
if (script.mod === undefined || !isPlainObject(script.mod.default)) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
const mod = script.mod.default;
|
|
71
|
-
return typeof mod.title === 'string' && mod.migrate !== undefined;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
//# sourceMappingURL=resolveMigrationScript.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/migration/resolveMigrationScript.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {fileExists} from '@sanity/cli-core'\nimport {type Migration} from '@sanity/migrate'\nimport {getTsconfig} from 'get-tsconfig'\nimport {isPlainObject} from 'lodash-es'\nimport {tsImport} from 'tsx/esm/api'\n\nimport {MIGRATION_SCRIPT_EXTENSIONS, MIGRATIONS_DIRECTORY} from '../../util/migration/constants.js'\n\ninterface ResolvedMigrationScript {\n /**\n * Absolute path to the migration script\n */\n absolutePath: string\n\n /**\n * Relative path from the working directory to the migration script\n */\n relativePath: string\n\n /**\n * The migration module, if it could be resolved - otherwise `undefined`\n */\n mod?: {default: Migration; down?: unknown; up?: unknown}\n}\n\n/**\n * Resolves the potential paths to a migration script.\n * Considers the following paths (where `<ext>` is 'mjs', 'js', 'ts' or 'cjs'):\n *\n * - `<migrationsDir>/<migrationName>.<ext>`\n * - `<migrationsDir>/<migrationName>/index.<ext>`\n *\n * Note that all possible paths are returned, even if the files do not exist.\n * Check the `mod` property to see if a module could actually be loaded.\n *\n * @param workDir - Working directory of the studio\n * @param migrationName - The name of the migration directory to resolve\n * @returns An array of potential migration scripts\n * @internal\n */\nexport async function resolveMigrationScript(\n workDir: string,\n migrationName: string,\n): Promise<ResolvedMigrationScript[]> {\n const tsconfig = getTsconfig(workDir)\n const locations = [migrationName, path.join(migrationName, 'index')]\n const results: ResolvedMigrationScript[] = []\n\n for (const location of locations) {\n for (const ext of MIGRATION_SCRIPT_EXTENSIONS) {\n const relativePath = path.join(MIGRATIONS_DIRECTORY, `${location}.${ext}`)\n const absolutePath = path.resolve(workDir, relativePath)\n let mod: {default: Migration; down?: unknown; up?: unknown} | undefined\n\n // Check if the file exists before trying to import it\n const exists = await fileExists(absolutePath)\n if (!exists) {\n continue\n }\n\n try {\n const imported = await tsImport(absolutePath, {\n parentURL: import.meta.url,\n tsconfig: tsconfig?.path,\n })\n // Handle both ESM and CJS default exports\n mod = imported as {default: Migration; down?: unknown; up?: unknown}\n } catch (err) {\n // Ignore MODULE_NOT_FOUND errors, but throw others\n if (\n (err as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND' &&\n (err as NodeJS.ErrnoException).code !== 'ERR_MODULE_NOT_FOUND'\n ) {\n throw new Error(`Error loading migration: ${(err as Error).message}`)\n }\n }\n\n results.push({absolutePath, mod, relativePath})\n }\n }\n\n return results\n}\n\n/**\n * Checks whether or not the passed resolved migration script is actually loadable (eg has a default export)\n *\n * @param script - The resolved migration script to check\n * @returns `true` if the script is loadable, `false` otherwise\n * @internal\n */\nexport function isLoadableMigrationScript(\n script: ResolvedMigrationScript,\n): script is Required<ResolvedMigrationScript> {\n if (script.mod === undefined || !isPlainObject(script.mod.default)) {\n return false\n }\n\n const mod = script.mod.default\n return typeof mod.title === 'string' && mod.migrate !== undefined\n}\n"],"names":["path","fileExists","getTsconfig","isPlainObject","tsImport","MIGRATION_SCRIPT_EXTENSIONS","MIGRATIONS_DIRECTORY","resolveMigrationScript","workDir","migrationName","tsconfig","locations","join","results","location","ext","relativePath","absolutePath","resolve","mod","exists","imported","parentURL","url","err","code","Error","message","push","isLoadableMigrationScript","script","undefined","default","title","migrate"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAQC,UAAU,QAAO,mBAAkB;AAE3C,SAAQC,WAAW,QAAO,eAAc;AACxC,SAAQC,aAAa,QAAO,YAAW;AACvC,SAAQC,QAAQ,QAAO,cAAa;AAEpC,SAAQC,2BAA2B,EAAEC,oBAAoB,QAAO,oCAAmC;AAmBnG;;;;;;;;;;;;;;CAcC,GACD,OAAO,eAAeC,uBACpBC,OAAe,EACfC,aAAqB;IAErB,MAAMC,WAAWR,YAAYM;IAC7B,MAAMG,YAAY;QAACF;QAAeT,KAAKY,IAAI,CAACH,eAAe;KAAS;IACpE,MAAMI,UAAqC,EAAE;IAE7C,KAAK,MAAMC,YAAYH,UAAW;QAChC,KAAK,MAAMI,OAAOV,4BAA6B;YAC7C,MAAMW,eAAehB,KAAKY,IAAI,CAACN,sBAAsB,GAAGQ,SAAS,CAAC,EAAEC,KAAK;YACzE,MAAME,eAAejB,KAAKkB,OAAO,CAACV,SAASQ;YAC3C,IAAIG;YAEJ,sDAAsD;YACtD,MAAMC,SAAS,MAAMnB,WAAWgB;YAChC,IAAI,CAACG,QAAQ;gBACX;YACF;YAEA,IAAI;gBACF,M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