@sanity/runtime-cli 17.21.2 → 17.21.3-app-functions.g1a9a040

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.
Files changed (34) hide show
  1. package/README.md +19 -19
  2. package/dist/actions/blueprints/stacks.d.ts +9 -3
  3. package/dist/actions/blueprints/stacks.js +11 -8
  4. package/dist/actions/blueprints/wait-for-operation.d.ts +1 -0
  5. package/dist/actions/blueprints/wait-for-operation.js +1 -1
  6. package/dist/cores/blueprints/deploy.d.ts +8 -0
  7. package/dist/cores/blueprints/deploy.js +12 -4
  8. package/dist/cores/blueprints/destroy.d.ts +14 -1
  9. package/dist/cores/blueprints/destroy.js +2 -1
  10. package/dist/functions/artifacts.d.ts +13 -0
  11. package/dist/functions/artifacts.js +26 -0
  12. package/dist/functions/build.d.ts +15 -0
  13. package/dist/functions/build.js +30 -0
  14. package/dist/functions/contractPlugin.d.ts +7 -0
  15. package/dist/functions/contractPlugin.js +32 -0
  16. package/dist/functions/contracts/schema.d.ts +22 -0
  17. package/dist/functions/contracts/schema.js +99 -0
  18. package/dist/functions/contracts/validation.d.ts +3 -0
  19. package/dist/functions/contracts/validation.js +66 -0
  20. package/dist/functions/contracts.d.ts +33 -0
  21. package/dist/functions/contracts.js +162 -0
  22. package/dist/functions/deploy.d.ts +16 -0
  23. package/dist/functions/deploy.js +69 -0
  24. package/dist/functions/schedule.d.ts +21 -0
  25. package/dist/functions/schedule.js +34 -0
  26. package/dist/functions/stack.d.ts +41 -0
  27. package/dist/functions/stack.js +153 -0
  28. package/dist/server/static/components/console-panel.js +4 -4
  29. package/dist/server/static/components/response-panel.js +6 -6
  30. package/dist/server/static/vendor/vendor.bundle.js +127 -78
  31. package/dist/utils/functions/transpile/function.d.ts +7 -1
  32. package/dist/utils/functions/transpile/function.js +15 -9
  33. package/oclif.manifest.json +990 -990
  34. package/package.json +41 -20
@@ -3143,7 +3143,7 @@ function styleTags(spec) {
3143
3143
  var ruleNodeProp = new NodeProp({ combine(a, b) {
3144
3144
  let cur, root, take;
3145
3145
  while (a || b) {
3146
- if (!a || b && a.depth >= b.depth) {
3146
+ if (!a || b && a.depth <= b.depth) {
3147
3147
  take = b;
3148
3148
  b = b.next;
3149
3149
  } else {
@@ -3326,7 +3326,7 @@ and necessarily incomplete. A full ontology of syntactic
3326
3326
  constructs would fill a stack of books, and be impractical to
3327
3327
  write themes for. So try to make do with this set. If all else
3328
3328
  fails, [open an
3329
- issue](https://github.com/codemirror/codemirror.next) to propose a
3329
+ issue](https://code.haverbeke.berlin/codemirror/dev/issues) to propose a
3330
3330
  new tag, or [define](#highlight.Tag^define) a local custom tag for
3331
3331
  your use case.
3332
3332
 
@@ -6260,7 +6260,7 @@ var EditorState = class EditorState {
6260
6260
  to: range.to,
6261
6261
  insert: text
6262
6262
  },
6263
- range: EditorSelection.cursor(range.from + text.length)
6263
+ range: EditorSelection.cursor(range.from + text.length, -1)
6264
6264
  }));
6265
6265
  }
6266
6266
  /**
@@ -7301,7 +7301,10 @@ function compare(a, startA, b, startB, length, comparator) {
7301
7301
  if (!(a.point && b.point && cmpVal(a.point, b.point) && sameValues(a.activeForPoint(a.to), b.activeForPoint(b.to)))) comparator.comparePoint(pos, clipEnd, a.point, b.point);
7302
7302
  boundChange = false;
7303
7303
  } else {
7304
- if (boundChange) comparator.boundChange(pos);
7304
+ if (boundChange) {
7305
+ comparator.boundChange(pos);
7306
+ boundChange = false;
7307
+ }
7305
7308
  if (clipEnd > pos && !sameValues(a.active, b.active)) comparator.compareRange(pos, clipEnd, a.active, b.active);
7306
7309
  if (bounds && clipEnd < endB && (dEnd || a.openEnd(end) != b.openEnd(end))) boundChange = true;
7307
7310
  }
@@ -24163,59 +24166,78 @@ var basicSetup = /*@__PURE__*/ (() => [
24163
24166
  ])
24164
24167
  ])();
24165
24168
  // node_modules/pretty-bytes/index.js
24166
- var BYTE_UNITS = [
24167
- "B",
24168
- "kB",
24169
- "MB",
24170
- "GB",
24171
- "TB",
24172
- "PB",
24173
- "EB",
24174
- "ZB",
24175
- "YB"
24176
- ];
24177
- var BIBYTE_UNITS = [
24178
- "B",
24179
- "KiB",
24180
- "MiB",
24181
- "GiB",
24182
- "TiB",
24183
- "PiB",
24184
- "EiB",
24185
- "ZiB",
24186
- "YiB"
24187
- ];
24188
- var BIT_UNITS = [
24189
- "b",
24190
- "kbit",
24191
- "Mbit",
24192
- "Gbit",
24193
- "Tbit",
24194
- "Pbit",
24195
- "Ebit",
24196
- "Zbit",
24197
- "Ybit"
24198
- ];
24199
- var BIBIT_UNITS = [
24200
- "b",
24201
- "kibit",
24202
- "Mibit",
24203
- "Gibit",
24204
- "Tibit",
24205
- "Pibit",
24206
- "Eibit",
24207
- "Zibit",
24208
- "Yibit"
24169
+ var UNIT_SETS = [
24170
+ [
24171
+ "B",
24172
+ "kB",
24173
+ "MB",
24174
+ "GB",
24175
+ "TB",
24176
+ "PB",
24177
+ "EB",
24178
+ "ZB",
24179
+ "YB"
24180
+ ],
24181
+ [
24182
+ "B",
24183
+ "KiB",
24184
+ "MiB",
24185
+ "GiB",
24186
+ "TiB",
24187
+ "PiB",
24188
+ "EiB",
24189
+ "ZiB",
24190
+ "YiB"
24191
+ ],
24192
+ [
24193
+ "b",
24194
+ "kbit",
24195
+ "Mbit",
24196
+ "Gbit",
24197
+ "Tbit",
24198
+ "Pbit",
24199
+ "Ebit",
24200
+ "Zbit",
24201
+ "Ybit"
24202
+ ],
24203
+ [
24204
+ "b",
24205
+ "kibit",
24206
+ "Mibit",
24207
+ "Gibit",
24208
+ "Tibit",
24209
+ "Pibit",
24210
+ "Eibit",
24211
+ "Zibit",
24212
+ "Yibit"
24213
+ ]
24209
24214
  ];
24215
+ var toDecimalString = (number) => {
24216
+ if (number >= 1e-6 && number < 1e21) return String(number);
24217
+ const [mantissa, exponentString] = number.toExponential().split("e");
24218
+ const digits = mantissa.replace(".", "");
24219
+ const pointPosition = Number(exponentString) + 1;
24220
+ const isPositive = pointPosition > 0;
24221
+ const padded = isPositive ? digits.padEnd(pointPosition, "0") : "0".repeat(1 - pointPosition) + digits;
24222
+ const integerPart = padded.slice(0, isPositive ? pointPosition : 1);
24223
+ const fractionPart = padded.slice(isPositive ? pointPosition : 1).replace(/0+$/, "");
24224
+ return fractionPart ? `${integerPart}.${fractionPart}` : integerPart;
24225
+ };
24210
24226
  var toLocaleString = (number, locale, options) => {
24211
- let result = number;
24212
- if (typeof locale === "string" || Array.isArray(locale)) result = number.toLocaleString(locale, options);
24213
- else if (locale === true) result = number.toLocaleString(void 0, options);
24214
- else if (options !== void 0) result = number.toLocaleString("en-US", {
24227
+ if (typeof locale === "string" || Array.isArray(locale) || locale === true) {
24228
+ const locales = locale === true ? void 0 : locale;
24229
+ if (options !== void 0) return number.toLocaleString(locales, options);
24230
+ const text = toDecimalString(number);
24231
+ const pointIndex = text.indexOf(".");
24232
+ const maximumFractionDigits = pointIndex === -1 ? 0 : text.length - pointIndex - 1;
24233
+ if (maximumFractionDigits > 100) return text;
24234
+ return number.toLocaleString(locales, { maximumFractionDigits });
24235
+ }
24236
+ if (options === void 0) return toDecimalString(number);
24237
+ return number.toLocaleString("en-US", {
24215
24238
  ...options,
24216
24239
  useGrouping: false
24217
24240
  });
24218
- return result;
24219
24241
  };
24220
24242
  var log10 = (numberOrBigInt) => {
24221
24243
  if (typeof numberOrBigInt === "number") return Math.log10(numberOrBigInt);
@@ -24226,21 +24248,40 @@ var log = (numberOrBigInt) => {
24226
24248
  if (typeof numberOrBigInt === "number") return Math.log(numberOrBigInt);
24227
24249
  return log10(numberOrBigInt) * Math.log(10);
24228
24250
  };
24229
- var divide = (numberOrBigInt, divisor) => {
24230
- if (typeof numberOrBigInt === "number") return numberOrBigInt / divisor;
24231
- const integerPart = numberOrBigInt / BigInt(divisor);
24232
- const remainder = numberOrBigInt % BigInt(divisor);
24251
+ var divide = (numberOrBigInt, base, exponent) => {
24252
+ const divisor = base ** exponent;
24253
+ if (typeof numberOrBigInt === "number" || numberOrBigInt <= Number.MAX_SAFE_INTEGER) return Number(numberOrBigInt) / divisor;
24254
+ const bigintDivisor = BigInt(base) ** BigInt(exponent);
24255
+ const integerPart = numberOrBigInt / bigintDivisor;
24256
+ const remainder = numberOrBigInt % bigintDivisor;
24233
24257
  return Number(integerPart) + Number(remainder) / divisor;
24234
24258
  };
24235
- var applyFixedWidth = (result, fixedWidth) => {
24236
- if (fixedWidth === void 0) return result;
24237
- if (typeof fixedWidth !== "number" || !Number.isSafeInteger(fixedWidth) || fixedWidth < 0) throw new TypeError(`Expected fixedWidth to be a non-negative integer, got ${typeof fixedWidth}: ${fixedWidth}`);
24238
- if (fixedWidth === 0) return result;
24239
- return result.length < fixedWidth ? result.padStart(fixedWidth, " ") : result;
24259
+ var toUnrepresentableString = (number, base, exponent, localeOptions) => {
24260
+ const scale = BigInt(base) ** BigInt(exponent);
24261
+ const whole = number / scale;
24262
+ if (localeOptions === void 0) return whole.toString();
24263
+ const minimumFractionDigits = localeOptions.minimumFractionDigits ?? 0;
24264
+ const maximumFractionDigits = Math.max(localeOptions.maximumFractionDigits ?? 3, minimumFractionDigits);
24265
+ const fraction = (number % scale * 10n ** BigInt(maximumFractionDigits) / scale).toString().padStart(maximumFractionDigits, "0").replace(/0+$/, "").padEnd(minimumFractionDigits, "0");
24266
+ return fraction ? `${whole}.${fraction}` : whole.toString();
24267
+ };
24268
+ var signOf = (number, signed) => {
24269
+ if (number < 0) return "-";
24270
+ if (!signed) return "";
24271
+ return number === 0 || number === 0n ? " " : "+";
24272
+ };
24273
+ var assertFixedWidth = (fixedWidth) => {
24274
+ if (fixedWidth !== void 0 && (typeof fixedWidth !== "number" || !Number.isSafeInteger(fixedWidth) || fixedWidth < 0)) throw new TypeError(`Expected fixedWidth to be a non-negative integer, got ${typeof fixedWidth}: ${fixedWidth}`);
24275
+ };
24276
+ var assertFractionDigits = (name, value) => {
24277
+ if (value !== void 0 && (typeof value !== "number" || !Number.isInteger(value) || value < 0 || value > 100)) throw new TypeError(`Expected ${name} to be an integer between 0 and 100, got ${typeof value}: ${value}`);
24240
24278
  };
24241
24279
  var buildLocaleOptions = (options) => {
24242
24280
  const { minimumFractionDigits, maximumFractionDigits } = options;
24243
24281
  if (minimumFractionDigits === void 0 && maximumFractionDigits === void 0) return;
24282
+ assertFractionDigits("minimumFractionDigits", minimumFractionDigits);
24283
+ assertFractionDigits("maximumFractionDigits", maximumFractionDigits);
24284
+ if (minimumFractionDigits > maximumFractionDigits) throw new RangeError(`Expected minimumFractionDigits (${minimumFractionDigits}) to not be greater than maximumFractionDigits (${maximumFractionDigits})`);
24244
24285
  return {
24245
24286
  ...minimumFractionDigits !== void 0 && { minimumFractionDigits },
24246
24287
  ...maximumFractionDigits !== void 0 && { maximumFractionDigits },
@@ -24256,27 +24297,35 @@ function prettyBytes(number, options) {
24256
24297
  nonBreakingSpace: false,
24257
24298
  ...options
24258
24299
  };
24259
- const UNITS = options.bits ? options.binary ? BIBIT_UNITS : BIT_UNITS : options.binary ? BIBYTE_UNITS : BYTE_UNITS;
24260
- const separator = options.space ? options.nonBreakingSpace ? "\xA0" : " " : "";
24261
- const isZero = typeof number === "number" ? number === 0 : number === 0n;
24262
- if (options.signed && isZero) return applyFixedWidth(` 0${separator}${UNITS[0]}`, options.fixedWidth);
24263
- const isNegative = number < 0;
24264
- const prefix = isNegative ? "-" : options.signed ? "+" : "";
24265
- if (isNegative) number = -number;
24300
+ assertFixedWidth(options.fixedWidth);
24266
24301
  const localeOptions = buildLocaleOptions(options);
24302
+ const UNITS = UNIT_SETS[(options.bits ? 2 : 0) + (options.binary ? 1 : 0)];
24303
+ const separator = options.space ? options.nonBreakingSpace ? "\xA0" : " " : "";
24304
+ if (Object.is(number, -0)) number = 0;
24305
+ const prefix = signOf(number, options.signed);
24306
+ if (number < 0) number = -number;
24267
24307
  const base = options.binary ? 1024 : 1e3;
24268
24308
  let exponent = 0;
24269
24309
  if (number >= 1) exponent = Math.min(Math.floor(options.binary ? log(number) / Math.log(base) : log10(number) / 3), UNITS.length - 1);
24270
- number = divide(number, base ** exponent);
24271
- if (!localeOptions) {
24272
- const minimumPrecision = Math.max(3, Math.floor(number).toString().length);
24273
- number = Number(number.toPrecision(minimumPrecision));
24274
- if (number >= base && exponent < UNITS.length - 1) {
24275
- number /= base;
24276
- exponent += 1;
24277
- }
24278
- }
24279
- return applyFixedWidth(prefix + toLocaleString(number, options.locale, localeOptions) + separator + UNITS[exponent], options.fixedWidth);
24310
+ const scaled = divide(number, base, exponent);
24311
+ let numberString;
24312
+ if (Number.isFinite(scaled)) {
24313
+ number = scaled;
24314
+ if (number < 1 && exponent > 0) {
24315
+ number *= base;
24316
+ exponent -= 1;
24317
+ }
24318
+ if (!localeOptions) {
24319
+ const minimumPrecision = Math.max(3, Math.floor(number).toString().length);
24320
+ number = Number(number.toPrecision(minimumPrecision));
24321
+ if (number >= base && exponent < UNITS.length - 1) {
24322
+ number /= base;
24323
+ exponent += 1;
24324
+ }
24325
+ }
24326
+ numberString = toLocaleString(number, options.locale, localeOptions);
24327
+ } else numberString = toUnrepresentableString(number, base, exponent, localeOptions);
24328
+ return (prefix + numberString + separator + UNITS[exponent]).padStart(options.fixedWidth ?? 0);
24280
24329
  }
24281
24330
  // node_modules/parse-ms/index.js
24282
24331
  var toZeroIfInfinity = (value) => Number.isFinite(value) ? value : 0;
@@ -1,10 +1,16 @@
1
+ import type { Plugin } from 'vite';
1
2
  import type { FunctionResource, InstallerType } from '../../types.js';
2
3
  export declare const resolveViteRoot: (entry: string) => string;
3
- export declare function transpileFunction({ resource, functionPath, entryPoint, installer, }: {
4
+ export declare function transpileFunction({ resource, functionPath, entryPoint, installer, workDir, outDir, outputFileName, bundle: bundleDependencies, plugins: extraPlugins, }: {
4
5
  resource: FunctionResource;
5
6
  functionPath: string;
6
7
  entryPoint: string;
7
8
  installer?: InstallerType;
9
+ workDir?: string;
10
+ outDir?: string;
11
+ outputFileName?: string;
12
+ bundle?: boolean;
13
+ plugins?: Plugin[];
8
14
  }): Promise<{
9
15
  type: string;
10
16
  outputDir: string;
@@ -13,7 +13,7 @@ export const resolveViteRoot = (entry) => {
13
13
  const nodeModulesDir = find.dir('node_modules', { cwd: entry });
14
14
  return nodeModulesDir ? path.dirname(nodeModulesDir) : entry;
15
15
  };
16
- export async function transpileFunction({ resource, functionPath, entryPoint, installer, }) {
16
+ export async function transpileFunction({ resource, functionPath, entryPoint, installer, workDir = cwd(), outDir, outputFileName = getOutputFilename(entryPoint), bundle: bundleDependencies, plugins: extraPlugins = [], }) {
17
17
  if (!resource.src)
18
18
  throw new Error('Resource src is required');
19
19
  if (!resource.name)
@@ -23,8 +23,8 @@ export async function transpileFunction({ resource, functionPath, entryPoint, in
23
23
  const stats = await stat(functionPath);
24
24
  const entryDir = stats.isFile() ? path.dirname(functionPath) : functionPath;
25
25
  const outputPathStart = performance.now();
26
- const outputDir = await getTranspileOutputPath(entryDir, resource.name);
27
- const outputFile = path.join(outputDir, getOutputFilename(entryPoint));
26
+ const outputDir = await getTranspileOutputPath(entryDir, resource.name, outDir);
27
+ const outputFile = path.join(outputDir, outputFileName);
28
28
  const fnRootDir = resolveViteRoot(entryDir);
29
29
  timings['transpile:setupOutput'] = performance.now() - outputPathStart;
30
30
  async function cleanupTmpDir() {
@@ -34,7 +34,8 @@ export async function transpileFunction({ resource, functionPath, entryPoint, in
34
34
  try {
35
35
  const viteStart = performance.now();
36
36
  // Always bundle the code if pnpm usage is detected or specified by the user
37
- const bundle = !!find.file('pnpm-workspace.yaml') || installer === 'pnpm';
37
+ const bundle = bundleDependencies ??
38
+ (!!find.file('pnpm-workspace.yaml', { cwd: workDir }) || installer === 'pnpm');
38
39
  const result = await viteBuild({
39
40
  root: fnRootDir,
40
41
  // Don't pick up the surrounding project's public/ folder or vite.config.*
@@ -52,7 +53,7 @@ export async function transpileFunction({ resource, functionPath, entryPoint, in
52
53
  input: entryPoint,
53
54
  output: {
54
55
  format: 'esm',
55
- entryFileNames: getOutputFilename(entryPoint),
56
+ entryFileNames: outputFileName,
56
57
  ...(bundle
57
58
  ? {}
58
59
  : {
@@ -74,7 +75,10 @@ export async function transpileFunction({ resource, functionPath, entryPoint, in
74
75
  conditions: ['node'],
75
76
  },
76
77
  },
77
- plugins: bundle ? [detectNativeModulesPlugin(), pnpmResolvePlugin(cwd())] : [],
78
+ plugins: [
79
+ ...(bundle ? [detectNativeModulesPlugin(), pnpmResolvePlugin(workDir)] : []),
80
+ ...extraPlugins,
81
+ ],
78
82
  });
79
83
  timings['transpile:build'] = performance.now() - viteStart;
80
84
  const verifyStart = performance.now();
@@ -84,7 +88,7 @@ export async function transpileFunction({ resource, functionPath, entryPoint, in
84
88
  await writeTranspiledPackageJson(entryDir, outputFile);
85
89
  timings['transpile:writePackage'] = performance.now() - pkgStart;
86
90
  const cleanupStart = performance.now();
87
- await cleanupSourceMaps(functionPath, outputDir);
91
+ await cleanupSourceMaps(entryDir, outputDir);
88
92
  timings['transpile:cleanupMaps'] = performance.now() - cleanupStart;
89
93
  timings.bundle = performance.now() - transpileStart;
90
94
  return {
@@ -151,8 +155,10 @@ async function writeTranspiledPackageJson(inputDir, outputFilePath) {
151
155
  const pkgJsonOutputPath = path.join(path.dirname(outputFilePath), 'package.json');
152
156
  await writeFile(pkgJsonOutputPath, JSON.stringify(bundled, null, 2));
153
157
  }
154
- async function getTranspileOutputPath(entryDir, fnName) {
155
- const tmpPath = path.resolve(entryDir, '.build', `function-${fnName}`);
158
+ async function getTranspileOutputPath(entryDir, fnName, outDir) {
159
+ const tmpPath = outDir
160
+ ? path.resolve(outDir)
161
+ : path.resolve(entryDir, '.build', `function-${fnName}`);
156
162
  await rm(tmpPath, { recursive: true, force: true }).catch(logCleanupFailure);
157
163
  await mkdir(tmpPath, { recursive: true });
158
164
  return tmpPath;