@diagonal-hq/cli 0.9.0 → 0.9.2

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/cli.mjs CHANGED
@@ -101,7 +101,7 @@ var require_jsesc = __commonJS({
101
101
  var isBuffer = (value) => {
102
102
  return typeof Buffer === "function" && Buffer.isBuffer(value);
103
103
  };
104
- var isObject2 = (value) => {
104
+ var isObject = (value) => {
105
105
  return toString.call(value) == "[object Object]";
106
106
  };
107
107
  var isString = (value) => {
@@ -261,7 +261,7 @@ var require_jsesc = __commonJS({
261
261
  return JSON.stringify(Number(argument));
262
262
  }
263
263
  return argument + "n";
264
- } else if (!isObject2(argument)) {
264
+ } else if (!isObject(argument)) {
265
265
  if (json) {
266
266
  return JSON.stringify(argument) || "null";
267
267
  }
@@ -13287,7 +13287,7 @@ ${lanes.join("\n")}
13287
13287
  return process.memoryUsage().heapUsed;
13288
13288
  },
13289
13289
  getFileSize(path) {
13290
- const stat = statSync4(path);
13290
+ const stat = statSync5(path);
13291
13291
  if (stat == null ? void 0 : stat.isFile()) {
13292
13292
  return stat.size;
13293
13293
  }
@@ -13331,7 +13331,7 @@ ${lanes.join("\n")}
13331
13331
  }
13332
13332
  };
13333
13333
  return nodeSystem;
13334
- function statSync4(path) {
13334
+ function statSync5(path) {
13335
13335
  try {
13336
13336
  return _fs.statSync(path, statSyncOptions);
13337
13337
  } catch {
@@ -13390,7 +13390,7 @@ ${lanes.join("\n")}
13390
13390
  activeSession.post("Profiler.stop", (err, { profile }) => {
13391
13391
  var _a;
13392
13392
  if (!err) {
13393
- if ((_a = statSync4(profilePath)) == null ? void 0 : _a.isDirectory()) {
13393
+ if ((_a = statSync5(profilePath)) == null ? void 0 : _a.isDirectory()) {
13394
13394
  profilePath = _path.join(profilePath, `${(/* @__PURE__ */ new Date()).toISOString().replace(/:/g, "-")}+P${process.pid}.cpuprofile`);
13395
13395
  }
13396
13396
  try {
@@ -13510,7 +13510,7 @@ ${lanes.join("\n")}
13510
13510
  let stat;
13511
13511
  if (typeof dirent === "string" || dirent.isSymbolicLink()) {
13512
13512
  const name = combinePaths(path, entry);
13513
- stat = statSync4(name);
13513
+ stat = statSync5(name);
13514
13514
  if (!stat) {
13515
13515
  continue;
13516
13516
  }
@@ -13534,7 +13534,7 @@ ${lanes.join("\n")}
13534
13534
  return matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames2, process.cwd(), depth, getAccessibleFileSystemEntries, realpath);
13535
13535
  }
13536
13536
  function fileSystemEntryExists(path, entryKind) {
13537
- const stat = statSync4(path);
13537
+ const stat = statSync5(path);
13538
13538
  if (!stat) {
13539
13539
  return false;
13540
13540
  }
@@ -13576,7 +13576,7 @@ ${lanes.join("\n")}
13576
13576
  }
13577
13577
  function getModifiedTime3(path) {
13578
13578
  var _a;
13579
- return (_a = statSync4(path)) == null ? void 0 : _a.mtime;
13579
+ return (_a = statSync5(path)) == null ? void 0 : _a.mtime;
13580
13580
  }
13581
13581
  function setModifiedTime(path, time) {
13582
13582
  try {
@@ -128929,7 +128929,7 @@ ${lanes.join("\n")}
128929
128929
  }
128930
128930
  }
128931
128931
  function createImportCallExpressionAMD(arg, containsLexicalThis) {
128932
- const resolve5 = factory2.createUniqueName("resolve");
128932
+ const resolve6 = factory2.createUniqueName("resolve");
128933
128933
  const reject = factory2.createUniqueName("reject");
128934
128934
  const parameters = [
128935
128935
  factory2.createParameterDeclaration(
@@ -128938,7 +128938,7 @@ ${lanes.join("\n")}
128938
128938
  /*dotDotDotToken*/
128939
128939
  void 0,
128940
128940
  /*name*/
128941
- resolve5
128941
+ resolve6
128942
128942
  ),
128943
128943
  factory2.createParameterDeclaration(
128944
128944
  /*modifiers*/
@@ -128955,7 +128955,7 @@ ${lanes.join("\n")}
128955
128955
  factory2.createIdentifier("require"),
128956
128956
  /*typeArguments*/
128957
128957
  void 0,
128958
- [factory2.createArrayLiteralExpression([arg || factory2.createOmittedExpression()]), resolve5, reject]
128958
+ [factory2.createArrayLiteralExpression([arg || factory2.createOmittedExpression()]), resolve6, reject]
128959
128959
  )
128960
128960
  )
128961
128961
  ]);
@@ -141766,9 +141766,9 @@ ${lanes.join("\n")}
141766
141766
  /*ignoreCase*/
141767
141767
  false
141768
141768
  )) {
141769
- const basename4 = getBaseFileName(a.fileName);
141770
- if (basename4 === "lib.d.ts" || basename4 === "lib.es6.d.ts") return 0;
141771
- const name = removeSuffix(removePrefix(basename4, "lib."), ".d.ts");
141769
+ const basename5 = getBaseFileName(a.fileName);
141770
+ if (basename5 === "lib.d.ts" || basename5 === "lib.es6.d.ts") return 0;
141771
+ const name = removeSuffix(removePrefix(basename5, "lib."), ".d.ts");
141772
141772
  const index3 = libs.indexOf(name);
141773
141773
  if (index3 !== -1) return index3 + 1;
141774
141774
  }
@@ -183036,7 +183036,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
183036
183036
  return void 0;
183037
183037
  }
183038
183038
  }
183039
- function getJSDocParamAnnotation(paramName, initializer, dotDotDotToken, isJs, isObject2, isSnippet, checker, options2, preferences, tabstopCounter) {
183039
+ function getJSDocParamAnnotation(paramName, initializer, dotDotDotToken, isJs, isObject, isSnippet, checker, options2, preferences, tabstopCounter) {
183040
183040
  if (isSnippet) {
183041
183041
  Debug.assertIsDefined(tabstopCounter);
183042
183042
  }
@@ -183048,7 +183048,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
183048
183048
  }
183049
183049
  if (isJs) {
183050
183050
  let type = "*";
183051
- if (isObject2) {
183051
+ if (isObject) {
183052
183052
  Debug.assert(!dotDotDotToken, `Cannot annotate a rest parameter with type 'Object'.`);
183053
183053
  type = "Object";
183054
183054
  } else {
@@ -183084,7 +183084,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
183084
183084
  type = `\${${tabstopCounter.tabstop++}:${type}}`;
183085
183085
  }
183086
183086
  }
183087
- const dotDotDot = !isObject2 && dotDotDotToken ? "..." : "";
183087
+ const dotDotDot = !isObject && dotDotDotToken ? "..." : "";
183088
183088
  const description3 = isSnippet ? `\${${tabstopCounter.tabstop++}}` : "";
183089
183089
  return `@param {${dotDotDot}${type}} ${paramName} ${description3}`;
183090
183090
  } else {
@@ -205714,8 +205714,8 @@ ${options2.prefix}` : "\n" : options2.prefix
205714
205714
  }
205715
205715
  };
205716
205716
  for (const file2 of files) {
205717
- const basename4 = getBaseFileName(file2);
205718
- if (basename4 === "package.json" || basename4 === "bower.json") {
205717
+ const basename5 = getBaseFileName(file2);
205718
+ if (basename5 === "package.json" || basename5 === "bower.json") {
205719
205719
  createProjectWatcher(
205720
205720
  file2,
205721
205721
  "FileWatcher"
@@ -209399,8 +209399,8 @@ All files are: ${JSON.stringify(names2)}`,
209399
209399
  var _a;
209400
209400
  const fileOrDirectoryPath = removeIgnoredPath(this.toPath(fileOrDirectory));
209401
209401
  if (!fileOrDirectoryPath) return;
209402
- const basename4 = getBaseFileName(fileOrDirectoryPath);
209403
- if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (basename4 === "package.json" || basename4 === "node_modules")) {
209402
+ const basename5 = getBaseFileName(fileOrDirectoryPath);
209403
+ if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (basename5 === "package.json" || basename5 === "node_modules")) {
209404
209404
  result.affectedModuleSpecifierCacheProjects.forEach((project) => {
209405
209405
  var _a2;
209406
209406
  (_a2 = project.getModuleSpecifierCache()) == null ? void 0 : _a2.clear();
@@ -215089,11 +215089,11 @@ Additional information: BADCLIENT: Bad error code, ${badCode} not found in range
215089
215089
  return { fileName: textChanges2.fileName, textChanges: [{ start: { line: 0, offset: 0 }, end: { line: 0, offset: 0 }, newText: change.newText }] };
215090
215090
  }
215091
215091
  function getLocationInNewDocument(oldText, renameFilename, renameLocation, edits) {
215092
- const newText = applyEdits(oldText, renameFilename, edits);
215092
+ const newText = applyEdits2(oldText, renameFilename, edits);
215093
215093
  const { line, character } = computeLineAndCharacterOfPosition(computeLineStarts(newText), renameLocation);
215094
215094
  return { line: line + 1, offset: character + 1 };
215095
215095
  }
215096
- function applyEdits(text, textFilename, edits) {
215096
+ function applyEdits2(text, textFilename, edits) {
215097
215097
  for (const { fileName, textChanges: textChanges2 } of edits) {
215098
215098
  if (fileName !== textFilename) {
215099
215099
  continue;
@@ -215886,8 +215886,8 @@ Additional information: BADCLIENT: Bad error code, ${badCode} not found in range
215886
215886
  installPackage(options2) {
215887
215887
  this.packageInstallId++;
215888
215888
  const request2 = { kind: "installPackage", ...options2, id: this.packageInstallId };
215889
- const promise = new Promise((resolve5, reject) => {
215890
- (this.packageInstalledPromise ?? (this.packageInstalledPromise = /* @__PURE__ */ new Map())).set(this.packageInstallId, { resolve: resolve5, reject });
215889
+ const promise = new Promise((resolve6, reject) => {
215890
+ (this.packageInstalledPromise ?? (this.packageInstalledPromise = /* @__PURE__ */ new Map())).set(this.packageInstallId, { resolve: resolve6, reject });
215891
215891
  });
215892
215892
  this.installer.send(request2);
215893
215893
  return promise;
@@ -229491,7 +229491,7 @@ var require_resolve_uri_umd = __commonJS({
229491
229491
  }
229492
229492
  url.path = path;
229493
229493
  }
229494
- function resolve5(input, base2) {
229494
+ function resolve6(input, base2) {
229495
229495
  if (!input && !base2)
229496
229496
  return "";
229497
229497
  const url = parseUrl2(input);
@@ -229544,7 +229544,7 @@ var require_resolve_uri_umd = __commonJS({
229544
229544
  return url.scheme + "//" + url.user + url.host + url.port + url.path + queryHash;
229545
229545
  }
229546
229546
  }
229547
- return resolve5;
229547
+ return resolve6;
229548
229548
  }));
229549
229549
  }
229550
229550
  });
@@ -229890,8 +229890,8 @@ var require_trace_mapping_umd = __commonJS({
229890
229890
  this.sources = sources;
229891
229891
  this.sourcesContent = sourcesContent;
229892
229892
  this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
229893
- const resolve5 = resolver2(mapUrl, sourceRoot);
229894
- this.resolvedSources = sources.map(resolve5);
229893
+ const resolve6 = resolver2(mapUrl, sourceRoot);
229894
+ this.resolvedSources = sources.map(resolve6);
229895
229895
  const { mappings } = parsed;
229896
229896
  if (typeof mappings === "string") {
229897
229897
  this._encoded = mappings;
@@ -249229,8 +249229,8 @@ interface GeneratorFunctionConstructor {
249229
249229
 
249230
249230
  // scripts/lib/runtime-build/check-cli.mjs
249231
249231
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
249232
- import { statSync as statSync3 } from "node:fs";
249233
- import { resolve as resolve4 } from "node:path";
249232
+ import { statSync as statSync4 } from "node:fs";
249233
+ import { resolve as resolve5 } from "node:path";
249234
249234
 
249235
249235
  // scripts/lib/runtime-build/api-cli.mjs
249236
249236
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -249260,16 +249260,18 @@ function errorText(status, body) {
249260
249260
  return `${lines.join("\n")}
249261
249261
  `;
249262
249262
  }
249263
- async function request({ url, apiKey }, method, path, body, stderr) {
249263
+ async function request({ url, apiKey }, method, path, body, stderr, { responseDetails = false } = {}) {
249264
249264
  const headers = { Accept: "application/json", Authorization: `Bearer ${apiKey}` };
249265
- const init = body === void 0 ? { method, headers } : {
249265
+ const init = body === void 0 || body instanceof FormData ? { method, headers, body } : {
249266
249266
  method,
249267
249267
  headers: { ...headers, "Content-Type": "application/json" },
249268
249268
  body: JSON.stringify(body)
249269
249269
  };
249270
249270
  let response;
249271
+ let text;
249271
249272
  try {
249272
249273
  response = await fetch(`${url}${path}`, init);
249274
+ text = await response.text();
249273
249275
  } catch (error) {
249274
249276
  if (!(error instanceof TypeError)) {
249275
249277
  throw error;
@@ -249278,7 +249280,6 @@ async function request({ url, apiKey }, method, path, body, stderr) {
249278
249280
  `);
249279
249281
  return null;
249280
249282
  }
249281
- const text = await response.text();
249282
249283
  let json;
249283
249284
  try {
249284
249285
  json = JSON.parse(text);
@@ -249290,6 +249291,9 @@ async function request({ url, apiKey }, method, path, body, stderr) {
249290
249291
  `);
249291
249292
  return null;
249292
249293
  }
249294
+ if (responseDetails) {
249295
+ return { ok: response.ok, status: response.status, body: json };
249296
+ }
249293
249297
  if (!response.ok) {
249294
249298
  stderr.write(errorText(response.status, json));
249295
249299
  return null;
@@ -249313,7 +249317,7 @@ function parseFlags(args, valueFlags, booleanFlags) {
249313
249317
  if (!valueFlags.includes(arg)) {
249314
249318
  return { error: `Unknown option ${arg}` };
249315
249319
  }
249316
- if (index3 + 1 >= args.length) {
249320
+ if (index3 + 1 >= args.length || args[index3 + 1].startsWith("--")) {
249317
249321
  return { error: `${arg} needs a value` };
249318
249322
  }
249319
249323
  values[arg] = args[++index3];
@@ -249424,10 +249428,13 @@ ${RUN_USAGE}
249424
249428
  return succeeded ? 0 : 1;
249425
249429
  }
249426
249430
 
249427
- // scripts/lib/runtime-build/build-workspace.mjs
249431
+ // scripts/lib/runtime-build/assets-cli.mjs
249432
+ init_define_globalThis_DIAGONAL_SDK_RUNTIME();
249433
+ import { readFileSync, statSync as statSync2, writeFileSync } from "node:fs";
249434
+ import { basename as basename2, join as join2, resolve } from "node:path";
249435
+
249436
+ // scripts/lib/runtime-build/assets-file.mjs
249428
249437
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
249429
- import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync7, readdirSync as readdirSync3, writeFileSync as writeFileSync3 } from "node:fs";
249430
- import { basename as basename3, dirname as dirname6, extname as extname2, join as join10, relative as relative4, sep } from "node:path";
249431
249438
 
249432
249439
  // scripts/lib/runtime-build/assets.mjs
249433
249440
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -260949,14 +260956,14 @@ var typescript = (superClass) => class TypeScriptParserMixin extends superClass
260949
260956
  const node = this.startNode();
260950
260957
  node.elementTypes = this.tsParseBracketedList("TupleElementTypes", this.tsParseTupleElementType.bind(this), true, false);
260951
260958
  let seenOptionalElement = false;
260952
- node.elementTypes.forEach((elementNode3) => {
260959
+ node.elementTypes.forEach((elementNode2) => {
260953
260960
  const {
260954
260961
  type
260955
- } = elementNode3;
260956
- if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode3.optional)) {
260957
- this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode3);
260962
+ } = elementNode2;
260963
+ if (seenOptionalElement && type !== "TSRestType" && type !== "TSOptionalType" && !(type === "TSNamedTupleMember" && elementNode2.optional)) {
260964
+ this.raise(TSErrors.OptionalTypeBeforeRequired, elementNode2);
260958
260965
  }
260959
- seenOptionalElement ||= type === "TSNamedTupleMember" && elementNode3.optional || type === "TSOptionalType";
260966
+ seenOptionalElement ||= type === "TSNamedTupleMember" && elementNode2.optional || type === "TSOptionalType";
260960
260967
  });
260961
260968
  return this.finishNode(node, "TSTupleType");
260962
260969
  }
@@ -264334,6 +264341,33 @@ function staticObject(node, options2 = {}) {
264334
264341
  }
264335
264342
  return { value, nodes };
264336
264343
  }
264344
+ function propertyNode(objectNode, key) {
264345
+ const node = objectNode?.value ?? objectNode;
264346
+ if (node?.type !== "ObjectExpression") {
264347
+ return objectNode;
264348
+ }
264349
+ return node.properties.find((property) => (property.key.name ?? property.key.value) === key) ?? objectNode;
264350
+ }
264351
+ function elementNode(listNode, position2) {
264352
+ const node = listNode?.value ?? listNode;
264353
+ return node?.type === "ArrayExpression" ? node.elements[position2] ?? listNode : listNode;
264354
+ }
264355
+ function isPlainObject(value) {
264356
+ return value !== null && typeof value === "object" && !Array.isArray(value);
264357
+ }
264358
+ function requireString(value, key, node, { optional = false } = {}) {
264359
+ const item = value[key];
264360
+ if (item === void 0 || item === null) {
264361
+ if (optional) {
264362
+ return null;
264363
+ }
264364
+ throw new SourceError(`"${key}" is required`, node);
264365
+ }
264366
+ if (typeof item !== "string" || item === "") {
264367
+ throw new SourceError(`"${key}" must be a non-empty string`, node);
264368
+ }
264369
+ return item;
264370
+ }
264337
264371
 
264338
264372
  // scripts/lib/runtime-build/assets.mjs
264339
264373
  var ASSET_KEY = /^[a-z][A-Za-z0-9]*$/;
@@ -264342,6 +264376,12 @@ var VERSION_REFERENCE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-
264342
264376
  function isAssetKey(key) {
264343
264377
  return key.length <= 64 && ASSET_KEY.test(key);
264344
264378
  }
264379
+ function assetKeyMessage(key) {
264380
+ return `Asset key "${key}" must be a camelCase name of at most 64 letters and digits that starts with a lowercase letter, such as 'hero'`;
264381
+ }
264382
+ function assetLibraryMessage(reference) {
264383
+ return `Asset version "${reference}" is not in this application's asset library`;
264384
+ }
264345
264385
  function buildAssets(ast, catalog) {
264346
264386
  const { declaration } = defaultExportOf(ast);
264347
264387
  const [definition] = expectDefineCall(declaration, "defineAssets", 1);
@@ -264351,10 +264391,7 @@ function buildAssets(ast, catalog) {
264351
264391
  }
264352
264392
  return Object.entries(value).map(([key, version]) => {
264353
264393
  if (!isAssetKey(key)) {
264354
- throw new SourceError(
264355
- `Asset key "${key}" must be a camelCase name of at most 64 letters and digits that starts with a lowercase letter, such as 'hero'`,
264356
- nodes[key].key
264357
- );
264394
+ throw new SourceError(assetKeyMessage(key), nodes[key].key);
264358
264395
  }
264359
264396
  if (!(version instanceof AssetVersionValue)) {
264360
264397
  throw new SourceError(
@@ -264366,10 +264403,7 @@ function buildAssets(ast, catalog) {
264366
264403
  throw new SourceError("An asset version reference must be a lower-case UUID", version.node);
264367
264404
  }
264368
264405
  if (catalog !== null && !Object.hasOwn(catalog, version.reference)) {
264369
- throw new SourceError(
264370
- `Asset version "${version.reference}" is not in this application's asset library`,
264371
- version.node
264372
- );
264406
+ throw new SourceError(assetLibraryMessage(version.reference), version.node);
264373
264407
  }
264374
264408
  return {
264375
264409
  key,
@@ -264380,6 +264414,368 @@ function buildAssets(ast, catalog) {
264380
264414
  });
264381
264415
  }
264382
264416
 
264417
+ // scripts/lib/runtime-build/assets-file.mjs
264418
+ function readAssetEntries(source) {
264419
+ return source === null ? [] : buildAssets(parseSource(source, { jsx: false }), null);
264420
+ }
264421
+ function applyEdits(source, edits) {
264422
+ for (const { start, end = start, text } of edits.sort((a, b2) => b2.start - a.start)) {
264423
+ source = source.slice(0, start) + text + source.slice(end);
264424
+ }
264425
+ return source;
264426
+ }
264427
+ function addAssetImport(ast, source, edits) {
264428
+ const imports = ast.program.body.filter(
264429
+ (node) => node.type === "ImportDeclaration" && node.source.value === "@diagonal-hq/cli"
264430
+ );
264431
+ const hasAsset = imports.some(
264432
+ (node) => node.importKind !== "type" && node.specifiers.some(
264433
+ (specifier) => specifier.type === "ImportSpecifier" && specifier.importKind !== "type" && specifier.imported.name === "asset" && specifier.local.name === "asset"
264434
+ )
264435
+ );
264436
+ if (hasAsset) {
264437
+ return;
264438
+ }
264439
+ const namedImport = imports.find(
264440
+ (node) => node.importKind !== "type" && node.specifiers.some((specifier) => specifier.type === "ImportSpecifier")
264441
+ );
264442
+ if (namedImport) {
264443
+ const brace = source.indexOf("{", namedImport.start);
264444
+ edits.push({ start: brace + 1, text: " asset," });
264445
+ } else {
264446
+ edits.push({
264447
+ start: ast.program.interpreter?.end ?? 0,
264448
+ text: "\nimport { asset } from '@diagonal-hq/cli';\n"
264449
+ });
264450
+ }
264451
+ }
264452
+ function writeAssetEntry(source, key, reference) {
264453
+ if (!isAssetKey(key)) {
264454
+ throw new SourceError(assetKeyMessage(key));
264455
+ }
264456
+ const entries = readAssetEntries(source);
264457
+ let output;
264458
+ if (source === null) {
264459
+ output = `import { defineAssets, asset } from '@diagonal-hq/cli';
264460
+
264461
+ export default defineAssets({
264462
+ ${key}: asset.version('${reference}')
264463
+ });
264464
+ `;
264465
+ } else {
264466
+ const ast = parseSource(source, { jsx: false });
264467
+ const { declaration } = defaultExportOf(ast);
264468
+ const [argument] = expectDefineCall(declaration, "defineAssets", 1);
264469
+ const definition = ["TSAsExpression", "TSSatisfiesExpression"].includes(argument.type) ? argument.expression : argument;
264470
+ const { value } = staticObject(definition, { assetVersions: true });
264471
+ const edits = [];
264472
+ const existing = entries.find((entry) => entry.key === key);
264473
+ if (existing) {
264474
+ const node = value[key].node;
264475
+ const quote = source[node.start];
264476
+ edits.push({ start: node.start, end: node.end, text: `${quote}${reference}${quote}` });
264477
+ } else {
264478
+ const last2 = definition.properties.at(-1);
264479
+ const property = `${key}: asset.version('${reference}')`;
264480
+ const newline = source.includes("\r\n") ? "\r\n" : "\n";
264481
+ if (!last2) {
264482
+ edits.push({ start: definition.start + 1, text: `${newline} ${property}${newline}` });
264483
+ } else {
264484
+ let between = source.slice(last2.end, definition.end - 1);
264485
+ for (const comment of ast.comments) {
264486
+ if (comment.start >= last2.end && comment.end < definition.end) {
264487
+ const start = comment.start - last2.end;
264488
+ between = between.slice(0, start) + " ".repeat(comment.end - comment.start) + between.slice(comment.end - last2.end);
264489
+ }
264490
+ }
264491
+ const comma2 = between.indexOf(",");
264492
+ const trailingComma = comma2 !== -1;
264493
+ let lineEnd = source.indexOf("\n", last2.end);
264494
+ for (const comment of ast.comments) {
264495
+ if (comment.start >= last2.end && comment.start < lineEnd && comment.end > lineEnd) {
264496
+ lineEnd = source.indexOf("\n", comment.end);
264497
+ }
264498
+ }
264499
+ const multiline = last2.loc.end.line < definition.loc.end.line;
264500
+ if (multiline) {
264501
+ const lineStart = source.lastIndexOf("\n", last2.start - 1) + 1;
264502
+ const indent = source.slice(lineStart, last2.start).match(/^[\t ]*/)[0];
264503
+ if (!trailingComma) {
264504
+ edits.push({ start: last2.end, text: "," });
264505
+ }
264506
+ const insertBeforeBrace = lineEnd === -1 || lineEnd >= definition.end;
264507
+ edits.push({
264508
+ start: insertBeforeBrace ? definition.end - 1 : lineEnd + 1,
264509
+ text: `${insertBeforeBrace ? newline : ""}${indent}${property}${trailingComma ? "," : ""}${newline}`
264510
+ });
264511
+ } else {
264512
+ edits.push({
264513
+ start: trailingComma ? last2.end + comma2 + 1 : last2.end,
264514
+ text: `${trailingComma ? "" : ","} ${property}${trailingComma ? "," : ""}`
264515
+ });
264516
+ }
264517
+ }
264518
+ }
264519
+ addAssetImport(ast, source, edits);
264520
+ output = applyEdits(source, edits);
264521
+ }
264522
+ const result = readAssetEntries(output);
264523
+ const expected = new Map(entries.map((entry) => [entry.key, entry.reference]));
264524
+ expected.set(key, reference);
264525
+ if (result.length !== expected.size || result.some((entry) => expected.get(entry.key) !== entry.reference)) {
264526
+ throw new SourceError("The assets.ts edit did not preserve the asset entries.");
264527
+ }
264528
+ return output;
264529
+ }
264530
+
264531
+ // scripts/lib/runtime-build/format-diagnostic.mjs
264532
+ init_define_globalThis_DIAGONAL_SDK_RUNTIME();
264533
+ function formatDiagnostic(diagnostic2) {
264534
+ const [headline, ...details] = diagnostic2.message.split("\n");
264535
+ const lines = [
264536
+ `${diagnostic2.path}:${diagnostic2.line}:${diagnostic2.column} ${diagnostic2.severity} ${headline}`
264537
+ ];
264538
+ for (const detail of details) {
264539
+ lines.push(` ${detail}`);
264540
+ }
264541
+ return lines.join("\n");
264542
+ }
264543
+
264544
+ // scripts/lib/runtime-build/assets-cli.mjs
264545
+ var ASSETS_UPLOAD_USAGE = "Usage: diagonal assets upload <file> [--key <key>] [--no-write] [--json]";
264546
+ var ASSETS_LIST_USAGE = "Usage: diagonal assets list [--search <text>] [--versions] [--json]";
264547
+ var NIL_REFERENCE = "00000000-0000-0000-0000-000000000000";
264548
+ var MISSING_VERSION = "This version is not in the Application Asset library.";
264549
+ function readManifest(path) {
264550
+ try {
264551
+ return readFileSync(path, "utf8");
264552
+ } catch (error) {
264553
+ if (error.code === "ENOENT") {
264554
+ return null;
264555
+ }
264556
+ throw error;
264557
+ }
264558
+ }
264559
+ function printFileError(error, stderr) {
264560
+ if (error instanceof SourceError || error instanceof SyntaxError) {
264561
+ stderr.write(`${formatDiagnostic(diagnosticFromError("assets.ts", error))}
264562
+ `);
264563
+ } else if (error.code) {
264564
+ stderr.write(`Could not access assets.ts: ${error.message}
264565
+ `);
264566
+ } else {
264567
+ throw error;
264568
+ }
264569
+ }
264570
+ async function uploadAsset(args, { cwd, env: env2, stdout, stderr }) {
264571
+ const parsed = parseFlags(args, ["--key"], ["--no-write", "--json"]);
264572
+ const key = parsed.values?.["--key"];
264573
+ const noWrite = parsed.booleans?.has("--no-write");
264574
+ const usageError = parsed.error ?? (parsed.positional.length !== 1 ? "Give one file to upload" : key !== void 0 && !isAssetKey(key) ? assetKeyMessage(key) : !noWrite && key === void 0 ? "--key is required unless --no-write is given" : null);
264575
+ if (usageError !== null) {
264576
+ stderr.write(`${usageError}
264577
+ ${ASSETS_UPLOAD_USAGE}
264578
+ `);
264579
+ return 2;
264580
+ }
264581
+ const file2 = resolve(cwd, parsed.positional[0]);
264582
+ let bytes;
264583
+ try {
264584
+ if (!statSync2(file2, { throwIfNoEntry: false })?.isFile()) {
264585
+ stderr.write(`Not a regular file: ${file2}
264586
+ `);
264587
+ return 2;
264588
+ }
264589
+ bytes = readFileSync(file2);
264590
+ } catch (error) {
264591
+ if (!error.code) throw error;
264592
+ stderr.write(`Could not read ${file2}: ${error.message}
264593
+ `);
264594
+ return 2;
264595
+ }
264596
+ const manifest = join2(cwd, "assets.ts");
264597
+ let source = null;
264598
+ let current;
264599
+ if (!noWrite && !statSync2(join2(cwd, "diagonal.config.ts"), { throwIfNoEntry: false })?.isFile()) {
264600
+ stderr.write(
264601
+ "Run diagonal assets upload in the workspace root, the folder with diagonal.config.ts, or pass --no-write.\n"
264602
+ );
264603
+ return 2;
264604
+ }
264605
+ try {
264606
+ source = readManifest(manifest);
264607
+ const entries = readAssetEntries(source);
264608
+ current = entries.find((entry) => entry.key === key);
264609
+ if (!noWrite) writeAssetEntry(source, key, NIL_REFERENCE);
264610
+ } catch (error) {
264611
+ printFileError(error, stderr);
264612
+ return 1;
264613
+ }
264614
+ const target = credentials(env2, stderr);
264615
+ if (target === null) return 2;
264616
+ if (await request(target, "GET", "/api/application-assets?per_page=1", void 0, stderr) === null)
264617
+ return 1;
264618
+ let assetId;
264619
+ if (current) {
264620
+ const lookup = await request(
264621
+ target,
264622
+ "GET",
264623
+ `/api/application-asset-versions/${current.reference}`,
264624
+ void 0,
264625
+ stderr,
264626
+ { responseDetails: true }
264627
+ );
264628
+ if (lookup === null) return 1;
264629
+ if (!lookup.ok) {
264630
+ if (lookup.status === 404 && lookup.body.message === MISSING_VERSION) {
264631
+ stderr.write(
264632
+ `${formatDiagnostic(diagnostic("assets.ts", current.line, current.column, assetLibraryMessage(current.reference)))}
264633
+ `
264634
+ );
264635
+ } else {
264636
+ stderr.write(errorText(lookup.status, lookup.body));
264637
+ }
264638
+ return 1;
264639
+ }
264640
+ assetId = lookup.body.asset.id;
264641
+ }
264642
+ const form = new FormData();
264643
+ form.append("file", new Blob([bytes]), basename2(file2));
264644
+ const uploaded = await request(target, "POST", "/api/files/uploads", form, stderr);
264645
+ if (uploaded === null) return 1;
264646
+ const result = await request(
264647
+ target,
264648
+ "POST",
264649
+ assetId ? `/api/application-assets/${assetId}/versions` : "/api/application-assets",
264650
+ { upload_key: uploaded.key },
264651
+ stderr,
264652
+ { responseDetails: true }
264653
+ );
264654
+ if (result === null) return 1;
264655
+ if (!result.ok) {
264656
+ stderr.write(errorText(result.status, result.body));
264657
+ return 1;
264658
+ }
264659
+ const { asset: asset2, version } = result.body;
264660
+ let written = false;
264661
+ let action;
264662
+ if (!noWrite) {
264663
+ try {
264664
+ const latest = readManifest(manifest);
264665
+ const existing = readAssetEntries(latest).find((entry) => entry.key === key);
264666
+ const output = writeAssetEntry(latest, key, version.reference);
264667
+ if (output !== latest) writeFileSync(manifest, output);
264668
+ written = true;
264669
+ action = existing?.reference === version.reference ? `${key} already uses this version` : existing ? `Updated ${key} in assets.ts` : `Added ${key} to assets.ts`;
264670
+ } catch (error) {
264671
+ printFileError(error, stderr);
264672
+ stderr.write(
264673
+ `${key}: asset.version('${version.reference}')
264674
+ Do not run the upload again: a new key creates another asset.
264675
+ `
264676
+ );
264677
+ return 1;
264678
+ }
264679
+ }
264680
+ if (parsed.booleans.has("--json")) {
264681
+ stdout.write(`${JSON.stringify({ key: key ?? null, written, asset: asset2, version }, null, 2)}
264682
+ `);
264683
+ } else if (noWrite) {
264684
+ stdout.write(`${version.reference}
264685
+ `);
264686
+ } else {
264687
+ if (result.status === 200)
264688
+ stdout.write(`The bytes match version ${version.number}; no new version was created.
264689
+ `);
264690
+ stdout.write(
264691
+ `${key} ${version.reference} ${asset2.display_name} v${version.number}
264692
+ ${action}
264693
+ `
264694
+ );
264695
+ }
264696
+ return 0;
264697
+ }
264698
+ async function listAssets(args, { env: env2, stdout, stderr }) {
264699
+ const parsed = parseFlags(args, ["--search"], ["--versions", "--json"]);
264700
+ if (parsed.error !== void 0 || parsed.positional.length > 0) {
264701
+ stderr.write(
264702
+ `${parsed.error ?? "diagonal assets list takes no arguments"}
264703
+ ${ASSETS_LIST_USAGE}
264704
+ `
264705
+ );
264706
+ return 2;
264707
+ }
264708
+ const target = credentials(env2, stderr);
264709
+ if (target === null) return 2;
264710
+ const assets = [];
264711
+ let page = 1;
264712
+ while (true) {
264713
+ const query = new URLSearchParams({ per_page: "100", page: String(page) });
264714
+ if (parsed.values["--search"] !== void 0) query.set("search", parsed.values["--search"]);
264715
+ const body = await request(
264716
+ target,
264717
+ "GET",
264718
+ `/api/application-assets?${query}`,
264719
+ void 0,
264720
+ stderr
264721
+ );
264722
+ if (body === null) return 1;
264723
+ assets.push(...body.data);
264724
+ if (body.pagination.current_page >= body.pagination.last_page) break;
264725
+ page++;
264726
+ }
264727
+ if (parsed.booleans.has("--versions")) {
264728
+ for (const asset2 of assets) {
264729
+ const body = await request(
264730
+ target,
264731
+ "GET",
264732
+ `/api/application-assets/${asset2.id}`,
264733
+ void 0,
264734
+ stderr
264735
+ );
264736
+ if (body === null) return 1;
264737
+ asset2.versions = body.versions;
264738
+ }
264739
+ }
264740
+ if (parsed.booleans.has("--json")) {
264741
+ stdout.write(`${JSON.stringify({ data: assets }, null, 2)}
264742
+ `);
264743
+ return 0;
264744
+ }
264745
+ const rows = assets.map((asset2) => [
264746
+ asset2.latest_version?.reference ?? "-",
264747
+ asset2.latest_version ? `v${asset2.latest_version.number} of ${asset2.versions_count}` : `- of ${asset2.versions_count}`,
264748
+ asset2.latest_version?.mime_type ?? "-",
264749
+ asset2.display_name
264750
+ ]);
264751
+ const widths = [0, 1, 2].map((column) => Math.max(0, ...rows.map((row) => row[column].length)));
264752
+ for (const [index3, row] of rows.entries()) {
264753
+ stdout.write(
264754
+ `${row.map((value, column) => column < 3 ? value.padEnd(widths[column]) : value).join(" ")}
264755
+ `
264756
+ );
264757
+ const asset2 = assets[index3];
264758
+ for (const version of asset2.versions ?? []) {
264759
+ stdout.write(
264760
+ ` v${version.number} ${version.reference} ${version.original_filename} ${version.bytes} bytes
264761
+ `
264762
+ );
264763
+ }
264764
+ if (asset2.versions && asset2.versions.length < asset2.versions_count) {
264765
+ stdout.write(` showing the newest ${asset2.versions.length} of ${asset2.versions_count}
264766
+ `);
264767
+ }
264768
+ }
264769
+ stdout.write(`${assets.length} asset${assets.length === 1 ? "" : "s"}
264770
+ `);
264771
+ return 0;
264772
+ }
264773
+
264774
+ // scripts/lib/runtime-build/build-workspace.mjs
264775
+ init_define_globalThis_DIAGONAL_SDK_RUNTIME();
264776
+ import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync8, readdirSync as readdirSync3, writeFileSync as writeFileSync4 } from "node:fs";
264777
+ import { basename as basename4, dirname as dirname6, extname as extname2, join as join11, relative as relative4, sep } from "node:path";
264778
+
264383
264779
  // scripts/lib/runtime-build/capabilities.mjs
264384
264780
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
264385
264781
 
@@ -267398,25 +267794,11 @@ var capability_catalog_default = {
267398
267794
 
267399
267795
  // scripts/lib/runtime-build/capabilities.mjs
267400
267796
  var FIELD_REFERENCE_TYPES = /* @__PURE__ */ new Set(["field_reference", "resource_field_key_reference"]);
267401
- function isObject(value) {
267402
- return value !== null && typeof value === "object" && !Array.isArray(value);
267403
- }
267404
- function propertyNode(objectNode, key) {
267405
- const node = objectNode?.value ?? objectNode;
267406
- if (node?.type !== "ObjectExpression") {
267407
- return objectNode;
267408
- }
267409
- return node.properties.find((property) => (property.key.name ?? property.key.value) === key) ?? objectNode;
267410
- }
267411
- function elementNode(listNode, position2) {
267412
- const node = listNode?.value ?? listNode;
267413
- return node?.type === "ArrayExpression" ? node.elements[position2] ?? listNode : listNode;
267414
- }
267415
267797
  function readCapabilities(capabilities, node) {
267416
267798
  if (capabilities === void 0) {
267417
267799
  return {};
267418
267800
  }
267419
- if (!isObject(capabilities)) {
267801
+ if (!isPlainObject(capabilities)) {
267420
267802
  throw new SourceError('"capabilities" must be an object keyed by capability', node);
267421
267803
  }
267422
267804
  for (const [identifier4, settings] of Object.entries(capabilities)) {
@@ -267431,7 +267813,7 @@ function readCapabilities(capabilities, node) {
267431
267813
  capabilityNode
267432
267814
  );
267433
267815
  }
267434
- if (!isObject(settings)) {
267816
+ if (!isPlainObject(settings)) {
267435
267817
  throw new SourceError(
267436
267818
  `Capability "${identifier4}" must be an object of settings`,
267437
267819
  capabilityNode
@@ -267513,7 +267895,7 @@ function checkSetting(context, setting, value, label, node) {
267513
267895
  return;
267514
267896
  }
267515
267897
  if (setting.properties !== null) {
267516
- if (!isObject(value)) {
267898
+ if (!isPlainObject(value)) {
267517
267899
  problems.push({ message: `${label} must be an object`, node });
267518
267900
  return;
267519
267901
  }
@@ -267572,8 +267954,8 @@ function checkCapabilities(resources, platformSlugs, diagnostics) {
267572
267954
  // scripts/lib/runtime-build/definition-uid.mjs
267573
267955
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
267574
267956
  import { randomUUID } from "node:crypto";
267575
- import { writeFileSync } from "node:fs";
267576
- import { join as join2 } from "node:path";
267957
+ import { writeFileSync as writeFileSync2 } from "node:fs";
267958
+ import { join as join3 } from "node:path";
267577
267959
  var UID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
267578
267960
  var UID_EXAMPLE = "3f2b8c1e-7d4a-4e9b-a6c5-1d0e9f8a7b6c";
267579
267961
  function isUid(value) {
@@ -267683,15 +268065,15 @@ function checkDefinitionUids(root, definitions, { write }) {
267683
268065
  uids.push(generated);
267684
268066
  }
267685
268067
  for (const [path, insertions] of insertionsByPath) {
267686
- writeFileSync(join2(root, path), withInsertions(sourceByPath.get(path), insertions));
268068
+ writeFileSync2(join3(root, path), withInsertions(sourceByPath.get(path), insertions));
267687
268069
  }
267688
268070
  return { uids, diagnostics };
267689
268071
  }
267690
268072
 
267691
268073
  // scripts/lib/runtime-build/module-graph.mjs
267692
268074
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
267693
- import { readFileSync } from "node:fs";
267694
- import { posix as posix2, join as join3 } from "node:path";
268075
+ import { readFileSync as readFileSync2 } from "node:fs";
268076
+ import { posix as posix2, join as join4 } from "node:path";
267695
268077
 
267696
268078
  // scripts/lib/runtime-build/page-build-protocol.mjs
267697
268079
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -267704,7 +268086,7 @@ function sha256(value) {
267704
268086
 
267705
268087
  // scripts/lib/runtime-build/resource-references.mjs
267706
268088
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
267707
- import { basename as basename2, extname } from "node:path";
268089
+ import { basename as basename3, extname } from "node:path";
267708
268090
 
267709
268091
  // node_modules/@babel/traverse/lib/index.js
267710
268092
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -279666,7 +280048,7 @@ var objectToString = Function.call.bind(Object.prototype.toString);
279666
280048
  function isRegExp(value) {
279667
280049
  return objectToString(value) === "[object RegExp]";
279668
280050
  }
279669
- function isPlainObject(value) {
280051
+ function isPlainObject2(value) {
279670
280052
  if (typeof value !== "object" || value === null || Object.prototype.toString.call(value) !== "[object Object]") {
279671
280053
  return false;
279672
280054
  }
@@ -279719,7 +280101,7 @@ function valueToNode(value) {
279719
280101
  if (Array.isArray(value)) {
279720
280102
  return arrayExpression(value.map(valueToNode));
279721
280103
  }
279722
- if (isPlainObject(value)) {
280104
+ if (isPlainObject2(value)) {
279723
280105
  const props = [];
279724
280106
  for (const key of Object.keys(value)) {
279725
280107
  let nodeKey, computed = false;
@@ -280579,7 +280961,7 @@ function normalizePath(url, type) {
280579
280961
  }
280580
280962
  url.path = path;
280581
280963
  }
280582
- function resolve(input, base2) {
280964
+ function resolve2(input, base2) {
280583
280965
  if (!input && !base2)
280584
280966
  return "";
280585
280967
  const url = parseUrl(input);
@@ -280642,7 +281024,7 @@ function stripFilename(path) {
280642
281024
  function resolver(mapUrl, sourceRoot) {
280643
281025
  const from = stripFilename(mapUrl);
280644
281026
  const prefix2 = sourceRoot ? sourceRoot + "/" : "";
280645
- return (source) => resolve(prefix2 + (source || ""), from);
281027
+ return (source) => resolve2(prefix2 + (source || ""), from);
280646
281028
  }
280647
281029
  var COLUMN = 0;
280648
281030
  var SOURCES_INDEX = 1;
@@ -280755,8 +281137,8 @@ var TraceMap = class {
280755
281137
  this.sources = sources;
280756
281138
  this.sourcesContent = sourcesContent;
280757
281139
  this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
280758
- const resolve5 = resolver(mapUrl, sourceRoot);
280759
- this.resolvedSources = sources.map(resolve5);
281140
+ const resolve6 = resolver(mapUrl, sourceRoot);
281141
+ this.resolvedSources = sources.map(resolve6);
280760
281142
  const { mappings } = parsed;
280761
281143
  if (typeof mappings === "string") {
280762
281144
  this._encoded = mappings;
@@ -291030,7 +291412,7 @@ function _guessExecutionStatusRelativeToDifferentFunctionsCached(base2, target,
291030
291412
  nodeMap.set(target.node, result);
291031
291413
  return result;
291032
291414
  }
291033
- function resolve2(dangerous, resolved) {
291415
+ function resolve3(dangerous, resolved) {
291034
291416
  if (resolved?.includes(this)) return this;
291035
291417
  resolved = resolved || [];
291036
291418
  resolved.push(this);
@@ -291678,7 +292060,7 @@ var methods = {
291678
292060
  getSource,
291679
292061
  willIMaybeExecuteBefore,
291680
292062
  _guessExecutionStatusRelativeTo,
291681
- resolve: resolve2,
292063
+ resolve: resolve3,
291682
292064
  isConstantExpression,
291683
292065
  isInStrictMode,
291684
292066
  isDenylisted,
@@ -291964,7 +292346,7 @@ function resourceNames(paths, diagnostics) {
291964
292346
  const slugsByName = /* @__PURE__ */ new Map();
291965
292347
  const namesBySlug = /* @__PURE__ */ new Map();
291966
292348
  for (const path of paths) {
291967
- const slug = basename2(path, extname(path));
292349
+ const slug = basename3(path, extname(path));
291968
292350
  if (!SLUG_PATTERN.test(slug)) {
291969
292351
  diagnostics.push(
291970
292352
  diagnosticAt(
@@ -292419,12 +292801,12 @@ function buildModuleGraph(root, entries, manifest, diagnostics, assetKeys = /* @
292419
292801
  const kind = importKind(`./${posix2.basename(path)}`);
292420
292802
  if (STYLE_KINDS.has(kind)) {
292421
292803
  checkStylesheet(root, path, assetKeys, diagnostics, scannedStyles);
292422
- modules[path] = { kind, source_sha256: sha256(readFileSync(join3(root, path))), imports: [] };
292804
+ modules[path] = { kind, source_sha256: sha256(readFileSync2(join4(root, path))), imports: [] };
292423
292805
  continue;
292424
292806
  }
292425
292807
  let entry = parsed.get(path);
292426
292808
  if (entry === void 0) {
292427
- const source = readFileSync(join3(root, path), "utf8");
292809
+ const source = readFileSync2(join4(root, path), "utf8");
292428
292810
  try {
292429
292811
  entry = { path, source, ast: parseSource(source, { jsx: path.endsWith("x") }) };
292430
292812
  } catch (error) {
@@ -292608,7 +292990,7 @@ function checkStylesheet(root, path, assetKeys, diagnostics, scanned) {
292608
292990
  return;
292609
292991
  }
292610
292992
  scanned.add(path);
292611
- const { urls, imports } = cssReferences(readFileSync(join3(root, path), "utf8"));
292993
+ const { urls, imports } = cssReferences(readFileSync2(join4(root, path), "utf8"));
292612
292994
  for (const url of urls) {
292613
292995
  const key = assetUrlKey(url.value);
292614
292996
  if (key !== null && assetKeys !== null && !assetKeys.has(key)) {
@@ -293835,8 +294217,8 @@ and limitations under the License.
293835
294217
 
293836
294218
  // scripts/pageTypeCheck.mjs
293837
294219
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
293838
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
293839
- import { dirname as dirname2, join as join4 } from "node:path";
294220
+ import { existsSync as existsSync2, readFileSync as readFileSync3 } from "node:fs";
294221
+ import { dirname as dirname2, join as join5 } from "node:path";
293840
294222
 
293841
294223
  // app/pages/resources/js/pageRuntime/sdk/buildCustomComponentTypes.ts
293842
294224
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -294888,8 +295270,8 @@ function typeCheckPage(userSource, {
294888
295270
  if (libFiles3) {
294889
295271
  return libFiles3.get(name);
294890
295272
  }
294891
- const path = join4(libDir, name);
294892
- return existsSync2(path) ? readFileSync2(path, "utf8") : void 0;
295273
+ const path = join5(libDir, name);
295274
+ return existsSync2(path) ? readFileSync3(path, "utf8") : void 0;
294893
295275
  };
294894
295276
  const getText = (name) => virtual.get(name) ?? readLib(name);
294895
295277
  const host = {
@@ -296164,7 +296546,7 @@ function lintUnit(unit, catalogs) {
296164
296546
  return [];
296165
296547
  }
296166
296548
 
296167
- // scripts/lib/runtime-build/resources.mjs
296549
+ // scripts/lib/runtime-build/policies.mjs
296168
296550
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
296169
296551
 
296170
296552
  // scripts/lib/runtime-build/fields.mjs
@@ -297839,6 +298221,44 @@ var field_catalog_default = {
297839
298221
  "update_many",
297840
298222
  "upsert",
297841
298223
  "upsert_many"
298224
+ ],
298225
+ filter_operators: [
298226
+ "all",
298227
+ "between",
298228
+ "contains",
298229
+ "elem_match",
298230
+ "ends_with",
298231
+ "=",
298232
+ "exists",
298233
+ ">",
298234
+ ">=",
298235
+ "has_value",
298236
+ "in",
298237
+ "is",
298238
+ "is_not",
298239
+ "is_not_null",
298240
+ "is_null",
298241
+ "<",
298242
+ "<=",
298243
+ "missing_value",
298244
+ "mod",
298245
+ "not",
298246
+ "!=",
298247
+ "not_exists",
298248
+ "not_in",
298249
+ "regex",
298250
+ "search",
298251
+ "starts_with"
298252
+ ],
298253
+ record_meta_fields: [
298254
+ "id",
298255
+ "workspace_id",
298256
+ "resource_id",
298257
+ "__meta",
298258
+ "created_at",
298259
+ "updated_at",
298260
+ "deleted_at",
298261
+ "cascade_key"
297842
298262
  ]
297843
298263
  };
297844
298264
 
@@ -297889,9 +298309,6 @@ function optionNode(builder2, ...path) {
297889
298309
  }
297890
298310
  return node;
297891
298311
  }
297892
- function isPlainObject2(value) {
297893
- return value !== null && typeof value === "object" && !Array.isArray(value);
297894
- }
297895
298312
  function humanize2(key) {
297896
298313
  const words = key.replaceAll("_", " ");
297897
298314
  return words.charAt(0).toUpperCase() + words.slice(1);
@@ -297911,7 +298328,7 @@ function resolverOption(builder2, key, fieldKey) {
297911
298328
  if (value === void 0) {
297912
298329
  return null;
297913
298330
  }
297914
- if (!isPlainObject2(value) || typeof value.$type !== "string" || value.$type === "") {
298331
+ if (!isPlainObject(value) || typeof value.$type !== "string" || value.$type === "") {
297915
298332
  throw new SourceError(
297916
298333
  `"${key}" of field "${fieldKey}" must be a resolver: { $type: '<task>', $value: {...} }`,
297917
298334
  optionNode(builder2, key)
@@ -297951,7 +298368,7 @@ function checkValue(entry, value, describe, node) {
297951
298368
  }
297952
298369
  }
297953
298370
  function checkUiSettings(ui, typeCatalog, describe, nodeAt) {
297954
- if (!isPlainObject2(ui)) {
298371
+ if (!isPlainObject(ui)) {
297955
298372
  throw new SourceError(`${describe}.ui must be an object`, nodeAt());
297956
298373
  }
297957
298374
  for (const [key, value] of Object.entries(ui)) {
@@ -297967,7 +298384,7 @@ function checkUiSettings(ui, typeCatalog, describe, nodeAt) {
297967
298384
  }
297968
298385
  function selectOptions(options2, fieldKey, node) {
297969
298386
  if (!Array.isArray(options2) || options2.length === 0 || options2.some(
297970
- (option) => !isPlainObject2(option) || typeof option.label !== "string" || typeof option.value !== "string" || Object.keys(option).some((key) => !OPTION_KEYS.has(key)) || option.color !== void 0 && option.color !== null && typeof option.color !== "string"
298387
+ (option) => !isPlainObject(option) || typeof option.label !== "string" || typeof option.value !== "string" || Object.keys(option).some((key) => !OPTION_KEYS.has(key)) || option.color !== void 0 && option.color !== null && typeof option.color !== "string"
297971
298388
  )) {
297972
298389
  throw new SourceError(
297973
298390
  `field.select "${fieldKey}" needs "options": [{ label, value, color? }] with string labels and values`,
@@ -297989,7 +298406,7 @@ function checkInverse(inverse, fieldKey, relationSettings2, nodeAt) {
297989
298406
  if (inverse === null) {
297990
298407
  return;
297991
298408
  }
297992
- if (!isPlainObject2(inverse)) {
298409
+ if (!isPlainObject(inverse)) {
297993
298410
  throw new SourceError(`settings.inverse of field "${fieldKey}" must be an object`, nodeAt());
297994
298411
  }
297995
298412
  for (const key of Object.keys(inverse)) {
@@ -298018,7 +298435,7 @@ function checkInverse(inverse, fieldKey, relationSettings2, nodeAt) {
298018
298435
  if (inverse.settings === void 0) {
298019
298436
  return;
298020
298437
  }
298021
- if (!isPlainObject2(inverse.settings)) {
298438
+ if (!isPlainObject(inverse.settings)) {
298022
298439
  throw new SourceError(
298023
298440
  `settings.inverse.settings of field "${fieldKey}" must be an object`,
298024
298441
  nodeAt("settings")
@@ -298051,7 +298468,7 @@ function buildSettings(key, builder2, entry, typeCatalog) {
298051
298468
  const shorthandFor = Object.fromEntries(
298052
298469
  Object.entries(entry.shorthands).map(([option, setting]) => [setting, option])
298053
298470
  );
298054
- if (!isPlainObject2(authored)) {
298471
+ if (!isPlainObject(authored)) {
298055
298472
  throw new SourceError(`"settings" of field "${key}" must be an object`, nodeAt());
298056
298473
  }
298057
298474
  for (const [setting, value] of Object.entries(authored)) {
@@ -298238,7 +298655,7 @@ function buildField(key, builder2, keyNode) {
298238
298655
  return relationNode === null ? field2 : { ...field2, relationNode };
298239
298656
  }
298240
298657
 
298241
- // scripts/lib/runtime-build/resources.mjs
298658
+ // scripts/lib/runtime-build/policies.mjs
298242
298659
  var POLICY_SCOPES = [
298243
298660
  "index",
298244
298661
  "show",
@@ -298252,35 +298669,200 @@ var POLICY_SCOPES = [
298252
298669
  "validate"
298253
298670
  ];
298254
298671
  var POLICY_ACCESS = /* @__PURE__ */ new Set(["public", "protected"]);
298255
- var RESOURCE_KEYS = /* @__PURE__ */ new Set([
298672
+ var POLICY_KEYS = /* @__PURE__ */ new Set([
298256
298673
  "name",
298257
- "singularName",
298258
- "displayField",
298259
- "searchableFields",
298260
- "fieldOrder",
298261
- "fields",
298262
- "indexes",
298263
- "embeddings",
298264
- "dataApi",
298265
- "static",
298266
- "policies",
298267
- "capabilities"
298674
+ "scope",
298675
+ "access",
298676
+ "description",
298677
+ "enabled",
298678
+ "resource",
298679
+ "authorizer",
298680
+ "filter",
298681
+ "fields"
298268
298682
  ]);
298269
- var INDEX_KEYS = /* @__PURE__ */ new Set(["fields", "unique"]);
298270
- var EMBEDDINGS_KEYS = /* @__PURE__ */ new Set(["enabled", "fields"]);
298271
- var DEFAULT_SEARCHABLE_TYPES = /* @__PURE__ */ new Set(["text", "markdown"]);
298272
- function requireString(value, key, node, { optional = false } = {}) {
298273
- const item = value[key];
298274
- if (item === void 0 || item === null) {
298275
- if (optional) {
298276
- return null;
298683
+ var PUBLIC_REFUSED_KEYS = ["resource", "authorizer"];
298684
+ var GROUP_OPERATORS = /* @__PURE__ */ new Set(["and", "or", "nor"]);
298685
+ var GROUP_KEYS = /* @__PURE__ */ new Set(["operator", "conditions"]);
298686
+ var CONDITION_KEYS = /* @__PURE__ */ new Set(["field", "operator", "value", "case_insensitive"]);
298687
+ var FILTER_OPERATORS = new Set(FIELD_CATALOG.filter_operators);
298688
+ function isResolver(value) {
298689
+ return isPlainObject(value) && typeof value.$type === "string" && value.$type !== "";
298690
+ }
298691
+ function buildScope(policy, label, node) {
298692
+ if (policy.scope === "all") {
298693
+ return [...POLICY_SCOPES];
298694
+ }
298695
+ if (Array.isArray(policy.scope) && policy.scope.length > 0 && policy.scope.every((item) => POLICY_SCOPES.includes(item))) {
298696
+ return [...new Set(policy.scope)];
298697
+ }
298698
+ throw new SourceError(
298699
+ `${label} scope must be "all" or a list of: ${POLICY_SCOPES.join(", ")}`,
298700
+ propertyNode(node, "scope")
298701
+ );
298702
+ }
298703
+ function checkFilterGroup(group, path, node) {
298704
+ if (!isPlainObject(group)) {
298705
+ throw new SourceError(`${path} must be { operator, conditions }`, node);
298706
+ }
298707
+ for (const key of Object.keys(group)) {
298708
+ if (!GROUP_KEYS.has(key)) {
298709
+ throw new SourceError(
298710
+ `${path} has an unknown option "${key}". Use operator or conditions`,
298711
+ propertyNode(node, key)
298712
+ );
298277
298713
  }
298278
- throw new SourceError(`"${key}" is required`, node);
298279
298714
  }
298280
- if (typeof item !== "string" || item === "") {
298281
- throw new SourceError(`"${key}" must be a non-empty string`, node);
298715
+ if (!GROUP_OPERATORS.has(group.operator)) {
298716
+ throw new SourceError(
298717
+ `${path}.operator must be "and", "or", or "nor"`,
298718
+ propertyNode(node, "operator")
298719
+ );
298282
298720
  }
298283
- return item;
298721
+ const conditionsNode = propertyNode(node, "conditions");
298722
+ if (!Array.isArray(group.conditions) || group.conditions.length === 0) {
298723
+ throw new SourceError(`${path}.conditions must be a non-empty list`, conditionsNode);
298724
+ }
298725
+ group.conditions.forEach((condition, position2) => {
298726
+ const conditionPath = `${path}.conditions[${position2}]`;
298727
+ const conditionNode = elementNode(conditionsNode, position2);
298728
+ if (isPlainObject(condition) && Object.hasOwn(condition, "conditions")) {
298729
+ checkFilterGroup(condition, conditionPath, conditionNode);
298730
+ return;
298731
+ }
298732
+ checkFilterCondition(condition, conditionPath, conditionNode);
298733
+ });
298734
+ }
298735
+ function checkFilterCondition(condition, path, node) {
298736
+ if (!isPlainObject(condition)) {
298737
+ throw new SourceError(`${path} must be { field, operator, value } or a nested group`, node);
298738
+ }
298739
+ for (const key of Object.keys(condition)) {
298740
+ if (!CONDITION_KEYS.has(key)) {
298741
+ throw new SourceError(
298742
+ `${path} has an unknown option "${key}". Use field, operator, value, or case_insensitive`,
298743
+ propertyNode(node, key)
298744
+ );
298745
+ }
298746
+ }
298747
+ if (typeof condition.field !== "string" || condition.field === "") {
298748
+ throw new SourceError(`${path}.field must be a field key or path`, propertyNode(node, "field"));
298749
+ }
298750
+ if (!FILTER_OPERATORS.has(condition.operator)) {
298751
+ throw new SourceError(
298752
+ `${path}.operator must be one of: ${FIELD_CATALOG.filter_operators.join(", ")}`,
298753
+ propertyNode(node, "operator")
298754
+ );
298755
+ }
298756
+ if (condition.case_insensitive !== void 0 && typeof condition.case_insensitive !== "boolean") {
298757
+ throw new SourceError(
298758
+ `${path}.case_insensitive must be true or false`,
298759
+ propertyNode(node, "case_insensitive")
298760
+ );
298761
+ }
298762
+ }
298763
+ function buildFilter(policy, key, label, node) {
298764
+ const value = policy[key];
298765
+ if (value === void 0 || value === null) {
298766
+ return null;
298767
+ }
298768
+ checkFilterGroup(value, `${label} ${key}`, propertyNode(node, key));
298769
+ return value;
298770
+ }
298771
+ function buildFields(policy, label, node) {
298772
+ if (policy.fields === void 0 || policy.fields === null) {
298773
+ return null;
298774
+ }
298775
+ const fieldsNode = propertyNode(node, "fields");
298776
+ if (!Array.isArray(policy.fields)) {
298777
+ throw new SourceError(
298778
+ `${label} fields must be a list of field keys or { key, condition }`,
298779
+ fieldsNode
298780
+ );
298781
+ }
298782
+ const seen = /* @__PURE__ */ new Set();
298783
+ return policy.fields.map((item, position2) => {
298784
+ const itemNode = elementNode(fieldsNode, position2);
298785
+ const rule = typeof item === "string" ? { key: item } : item;
298786
+ if (!isPlainObject(rule) || typeof rule.key !== "string" || rule.key === "" || Object.keys(rule).some((key) => key !== "key" && key !== "condition")) {
298787
+ throw new SourceError(
298788
+ `${label} fields must be a list of field keys or { key, condition }`,
298789
+ itemNode
298790
+ );
298791
+ }
298792
+ if (rule.condition !== void 0 && rule.condition !== null && !isResolver(rule.condition)) {
298793
+ throw new SourceError(
298794
+ `${label} field "${rule.key}" condition must be a resolver, for example { $type: 'user.current' }`,
298795
+ itemNode
298796
+ );
298797
+ }
298798
+ if (seen.has(rule.key)) {
298799
+ throw new SourceError(`${label} fields list "${rule.key}" twice`, itemNode);
298800
+ }
298801
+ seen.add(rule.key);
298802
+ return rule.condition === void 0 || rule.condition === null ? { key: rule.key } : { key: rule.key, condition: rule.condition };
298803
+ });
298804
+ }
298805
+ function buildPolicy(policy, node) {
298806
+ if (!isPlainObject(policy)) {
298807
+ throw new SourceError("Each policy must be an object", node);
298808
+ }
298809
+ const name = requireString(policy, "name", propertyNode(node, "name"));
298810
+ const label = `Policy "${name}"`;
298811
+ for (const key of Object.keys(policy)) {
298812
+ if (!POLICY_KEYS.has(key)) {
298813
+ throw new SourceError(
298814
+ `${label} has an unknown option "${key}". Use ${[...POLICY_KEYS].join(", ")}`,
298815
+ propertyNode(node, key)
298816
+ );
298817
+ }
298818
+ }
298819
+ const access = policy.access ?? "protected";
298820
+ if (!POLICY_ACCESS.has(access)) {
298821
+ throw new SourceError(
298822
+ `${label} access must be "public" or "protected"`,
298823
+ propertyNode(node, "access")
298824
+ );
298825
+ }
298826
+ if (access === "public") {
298827
+ const refused = PUBLIC_REFUSED_KEYS.find(
298828
+ (key) => policy[key] !== void 0 && policy[key] !== null
298829
+ );
298830
+ if (refused !== void 0) {
298831
+ throw new SourceError(
298832
+ `${label} is public, so it cannot set "${refused}". Remove it, or make the policy protected`,
298833
+ propertyNode(node, refused)
298834
+ );
298835
+ }
298836
+ }
298837
+ const description = policy.description ?? null;
298838
+ if (description !== null && typeof description !== "string") {
298839
+ throw new SourceError(
298840
+ `${label} description must be a string`,
298841
+ propertyNode(node, "description")
298842
+ );
298843
+ }
298844
+ if (policy.enabled !== void 0 && typeof policy.enabled !== "boolean") {
298845
+ throw new SourceError(`${label} enabled must be true or false`, propertyNode(node, "enabled"));
298846
+ }
298847
+ const resource = policy.resource ?? null;
298848
+ if (resource !== null && (typeof resource !== "string" || resource === "")) {
298849
+ throw new SourceError(
298850
+ `${label} resource must be Resources.<Name>.slug`,
298851
+ propertyNode(node, "resource")
298852
+ );
298853
+ }
298854
+ return {
298855
+ name,
298856
+ scope: buildScope(policy, label, node),
298857
+ access,
298858
+ description,
298859
+ enabled: policy.enabled ?? true,
298860
+ resource,
298861
+ authorizer: buildFilter(policy, "authorizer", label, node),
298862
+ filter: buildFilter(policy, "filter", label, node),
298863
+ fields: buildFields(policy, label, node),
298864
+ resourceNode: resource === null ? void 0 : propertyNode(node, "resource")
298865
+ };
298284
298866
  }
298285
298867
  function buildPolicies(policies, node) {
298286
298868
  if (policies === void 0) {
@@ -298289,37 +298871,68 @@ function buildPolicies(policies, node) {
298289
298871
  if (!Array.isArray(policies)) {
298290
298872
  throw new SourceError('"policies" must be an array', node);
298291
298873
  }
298874
+ const names2 = /* @__PURE__ */ new Set();
298292
298875
  return policies.map((policy, position2) => {
298293
- const elementNode3 = node.value.elements?.[position2] ?? node;
298294
- if (policy === null || typeof policy !== "object" || Array.isArray(policy)) {
298295
- throw new SourceError("Each policy must be an object", elementNode3);
298296
- }
298297
- const name = requireString(policy, "name", elementNode3);
298298
- const access = requireString(policy, "access", elementNode3);
298299
- if (!POLICY_ACCESS.has(access)) {
298300
- throw new SourceError(`Policy "${name}" access must be "public" or "protected"`, elementNode3);
298301
- }
298302
- let scope2;
298303
- if (policy.scope === "all") {
298304
- scope2 = [...POLICY_SCOPES];
298305
- } else if (Array.isArray(policy.scope) && policy.scope.length > 0 && policy.scope.every((item) => POLICY_SCOPES.includes(item))) {
298306
- scope2 = [...new Set(policy.scope)];
298307
- } else {
298308
- throw new SourceError(
298309
- `Policy "${name}" scope must be "all" or a list of: ${POLICY_SCOPES.join(", ")}`,
298310
- elementNode3
298311
- );
298312
- }
298313
- const description = policy.description ?? null;
298314
- if (description !== null && typeof description !== "string") {
298315
- throw new SourceError(`Policy "${name}" description must be a string`, elementNode3);
298876
+ const policyNode = elementNode(node, position2);
298877
+ const built = buildPolicy(policy, policyNode);
298878
+ if (names2.has(built.name)) {
298879
+ throw new SourceError(`Two policies are named "${built.name}"`, policyNode);
298316
298880
  }
298317
- return { name, scope: scope2, access, description };
298881
+ names2.add(built.name);
298882
+ return built;
298318
298883
  });
298319
298884
  }
298320
- function elementNode2(node, position2) {
298321
- return node?.value?.elements?.[position2] ?? node;
298885
+ function checkPolicyResources(resources, platformSlugs, names2, diagnostics) {
298886
+ const resourcesBySlug = new Map(resources.map((resource) => [resource.slug, resource]));
298887
+ for (const resource of resources) {
298888
+ for (const policy of resource.policies) {
298889
+ if (policy.resource === null || platformSlugs.has(policy.resource)) {
298890
+ continue;
298891
+ }
298892
+ const target = resourcesBySlug.get(policy.resource);
298893
+ const label = `Policy "${policy.name}" resource`;
298894
+ if (target === void 0) {
298895
+ diagnostics.push(
298896
+ diagnosticAt(
298897
+ resource.path,
298898
+ policy.resourceNode,
298899
+ `${label}: ${referenceProblem(policy.resource, resources, names2).message}`
298900
+ )
298901
+ );
298902
+ continue;
298903
+ }
298904
+ if (!Object.hasOwn(target.capabilities, "authenticatable")) {
298905
+ diagnostics.push(
298906
+ diagnosticAt(
298907
+ resource.path,
298908
+ policy.resourceNode,
298909
+ `${label}: "${policy.resource}" does not declare the authenticatable capability, so no member signs in as it`
298910
+ )
298911
+ );
298912
+ }
298913
+ }
298914
+ }
298322
298915
  }
298916
+
298917
+ // scripts/lib/runtime-build/resources.mjs
298918
+ init_define_globalThis_DIAGONAL_SDK_RUNTIME();
298919
+ var RESOURCE_KEYS = /* @__PURE__ */ new Set([
298920
+ "name",
298921
+ "singularName",
298922
+ "displayField",
298923
+ "searchableFields",
298924
+ "fieldOrder",
298925
+ "fields",
298926
+ "indexes",
298927
+ "embeddings",
298928
+ "dataApi",
298929
+ "static",
298930
+ "policies",
298931
+ "capabilities"
298932
+ ]);
298933
+ var INDEX_KEYS = /* @__PURE__ */ new Set(["fields", "unique"]);
298934
+ var EMBEDDINGS_KEYS = /* @__PURE__ */ new Set(["enabled", "fields"]);
298935
+ var DEFAULT_SEARCHABLE_TYPES = /* @__PURE__ */ new Set(["text", "markdown"]);
298323
298936
  function stringList(value, key, node) {
298324
298937
  if (!Array.isArray(value)) {
298325
298938
  throw new SourceError(`"${key}" must be a list of strings`, node);
@@ -298327,10 +298940,10 @@ function stringList(value, key, node) {
298327
298940
  const seen = /* @__PURE__ */ new Set();
298328
298941
  value.forEach((item, position2) => {
298329
298942
  if (typeof item !== "string" || item === "") {
298330
- throw new SourceError(`"${key}" must be a list of strings`, elementNode2(node, position2));
298943
+ throw new SourceError(`"${key}" must be a list of strings`, elementNode(node, position2));
298331
298944
  }
298332
298945
  if (seen.has(item)) {
298333
- throw new SourceError(`"${key}" lists "${item}" twice`, elementNode2(node, position2));
298946
+ throw new SourceError(`"${key}" lists "${item}" twice`, elementNode(node, position2));
298334
298947
  }
298335
298948
  seen.add(item);
298336
298949
  });
@@ -298345,7 +298958,7 @@ function buildIndexes(indexes, node, fieldsByKey) {
298345
298958
  }
298346
298959
  const patterns = /* @__PURE__ */ new Set();
298347
298960
  return indexes.map((index3, position2) => {
298348
- const indexNode = elementNode2(node, position2);
298961
+ const indexNode = elementNode(node, position2);
298349
298962
  if (index3 === null || typeof index3 !== "object" || Array.isArray(index3) || !Array.isArray(index3.fields) || index3.fields.length === 0) {
298350
298963
  throw new SourceError("Each index must be { fields: [...], unique?: boolean }", indexNode);
298351
298964
  }
@@ -298385,7 +298998,7 @@ function orderFields(fields, fieldOrder, node) {
298385
298998
  if (!fieldsByKey.has(key)) {
298386
298999
  throw new SourceError(
298387
299000
  `fieldOrder names "${key}", which is not a field of this resource`,
298388
- elementNode2(node, position2)
299001
+ elementNode(node, position2)
298389
299002
  );
298390
299003
  }
298391
299004
  });
@@ -298659,23 +299272,27 @@ function checkFieldPaths(resources, diagnostics) {
298659
299272
  }
298660
299273
  function withoutBuildNodes(resource) {
298661
299274
  const { pathNodes: _pathNodes, ...rest } = resource;
298662
- return { ...rest, fields: rest.fields.map(({ relationNode: _relationNode, ...field2 }) => field2) };
299275
+ return {
299276
+ ...rest,
299277
+ fields: rest.fields.map(({ relationNode: _relationNode, ...field2 }) => field2),
299278
+ policies: rest.policies.map(({ resourceNode: _resourceNode, ...policy }) => policy)
299279
+ };
298663
299280
  }
298664
299281
 
298665
299282
  // scripts/lib/runtime-build/sdk-packages.mjs
298666
299283
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
298667
- import { existsSync as existsSync3, readFileSync as readFileSync3 } from "node:fs";
298668
- import { join as join5 } from "node:path";
299284
+ import { existsSync as existsSync3, readFileSync as readFileSync4 } from "node:fs";
299285
+ import { join as join6 } from "node:path";
298669
299286
  var DIAGONAL_PACKAGE = /^@diagonal(-hq)?\//;
298670
299287
  var TARBALL_VERSION = /-(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)\.tgz$/;
298671
299288
  var EXACT_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
298672
299289
  function readPackageFiles(root, diagnostics) {
298673
299290
  const read = (path) => {
298674
- if (!existsSync3(join5(root, path))) {
299291
+ if (!existsSync3(join6(root, path))) {
298675
299292
  return null;
298676
299293
  }
298677
299294
  try {
298678
- return JSON.parse(readFileSync3(join5(root, path), "utf8"));
299295
+ return JSON.parse(readFileSync4(join6(root, path), "utf8"));
298679
299296
  } catch (error) {
298680
299297
  if (!(error instanceof SyntaxError)) {
298681
299298
  throw error;
@@ -298867,8 +299484,8 @@ init_define_globalThis_DIAGONAL_SDK_RUNTIME();
298867
299484
  // scripts/lib/runtime-build/app-modules.mjs
298868
299485
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
298869
299486
  var import_sucrase2 = __toESM(require_dist2(), 1);
298870
- import { readFileSync as readFileSync4 } from "node:fs";
298871
- import { join as join6 } from "node:path";
299487
+ import { readFileSync as readFileSync5 } from "node:fs";
299488
+ import { join as join7 } from "node:path";
298872
299489
 
298873
299490
  // packages/cli/index.js
298874
299491
  var cli_exports = {};
@@ -299020,7 +299637,7 @@ function appModuleClosure(root, imports, external = /* @__PURE__ */ new Set(), {
299020
299637
  if (modules.has(path)) {
299021
299638
  continue;
299022
299639
  }
299023
- const read = readFileSync4(join6(root, path), "utf8");
299640
+ const read = readFileSync5(join7(root, path), "utf8");
299024
299641
  const source = transform3 === null ? read : transform3(path, read);
299025
299642
  const ast = parseModule(path, source);
299026
299643
  const requires = {};
@@ -299671,34 +300288,34 @@ function pageKeyOf(path, ast) {
299671
300288
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
299672
300289
  var import_typescript2 = __toESM(require_typescript(), 1);
299673
300290
  import { spawnSync } from "node:child_process";
299674
- import { mkdirSync, mkdtempSync, realpathSync as realpathSync2, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
300291
+ import { mkdirSync, mkdtempSync, realpathSync as realpathSync2, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
299675
300292
  import { tmpdir } from "node:os";
299676
- import { dirname as dirname4, join as join8, relative as relative3 } from "node:path";
300293
+ import { dirname as dirname4, join as join9, relative as relative3 } from "node:path";
299677
300294
 
299678
300295
  // scripts/lib/runtime-build/script-sdk.mjs
299679
300296
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
299680
- import { readFileSync as readFileSync5, readdirSync as readdirSync2, statSync as statSync2 } from "node:fs";
300297
+ import { readFileSync as readFileSync6, readdirSync as readdirSync2, statSync as statSync3 } from "node:fs";
299681
300298
  import { createRequire } from "node:module";
299682
- import { dirname as dirname3, join as join7, relative as relative2, resolve as resolve3 } from "node:path";
300299
+ import { dirname as dirname3, join as join8, relative as relative2, resolve as resolve4 } from "node:path";
299683
300300
  import { fileURLToPath } from "node:url";
299684
- var SCRIPT_SDK_ROOT = resolve3(
300301
+ var SCRIPT_SDK_ROOT = resolve4(
299685
300302
  dirname3(fileURLToPath(import.meta.url)),
299686
300303
  "../../../packages/workflows/src"
299687
300304
  );
299688
300305
  var SDK_RUNTIME_ENTRY_POINTS = {
299689
- workflow: join7(SCRIPT_SDK_ROOT, "index.ts"),
299690
- testing: join7(SCRIPT_SDK_ROOT, "testing/index.ts")
300306
+ workflow: join8(SCRIPT_SDK_ROOT, "index.ts"),
300307
+ testing: join8(SCRIPT_SDK_ROOT, "testing/index.ts")
299691
300308
  };
299692
300309
  function walk(directory) {
299693
300310
  return readdirSync2(directory).flatMap(
299694
- (name) => statSync2(join7(directory, name)).isDirectory() ? walk(join7(directory, name)) : [join7(directory, name)]
300311
+ (name) => statSync3(join8(directory, name)).isDirectory() ? walk(join8(directory, name)) : [join8(directory, name)]
299695
300312
  );
299696
300313
  }
299697
300314
  function readSandboxSdkFiles() {
299698
300315
  return Object.fromEntries(
299699
300316
  walk(SCRIPT_SDK_ROOT).filter(
299700
300317
  (file2) => file2.endsWith(".ts") && !file2.includes("/testing/") && !file2.endsWith("/http-transport.ts") && !file2.endsWith("/workspace.generated.ts")
299701
- ).map((file2) => [`/sdk/${relative2(SCRIPT_SDK_ROOT, file2)}`, readFileSync5(file2, "utf8")])
300318
+ ).map((file2) => [`/sdk/${relative2(SCRIPT_SDK_ROOT, file2)}`, readFileSync6(file2, "utf8")])
299702
300319
  );
299703
300320
  }
299704
300321
  function bundleSdkRuntime(buildSync) {
@@ -299846,8 +300463,8 @@ function relativeSandboxPath(from, target) {
299846
300463
  return path.startsWith(".") ? path : `./${path}`;
299847
300464
  }
299848
300465
  function writeFile(root, path, content) {
299849
- mkdirSync(dirname4(join8(root, path)), { recursive: true });
299850
- writeFileSync2(join8(root, path), content);
300466
+ mkdirSync(dirname4(join9(root, path)), { recursive: true });
300467
+ writeFileSync3(join9(root, path), content);
299851
300468
  }
299852
300469
  function parseResults(stdout) {
299853
300470
  return stdout.split("\n").filter((line) => line.startsWith(RESULT_PREFIX)).map((line) => JSON.parse(line.slice(RESULT_PREFIX.length)));
@@ -299895,7 +300512,7 @@ function runWorkflowTests({
299895
300512
  modules.set(path, module);
299896
300513
  }
299897
300514
  }
299898
- const root = realpathSync2(mkdtempSync(join8(tmpdir(), "diagonal-workflow-tests-")));
300515
+ const root = realpathSync2(mkdtempSync(join9(tmpdir(), "diagonal-workflow-tests-")));
299899
300516
  try {
299900
300517
  writeFile(root, "package.json", '{"type":"module"}\n');
299901
300518
  writeFile(root, "reporter.mjs", REPORTER_SOURCE);
@@ -299967,7 +300584,7 @@ function runWorkflowTests({
299967
300584
  const results = parseResults(run.stdout ?? "");
299968
300585
  const timedOut = run.error?.code === "ETIMEDOUT" || run.signal !== null;
299969
300586
  const workflowTests = runnable.map((test) => {
299970
- const file2 = join8(root, test.path.replace(/\.ts$/, ".js"));
300587
+ const file2 = join9(root, test.path.replace(/\.ts$/, ".js"));
299971
300588
  const own = results.filter((result) => result.file === file2);
299972
300589
  for (const result of own) {
299973
300590
  if (!result.ok) {
@@ -300315,9 +300932,9 @@ function literal(node) {
300315
300932
 
300316
300933
  // scripts/lib/workflow-script/lib-files.mjs
300317
300934
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
300318
- import { readFileSync as readFileSync6 } from "node:fs";
300935
+ import { readFileSync as readFileSync7 } from "node:fs";
300319
300936
  import { createRequire as createRequire2 } from "node:module";
300320
- import { dirname as dirname5, join as join9 } from "node:path";
300937
+ import { dirname as dirname5, join as join10 } from "node:path";
300321
300938
  var ROOT_LIB = "lib.es2023.d.ts";
300322
300939
  function libClosure(read, root = ROOT_LIB) {
300323
300940
  const files = {};
@@ -300336,7 +300953,7 @@ function libClosure(read, root = ROOT_LIB) {
300336
300953
  }
300337
300954
  function readLibClosure(root = ROOT_LIB) {
300338
300955
  const libDir = dirname5(createRequire2(import.meta.url).resolve("typescript/lib/lib.d.ts"));
300339
- return libClosure((name) => readFileSync6(join9(libDir, name), "utf8"), root);
300956
+ return libClosure((name) => readFileSync7(join10(libDir, name), "utf8"), root);
300340
300957
  }
300341
300958
 
300342
300959
  // scripts/lib/workflow-script/lint-rules.mjs
@@ -300956,9 +301573,6 @@ function propertyNodes(node) {
300956
301573
  }
300957
301574
  return nodes;
300958
301575
  }
300959
- function isPlainObject3(value) {
300960
- return value !== null && typeof value === "object" && !Array.isArray(value);
300961
- }
300962
301576
  function listOf(values) {
300963
301577
  return values.map((value) => `'${value}'`).join(", ");
300964
301578
  }
@@ -301058,7 +301672,7 @@ function readWorkflowConfig(path, configNode, context) {
301058
301672
  report(error.node, error.message);
301059
301673
  return { config: null, diagnostics };
301060
301674
  }
301061
- if (!isPlainObject3(value)) {
301675
+ if (!isPlainObject(value)) {
301062
301676
  report(configNode, "The config must be an object literal");
301063
301677
  return { config: null, diagnostics };
301064
301678
  }
@@ -301120,7 +301734,7 @@ function oneOf(trigger, key, allowed, at, report) {
301120
301734
  return item;
301121
301735
  }
301122
301736
  function readTrigger(trigger, triggerNode, context, report) {
301123
- if (!isPlainObject3(trigger)) {
301737
+ if (!isPlainObject(trigger)) {
301124
301738
  report(triggerNode, `"trigger" is required: { type: ${listOf(Object.keys(TRIGGERS))}, ... }`);
301125
301739
  return null;
301126
301740
  }
@@ -301293,7 +301907,7 @@ function readRunAs(runAs, node, trigger, context, report) {
301293
301907
  }
301294
301908
  return { mode: "session" };
301295
301909
  }
301296
- if (!isPlainObject3(runAs)) {
301910
+ if (!isPlainObject(runAs)) {
301297
301911
  report(node, "runAs must be 'system', 'session', or { resource, record }");
301298
301912
  return null;
301299
301913
  }
@@ -301602,10 +302216,10 @@ function listFiles(root) {
301602
302216
  }
301603
302217
  if (entry.isDirectory()) {
301604
302218
  if (!IGNORED_DIRECTORIES.has(entry.name)) {
301605
- pending.push(join10(directory, entry.name));
302219
+ pending.push(join11(directory, entry.name));
301606
302220
  }
301607
302221
  } else if (entry.isFile()) {
301608
- files.push(relative4(root, join10(directory, entry.name)).split(sep).join("/"));
302222
+ files.push(relative4(root, join11(directory, entry.name)).split(sep).join("/"));
301609
302223
  }
301610
302224
  }
301611
302225
  }
@@ -301619,7 +302233,7 @@ function isDirectChild(path, directory) {
301619
302233
  return path.startsWith(`${directory}/`) && !path.slice(directory.length + 1).includes("/");
301620
302234
  }
301621
302235
  function stem(path) {
301622
- return basename3(path, extname2(path));
302236
+ return basename4(path, extname2(path));
301623
302237
  }
301624
302238
  function buildConfig(source, ast) {
301625
302239
  const { declaration } = defaultExportOf(ast);
@@ -301802,16 +302416,16 @@ function checkPageResources(pages, resources, platformSlugs, names2, diagnostics
301802
302416
  }
301803
302417
  }
301804
302418
  function writeGeneratedResources(root, names2, resources) {
301805
- const path = join10(root, GENERATED_RESOURCES_PATH);
302419
+ const path = join11(root, GENERATED_RESOURCES_PATH);
301806
302420
  if (names2.slugsByName.size === 0 && !existsSync4(path)) {
301807
302421
  return;
301808
302422
  }
301809
302423
  const source = generatedResourcesSource(names2, resources);
301810
- if (existsSync4(path) && readFileSync7(path, "utf8") === source) {
302424
+ if (existsSync4(path) && readFileSync8(path, "utf8") === source) {
301811
302425
  return;
301812
302426
  }
301813
302427
  mkdirSync2(dirname6(path), { recursive: true });
301814
- writeFileSync3(path, source);
302428
+ writeFileSync4(path, source);
301815
302429
  }
301816
302430
  function lintUnits(units, resources, components, pages, diagnostics) {
301817
302431
  const catalogs = {
@@ -301876,7 +302490,7 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
301876
302490
  );
301877
302491
  return;
301878
302492
  }
301879
- const source = readFileSync7(join10(root, path), "utf8");
302493
+ const source = readFileSync8(join11(root, path), "utf8");
301880
302494
  if (kind === "skill") {
301881
302495
  skillFiles.push({ path, content: source });
301882
302496
  return;
@@ -301954,6 +302568,7 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
301954
302568
  addInverseFields(output.resources, diagnostics);
301955
302569
  checkFieldPaths(output.resources, diagnostics);
301956
302570
  checkCapabilities(output.resources, platformSlugs, diagnostics);
302571
+ checkPolicyResources(output.resources, platformSlugs, names2, diagnostics);
301957
302572
  }
301958
302573
  output.resources = output.resources.map(withoutBuildNodes);
301959
302574
  writeGeneratedResources(root, names2, [...output.resources, ...output.platform_resources]);
@@ -302079,17 +302694,13 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false } = {})
302079
302694
 
302080
302695
  // scripts/lib/runtime-build/check-cli.mjs
302081
302696
  var CHECK_USAGE = "Usage: diagonal check [dir] [--json]";
302082
- var USAGE = [CHECK_USAGE, WORKFLOWS_USAGE, RUN_USAGE].join("\n");
302083
- function formatDiagnostic(diagnostic2) {
302084
- const [headline, ...details] = diagnostic2.message.split("\n");
302085
- const lines = [
302086
- `${diagnostic2.path}:${diagnostic2.line}:${diagnostic2.column} ${diagnostic2.severity} ${headline}`
302087
- ];
302088
- for (const detail of details) {
302089
- lines.push(` ${detail}`);
302090
- }
302091
- return lines.join("\n");
302092
- }
302697
+ var USAGE = [
302698
+ CHECK_USAGE,
302699
+ WORKFLOWS_USAGE,
302700
+ RUN_USAGE,
302701
+ ASSETS_UPLOAD_USAGE,
302702
+ ASSETS_LIST_USAGE
302703
+ ].join("\n");
302093
302704
  function plural(count, word) {
302094
302705
  return `${count} ${word}${count === 1 ? "" : "s"}`;
302095
302706
  }
@@ -302118,8 +302729,8 @@ ${CHECK_USAGE}
302118
302729
  `);
302119
302730
  return 2;
302120
302731
  }
302121
- const root = resolve4(cwd, parsed.dir);
302122
- if (!statSync3(root, { throwIfNoEntry: false })?.isDirectory()) {
302732
+ const root = resolve5(cwd, parsed.dir);
302733
+ if (!statSync4(root, { throwIfNoEntry: false })?.isDirectory()) {
302123
302734
  stderr.write(`Not a directory: ${root}
302124
302735
  `);
302125
302736
  return 2;
@@ -302148,6 +302759,15 @@ async function main(argv, io) {
302148
302759
  switch (command) {
302149
302760
  case "check":
302150
302761
  return check(args, io);
302762
+ case "assets": {
302763
+ const [subcommand, ...assetArgs] = args;
302764
+ if (subcommand === "upload") return uploadAsset(assetArgs, io);
302765
+ if (subcommand === "list") return listAssets(assetArgs, io);
302766
+ io.stderr.write(`${ASSETS_UPLOAD_USAGE}
302767
+ ${ASSETS_LIST_USAGE}
302768
+ `);
302769
+ return 2;
302770
+ }
302151
302771
  case "workflows":
302152
302772
  return listWorkflows(args, io);
302153
302773
  case "run":