@sanity/cli 7.10.0 → 7.11.0
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/README.md +31 -22
- package/dist/actions/auth/ensureAuthenticated.js +2 -0
- package/dist/actions/auth/ensureAuthenticated.js.map +1 -1
- package/dist/actions/auth/login/loginInstructions.js +19 -0
- package/dist/actions/auth/login/loginInstructions.js.map +1 -0
- package/dist/actions/dataset/resolveDataset.js +7 -1
- package/dist/actions/dataset/resolveDataset.js.map +1 -1
- package/dist/actions/deploy/deployApp.js +17 -12
- package/dist/actions/deploy/deployApp.js.map +1 -1
- package/dist/actions/deploy/deployStudio.js +2 -0
- package/dist/actions/deploy/deployStudio.js.map +1 -1
- package/dist/actions/graphql/resolveApiGeneration.js +9 -6
- package/dist/actions/graphql/resolveApiGeneration.js.map +1 -1
- package/dist/actions/init/initAction.js +23 -15
- package/dist/actions/init/initAction.js.map +1 -1
- package/dist/actions/manifest/extractCoreAppManifest.js +5 -3
- package/dist/actions/manifest/extractCoreAppManifest.js.map +1 -1
- package/dist/actions/migration/constants.js +10 -0
- package/dist/actions/migration/constants.js.map +1 -0
- package/dist/actions/migration/ensureApiVersionFormat.js +16 -0
- package/dist/actions/migration/ensureApiVersionFormat.js.map +1 -0
- package/dist/actions/migration/fileExists.js +13 -0
- package/dist/actions/migration/fileExists.js.map +1 -0
- package/dist/actions/migration/prettyMutationFormatter.js +155 -0
- package/dist/actions/migration/prettyMutationFormatter.js.map +1 -0
- package/dist/actions/migration/resolveMigrationScript.js +75 -0
- package/dist/actions/migration/resolveMigrationScript.js.map +1 -0
- package/dist/actions/migration/resolveMigrations.js +50 -0
- package/dist/actions/migration/resolveMigrations.js.map +1 -0
- package/dist/actions/migration/templates/index.js +7 -0
- package/dist/actions/migration/templates/index.js.map +1 -0
- package/dist/actions/migration/templates/minimalAdvanced.js +21 -0
- package/dist/actions/migration/templates/minimalAdvanced.js.map +1 -0
- package/dist/actions/migration/templates/minimalSimple.js +61 -0
- package/dist/actions/migration/templates/minimalSimple.js.map +1 -0
- package/dist/actions/migration/templates/renameField.js +20 -0
- package/dist/actions/migration/templates/renameField.js.map +1 -0
- package/dist/actions/migration/templates/renameType.js +19 -0
- package/dist/actions/migration/templates/renameType.js.map +1 -0
- package/dist/actions/migration/templates/stringToPTE.js +32 -0
- package/dist/actions/migration/templates/stringToPTE.js.map +1 -0
- package/dist/actions/migration/tree.js +111 -0
- package/dist/actions/migration/tree.js.map +1 -0
- package/dist/actions/preview/previewAction.js +33 -1
- package/dist/actions/preview/previewAction.js.map +1 -1
- package/dist/actions/schema/listSchemas.js +6 -4
- package/dist/actions/schema/listSchemas.js.map +1 -1
- package/dist/actions/tokens/validateRole.js +2 -1
- package/dist/actions/tokens/validateRole.js.map +1 -1
- package/dist/actions/undeploy/runUndeploy.js +13 -4
- package/dist/actions/undeploy/runUndeploy.js.map +1 -1
- package/dist/commands/backups/disable.js +5 -1
- package/dist/commands/backups/disable.js.map +1 -1
- package/dist/commands/backups/download.js +30 -6
- package/dist/commands/backups/download.js.map +1 -1
- package/dist/commands/backups/enable.js +5 -1
- package/dist/commands/backups/enable.js.map +1 -1
- package/dist/commands/backups/list.js +5 -1
- package/dist/commands/backups/list.js.map +1 -1
- package/dist/commands/cors/add.js +15 -7
- package/dist/commands/cors/add.js.map +1 -1
- package/dist/commands/cors/delete.js +6 -1
- package/dist/commands/cors/delete.js.map +1 -1
- package/dist/commands/datasets/alias/create.js +25 -18
- package/dist/commands/datasets/alias/create.js.map +1 -1
- package/dist/commands/datasets/alias/delete.js +15 -8
- package/dist/commands/datasets/alias/delete.js.map +1 -1
- package/dist/commands/datasets/alias/link.js +39 -17
- package/dist/commands/datasets/alias/link.js.map +1 -1
- package/dist/commands/datasets/alias/unlink.js +23 -2
- package/dist/commands/datasets/alias/unlink.js.map +1 -1
- package/dist/commands/datasets/copy.js +18 -2
- package/dist/commands/datasets/copy.js.map +1 -1
- package/dist/commands/datasets/create.js +8 -2
- package/dist/commands/datasets/create.js.map +1 -1
- package/dist/commands/datasets/delete.js +14 -17
- package/dist/commands/datasets/delete.js.map +1 -1
- package/dist/commands/datasets/embeddings/disable.js +3 -0
- package/dist/commands/datasets/embeddings/disable.js.map +1 -1
- package/dist/commands/datasets/embeddings/enable.js +5 -2
- package/dist/commands/datasets/embeddings/enable.js.map +1 -1
- package/dist/commands/datasets/embeddings/status.js +3 -0
- package/dist/commands/datasets/embeddings/status.js.map +1 -1
- package/dist/commands/datasets/export.js +27 -15
- package/dist/commands/datasets/export.js.map +1 -1
- package/dist/commands/datasets/import.js +3 -3
- package/dist/commands/datasets/import.js.map +1 -1
- package/dist/commands/datasets/visibility/get.js +2 -2
- package/dist/commands/datasets/visibility/get.js.map +1 -1
- package/dist/commands/datasets/visibility/set.js +2 -2
- package/dist/commands/datasets/visibility/set.js.map +1 -1
- package/dist/commands/docs/read.js +3 -3
- package/dist/commands/docs/read.js.map +1 -1
- package/dist/commands/documents/create.js +18 -13
- package/dist/commands/documents/create.js.map +1 -1
- package/dist/commands/documents/delete.js +3 -3
- package/dist/commands/documents/delete.js.map +1 -1
- package/dist/commands/documents/get.js +3 -3
- package/dist/commands/documents/get.js.map +1 -1
- package/dist/commands/documents/query.js +3 -3
- package/dist/commands/documents/query.js.map +1 -1
- package/dist/commands/documents/validate.js +29 -26
- package/dist/commands/documents/validate.js.map +1 -1
- package/dist/commands/graphql/deploy.js +20 -16
- package/dist/commands/graphql/deploy.js.map +1 -1
- package/dist/commands/graphql/undeploy.js +15 -18
- package/dist/commands/graphql/undeploy.js.map +1 -1
- package/dist/commands/hooks/delete.js +2 -2
- package/dist/commands/hooks/delete.js.map +1 -1
- package/dist/commands/hooks/logs.js +2 -2
- package/dist/commands/hooks/logs.js.map +1 -1
- package/dist/commands/login.js +2 -1
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/media/create-aspect.js +20 -8
- package/dist/commands/media/create-aspect.js.map +1 -1
- package/dist/commands/media/delete-aspect.js +31 -16
- package/dist/commands/media/delete-aspect.js.map +1 -1
- package/dist/commands/media/deploy-aspect.js +10 -5
- package/dist/commands/media/deploy-aspect.js.map +1 -1
- package/dist/commands/media/export.js +9 -4
- package/dist/commands/media/export.js.map +1 -1
- package/dist/commands/media/import.js +6 -1
- package/dist/commands/media/import.js.map +1 -1
- package/dist/commands/migrations/create.js +150 -0
- package/dist/commands/migrations/create.js.map +1 -0
- package/dist/commands/migrations/list.js +64 -0
- package/dist/commands/migrations/list.js.map +1 -0
- package/dist/commands/migrations/run.js +306 -0
- package/dist/commands/migrations/run.js.map +1 -0
- package/dist/commands/preview.js +1 -0
- package/dist/commands/preview.js.map +1 -1
- package/dist/commands/projects/create.js +2 -1
- package/dist/commands/projects/create.js.map +1 -1
- package/dist/commands/schemas/delete.js +23 -2
- package/dist/commands/schemas/delete.js.map +1 -1
- package/dist/commands/schemas/deploy.js +6 -4
- package/dist/commands/schemas/deploy.js.map +1 -1
- package/dist/commands/schemas/extract.js +22 -1
- package/dist/commands/schemas/extract.js.map +1 -1
- package/dist/commands/schemas/list.js +8 -8
- package/dist/commands/schemas/list.js.map +1 -1
- package/dist/commands/tokens/{add.js → create.js} +25 -18
- package/dist/commands/tokens/create.js.map +1 -0
- package/dist/commands/tokens/delete.js +41 -23
- package/dist/commands/tokens/delete.js.map +1 -1
- package/dist/commands/undeploy.js +2 -7
- package/dist/commands/undeploy.js.map +1 -1
- package/dist/commands/users/invite.js +25 -3
- package/dist/commands/users/invite.js.map +1 -1
- package/dist/topicAliases.js +3 -0
- package/dist/topicAliases.js.map +1 -1
- package/dist/util/formatCliErrorMessages.js +5 -0
- package/dist/util/formatCliErrorMessages.js.map +1 -0
- package/oclif.config.js +5 -1
- package/oclif.manifest.json +326 -121
- package/package.json +7 -7
- package/dist/commands/tokens/add.js.map +0 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { importModule, subdebug } from '@sanity/cli-core';
|
|
3
|
+
import { MIGRATION_SCRIPT_EXTENSIONS, MIGRATIONS_DIRECTORY } from './constants.js';
|
|
4
|
+
import { fileExists } from './fileExists.js';
|
|
5
|
+
const debug = subdebug('migration:resolveMigrationScript');
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the potential paths to a migration script.
|
|
8
|
+
* Considers the following paths (where `<ext>` is 'mjs', 'js', 'ts' or 'cjs'):
|
|
9
|
+
*
|
|
10
|
+
* - `<migrationsDir>/<migrationName>.<ext>`
|
|
11
|
+
* - `<migrationsDir>/<migrationName>/index.<ext>`
|
|
12
|
+
*
|
|
13
|
+
* Note that all possible paths are returned, even if the files do not exist.
|
|
14
|
+
* Check the `mod` property to see if a module could actually be loaded.
|
|
15
|
+
*
|
|
16
|
+
* @param workDir - Working directory of the studio
|
|
17
|
+
* @param migrationName - The name of the migration directory to resolve
|
|
18
|
+
* @returns An array of potential migration scripts
|
|
19
|
+
* @internal
|
|
20
|
+
*/ export async function resolveMigrationScript(workDir, migrationName) {
|
|
21
|
+
const locations = [
|
|
22
|
+
migrationName,
|
|
23
|
+
path.join(migrationName, 'index')
|
|
24
|
+
];
|
|
25
|
+
const results = [];
|
|
26
|
+
for (const location of locations){
|
|
27
|
+
for (const ext of MIGRATION_SCRIPT_EXTENSIONS){
|
|
28
|
+
const relativePath = path.join(MIGRATIONS_DIRECTORY, `${location}.${ext}`);
|
|
29
|
+
const absolutePath = path.resolve(workDir, relativePath);
|
|
30
|
+
let mod;
|
|
31
|
+
// Check if the file exists before trying to import it
|
|
32
|
+
const exists = await fileExists(absolutePath);
|
|
33
|
+
if (!exists) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
debug(`importing migration from ${absolutePath}`);
|
|
38
|
+
const imported = await importModule(absolutePath, {
|
|
39
|
+
default: false
|
|
40
|
+
});
|
|
41
|
+
// Handle both ESM and CJS default exports
|
|
42
|
+
mod = imported;
|
|
43
|
+
} catch (err) {
|
|
44
|
+
debug(`error importing migration from ${absolutePath}`, err);
|
|
45
|
+
// Ignore MODULE_NOT_FOUND errors, but throw others
|
|
46
|
+
if (err.code !== 'MODULE_NOT_FOUND' && err.code !== 'ERR_MODULE_NOT_FOUND') {
|
|
47
|
+
throw new Error(`Error loading migration: ${err.message}`, {
|
|
48
|
+
cause: err
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
results.push({
|
|
53
|
+
absolutePath,
|
|
54
|
+
mod,
|
|
55
|
+
relativePath
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return results;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Checks whether or not the passed resolved migration script is actually loadable (eg has a default export)
|
|
63
|
+
*
|
|
64
|
+
* @param script - The resolved migration script to check
|
|
65
|
+
* @returns `true` if the script is loadable, `false` otherwise
|
|
66
|
+
* @internal
|
|
67
|
+
*/ export function isLoadableMigrationScript(script) {
|
|
68
|
+
if (script.mod === undefined || typeof script.mod.default !== 'object' || script.mod.default === null || Array.isArray(script.mod.default)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
const mod = script.mod.default;
|
|
72
|
+
return typeof mod.title === 'string' && mod.migrate !== undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=resolveMigrationScript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/migration/resolveMigrationScript.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {importModule, subdebug} from '@sanity/cli-core'\nimport {type Migration} from '@sanity/migrate'\n\nimport {MIGRATION_SCRIPT_EXTENSIONS, MIGRATIONS_DIRECTORY} from './constants.js'\nimport {fileExists} from './fileExists.js'\n\ninterface ResolvedMigrationScript {\n /**\n * Absolute path to the migration script\n */\n absolutePath: string\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\nconst debug = subdebug('migration:resolveMigrationScript')\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 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 debug(`importing migration from ${absolutePath}`)\n const imported = await importModule<{default: Migration; down?: unknown; up?: unknown}>(\n absolutePath,\n {\n default: false,\n },\n )\n // Handle both ESM and CJS default exports\n mod = imported\n } catch (err) {\n debug(`error importing migration from ${absolutePath}`, 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}`, {cause: err})\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 (\n script.mod === undefined ||\n typeof script.mod.default !== 'object' ||\n script.mod.default === null ||\n Array.isArray(script.mod.default)\n ) {\n return false\n }\n\n const mod = script.mod.default\n return typeof mod.title === 'string' && mod.migrate !== undefined\n}\n"],"names":["path","importModule","subdebug","MIGRATION_SCRIPT_EXTENSIONS","MIGRATIONS_DIRECTORY","fileExists","debug","resolveMigrationScript","workDir","migrationName","locations","join","results","location","ext","relativePath","absolutePath","resolve","mod","exists","imported","default","err","code","Error","message","cause","push","isLoadableMigrationScript","script","undefined","Array","isArray","title","migrate"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAQC,YAAY,EAAEC,QAAQ,QAAO,mBAAkB;AAGvD,SAAQC,2BAA2B,EAAEC,oBAAoB,QAAO,iBAAgB;AAChF,SAAQC,UAAU,QAAO,kBAAiB;AAkB1C,MAAMC,QAAQJ,SAAS;AAEvB;;;;;;;;;;;;;;CAcC,GACD,OAAO,eAAeK,uBACpBC,OAAe,EACfC,aAAqB;IAErB,MAAMC,YAAY;QAACD;QAAeT,KAAKW,IAAI,CAACF,eAAe;KAAS;IACpE,MAAMG,UAAqC,EAAE;IAE7C,KAAK,MAAMC,YAAYH,UAAW;QAChC,KAAK,MAAMI,OAAOX,4BAA6B;YAC7C,MAAMY,eAAef,KAAKW,IAAI,CAACP,sBAAsB,GAAGS,SAAS,CAAC,EAAEC,KAAK;YACzE,MAAME,eAAehB,KAAKiB,OAAO,CAACT,SAASO;YAC3C,IAAIG;YAEJ,sDAAsD;YACtD,MAAMC,SAAS,MAAMd,WAAWW;YAChC,IAAI,CAACG,QAAQ;gBACX;YACF;YAEA,IAAI;gBACFb,MAAM,CAAC,yBAAyB,EAAEU,cAAc;gBAChD,MAAMI,WAAW,MAAMnB,aACrBe,cACA;oBACEK,SAAS;gBACX;gBAEF,0CAA0C;gBAC1CH,MAAME;YACR,EAAE,OAAOE,KAAK;gBACZhB,MAAM,CAAC,+BAA+B,EAAEU,cAAc,EAAEM;gBACxD,mDAAmD;gBACnD,IACE,AAACA,IAA8BC,IAAI,KAAK,sBACxC,AAACD,IAA8BC,IAAI,KAAK,wBACxC;oBACA,MAAM,IAAIC,MAAM,CAAC,yBAAyB,EAAE,AAACF,IAAcG,OAAO,EAAE,EAAE;wBAACC,OAAOJ;oBAAG;gBACnF;YACF;YAEAV,QAAQe,IAAI,CAAC;gBAACX;gBAAcE;gBAAKH;YAAY;QAC/C;IACF;IAEA,OAAOH;AACT;AAEA;;;;;;CAMC,GACD,OAAO,SAASgB,0BACdC,MAA+B;IAE/B,IACEA,OAAOX,GAAG,KAAKY,aACf,OAAOD,OAAOX,GAAG,CAACG,OAAO,KAAK,YAC9BQ,OAAOX,GAAG,CAACG,OAAO,KAAK,QACvBU,MAAMC,OAAO,CAACH,OAAOX,GAAG,CAACG,OAAO,GAChC;QACA,OAAO;IACT;IAEA,MAAMH,MAAMW,OAAOX,GAAG,CAACG,OAAO;IAC9B,OAAO,OAAOH,IAAIe,KAAK,KAAK,YAAYf,IAAIgB,OAAO,KAAKJ;AAC1D"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { readdir } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { MIGRATION_SCRIPT_EXTENSIONS, MIGRATIONS_DIRECTORY } from './constants.js';
|
|
4
|
+
import { isLoadableMigrationScript, resolveMigrationScript } from './resolveMigrationScript.js';
|
|
5
|
+
/**
|
|
6
|
+
* Removes migration script extensions from a filename
|
|
7
|
+
*
|
|
8
|
+
* @param fileName - The filename to process
|
|
9
|
+
* @returns The filename without the extension
|
|
10
|
+
* @internal
|
|
11
|
+
*/ function removeMigrationScriptExtension(fileName) {
|
|
12
|
+
// Remove `.ts`, `.js` etc from the end of a filename
|
|
13
|
+
const ext = MIGRATION_SCRIPT_EXTENSIONS.find((e)=>fileName.endsWith(`.${e}`));
|
|
14
|
+
return ext ? path.basename(fileName, `.${ext}`) : fileName;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolves all migrations in the studio working directory
|
|
18
|
+
*
|
|
19
|
+
* @param workDir - The studio working directory
|
|
20
|
+
* @returns Array of migrations and their respective paths
|
|
21
|
+
* @internal
|
|
22
|
+
*/ export async function resolveMigrations(workDir) {
|
|
23
|
+
const migrationsDir = path.join(workDir, MIGRATIONS_DIRECTORY);
|
|
24
|
+
const migrationEntries = await readdir(migrationsDir, {
|
|
25
|
+
withFileTypes: true
|
|
26
|
+
});
|
|
27
|
+
const migrations = [];
|
|
28
|
+
const seen = new Set();
|
|
29
|
+
for (const entry of migrationEntries){
|
|
30
|
+
const entryName = entry.isDirectory() ? entry.name : removeMigrationScriptExtension(entry.name);
|
|
31
|
+
// A file (e.g. `foo.ts`) and a directory (e.g. `foo/`) can both map to the
|
|
32
|
+
// same id; only resolve each id once.
|
|
33
|
+
if (seen.has(entryName)) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
// `resolveMigrationScript` may return several loadable candidates for a
|
|
37
|
+
// single id (e.g. both `foo.ts` and `foo/index.ts`). List it just once.
|
|
38
|
+
const candidate = (await resolveMigrationScript(workDir, entryName)).find((script)=>isLoadableMigrationScript(script));
|
|
39
|
+
if (candidate) {
|
|
40
|
+
seen.add(entryName);
|
|
41
|
+
migrations.push({
|
|
42
|
+
id: entryName,
|
|
43
|
+
migration: candidate.mod.default
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return migrations;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=resolveMigrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/migration/resolveMigrations.ts"],"sourcesContent":["import {readdir} from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {type Migration} from '@sanity/migrate'\n\nimport {MIGRATION_SCRIPT_EXTENSIONS, MIGRATIONS_DIRECTORY} from './constants.js'\nimport {isLoadableMigrationScript, resolveMigrationScript} from './resolveMigrationScript.js'\n\n/**\n * A resolved migration, where you are guaranteed that the migration file exists\n *\n * @internal\n */\ninterface ResolvedMigration {\n id: string\n migration: Migration\n}\n\n/**\n * Removes migration script extensions from a filename\n *\n * @param fileName - The filename to process\n * @returns The filename without the extension\n * @internal\n */\nfunction removeMigrationScriptExtension(fileName: string): string {\n // Remove `.ts`, `.js` etc from the end of a filename\n const ext = MIGRATION_SCRIPT_EXTENSIONS.find((e) => fileName.endsWith(`.${e}`))\n return ext ? path.basename(fileName, `.${ext}`) : fileName\n}\n\n/**\n * Resolves all migrations in the studio working directory\n *\n * @param workDir - The studio working directory\n * @returns Array of migrations and their respective paths\n * @internal\n */\nexport async function resolveMigrations(workDir: string): Promise<ResolvedMigration[]> {\n const migrationsDir = path.join(workDir, MIGRATIONS_DIRECTORY)\n const migrationEntries = await readdir(migrationsDir, {withFileTypes: true})\n\n const migrations: ResolvedMigration[] = []\n const seen = new Set<string>()\n for (const entry of migrationEntries) {\n const entryName = entry.isDirectory() ? entry.name : removeMigrationScriptExtension(entry.name)\n // A file (e.g. `foo.ts`) and a directory (e.g. `foo/`) can both map to the\n // same id; only resolve each id once.\n if (seen.has(entryName)) {\n continue\n }\n\n // `resolveMigrationScript` may return several loadable candidates for a\n // single id (e.g. both `foo.ts` and `foo/index.ts`). List it just once.\n const candidate = (await resolveMigrationScript(workDir, entryName)).find((script) =>\n isLoadableMigrationScript(script),\n )\n if (candidate) {\n seen.add(entryName)\n migrations.push({id: entryName, migration: candidate.mod.default})\n }\n }\n\n return migrations\n}\n"],"names":["readdir","path","MIGRATION_SCRIPT_EXTENSIONS","MIGRATIONS_DIRECTORY","isLoadableMigrationScript","resolveMigrationScript","removeMigrationScriptExtension","fileName","ext","find","e","endsWith","basename","resolveMigrations","workDir","migrationsDir","join","migrationEntries","withFileTypes","migrations","seen","Set","entry","entryName","isDirectory","name","has","candidate","script","add","push","id","migration","mod","default"],"mappings":"AAAA,SAAQA,OAAO,QAAO,mBAAkB;AACxC,OAAOC,UAAU,YAAW;AAI5B,SAAQC,2BAA2B,EAAEC,oBAAoB,QAAO,iBAAgB;AAChF,SAAQC,yBAAyB,EAAEC,sBAAsB,QAAO,8BAA6B;AAY7F;;;;;;CAMC,GACD,SAASC,+BAA+BC,QAAgB;IACtD,qDAAqD;IACrD,MAAMC,MAAMN,4BAA4BO,IAAI,CAAC,CAACC,IAAMH,SAASI,QAAQ,CAAC,CAAC,CAAC,EAAED,GAAG;IAC7E,OAAOF,MAAMP,KAAKW,QAAQ,CAACL,UAAU,CAAC,CAAC,EAAEC,KAAK,IAAID;AACpD;AAEA;;;;;;CAMC,GACD,OAAO,eAAeM,kBAAkBC,OAAe;IACrD,MAAMC,gBAAgBd,KAAKe,IAAI,CAACF,SAASX;IACzC,MAAMc,mBAAmB,MAAMjB,QAAQe,eAAe;QAACG,eAAe;IAAI;IAE1E,MAAMC,aAAkC,EAAE;IAC1C,MAAMC,OAAO,IAAIC;IACjB,KAAK,MAAMC,SAASL,iBAAkB;QACpC,MAAMM,YAAYD,MAAME,WAAW,KAAKF,MAAMG,IAAI,GAAGnB,+BAA+BgB,MAAMG,IAAI;QAC9F,2EAA2E;QAC3E,sCAAsC;QACtC,IAAIL,KAAKM,GAAG,CAACH,YAAY;YACvB;QACF;QAEA,wEAAwE;QACxE,wEAAwE;QACxE,MAAMI,YAAY,AAAC,CAAA,MAAMtB,uBAAuBS,SAASS,UAAS,EAAGd,IAAI,CAAC,CAACmB,SACzExB,0BAA0BwB;QAE5B,IAAID,WAAW;YACbP,KAAKS,GAAG,CAACN;YACTJ,WAAWW,IAAI,CAAC;gBAACC,IAAIR;gBAAWS,WAAWL,UAAUM,GAAG,CAACC,OAAO;YAAA;QAClE;IACF;IAEA,OAAOf;AACT"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { minimalAdvanced } from './minimalAdvanced.js';
|
|
2
|
+
export { minimalSimple } from './minimalSimple.js';
|
|
3
|
+
export { renameField } from './renameField.js';
|
|
4
|
+
export { renameType } from './renameType.js';
|
|
5
|
+
export { stringToPTE } from './stringToPTE.js';
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/migration/templates/index.ts"],"sourcesContent":["export {minimalAdvanced} from './minimalAdvanced.js'\nexport {minimalSimple} from './minimalSimple.js'\nexport {renameField} from './renameField.js'\nexport {renameType} from './renameType.js'\nexport {stringToPTE} from './stringToPTE.js'\n"],"names":["minimalAdvanced","minimalSimple","renameField","renameType","stringToPTE"],"mappings":"AAAA,SAAQA,eAAe,QAAO,uBAAsB;AACpD,SAAQC,aAAa,QAAO,qBAAoB;AAChD,SAAQC,WAAW,QAAO,mBAAkB;AAC5C,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,WAAW,QAAO,mBAAkB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const minimalAdvanced = ({ documentTypes, migrationName })=>`import {defineMigration, patch, at, setIfMissing} from 'sanity/migrate'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* this migration will set \`Default title\` on all documents that are missing a title
|
|
5
|
+
* and make \`true\` the default value for the \`enabled\` field
|
|
6
|
+
*/
|
|
7
|
+
export default defineMigration({
|
|
8
|
+
title: ${JSON.stringify(migrationName)},
|
|
9
|
+
${documentTypes.length > 0 ? ` documentTypes: [${documentTypes.map((t)=>JSON.stringify(t)).join(', ')}],\n` : ''}
|
|
10
|
+
async *migrate(documents, context) {
|
|
11
|
+
for await (const document of documents()) {
|
|
12
|
+
yield patch(document._id, [
|
|
13
|
+
at('title', setIfMissing('Default title')),
|
|
14
|
+
at('enabled', setIfMissing(true)),
|
|
15
|
+
])
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=minimalAdvanced.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/migration/templates/minimalAdvanced.ts"],"sourcesContent":["export const minimalAdvanced = ({\n documentTypes,\n migrationName,\n}: {\n documentTypes: string[]\n migrationName: string\n}) => `import {defineMigration, patch, at, setIfMissing} from 'sanity/migrate'\n\n/**\n * this migration will set \\`Default title\\` on all documents that are missing a title\n * and make \\`true\\` the default value for the \\`enabled\\` field\n */\nexport default defineMigration({\n title: ${JSON.stringify(migrationName)},\n${\n documentTypes.length > 0\n ? ` documentTypes: [${documentTypes.map((t) => JSON.stringify(t)).join(', ')}],\\n`\n : ''\n}\n async *migrate(documents, context) {\n for await (const document of documents()) {\n yield patch(document._id, [\n at('title', setIfMissing('Default title')),\n at('enabled', setIfMissing(true)),\n ])\n }\n }\n})\n`\n"],"names":["minimalAdvanced","documentTypes","migrationName","JSON","stringify","length","map","t","join"],"mappings":"AAAA,OAAO,MAAMA,kBAAkB,CAAC,EAC9BC,aAAa,EACbC,aAAa,EAId,GAAK,CAAC;;;;;;;SAOE,EAAEC,KAAKC,SAAS,CAACF,eAAe;AACzC,EACED,cAAcI,MAAM,GAAG,IACnB,CAAC,kBAAkB,EAAEJ,cAAcK,GAAG,CAAC,CAACC,IAAMJ,KAAKC,SAAS,CAACG,IAAIC,IAAI,CAAC,MAAM,IAAI,CAAC,GACjF,GACL;;;;;;;;;;AAUD,CAAC,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export const minimalSimple = ({ documentTypes, migrationName })=>`import {at, defineMigration, setIfMissing, unset} from 'sanity/migrate'
|
|
2
|
+
|
|
3
|
+
export default defineMigration({
|
|
4
|
+
title: ${JSON.stringify(migrationName)},
|
|
5
|
+
${documentTypes.length > 0 ? ` documentTypes: [${documentTypes.map((t)=>JSON.stringify(t)).join(', ')}],\n` : ''}
|
|
6
|
+
migrate: {
|
|
7
|
+
document(doc, context) {
|
|
8
|
+
// this will be called for every document of the matching type
|
|
9
|
+
// any patch returned will be applied to the document
|
|
10
|
+
// you can also return mutations that touches other documents
|
|
11
|
+
|
|
12
|
+
return at('title', setIfMissing('Default title'))
|
|
13
|
+
},
|
|
14
|
+
node(node, path, context) {
|
|
15
|
+
// this will be called for every node in every document of the matching type
|
|
16
|
+
// any patch returned will be applied to the document
|
|
17
|
+
// you can also return mutations that touches other documents
|
|
18
|
+
|
|
19
|
+
if (typeof node === 'string' && node === 'deleteme') {
|
|
20
|
+
return unset()
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
object(node, path, context) {
|
|
24
|
+
// this will be called for every object node in every document of the matching type
|
|
25
|
+
// any patch returned will be applied to the document
|
|
26
|
+
// you can also return mutations that touches other documents
|
|
27
|
+
if (node._type === 'author') {
|
|
28
|
+
// make sure all authors objects have a books array
|
|
29
|
+
return at('books', setIfMissing([]))
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
array(node, path, context) {
|
|
33
|
+
// this will be called for every array node in every document of the matching type
|
|
34
|
+
// any patch returned will be applied to the document
|
|
35
|
+
// you can also return mutations that touches other documents
|
|
36
|
+
},
|
|
37
|
+
string(node, path, context) {
|
|
38
|
+
// this will be called for every string node in every document of the matching type
|
|
39
|
+
// any patch returned will be applied to the document
|
|
40
|
+
// you can also return mutations that touches other documents
|
|
41
|
+
},
|
|
42
|
+
number(node, path, context) {
|
|
43
|
+
// this will be called for every number node in every document of the matching type
|
|
44
|
+
// any patch returned will be applied to the document
|
|
45
|
+
// you can also return mutations that touches other documents
|
|
46
|
+
},
|
|
47
|
+
boolean(node, path, context) {
|
|
48
|
+
// this will be called for every boolean node in every document of the matching type
|
|
49
|
+
// any patch returned will be applied to the document
|
|
50
|
+
// you can also return mutations that touches other documents
|
|
51
|
+
},
|
|
52
|
+
null(node, path, context) {
|
|
53
|
+
// this will be called for every null node in every document of the matching type
|
|
54
|
+
// any patch returned will be applied to the document
|
|
55
|
+
// you can also return mutations that touches other documents
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=minimalSimple.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/migration/templates/minimalSimple.ts"],"sourcesContent":["export const minimalSimple = ({\n documentTypes,\n migrationName,\n}: {\n documentTypes: string[]\n migrationName: string\n}) => `import {at, defineMigration, setIfMissing, unset} from 'sanity/migrate'\n\nexport default defineMigration({\n title: ${JSON.stringify(migrationName)},\n${\n documentTypes.length > 0\n ? ` documentTypes: [${documentTypes.map((t) => JSON.stringify(t)).join(', ')}],\\n`\n : ''\n}\n migrate: {\n document(doc, context) {\n // this will be called for every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n\n return at('title', setIfMissing('Default title'))\n },\n node(node, path, context) {\n // this will be called for every node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n\n if (typeof node === 'string' && node === 'deleteme') {\n return unset()\n }\n },\n object(node, path, context) {\n // this will be called for every object node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n if (node._type === 'author') {\n // make sure all authors objects have a books array\n return at('books', setIfMissing([]))\n }\n },\n array(node, path, context) {\n // this will be called for every array node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n string(node, path, context) {\n // this will be called for every string node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n number(node, path, context) {\n // this will be called for every number node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n boolean(node, path, context) {\n // this will be called for every boolean node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n null(node, path, context) {\n // this will be called for every null node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n },\n})\n`\n"],"names":["minimalSimple","documentTypes","migrationName","JSON","stringify","length","map","t","join"],"mappings":"AAAA,OAAO,MAAMA,gBAAgB,CAAC,EAC5BC,aAAa,EACbC,aAAa,EAId,GAAK,CAAC;;;SAGE,EAAEC,KAAKC,SAAS,CAACF,eAAe;AACzC,EACED,cAAcI,MAAM,GAAG,IACnB,CAAC,kBAAkB,EAAEJ,cAAcK,GAAG,CAAC,CAACC,IAAMJ,KAAKC,SAAS,CAACG,IAAIC,IAAI,CAAC,MAAM,IAAI,CAAC,GACjF,GACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDD,CAAC,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const renameField = ({ documentTypes, migrationName })=>`import {defineMigration, at, setIfMissing, unset} from 'sanity/migrate'
|
|
2
|
+
|
|
3
|
+
const from = 'oldFieldName'
|
|
4
|
+
const to = 'newFieldName'
|
|
5
|
+
|
|
6
|
+
export default defineMigration({
|
|
7
|
+
title: ${JSON.stringify(migrationName)},
|
|
8
|
+
${documentTypes.length > 0 ? ` documentTypes: [${documentTypes.map((t)=>JSON.stringify(t)).join(', ')}],\n` : ''}
|
|
9
|
+
migrate: {
|
|
10
|
+
document(doc, context) {
|
|
11
|
+
return [
|
|
12
|
+
at(to, setIfMissing(doc[from])),
|
|
13
|
+
at(from, unset())
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=renameField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/migration/templates/renameField.ts"],"sourcesContent":["export const renameField = ({\n documentTypes,\n migrationName,\n}: {\n documentTypes: string[]\n migrationName: string\n}) => `import {defineMigration, at, setIfMissing, unset} from 'sanity/migrate'\n\nconst from = 'oldFieldName'\nconst to = 'newFieldName'\n\nexport default defineMigration({\n title: ${JSON.stringify(migrationName)},\n${\n documentTypes.length > 0\n ? ` documentTypes: [${documentTypes.map((t) => JSON.stringify(t)).join(', ')}],\\n`\n : ''\n}\n migrate: {\n document(doc, context) {\n return [\n at(to, setIfMissing(doc[from])),\n at(from, unset())\n ]\n }\n }\n})\n`\n"],"names":["renameField","documentTypes","migrationName","JSON","stringify","length","map","t","join"],"mappings":"AAAA,OAAO,MAAMA,cAAc,CAAC,EAC1BC,aAAa,EACbC,aAAa,EAId,GAAK,CAAC;;;;;;SAME,EAAEC,KAAKC,SAAS,CAACF,eAAe;AACzC,EACED,cAAcI,MAAM,GAAG,IACnB,CAAC,kBAAkB,EAAEJ,cAAcK,GAAG,CAAC,CAACC,IAAMJ,KAAKC,SAAS,CAACG,IAAIC,IAAI,CAAC,MAAM,IAAI,CAAC,GACjF,GACL;;;;;;;;;;AAUD,CAAC,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const renameType = ({ documentTypes, migrationName })=>`import {defineMigration, at, set} from 'sanity/migrate'
|
|
2
|
+
|
|
3
|
+
const oldType = 'old'
|
|
4
|
+
const newType = 'new'
|
|
5
|
+
|
|
6
|
+
export default defineMigration({
|
|
7
|
+
title: ${JSON.stringify(migrationName)},
|
|
8
|
+
${documentTypes.length > 0 ? ` documentTypes: [${documentTypes.map((t)=>JSON.stringify(t)).join(', ')}],\n` : ''}
|
|
9
|
+
migrate: {
|
|
10
|
+
object(object, path, context) {
|
|
11
|
+
if (object._type === oldType) {
|
|
12
|
+
return at('_type', set(newType))
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=renameType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/migration/templates/renameType.ts"],"sourcesContent":["export const renameType = ({\n documentTypes,\n migrationName,\n}: {\n documentTypes: string[]\n migrationName: string\n}) => `import {defineMigration, at, set} from 'sanity/migrate'\n\nconst oldType = 'old'\nconst newType = 'new'\n\nexport default defineMigration({\n title: ${JSON.stringify(migrationName)},\n${\n documentTypes.length > 0\n ? ` documentTypes: [${documentTypes.map((t) => JSON.stringify(t)).join(', ')}],\\n`\n : ''\n}\n migrate: {\n object(object, path, context) {\n if (object._type === oldType) {\n return at('_type', set(newType))\n }\n }\n }\n})\n`\n"],"names":["renameType","documentTypes","migrationName","JSON","stringify","length","map","t","join"],"mappings":"AAAA,OAAO,MAAMA,aAAa,CAAC,EACzBC,aAAa,EACbC,aAAa,EAId,GAAK,CAAC;;;;;;SAME,EAAEC,KAAKC,SAAS,CAACF,eAAe;AACzC,EACED,cAAcI,MAAM,GAAG,IACnB,CAAC,kBAAkB,EAAEJ,cAAcK,GAAG,CAAC,CAACC,IAAMJ,KAAKC,SAAS,CAACG,IAAIC,IAAI,CAAC,MAAM,IAAI,CAAC,GACjF,GACL;;;;;;;;;AASD,CAAC,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const stringToPTE = ({ documentTypes, migrationName })=>`import {pathsAreEqual, stringToPath} from 'sanity'
|
|
2
|
+
import {defineMigration, set} from 'sanity/migrate'
|
|
3
|
+
|
|
4
|
+
const targetPath = stringToPath('some.path')
|
|
5
|
+
|
|
6
|
+
export default defineMigration({
|
|
7
|
+
title: ${JSON.stringify(migrationName)},
|
|
8
|
+
${documentTypes.length > 0 ? ` documentTypes: [${documentTypes.map((t)=>JSON.stringify(t)).join(', ')}],\n` : ''}
|
|
9
|
+
migrate: {
|
|
10
|
+
string(node, path, ctx) {
|
|
11
|
+
if (pathsAreEqual(path, targetPath)) {
|
|
12
|
+
return set([
|
|
13
|
+
{
|
|
14
|
+
style: 'normal',
|
|
15
|
+
_type: 'block',
|
|
16
|
+
children: [
|
|
17
|
+
{
|
|
18
|
+
_type: 'span',
|
|
19
|
+
marks: [],
|
|
20
|
+
text: node,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
markDefs: [],
|
|
24
|
+
},
|
|
25
|
+
])
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=stringToPTE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/migration/templates/stringToPTE.ts"],"sourcesContent":["export const stringToPTE = ({\n documentTypes,\n migrationName,\n}: {\n documentTypes: string[]\n migrationName: string\n}) => `import {pathsAreEqual, stringToPath} from 'sanity'\nimport {defineMigration, set} from 'sanity/migrate'\n\nconst targetPath = stringToPath('some.path')\n\nexport default defineMigration({\n title: ${JSON.stringify(migrationName)},\n${\n documentTypes.length > 0\n ? ` documentTypes: [${documentTypes.map((t) => JSON.stringify(t)).join(', ')}],\\n`\n : ''\n}\n migrate: {\n string(node, path, ctx) {\n if (pathsAreEqual(path, targetPath)) {\n return set([\n {\n style: 'normal',\n _type: 'block',\n children: [\n {\n _type: 'span',\n marks: [],\n text: node,\n },\n ],\n markDefs: [],\n },\n ])\n }\n },\n },\n})\n`\n"],"names":["stringToPTE","documentTypes","migrationName","JSON","stringify","length","map","t","join"],"mappings":"AAAA,OAAO,MAAMA,cAAc,CAAC,EAC1BC,aAAa,EACbC,aAAa,EAId,GAAK,CAAC;;;;;;SAME,EAAEC,KAAKC,SAAS,CAACF,eAAe;AACzC,EACED,cAAcI,MAAM,GAAG,IACnB,CAAC,kBAAkB,EAAEJ,cAAcK,GAAG,CAAC,CAACC,IAAMJ,KAAKC,SAAS,CAACG,IAAIC,IAAI,CAAC,MAAM,IAAI,CAAC,GACjF,GACL;;;;;;;;;;;;;;;;;;;;;;AAsBD,CAAC,CAAA"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { isIndexSegment, isIndexTuple, isKeySegment } from '@sanity/types';
|
|
2
|
+
// copy/paste of `pathToString` from 'sanity' to prevent circular imports
|
|
3
|
+
function pathToString(path) {
|
|
4
|
+
if (!Array.isArray(path)) {
|
|
5
|
+
throw new TypeError('Path is not an array');
|
|
6
|
+
}
|
|
7
|
+
let target = '';
|
|
8
|
+
let i = 0;
|
|
9
|
+
for (const segment of path){
|
|
10
|
+
if (isIndexSegment(segment)) {
|
|
11
|
+
target = `${target}[${segment}]`;
|
|
12
|
+
} else if (isKeySegment(segment) && segment._key) {
|
|
13
|
+
target = `${target}[_key=="${segment._key}"]`;
|
|
14
|
+
} else if (isIndexTuple(segment)) {
|
|
15
|
+
const [from, to] = segment;
|
|
16
|
+
target = `${target}[${from}:${to}]`;
|
|
17
|
+
} else if (typeof segment === 'string') {
|
|
18
|
+
const separator = i === 0 ? '' : '.';
|
|
19
|
+
target = `${target}${separator}${segment}`;
|
|
20
|
+
} else {
|
|
21
|
+
throw new TypeError(`Unsupported path segment \`${JSON.stringify(segment)}\``);
|
|
22
|
+
}
|
|
23
|
+
i++;
|
|
24
|
+
}
|
|
25
|
+
return target;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Recursively calculates the max length of all the keys in the given validation
|
|
29
|
+
* tree respecting extra length due to indentation depth. Used to calculate the
|
|
30
|
+
* padding for the rest of the tree.
|
|
31
|
+
*/ export const maxKeyLength = (children = {}, depth = 0)=>{
|
|
32
|
+
let max = 0;
|
|
33
|
+
for (const [key, child] of Object.entries(children)){
|
|
34
|
+
const currentMax = Math.max(key.length + depth * 2, maxKeyLength(child.children, depth + 1));
|
|
35
|
+
max = Math.max(max, currentMax);
|
|
36
|
+
}
|
|
37
|
+
return max;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Recursively formats a given tree into a printed user-friendly tree structure
|
|
41
|
+
*/ export const formatTree = ({ getMessage, getNodes: getLeaves = ({ nodes })=>nodes, indent = '', node = {}, paddingLength })=>{
|
|
42
|
+
const entries = Object.entries(node);
|
|
43
|
+
return entries.map(([key, child], index)=>{
|
|
44
|
+
const isLast = index === entries.length - 1;
|
|
45
|
+
const nextIndent = `${indent}${isLast ? ' ' : '│ '}`;
|
|
46
|
+
const leaves = getLeaves(child);
|
|
47
|
+
const nested = formatTree({
|
|
48
|
+
getMessage,
|
|
49
|
+
getNodes: getLeaves,
|
|
50
|
+
indent: nextIndent,
|
|
51
|
+
node: child.children,
|
|
52
|
+
paddingLength
|
|
53
|
+
});
|
|
54
|
+
if (!leaves?.length) {
|
|
55
|
+
const current = `${indent}${isLast ? '└' : '├'}─ ${key}`;
|
|
56
|
+
return [
|
|
57
|
+
current,
|
|
58
|
+
nested
|
|
59
|
+
].filter(Boolean).join('\n');
|
|
60
|
+
}
|
|
61
|
+
const first = leaves[0];
|
|
62
|
+
const rest = leaves.slice(1);
|
|
63
|
+
if (!first) return '';
|
|
64
|
+
const firstPadding = '.'.repeat(paddingLength - indent.length - key.length);
|
|
65
|
+
const elbow = isLast ? '└' : '├';
|
|
66
|
+
const subsequentPadding = ' '.repeat(paddingLength - indent.length + 2);
|
|
67
|
+
const firstMessage = `${indent}${elbow}─ ${key} ${firstPadding} ${getMessage(first)}`;
|
|
68
|
+
const subsequentMessages = rest.map((marker)=>`${nextIndent}${subsequentPadding} ${getMessage(marker)}`).join('\n');
|
|
69
|
+
const current = [
|
|
70
|
+
firstMessage,
|
|
71
|
+
subsequentMessages
|
|
72
|
+
].filter(Boolean).join('\n');
|
|
73
|
+
return [
|
|
74
|
+
current,
|
|
75
|
+
nested
|
|
76
|
+
].filter(Boolean).join('\n');
|
|
77
|
+
}).join('\n');
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Converts a set of markers with paths into a tree of markers where the paths
|
|
81
|
+
* are embedded in the tree
|
|
82
|
+
*/ export function convertToTree(nodes) {
|
|
83
|
+
const root = {};
|
|
84
|
+
// add the markers to the tree
|
|
85
|
+
function addNode(node, tree = root) {
|
|
86
|
+
// if we've traversed the whole path
|
|
87
|
+
if (node.path.length === 0) {
|
|
88
|
+
if (!tree.nodes) tree.nodes = []; // ensure markers is defined
|
|
89
|
+
// then add the marker to the front
|
|
90
|
+
tree.nodes.push(node);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const current = node.path[0];
|
|
94
|
+
const rest = node.path.slice(1);
|
|
95
|
+
if (!current) return;
|
|
96
|
+
const key = pathToString([
|
|
97
|
+
current
|
|
98
|
+
]);
|
|
99
|
+
// ensure the current node has children and the next node
|
|
100
|
+
if (!tree.children) tree.children = {};
|
|
101
|
+
if (!(key in tree.children)) tree.children[key] = {};
|
|
102
|
+
addNode({
|
|
103
|
+
...node,
|
|
104
|
+
path: rest
|
|
105
|
+
}, tree.children[key]);
|
|
106
|
+
}
|
|
107
|
+
for (const node of nodes)addNode(node);
|
|
108
|
+
return root;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/migration/tree.ts"],"sourcesContent":["import {isIndexSegment, isIndexTuple, isKeySegment, type Path} from '@sanity/types'\n\n// copy/paste of `pathToString` from 'sanity' to prevent circular imports\nfunction pathToString(path: Path): string {\n if (!Array.isArray(path)) {\n throw new TypeError('Path is not an array')\n }\n\n let target = ''\n let i = 0\n for (const segment of path) {\n if (isIndexSegment(segment)) {\n target = `${target}[${segment}]`\n } else if (isKeySegment(segment) && segment._key) {\n target = `${target}[_key==\"${segment._key}\"]`\n } else if (isIndexTuple(segment)) {\n const [from, to] = segment\n target = `${target}[${from}:${to}]`\n } else if (typeof segment === 'string') {\n const separator = i === 0 ? '' : '.'\n target = `${target}${separator}${segment}`\n } else {\n throw new TypeError(`Unsupported path segment \\`${JSON.stringify(segment)}\\``)\n }\n i++\n }\n return target\n}\n\ninterface BaseNode {\n path: Path\n}\n\ninterface Tree<Node extends BaseNode> {\n children?: Record<string, Tree<Node>>\n nodes?: Node[]\n}\n\n/**\n * Recursively calculates the max length of all the keys in the given validation\n * tree respecting extra length due to indentation depth. Used to calculate the\n * padding for the rest of the tree.\n */\nexport const maxKeyLength = (children: Record<string, Tree<BaseNode>> = {}, depth = 0): number => {\n let max = 0\n for (const [key, child] of Object.entries(children)) {\n const currentMax = Math.max(key.length + depth * 2, maxKeyLength(child.children, depth + 1))\n max = Math.max(max, currentMax)\n }\n return max\n}\n\ninterface Options<Node extends BaseNode> {\n getMessage: (node: Node) => string\n paddingLength: number\n\n getNodes?: (node: Tree<Node>) => Node[] | undefined\n indent?: string\n node?: Record<string, Tree<Node>>\n}\n\n/**\n * Recursively formats a given tree into a printed user-friendly tree structure\n */\nexport const formatTree = <Node extends BaseNode>({\n getMessage,\n getNodes: getLeaves = ({nodes}) => nodes,\n indent = '',\n node = {},\n paddingLength,\n}: Options<Node>): string => {\n const entries = Object.entries(node)\n\n return entries\n .map(([key, child], index) => {\n const isLast = index === entries.length - 1\n const nextIndent = `${indent}${isLast ? ' ' : '│ '}`\n const leaves = getLeaves(child)\n\n const nested = formatTree({\n getMessage,\n getNodes: getLeaves,\n indent: nextIndent,\n node: child.children,\n paddingLength,\n })\n\n if (!leaves?.length) {\n const current = `${indent}${isLast ? '└' : '├'}─ ${key}`\n return [current, nested].filter(Boolean).join('\\n')\n }\n\n const first = leaves[0]\n const rest = leaves.slice(1)\n if (!first) return ''\n const firstPadding = '.'.repeat(paddingLength - indent.length - key.length)\n const elbow = isLast ? '└' : '├'\n const subsequentPadding = ' '.repeat(paddingLength - indent.length + 2)\n\n const firstMessage = `${indent}${elbow}─ ${key} ${firstPadding} ${getMessage(first)}`\n const subsequentMessages = rest\n .map((marker) => `${nextIndent}${subsequentPadding} ${getMessage(marker)}`)\n .join('\\n')\n\n const current = [firstMessage, subsequentMessages].filter(Boolean).join('\\n')\n return [current, nested].filter(Boolean).join('\\n')\n })\n .join('\\n')\n}\n\n/**\n * Converts a set of markers with paths into a tree of markers where the paths\n * are embedded in the tree\n */\nexport function convertToTree<const Node extends BaseNode>(nodes: Node[]): Tree<Node> {\n const root: Tree<Node> = {}\n\n // add the markers to the tree\n function addNode(node: Node, tree: Tree<Node> = root) {\n // if we've traversed the whole path\n if (node.path.length === 0) {\n if (!tree.nodes) tree.nodes = [] // ensure markers is defined\n\n // then add the marker to the front\n tree.nodes.push(node)\n return\n }\n\n const current = node.path[0]\n const rest = node.path.slice(1)\n if (!current) return\n const key = pathToString([current])\n\n // ensure the current node has children and the next node\n if (!tree.children) tree.children = {}\n if (!(key in tree.children)) tree.children[key] = {}\n\n addNode({...node, path: rest}, tree.children[key])\n }\n\n for (const node of nodes) addNode(node)\n return root\n}\n"],"names":["isIndexSegment","isIndexTuple","isKeySegment","pathToString","path","Array","isArray","TypeError","target","i","segment","_key","from","to","separator","JSON","stringify","maxKeyLength","children","depth","max","key","child","Object","entries","currentMax","Math","length","formatTree","getMessage","getNodes","getLeaves","nodes","indent","node","paddingLength","map","index","isLast","nextIndent","leaves","nested","current","filter","Boolean","join","first","rest","slice","firstPadding","repeat","elbow","subsequentPadding","firstMessage","subsequentMessages","marker","convertToTree","root","addNode","tree","push"],"mappings":"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"}
|
|
@@ -1,14 +1,46 @@
|
|
|
1
|
+
import { SANITY_CACHE_DIR } from '@sanity/cli-build/_internal/build';
|
|
2
|
+
import { isWorkbenchApp } from '@sanity/workbench-cli';
|
|
1
3
|
import { gracefulServerDeath } from '../../server/gracefulServerDeath.js';
|
|
2
4
|
import { startPreviewServer } from '../../server/previewServer.js';
|
|
5
|
+
import { checkForDeprecatedAppId } from '../../util/appId.js';
|
|
6
|
+
import { determineIsApp } from '../../util/determineIsApp.js';
|
|
7
|
+
import { resolveReactStrictMode } from '../../util/resolveReactStrictMode.js';
|
|
8
|
+
import { extractCoreAppManifest } from '../manifest/extractCoreAppManifest.js';
|
|
9
|
+
import { extractStudioManifest } from '../manifest/extractStudioManifest.js';
|
|
3
10
|
import { getPreviewServerConfig } from './getPreviewServerConfig.js';
|
|
4
11
|
export async function previewAction(options) {
|
|
5
|
-
const { cliConfig, flags, outDir, workDir } = options;
|
|
12
|
+
const { cliConfig, flags, outDir, output, workDir } = options;
|
|
6
13
|
const config = getPreviewServerConfig({
|
|
7
14
|
cliConfig,
|
|
8
15
|
flags,
|
|
9
16
|
rootDir: outDir,
|
|
10
17
|
workDir
|
|
11
18
|
});
|
|
19
|
+
if (isWorkbenchApp(cliConfig?.app)) {
|
|
20
|
+
const isApp = determineIsApp(cliConfig);
|
|
21
|
+
// Lazy so a non-workbench `sanity start` never loads the package. `doImport`
|
|
22
|
+
// is path-based and doesn't apply to a bare specifier.
|
|
23
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
24
|
+
const { startWorkbenchPreview } = await import('@sanity/workbench-cli/preview');
|
|
25
|
+
return startWorkbenchPreview({
|
|
26
|
+
cacheDir: `${SANITY_CACHE_DIR}/vite`,
|
|
27
|
+
checkForDeprecatedAppId: ()=>checkForDeprecatedAppId({
|
|
28
|
+
cliConfig,
|
|
29
|
+
output
|
|
30
|
+
}),
|
|
31
|
+
cliConfig,
|
|
32
|
+
extractManifest: isApp ? ({ workDir: wd })=>extractCoreAppManifest({
|
|
33
|
+
workDir: wd
|
|
34
|
+
}) : (params)=>extractStudioManifest(params),
|
|
35
|
+
httpHost: config.httpHost,
|
|
36
|
+
httpPort: config.httpPort,
|
|
37
|
+
isApp,
|
|
38
|
+
outDir,
|
|
39
|
+
output,
|
|
40
|
+
reactStrictMode: resolveReactStrictMode(cliConfig) ?? false,
|
|
41
|
+
workDir
|
|
42
|
+
});
|
|
43
|
+
}
|
|
12
44
|
try {
|
|
13
45
|
const server = await startPreviewServer(config);
|
|
14
46
|
return server;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/preview/previewAction.ts"],"sourcesContent":["import {type CliConfig} from '@sanity/cli-core'\n\nimport {gracefulServerDeath} from '../../server/gracefulServerDeath.js'\nimport {startPreviewServer} from '../../server/previewServer.js'\nimport {getPreviewServerConfig} from './getPreviewServerConfig.js'\nimport {type PreviewFlags} from './types.js'\n\ninterface PreviewActionOptions {\n cliConfig: CliConfig\n flags: PreviewFlags\n outDir: string\n workDir: string\n}\n\nexport async function previewAction(options: PreviewActionOptions) {\n const {cliConfig, flags, outDir, workDir} = options\n\n const config = getPreviewServerConfig({cliConfig, flags, rootDir: outDir, workDir})\n\n try {\n const server = await startPreviewServer(config)\n return server\n } catch (err) {\n throw gracefulServerDeath('preview', config.httpHost, config.httpPort, err)\n }\n}\n"],"names":["gracefulServerDeath","startPreviewServer","getPreviewServerConfig","previewAction","options","cliConfig","flags","outDir","workDir","config","rootDir","
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/preview/previewAction.ts"],"sourcesContent":["import {SANITY_CACHE_DIR} from '@sanity/cli-build/_internal/build'\nimport {type CliConfig, type Output} from '@sanity/cli-core'\nimport {isWorkbenchApp} from '@sanity/workbench-cli'\n\nimport {gracefulServerDeath} from '../../server/gracefulServerDeath.js'\nimport {type PreviewServer, startPreviewServer} from '../../server/previewServer.js'\nimport {checkForDeprecatedAppId} from '../../util/appId.js'\nimport {determineIsApp} from '../../util/determineIsApp.js'\nimport {resolveReactStrictMode} from '../../util/resolveReactStrictMode.js'\nimport {extractCoreAppManifest} from '../manifest/extractCoreAppManifest.js'\nimport {extractStudioManifest} from '../manifest/extractStudioManifest.js'\nimport {getPreviewServerConfig} from './getPreviewServerConfig.js'\nimport {type PreviewFlags} from './types.js'\n\ninterface PreviewActionOptions {\n cliConfig: CliConfig\n flags: PreviewFlags\n outDir: string\n output: Output\n workDir: string\n}\n\nexport async function previewAction(\n options: PreviewActionOptions,\n): Promise<PreviewServer | {close: () => Promise<void>}> {\n const {cliConfig, flags, outDir, output, workDir} = options\n\n const config = getPreviewServerConfig({cliConfig, flags, rootDir: outDir, workDir})\n\n if (isWorkbenchApp(cliConfig?.app)) {\n const isApp = determineIsApp(cliConfig)\n // Lazy so a non-workbench `sanity start` never loads the package. `doImport`\n // is path-based and doesn't apply to a bare specifier.\n // eslint-disable-next-line no-restricted-syntax\n const {startWorkbenchPreview} = await import('@sanity/workbench-cli/preview')\n return startWorkbenchPreview({\n cacheDir: `${SANITY_CACHE_DIR}/vite`,\n checkForDeprecatedAppId: () => checkForDeprecatedAppId({cliConfig, output}),\n cliConfig,\n extractManifest: isApp\n ? ({workDir: wd}) => extractCoreAppManifest({workDir: wd})\n : (params) => extractStudioManifest(params),\n httpHost: config.httpHost,\n httpPort: config.httpPort,\n isApp,\n outDir,\n output,\n reactStrictMode: resolveReactStrictMode(cliConfig) ?? false,\n workDir,\n })\n }\n\n try {\n const server = await startPreviewServer(config)\n return server\n } catch (err) {\n throw gracefulServerDeath('preview', config.httpHost, config.httpPort, err)\n }\n}\n"],"names":["SANITY_CACHE_DIR","isWorkbenchApp","gracefulServerDeath","startPreviewServer","checkForDeprecatedAppId","determineIsApp","resolveReactStrictMode","extractCoreAppManifest","extractStudioManifest","getPreviewServerConfig","previewAction","options","cliConfig","flags","outDir","output","workDir","config","rootDir","app","isApp","startWorkbenchPreview","cacheDir","extractManifest","wd","params","httpHost","httpPort","reactStrictMode","server","err"],"mappings":"AAAA,SAAQA,gBAAgB,QAAO,oCAAmC;AAElE,SAAQC,cAAc,QAAO,wBAAuB;AAEpD,SAAQC,mBAAmB,QAAO,sCAAqC;AACvE,SAA4BC,kBAAkB,QAAO,gCAA+B;AACpF,SAAQC,uBAAuB,QAAO,sBAAqB;AAC3D,SAAQC,cAAc,QAAO,+BAA8B;AAC3D,SAAQC,sBAAsB,QAAO,uCAAsC;AAC3E,SAAQC,sBAAsB,QAAO,wCAAuC;AAC5E,SAAQC,qBAAqB,QAAO,uCAAsC;AAC1E,SAAQC,sBAAsB,QAAO,8BAA6B;AAWlE,OAAO,eAAeC,cACpBC,OAA6B;IAE7B,MAAM,EAACC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAC,GAAGL;IAEpD,MAAMM,SAASR,uBAAuB;QAACG;QAAWC;QAAOK,SAASJ;QAAQE;IAAO;IAEjF,IAAIf,eAAeW,WAAWO,MAAM;QAClC,MAAMC,QAAQf,eAAeO;QAC7B,6EAA6E;QAC7E,uDAAuD;QACvD,gDAAgD;QAChD,MAAM,EAACS,qBAAqB,EAAC,GAAG,MAAM,MAAM,CAAC;QAC7C,OAAOA,sBAAsB;YAC3BC,UAAU,GAAGtB,iBAAiB,KAAK,CAAC;YACpCI,yBAAyB,IAAMA,wBAAwB;oBAACQ;oBAAWG;gBAAM;YACzEH;YACAW,iBAAiBH,QACb,CAAC,EAACJ,SAASQ,EAAE,EAAC,GAAKjB,uBAAuB;oBAACS,SAASQ;gBAAE,KACtD,CAACC,SAAWjB,sBAAsBiB;YACtCC,UAAUT,OAAOS,QAAQ;YACzBC,UAAUV,OAAOU,QAAQ;YACzBP;YACAN;YACAC;YACAa,iBAAiBtB,uBAAuBM,cAAc;YACtDI;QACF;IACF;IAEA,IAAI;QACF,MAAMa,SAAS,MAAM1B,mBAAmBc;QACxC,OAAOY;IACT,EAAE,OAAOC,KAAK;QACZ,MAAM5B,oBAAoB,WAAWe,OAAOS,QAAQ,EAAET,OAAOU,QAAQ,EAAEG;IACzE;AACF"}
|
|
@@ -26,7 +26,7 @@ export async function listSchemas(options) {
|
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
const schemas = await getDatasetSchemas(projectDatasets, id);
|
|
29
|
-
const parsedSchemas = parseSchemas(schemas, output);
|
|
29
|
+
const parsedSchemas = parseSchemas(schemas, output, json);
|
|
30
30
|
if (parsedSchemas.length === 0) {
|
|
31
31
|
const datasetString = getDatasetsOutString(projectDatasets.map((dataset)=>dataset.dataset));
|
|
32
32
|
throw new Error(id ? `Schema for id "${id}" not found in ${datasetString}` : `No schemas found in ${datasetString}`);
|
|
@@ -56,16 +56,18 @@ async function getDatasetSchemas(projectDatasets, id) {
|
|
|
56
56
|
}
|
|
57
57
|
}));
|
|
58
58
|
}
|
|
59
|
-
function parseSchemas(schemas, output) {
|
|
59
|
+
function parseSchemas(schemas, output, json) {
|
|
60
60
|
return schemas.map((schema)=>{
|
|
61
61
|
if (schema.status === 'fulfilled') return schema.value;
|
|
62
62
|
const error = schema.reason;
|
|
63
63
|
if (error instanceof DatasetError) {
|
|
64
64
|
if ('cause' in error && error.cause && typeof error.cause === 'object' && 'statusCode' in error.cause && error.cause.statusCode === 401) {
|
|
65
|
-
|
|
65
|
+
const logDiagnostic = json ? output.warn.bind(output) : output.log.bind(output);
|
|
66
|
+
logDiagnostic(styleText('yellow', `${logSymbols.warning} ↳ No permissions to read schema from "${error.dataset}". ${SCHEMA_PERMISSION_HELP_TEXT}:\n ${styleText('red', `${error.message}`)}`));
|
|
66
67
|
return [];
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
+
const logDiagnostic = json ? output.warn.bind(output) : output.log.bind(output);
|
|
70
|
+
logDiagnostic(styleText('red', `↳ Failed to fetch schema from "${error.dataset}":\n ${error.message}`));
|
|
69
71
|
return [];
|
|
70
72
|
} else {
|
|
71
73
|
//hubris inc: given the try-catch wrapping all the full promise "this should never happen"
|