@diagonal-hq/cli 0.32.2 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -8983,7 +8983,7 @@ var require_typescript = __commonJS({
8983
8983
  isCommaListExpression: () => isCommaListExpression,
8984
8984
  isCommaSequence: () => isCommaSequence,
8985
8985
  isCommaToken: () => isCommaToken,
8986
- isComment: () => isComment2,
8986
+ isComment: () => isComment,
8987
8987
  isCommonJsExportPropertyAssignment: () => isCommonJsExportPropertyAssignment,
8988
8988
  isCommonJsExportedExpression: () => isCommonJsExportedExpression,
8989
8989
  isCompoundAssignment: () => isCompoundAssignment,
@@ -19719,7 +19719,7 @@ ${lanes.join("\n")}
19719
19719
  function computeLineStarts(text2) {
19720
19720
  const result = [];
19721
19721
  let pos = 0;
19722
- let lineStart2 = 0;
19722
+ let lineStart = 0;
19723
19723
  while (pos < text2.length) {
19724
19724
  const ch = text2.charCodeAt(pos);
19725
19725
  pos++;
@@ -19730,18 +19730,18 @@ ${lanes.join("\n")}
19730
19730
  }
19731
19731
  // falls through
19732
19732
  case 10:
19733
- result.push(lineStart2);
19734
- lineStart2 = pos;
19733
+ result.push(lineStart);
19734
+ lineStart = pos;
19735
19735
  break;
19736
19736
  default:
19737
19737
  if (ch > 127 && isLineBreak(ch)) {
19738
- result.push(lineStart2);
19739
- lineStart2 = pos;
19738
+ result.push(lineStart);
19739
+ lineStart = pos;
19740
19740
  }
19741
19741
  break;
19742
19742
  }
19743
19743
  }
19744
- result.push(lineStart2);
19744
+ result.push(lineStart);
19745
19745
  return result;
19746
19746
  }
19747
19747
  function getPositionOfLineAndCharacter(sourceFile, line, character, allowEdits) {
@@ -22412,7 +22412,7 @@ ${lanes.join("\n")}
22412
22412
  error2(Diagnostics.This_regular_expression_flag_is_only_available_when_targeting_0_or_later, pos, size, getNameOfScriptTarget(availableFrom));
22413
22413
  }
22414
22414
  }
22415
- function appendIfCommentDirective(commentDirectives2, text22, commentDirectiveRegEx, lineStart2) {
22415
+ function appendIfCommentDirective(commentDirectives2, text22, commentDirectiveRegEx, lineStart) {
22416
22416
  const type = getDirectiveFromComment(text22.trimStart(), commentDirectiveRegEx);
22417
22417
  if (type === void 0) {
22418
22418
  return commentDirectives2;
@@ -22420,7 +22420,7 @@ ${lanes.join("\n")}
22420
22420
  return append(
22421
22421
  commentDirectives2,
22422
22422
  {
22423
- range: { pos: lineStart2, end: pos },
22423
+ range: { pos: lineStart, end: pos },
22424
22424
  type
22425
22425
  }
22426
22426
  );
@@ -28408,7 +28408,7 @@ ${lanes.join("\n")}
28408
28408
  function createTextWriter(newLine) {
28409
28409
  var output;
28410
28410
  var indent3;
28411
- var lineStart2;
28411
+ var lineStart;
28412
28412
  var lineCount;
28413
28413
  var linePos;
28414
28414
  var hasTrailingComment = false;
@@ -28417,16 +28417,16 @@ ${lanes.join("\n")}
28417
28417
  if (lineStartsOfS.length > 1) {
28418
28418
  lineCount = lineCount + lineStartsOfS.length - 1;
28419
28419
  linePos = output.length - s.length + last2(lineStartsOfS);
28420
- lineStart2 = linePos - output.length === 0;
28420
+ lineStart = linePos - output.length === 0;
28421
28421
  } else {
28422
- lineStart2 = false;
28422
+ lineStart = false;
28423
28423
  }
28424
28424
  }
28425
28425
  function writeText(s) {
28426
28426
  if (s && s.length) {
28427
- if (lineStart2) {
28427
+ if (lineStart) {
28428
28428
  s = getIndentString(indent3) + s;
28429
- lineStart2 = false;
28429
+ lineStart = false;
28430
28430
  }
28431
28431
  output += s;
28432
28432
  updateLineCountAndPosFor(s);
@@ -28443,7 +28443,7 @@ ${lanes.join("\n")}
28443
28443
  function reset2() {
28444
28444
  output = "";
28445
28445
  indent3 = 0;
28446
- lineStart2 = true;
28446
+ lineStart = true;
28447
28447
  lineCount = 0;
28448
28448
  linePos = 0;
28449
28449
  hasTrailingComment = false;
@@ -28461,11 +28461,11 @@ ${lanes.join("\n")}
28461
28461
  }
28462
28462
  }
28463
28463
  function writeLine(force) {
28464
- if (!lineStart2 || force) {
28464
+ if (!lineStart || force) {
28465
28465
  output += newLine;
28466
28466
  lineCount++;
28467
28467
  linePos = output.length;
28468
- lineStart2 = true;
28468
+ lineStart = true;
28469
28469
  hasTrailingComment = false;
28470
28470
  }
28471
28471
  }
@@ -28484,9 +28484,9 @@ ${lanes.join("\n")}
28484
28484
  getIndent: () => indent3,
28485
28485
  getTextPos: () => output.length,
28486
28486
  getLine: () => lineCount,
28487
- getColumn: () => lineStart2 ? indent3 * getIndentSize() : output.length - linePos,
28487
+ getColumn: () => lineStart ? indent3 * getIndentSize() : output.length - linePos,
28488
28488
  getText: () => output,
28489
- isAtStartOfLine: () => lineStart2,
28489
+ isAtStartOfLine: () => lineStart,
28490
28490
  hasTrailingComment: () => hasTrailingComment,
28491
28491
  hasTrailingWhitespace: () => !!output.length && isWhiteSpaceLike(output.charCodeAt(output.length - 1)),
28492
28492
  clear: reset2,
@@ -132030,7 +132030,7 @@ ${lanes.join("\n")}
132030
132030
  }
132031
132031
  }
132032
132032
  function createImportCallExpressionAMD(arg, containsLexicalThis) {
132033
- const resolve8 = factory2.createUniqueName("resolve");
132033
+ const resolve7 = factory2.createUniqueName("resolve");
132034
132034
  const reject = factory2.createUniqueName("reject");
132035
132035
  const parameters = [
132036
132036
  factory2.createParameterDeclaration(
@@ -132039,7 +132039,7 @@ ${lanes.join("\n")}
132039
132039
  /*dotDotDotToken*/
132040
132040
  void 0,
132041
132041
  /*name*/
132042
- resolve8
132042
+ resolve7
132043
132043
  ),
132044
132044
  factory2.createParameterDeclaration(
132045
132045
  /*modifiers*/
@@ -132056,7 +132056,7 @@ ${lanes.join("\n")}
132056
132056
  factory2.createIdentifier("require"),
132057
132057
  /*typeArguments*/
132058
132058
  void 0,
132059
- [factory2.createArrayLiteralExpression([arg || factory2.createOmittedExpression()]), resolve8, reject]
132059
+ [factory2.createArrayLiteralExpression([arg || factory2.createOmittedExpression()]), resolve7, reject]
132060
132060
  )
132061
132061
  )
132062
132062
  ]);
@@ -140997,15 +140997,15 @@ ${lanes.join("\n")}
140997
140997
  function emitJsxExpression(node) {
140998
140998
  var _a;
140999
140999
  if (node.expression || !commentsDisabled && !nodeIsSynthesized(node) && hasCommentsAtPosition(node.pos)) {
141000
- const isMultiline2 = currentSourceFile && !nodeIsSynthesized(node) && getLineAndCharacterOfPosition(currentSourceFile, node.pos).line !== getLineAndCharacterOfPosition(currentSourceFile, node.end).line;
141001
- if (isMultiline2) {
141000
+ const isMultiline = currentSourceFile && !nodeIsSynthesized(node) && getLineAndCharacterOfPosition(currentSourceFile, node.pos).line !== getLineAndCharacterOfPosition(currentSourceFile, node.end).line;
141001
+ if (isMultiline) {
141002
141002
  writer.increaseIndent();
141003
141003
  }
141004
141004
  const end = emitTokenWithComment(19, node.pos, writePunctuation, node);
141005
141005
  emit(node.dotDotDotToken);
141006
141006
  emitExpression(node.expression);
141007
141007
  emitTokenWithComment(20, ((_a = node.expression) == null ? void 0 : _a.end) || end, writePunctuation, node);
141008
- if (isMultiline2) {
141008
+ if (isMultiline) {
141009
141009
  writer.decreaseIndent();
141010
141010
  }
141011
141011
  }
@@ -143857,9 +143857,9 @@ ${lanes.join("\n")}
143857
143857
  context += indent3 + formatColorAndReset(ellipsis.padStart(gutterWidth), gutterStyleSequence) + gutterSeparator + host.getNewLine();
143858
143858
  i = lastLine - 1;
143859
143859
  }
143860
- const lineStart2 = getPositionOfLineAndCharacter(file2, i, 0);
143860
+ const lineStart = getPositionOfLineAndCharacter(file2, i, 0);
143861
143861
  const lineEnd = i < lastLineInFile ? getPositionOfLineAndCharacter(file2, i + 1, 0) : file2.text.length;
143862
- let lineContent = file2.text.slice(lineStart2, lineEnd);
143862
+ let lineContent = file2.text.slice(lineStart, lineEnd);
143863
143863
  lineContent = lineContent.trimEnd();
143864
143864
  lineContent = lineContent.replace(/\t/g, " ");
143865
143865
  context += indent3 + formatColorAndReset((i + 1 + "").padStart(gutterWidth), gutterStyleSequence) + gutterSeparator;
@@ -144867,9 +144867,9 @@ ${lanes.join("\n")}
144867
144867
  /*ignoreCase*/
144868
144868
  false
144869
144869
  )) {
144870
- const basename15 = getBaseFileName(a.fileName);
144871
- if (basename15 === "lib.d.ts" || basename15 === "lib.es6.d.ts") return 0;
144872
- const name = removeSuffix(removePrefix(basename15, "lib."), ".d.ts");
144870
+ const basename14 = getBaseFileName(a.fileName);
144871
+ if (basename14 === "lib.d.ts" || basename14 === "lib.es6.d.ts") return 0;
144872
+ const name = removeSuffix(removePrefix(basename14, "lib."), ".d.ts");
144873
144873
  const index3 = libs.indexOf(name);
144874
144874
  if (index3 !== -1) return index3 + 1;
144875
144875
  }
@@ -151458,7 +151458,7 @@ ${lanes.join("\n")}
151458
151458
  function getSourceFileVersionAsHashFromText(host, text2) {
151459
151459
  if (text2.match(sourceMapCommentRegExpDontCareLineStart)) {
151460
151460
  let lineEnd = text2.length;
151461
- let lineStart2 = lineEnd;
151461
+ let lineStart = lineEnd;
151462
151462
  for (let pos = lineEnd - 1; pos >= 0; pos--) {
151463
151463
  const ch = text2.charCodeAt(pos);
151464
151464
  switch (ch) {
@@ -151471,19 +151471,19 @@ ${lanes.join("\n")}
151471
151471
  break;
151472
151472
  default:
151473
151473
  if (ch < 127 || !isLineBreak(ch)) {
151474
- lineStart2 = pos;
151474
+ lineStart = pos;
151475
151475
  continue;
151476
151476
  }
151477
151477
  break;
151478
151478
  }
151479
- const line = text2.substring(lineStart2, lineEnd);
151479
+ const line = text2.substring(lineStart, lineEnd);
151480
151480
  if (line.match(sourceMapCommentRegExp)) {
151481
- text2 = text2.substring(0, lineStart2);
151481
+ text2 = text2.substring(0, lineStart);
151482
151482
  break;
151483
151483
  } else if (!line.match(whitespaceOrMapCommentRegExp)) {
151484
151484
  break;
151485
151485
  }
151486
- lineEnd = lineStart2;
151486
+ lineEnd = lineStart;
151487
151487
  }
151488
151488
  }
151489
151489
  return (host.createHash || generateDjb2Hash)(text2);
@@ -158538,7 +158538,7 @@ ${lanes.join("\n")}
158538
158538
  }
158539
158539
  return void 0;
158540
158540
  }
158541
- function isComment2(kind) {
158541
+ function isComment(kind) {
158542
158542
  return kind === 2 || kind === 3;
158543
158543
  }
158544
158544
  function isStringOrRegularExpressionOrTemplateLiteral(kind) {
@@ -158959,7 +158959,7 @@ ${lanes.join("\n")}
158959
158959
  function getDisplayPartWriterWorker(maximumLength) {
158960
158960
  const absoluteMaximumLength = maximumLength * 10;
158961
158961
  let displayParts;
158962
- let lineStart2;
158962
+ let lineStart;
158963
158963
  let indent3;
158964
158964
  let length2;
158965
158965
  resetWriter();
@@ -159055,7 +159055,7 @@ ${lanes.join("\n")}
159055
159055
  };
159056
159056
  function writeIndent() {
159057
159057
  if (length2 > absoluteMaximumLength) return;
159058
- if (lineStart2) {
159058
+ if (lineStart) {
159059
159059
  const indentString = getIndentString(indent3);
159060
159060
  if (indentString) {
159061
159061
  length2 += indentString.length;
@@ -159065,7 +159065,7 @@ ${lanes.join("\n")}
159065
159065
  /* space */
159066
159066
  ));
159067
159067
  }
159068
- lineStart2 = false;
159068
+ lineStart = false;
159069
159069
  }
159070
159070
  }
159071
159071
  function writeKind(text2, kind) {
@@ -159084,11 +159084,11 @@ ${lanes.join("\n")}
159084
159084
  if (length2 > absoluteMaximumLength) return;
159085
159085
  length2 += 1;
159086
159086
  displayParts.push(lineBreakPart());
159087
- lineStart2 = true;
159087
+ lineStart = true;
159088
159088
  }
159089
159089
  function resetWriter() {
159090
159090
  displayParts = [];
159091
- lineStart2 = true;
159091
+ lineStart = true;
159092
159092
  indent3 = 0;
159093
159093
  length2 = 0;
159094
159094
  }
@@ -187811,8 +187811,8 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
187811
187811
  /* JsDocTagName */
187812
187812
  };
187813
187813
  } else {
187814
- const lineStart2 = getLineStartPositionForPosition(position, sourceFile);
187815
- if (!/[^*|\s(/)]/.test(sourceFile.text.substring(lineStart2, position))) {
187814
+ const lineStart = getLineStartPositionForPosition(position, sourceFile);
187815
+ if (!/[^*|\s(/)]/.test(sourceFile.text.substring(lineStart, position))) {
187816
187816
  return {
187817
187817
  kind: 2
187818
187818
  /* JsDocTag */
@@ -195291,10 +195291,10 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
195291
195291
  }
195292
195292
  function getIndentationStringAtPosition(sourceFile, position) {
195293
195293
  const { text: text2 } = sourceFile;
195294
- const lineStart2 = getLineStartPositionForPosition(position, sourceFile);
195295
- let pos = lineStart2;
195294
+ const lineStart = getLineStartPositionForPosition(position, sourceFile);
195295
+ let pos = lineStart;
195296
195296
  for (; pos <= position && isWhiteSpaceSingleLine(text2.charCodeAt(pos)); pos++) ;
195297
- return text2.slice(lineStart2, pos);
195297
+ return text2.slice(lineStart, pos);
195298
195298
  }
195299
195299
  function parameterDocComments(parameters, isJavaScriptFile, indentationStr, newLine) {
195300
195300
  return parameters.map(({ name, dotDotDotToken }, i) => {
@@ -202982,7 +202982,7 @@ ${options.prefix}` : "\n" : options.prefix
202982
202982
  }
202983
202983
  function processTrivia(trivia, parent2, contextNode, dynamicIndentation) {
202984
202984
  for (const triviaItem of trivia) {
202985
- if (isComment2(triviaItem.kind) && rangeContainsRange(originalRange, triviaItem)) {
202985
+ if (isComment(triviaItem.kind) && rangeContainsRange(originalRange, triviaItem)) {
202986
202986
  const triviaItemStart = sourceFile.getLineAndCharacterOfPosition(triviaItem.pos);
202987
202987
  processRange(triviaItem, triviaItemStart, parent2, contextNode, dynamicIndentation);
202988
202988
  }
@@ -203125,7 +203125,7 @@ ${options.prefix}` : "\n" : options.prefix
203125
203125
  for (let line = line1; line < line2; line++) {
203126
203126
  const lineStartPosition = getStartPositionOfLine(line, sourceFile);
203127
203127
  const lineEndPosition = getEndLinePosition(line, sourceFile);
203128
- if (range && (isComment2(range.kind) || isStringOrRegularExpressionOrTemplateLiteral(range.kind)) && range.pos <= lineEndPosition && range.end > lineEndPosition) {
203128
+ if (range && (isComment(range.kind) || isStringOrRegularExpressionOrTemplateLiteral(range.kind)) && range.pos <= lineEndPosition && range.end > lineEndPosition) {
203129
203129
  continue;
203130
203130
  }
203131
203131
  const whitespaceStart = getTrailingWhitespaceStartPosition(lineStartPosition, lineEndPosition);
@@ -203148,7 +203148,7 @@ ${options.prefix}` : "\n" : options.prefix
203148
203148
  function trimTrailingWhitespacesForRemainingRange(trivias) {
203149
203149
  let startPos = previousRange ? previousRange.end : originalRange.pos;
203150
203150
  for (const trivia of trivias) {
203151
- if (isComment2(trivia.kind)) {
203151
+ if (isComment(trivia.kind)) {
203152
203152
  if (startPos < trivia.pos) {
203153
203153
  trimTrailingWitespacesForPositions(startPos, trivia.pos - 1, previousRange);
203154
203154
  }
@@ -203425,8 +203425,8 @@ ${options.prefix}` : "\n" : options.prefix
203425
203425
  }
203426
203426
  current--;
203427
203427
  }
203428
- const lineStart2 = getLineStartPositionForPosition(current, sourceFile);
203429
- return findFirstNonWhitespaceColumn(lineStart2, current, sourceFile, options);
203428
+ const lineStart = getLineStartPositionForPosition(current, sourceFile);
203429
+ return findFirstNonWhitespaceColumn(lineStart, current, sourceFile, options);
203430
203430
  }
203431
203431
  function getSmartIndent(sourceFile, position, precedingToken, lineAtPosition, assumeNewLineBeforeCloseBrace, options) {
203432
203432
  let previous;
@@ -203713,8 +203713,8 @@ ${options.prefix}` : "\n" : options.prefix
203713
203713
  return -1;
203714
203714
  }
203715
203715
  function findColumnForFirstNonWhitespaceCharacterInLine(lineAndCharacter, sourceFile, options) {
203716
- const lineStart2 = sourceFile.getPositionOfLineAndCharacter(lineAndCharacter.line, 0);
203717
- return findFirstNonWhitespaceColumn(lineStart2, lineStart2 + lineAndCharacter.character, sourceFile, options);
203716
+ const lineStart = sourceFile.getPositionOfLineAndCharacter(lineAndCharacter.line, 0);
203717
+ return findFirstNonWhitespaceColumn(lineStart, lineStart + lineAndCharacter.character, sourceFile, options);
203718
203718
  }
203719
203719
  function findFirstNonWhitespaceCharacterAndColumn(startPos, endPos, sourceFile, options) {
203720
203720
  let character = 0;
@@ -205240,7 +205240,7 @@ ${options.prefix}` : "\n" : options.prefix
205240
205240
  isCommaListExpression: () => isCommaListExpression,
205241
205241
  isCommaSequence: () => isCommaSequence,
205242
205242
  isCommaToken: () => isCommaToken,
205243
- isComment: () => isComment2,
205243
+ isComment: () => isComment,
205244
205244
  isCommonJsExportPropertyAssignment: () => isCommonJsExportPropertyAssignment,
205245
205245
  isCommonJsExportedExpression: () => isCommonJsExportedExpression,
205246
205246
  isCompoundAssignment: () => isCompoundAssignment,
@@ -208815,8 +208815,8 @@ ${options.prefix}` : "\n" : options.prefix
208815
208815
  }
208816
208816
  };
208817
208817
  for (const file2 of files) {
208818
- const basename15 = getBaseFileName(file2);
208819
- if (basename15 === "package.json" || basename15 === "bower.json") {
208818
+ const basename14 = getBaseFileName(file2);
208819
+ if (basename14 === "package.json" || basename14 === "bower.json") {
208820
208820
  createProjectWatcher(
208821
208821
  file2,
208822
208822
  "FileWatcher"
@@ -212500,8 +212500,8 @@ All files are: ${JSON.stringify(names2)}`,
212500
212500
  var _a;
212501
212501
  const fileOrDirectoryPath = removeIgnoredPath(this.toPath(fileOrDirectory));
212502
212502
  if (!fileOrDirectoryPath) return;
212503
- const basename15 = getBaseFileName(fileOrDirectoryPath);
212504
- if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (basename15 === "package.json" || basename15 === "node_modules")) {
212503
+ const basename14 = getBaseFileName(fileOrDirectoryPath);
212504
+ if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (basename14 === "package.json" || basename14 === "node_modules")) {
212505
212505
  result.affectedModuleSpecifierCacheProjects.forEach((project) => {
212506
212506
  var _a2;
212507
212507
  (_a2 = project.getModuleSpecifierCache()) == null ? void 0 : _a2.clear();
@@ -218987,8 +218987,8 @@ Additional information: BADCLIENT: Bad error code, ${badCode} not found in range
218987
218987
  installPackage(options) {
218988
218988
  this.packageInstallId++;
218989
218989
  const request2 = { kind: "installPackage", ...options, id: this.packageInstallId };
218990
- const promise = new Promise((resolve8, reject) => {
218991
- (this.packageInstalledPromise ?? (this.packageInstalledPromise = /* @__PURE__ */ new Map())).set(this.packageInstallId, { resolve: resolve8, reject });
218990
+ const promise = new Promise((resolve7, reject) => {
218991
+ (this.packageInstalledPromise ?? (this.packageInstalledPromise = /* @__PURE__ */ new Map())).set(this.packageInstallId, { resolve: resolve7, reject });
218992
218992
  });
218993
218993
  this.installer.send(request2);
218994
218994
  return promise;
@@ -232592,7 +232592,7 @@ var require_resolve_uri_umd = __commonJS({
232592
232592
  }
232593
232593
  url.path = path;
232594
232594
  }
232595
- function resolve8(input, base) {
232595
+ function resolve7(input, base) {
232596
232596
  if (!input && !base)
232597
232597
  return "";
232598
232598
  const url = parseUrl2(input);
@@ -232645,7 +232645,7 @@ var require_resolve_uri_umd = __commonJS({
232645
232645
  return url.scheme + "//" + url.user + url.host + url.port + url.path + queryHash;
232646
232646
  }
232647
232647
  }
232648
- return resolve8;
232648
+ return resolve7;
232649
232649
  }));
232650
232650
  }
232651
232651
  });
@@ -232991,8 +232991,8 @@ var require_trace_mapping_umd = __commonJS({
232991
232991
  this.sources = sources;
232992
232992
  this.sourcesContent = sourcesContent;
232993
232993
  this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
232994
- const resolve8 = resolver2(mapUrl, sourceRoot);
232995
- this.resolvedSources = sources.map(resolve8);
232994
+ const resolve7 = resolver2(mapUrl, sourceRoot);
232995
+ this.resolvedSources = sources.map(resolve7);
232996
232996
  const { mappings } = parsed;
232997
232997
  if (typeof mappings === "string") {
232998
232998
  this._encoded = mappings;
@@ -233561,13 +233561,13 @@ var require_computeSourceMap = __commonJS({
233561
233561
  currentMapping = rawMappings[tokenIndex];
233562
233562
  }
233563
233563
  let line = 0;
233564
- let lineStart2 = 0;
233565
- if (currentMapping !== lineStart2) {
233564
+ let lineStart = 0;
233565
+ if (currentMapping !== lineStart) {
233566
233566
  _genmapping.maybeAddSegment.call(void 0, map, line, 0, filePath, line, 0);
233567
233567
  }
233568
233568
  for (let i = 0; i < generatedCode.length; i++) {
233569
233569
  if (i === currentMapping) {
233570
- const genColumn = currentMapping - lineStart2;
233570
+ const genColumn = currentMapping - lineStart;
233571
233571
  const sourceColumn = sourceColumns[tokenIndex];
233572
233572
  _genmapping.maybeAddSegment.call(void 0, map, line, genColumn, filePath, line, sourceColumn);
233573
233573
  while ((currentMapping === i || currentMapping === void 0) && tokenIndex < rawMappings.length - 1) {
@@ -233577,8 +233577,8 @@ var require_computeSourceMap = __commonJS({
233577
233577
  }
233578
233578
  if (generatedCode.charCodeAt(i) === _charcodes.charCodes.lineFeed) {
233579
233579
  line++;
233580
- lineStart2 = i + 1;
233581
- if (currentMapping !== lineStart2) {
233580
+ lineStart = i + 1;
233581
+ if (currentMapping !== lineStart) {
233582
233582
  _genmapping.maybeAddSegment.call(void 0, map, line, 0, filePath, line, 0);
233583
233583
  }
233584
233584
  }
@@ -233591,15 +233591,15 @@ var require_computeSourceMap = __commonJS({
233591
233591
  const sourceColumns = new Array(tokens.length);
233592
233592
  let tokenIndex = 0;
233593
233593
  let currentMapping = tokens[tokenIndex].start;
233594
- let lineStart2 = 0;
233594
+ let lineStart = 0;
233595
233595
  for (let i = 0; i < code2.length; i++) {
233596
233596
  if (i === currentMapping) {
233597
- sourceColumns[tokenIndex] = currentMapping - lineStart2;
233597
+ sourceColumns[tokenIndex] = currentMapping - lineStart;
233598
233598
  tokenIndex++;
233599
233599
  currentMapping = tokens[tokenIndex].start;
233600
233600
  }
233601
233601
  if (code2.charCodeAt(i) === _charcodes.charCodes.lineFeed) {
233602
- lineStart2 = i + 1;
233602
+ lineStart = i + 1;
233603
233603
  }
233604
233604
  }
233605
233605
  return sourceColumns;
@@ -248778,7 +248778,7 @@ export type BindingSource = { context: BrowserContext, page: Page, frame: Frame
248778
248778
  // scripts/lib/runtime-build/check-cli.mjs
248779
248779
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
248780
248780
  import { statSync as statSync6 } from "node:fs";
248781
- import { resolve as resolve7 } from "node:path";
248781
+ import { resolve as resolve6 } from "node:path";
248782
248782
 
248783
248783
  // scripts/lib/runtime-build/api-cli.mjs
248784
248784
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -249109,7 +249109,7 @@ ${LOGS_USAGE}
249109
249109
  // scripts/lib/runtime-build/assets-cli.mjs
249110
249110
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
249111
249111
  import { readFileSync, statSync as statSync2, writeFileSync } from "node:fs";
249112
- import { basename as basename3, join as join2, resolve as resolve3 } from "node:path";
249112
+ import { basename as basename2, join as join2, resolve as resolve3 } from "node:path";
249113
249113
 
249114
249114
  // scripts/lib/runtime-build/assets-file.mjs
249115
249115
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -250750,9 +250750,9 @@ var isAllowedNumericSeparatorSibling = {
250750
250750
  dec: (ch) => ch >= 48 && ch <= 57,
250751
250751
  hex: (ch) => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
250752
250752
  };
250753
- function readStringContents(type, input, pos, lineStart2, curLine, errors) {
250753
+ function readStringContents(type, input, pos, lineStart, curLine, errors) {
250754
250754
  const initialPos = pos;
250755
- const initialLineStart = lineStart2;
250755
+ const initialLineStart = lineStart;
250756
250756
  const initialCurLine = curLine;
250757
250757
  let out = "";
250758
250758
  let firstInvalidLoc = null;
@@ -250773,11 +250773,11 @@ function readStringContents(type, input, pos, lineStart2, curLine, errors) {
250773
250773
  }
250774
250774
  if (ch === 92) {
250775
250775
  out += input.slice(chunkStart, pos);
250776
- const res = readEscapedChar(input, pos, lineStart2, curLine, type === "template", errors);
250776
+ const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
250777
250777
  if (res.ch === null && !firstInvalidLoc) {
250778
250778
  firstInvalidLoc = {
250779
250779
  pos,
250780
- lineStart: lineStart2,
250780
+ lineStart,
250781
250781
  curLine
250782
250782
  };
250783
250783
  } else {
@@ -250785,14 +250785,14 @@ function readStringContents(type, input, pos, lineStart2, curLine, errors) {
250785
250785
  }
250786
250786
  ({
250787
250787
  pos,
250788
- lineStart: lineStart2,
250788
+ lineStart,
250789
250789
  curLine
250790
250790
  } = res);
250791
250791
  chunkStart = pos;
250792
250792
  } else if (ch === 8232 || ch === 8233) {
250793
250793
  ++pos;
250794
250794
  ++curLine;
250795
- lineStart2 = pos;
250795
+ lineStart = pos;
250796
250796
  } else if (ch === 10 || ch === 13) {
250797
250797
  if (type === "template") {
250798
250798
  out += input.slice(chunkStart, pos) + "\n";
@@ -250801,7 +250801,7 @@ function readStringContents(type, input, pos, lineStart2, curLine, errors) {
250801
250801
  ++pos;
250802
250802
  }
250803
250803
  ++curLine;
250804
- chunkStart = lineStart2 = pos;
250804
+ chunkStart = lineStart = pos;
250805
250805
  } else {
250806
250806
  errors.unterminated(initialPos, initialLineStart, initialCurLine);
250807
250807
  }
@@ -250813,7 +250813,7 @@ function readStringContents(type, input, pos, lineStart2, curLine, errors) {
250813
250813
  pos,
250814
250814
  str: out,
250815
250815
  firstInvalidLoc,
250816
- lineStart: lineStart2,
250816
+ lineStart,
250817
250817
  curLine
250818
250818
  };
250819
250819
  }
@@ -250823,13 +250823,13 @@ function isStringEnd(type, ch, input, pos) {
250823
250823
  }
250824
250824
  return ch === (type === "double" ? 34 : 39);
250825
250825
  }
250826
- function readEscapedChar(input, pos, lineStart2, curLine, inTemplate, errors) {
250826
+ function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
250827
250827
  const throwOnInvalid = !inTemplate;
250828
250828
  pos++;
250829
250829
  const res = (ch2) => ({
250830
250830
  pos,
250831
250831
  ch: ch2,
250832
- lineStart: lineStart2,
250832
+ lineStart,
250833
250833
  curLine
250834
250834
  });
250835
250835
  const ch = input.charCodeAt(pos++);
@@ -250843,7 +250843,7 @@ function readEscapedChar(input, pos, lineStart2, curLine, inTemplate, errors) {
250843
250843
  ({
250844
250844
  code: code2,
250845
250845
  pos
250846
- } = readHexChar(input, pos, lineStart2, curLine, 2, false, throwOnInvalid, errors));
250846
+ } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
250847
250847
  return res(code2 === null ? null : String.fromCharCode(code2));
250848
250848
  }
250849
250849
  case 117: {
@@ -250851,7 +250851,7 @@ function readEscapedChar(input, pos, lineStart2, curLine, inTemplate, errors) {
250851
250851
  ({
250852
250852
  code: code2,
250853
250853
  pos
250854
- } = readCodePoint(input, pos, lineStart2, curLine, throwOnInvalid, errors));
250854
+ } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
250855
250855
  return res(code2 === null ? null : String.fromCodePoint(code2));
250856
250856
  }
250857
250857
  case 116:
@@ -250867,7 +250867,7 @@ function readEscapedChar(input, pos, lineStart2, curLine, inTemplate, errors) {
250867
250867
  ++pos;
250868
250868
  }
250869
250869
  case 10:
250870
- lineStart2 = pos;
250870
+ lineStart = pos;
250871
250871
  ++curLine;
250872
250872
  case 8232:
250873
250873
  case 8233:
@@ -250877,7 +250877,7 @@ function readEscapedChar(input, pos, lineStart2, curLine, inTemplate, errors) {
250877
250877
  if (inTemplate) {
250878
250878
  return res(null);
250879
250879
  } else {
250880
- errors.strictNumericEscape(pos - 1, lineStart2, curLine);
250880
+ errors.strictNumericEscape(pos - 1, lineStart, curLine);
250881
250881
  }
250882
250882
  default:
250883
250883
  if (ch >= 48 && ch <= 55) {
@@ -250895,7 +250895,7 @@ function readEscapedChar(input, pos, lineStart2, curLine, inTemplate, errors) {
250895
250895
  if (inTemplate) {
250896
250896
  return res(null);
250897
250897
  } else {
250898
- errors.strictNumericEscape(startPos, lineStart2, curLine);
250898
+ errors.strictNumericEscape(startPos, lineStart, curLine);
250899
250899
  }
250900
250900
  }
250901
250901
  return res(String.fromCharCode(octal));
@@ -250903,16 +250903,16 @@ function readEscapedChar(input, pos, lineStart2, curLine, inTemplate, errors) {
250903
250903
  return res(String.fromCharCode(ch));
250904
250904
  }
250905
250905
  }
250906
- function readHexChar(input, pos, lineStart2, curLine, len, forceLen, throwOnInvalid, errors) {
250906
+ function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
250907
250907
  const initialPos = pos;
250908
250908
  let n;
250909
250909
  ({
250910
250910
  n,
250911
250911
  pos
250912
- } = readInt(input, pos, lineStart2, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
250912
+ } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
250913
250913
  if (n === null) {
250914
250914
  if (throwOnInvalid) {
250915
- errors.invalidEscapeSequence(initialPos, lineStart2, curLine);
250915
+ errors.invalidEscapeSequence(initialPos, lineStart, curLine);
250916
250916
  } else {
250917
250917
  pos = initialPos - 1;
250918
250918
  }
@@ -250922,7 +250922,7 @@ function readHexChar(input, pos, lineStart2, curLine, len, forceLen, throwOnInva
250922
250922
  pos
250923
250923
  };
250924
250924
  }
250925
- function readInt(input, pos, lineStart2, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
250925
+ function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
250926
250926
  const start = pos;
250927
250927
  const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
250928
250928
  const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
@@ -250939,13 +250939,13 @@ function readInt(input, pos, lineStart2, curLine, radix, len, forceLen, allowNum
250939
250939
  n: null,
250940
250940
  pos
250941
250941
  };
250942
- errors.numericSeparatorInEscapeSequence(pos, lineStart2, curLine);
250942
+ errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
250943
250943
  } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev)) {
250944
250944
  if (bailOnError) return {
250945
250945
  n: null,
250946
250946
  pos
250947
250947
  };
250948
- errors.unexpectedNumericSeparator(pos, lineStart2, curLine);
250948
+ errors.unexpectedNumericSeparator(pos, lineStart, curLine);
250949
250949
  }
250950
250950
  ++pos;
250951
250951
  continue;
@@ -250965,7 +250965,7 @@ function readInt(input, pos, lineStart2, curLine, radix, len, forceLen, allowNum
250965
250965
  n: null,
250966
250966
  pos
250967
250967
  };
250968
- errors.invalidDigit(pos, lineStart2, curLine, radix);
250968
+ errors.invalidDigit(pos, lineStart, curLine, radix);
250969
250969
  val = 0;
250970
250970
  } else if (forceLen) {
250971
250971
  val = 0;
@@ -250988,7 +250988,7 @@ function readInt(input, pos, lineStart2, curLine, radix, len, forceLen, allowNum
250988
250988
  pos
250989
250989
  };
250990
250990
  }
250991
- function readCodePoint(input, pos, lineStart2, curLine, throwOnInvalid, errors) {
250991
+ function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
250992
250992
  const ch = input.charCodeAt(pos);
250993
250993
  let code2;
250994
250994
  if (ch === 123) {
@@ -250996,11 +250996,11 @@ function readCodePoint(input, pos, lineStart2, curLine, throwOnInvalid, errors)
250996
250996
  ({
250997
250997
  code: code2,
250998
250998
  pos
250999
- } = readHexChar(input, pos, lineStart2, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
250999
+ } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
251000
251000
  ++pos;
251001
251001
  if (code2 !== null && code2 > 1114111) {
251002
251002
  if (throwOnInvalid) {
251003
- errors.invalidCodePoint(pos, lineStart2, curLine);
251003
+ errors.invalidCodePoint(pos, lineStart, curLine);
251004
251004
  } else {
251005
251005
  return {
251006
251006
  code: null,
@@ -251012,7 +251012,7 @@ function readCodePoint(input, pos, lineStart2, curLine, throwOnInvalid, errors)
251012
251012
  ({
251013
251013
  code: code2,
251014
251014
  pos
251015
- } = readHexChar(input, pos, lineStart2, curLine, 4, false, throwOnInvalid, errors));
251015
+ } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
251016
251016
  }
251017
251017
  return {
251018
251018
  code: code2,
@@ -262254,8 +262254,8 @@ var TraceMap = class {
262254
262254
  this.sources = sources;
262255
262255
  this.sourcesContent = sourcesContent;
262256
262256
  this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
262257
- const resolve8 = resolver(mapUrl, sourceRoot);
262258
- this.resolvedSources = sources.map(resolve8);
262257
+ const resolve7 = resolver(mapUrl, sourceRoot);
262258
+ this.resolvedSources = sources.map(resolve7);
262259
262259
  const { mappings } = parsed;
262260
262260
  if (typeof mappings === "string") {
262261
262261
  this._encoded = mappings;
@@ -273414,9 +273414,9 @@ var isAllowedNumericSeparatorSibling2 = {
273414
273414
  dec: (ch) => ch >= 48 && ch <= 57,
273415
273415
  hex: (ch) => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
273416
273416
  };
273417
- function readStringContents2(type, input, pos, lineStart2, curLine, errors) {
273417
+ function readStringContents2(type, input, pos, lineStart, curLine, errors) {
273418
273418
  const initialPos = pos;
273419
- const initialLineStart = lineStart2;
273419
+ const initialLineStart = lineStart;
273420
273420
  const initialCurLine = curLine;
273421
273421
  let out = "";
273422
273422
  let firstInvalidLoc = null;
@@ -273437,11 +273437,11 @@ function readStringContents2(type, input, pos, lineStart2, curLine, errors) {
273437
273437
  }
273438
273438
  if (ch === 92) {
273439
273439
  out += input.slice(chunkStart, pos);
273440
- const res = readEscapedChar2(input, pos, lineStart2, curLine, type === "template", errors);
273440
+ const res = readEscapedChar2(input, pos, lineStart, curLine, type === "template", errors);
273441
273441
  if (res.ch === null && !firstInvalidLoc) {
273442
273442
  firstInvalidLoc = {
273443
273443
  pos,
273444
- lineStart: lineStart2,
273444
+ lineStart,
273445
273445
  curLine
273446
273446
  };
273447
273447
  } else {
@@ -273449,14 +273449,14 @@ function readStringContents2(type, input, pos, lineStart2, curLine, errors) {
273449
273449
  }
273450
273450
  ({
273451
273451
  pos,
273452
- lineStart: lineStart2,
273452
+ lineStart,
273453
273453
  curLine
273454
273454
  } = res);
273455
273455
  chunkStart = pos;
273456
273456
  } else if (ch === 8232 || ch === 8233) {
273457
273457
  ++pos;
273458
273458
  ++curLine;
273459
- lineStart2 = pos;
273459
+ lineStart = pos;
273460
273460
  } else if (ch === 10 || ch === 13) {
273461
273461
  if (type === "template") {
273462
273462
  out += input.slice(chunkStart, pos) + "\n";
@@ -273465,7 +273465,7 @@ function readStringContents2(type, input, pos, lineStart2, curLine, errors) {
273465
273465
  ++pos;
273466
273466
  }
273467
273467
  ++curLine;
273468
- chunkStart = lineStart2 = pos;
273468
+ chunkStart = lineStart = pos;
273469
273469
  } else {
273470
273470
  errors.unterminated(initialPos, initialLineStart, initialCurLine);
273471
273471
  }
@@ -273477,7 +273477,7 @@ function readStringContents2(type, input, pos, lineStart2, curLine, errors) {
273477
273477
  pos,
273478
273478
  str: out,
273479
273479
  firstInvalidLoc,
273480
- lineStart: lineStart2,
273480
+ lineStart,
273481
273481
  curLine
273482
273482
  };
273483
273483
  }
@@ -273487,13 +273487,13 @@ function isStringEnd2(type, ch, input, pos) {
273487
273487
  }
273488
273488
  return ch === (type === "double" ? 34 : 39);
273489
273489
  }
273490
- function readEscapedChar2(input, pos, lineStart2, curLine, inTemplate, errors) {
273490
+ function readEscapedChar2(input, pos, lineStart, curLine, inTemplate, errors) {
273491
273491
  const throwOnInvalid = !inTemplate;
273492
273492
  pos++;
273493
273493
  const res = (ch2) => ({
273494
273494
  pos,
273495
273495
  ch: ch2,
273496
- lineStart: lineStart2,
273496
+ lineStart,
273497
273497
  curLine
273498
273498
  });
273499
273499
  const ch = input.charCodeAt(pos++);
@@ -273507,7 +273507,7 @@ function readEscapedChar2(input, pos, lineStart2, curLine, inTemplate, errors) {
273507
273507
  ({
273508
273508
  code: code2,
273509
273509
  pos
273510
- } = readHexChar2(input, pos, lineStart2, curLine, 2, false, throwOnInvalid, errors));
273510
+ } = readHexChar2(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
273511
273511
  return res(code2 === null ? null : String.fromCharCode(code2));
273512
273512
  }
273513
273513
  case 117: {
@@ -273515,7 +273515,7 @@ function readEscapedChar2(input, pos, lineStart2, curLine, inTemplate, errors) {
273515
273515
  ({
273516
273516
  code: code2,
273517
273517
  pos
273518
- } = readCodePoint2(input, pos, lineStart2, curLine, throwOnInvalid, errors));
273518
+ } = readCodePoint2(input, pos, lineStart, curLine, throwOnInvalid, errors));
273519
273519
  return res(code2 === null ? null : String.fromCodePoint(code2));
273520
273520
  }
273521
273521
  case 116:
@@ -273531,7 +273531,7 @@ function readEscapedChar2(input, pos, lineStart2, curLine, inTemplate, errors) {
273531
273531
  ++pos;
273532
273532
  }
273533
273533
  case 10:
273534
- lineStart2 = pos;
273534
+ lineStart = pos;
273535
273535
  ++curLine;
273536
273536
  case 8232:
273537
273537
  case 8233:
@@ -273541,7 +273541,7 @@ function readEscapedChar2(input, pos, lineStart2, curLine, inTemplate, errors) {
273541
273541
  if (inTemplate) {
273542
273542
  return res(null);
273543
273543
  } else {
273544
- errors.strictNumericEscape(pos - 1, lineStart2, curLine);
273544
+ errors.strictNumericEscape(pos - 1, lineStart, curLine);
273545
273545
  }
273546
273546
  default:
273547
273547
  if (ch >= 48 && ch <= 55) {
@@ -273559,7 +273559,7 @@ function readEscapedChar2(input, pos, lineStart2, curLine, inTemplate, errors) {
273559
273559
  if (inTemplate) {
273560
273560
  return res(null);
273561
273561
  } else {
273562
- errors.strictNumericEscape(startPos, lineStart2, curLine);
273562
+ errors.strictNumericEscape(startPos, lineStart, curLine);
273563
273563
  }
273564
273564
  }
273565
273565
  return res(String.fromCharCode(octal));
@@ -273567,16 +273567,16 @@ function readEscapedChar2(input, pos, lineStart2, curLine, inTemplate, errors) {
273567
273567
  return res(String.fromCharCode(ch));
273568
273568
  }
273569
273569
  }
273570
- function readHexChar2(input, pos, lineStart2, curLine, len, forceLen, throwOnInvalid, errors) {
273570
+ function readHexChar2(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
273571
273571
  const initialPos = pos;
273572
273572
  let n;
273573
273573
  ({
273574
273574
  n,
273575
273575
  pos
273576
- } = readInt2(input, pos, lineStart2, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
273576
+ } = readInt2(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
273577
273577
  if (n === null) {
273578
273578
  if (throwOnInvalid) {
273579
- errors.invalidEscapeSequence(initialPos, lineStart2, curLine);
273579
+ errors.invalidEscapeSequence(initialPos, lineStart, curLine);
273580
273580
  } else {
273581
273581
  pos = initialPos - 1;
273582
273582
  }
@@ -273586,7 +273586,7 @@ function readHexChar2(input, pos, lineStart2, curLine, len, forceLen, throwOnInv
273586
273586
  pos
273587
273587
  };
273588
273588
  }
273589
- function readInt2(input, pos, lineStart2, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
273589
+ function readInt2(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
273590
273590
  const start = pos;
273591
273591
  const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings2.hex : forbiddenNumericSeparatorSiblings2.decBinOct;
273592
273592
  const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling2.hex : radix === 10 ? isAllowedNumericSeparatorSibling2.dec : radix === 8 ? isAllowedNumericSeparatorSibling2.oct : isAllowedNumericSeparatorSibling2.bin;
@@ -273603,13 +273603,13 @@ function readInt2(input, pos, lineStart2, curLine, radix, len, forceLen, allowNu
273603
273603
  n: null,
273604
273604
  pos
273605
273605
  };
273606
- errors.numericSeparatorInEscapeSequence(pos, lineStart2, curLine);
273606
+ errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
273607
273607
  } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev)) {
273608
273608
  if (bailOnError) return {
273609
273609
  n: null,
273610
273610
  pos
273611
273611
  };
273612
- errors.unexpectedNumericSeparator(pos, lineStart2, curLine);
273612
+ errors.unexpectedNumericSeparator(pos, lineStart, curLine);
273613
273613
  }
273614
273614
  ++pos;
273615
273615
  continue;
@@ -273629,7 +273629,7 @@ function readInt2(input, pos, lineStart2, curLine, radix, len, forceLen, allowNu
273629
273629
  n: null,
273630
273630
  pos
273631
273631
  };
273632
- errors.invalidDigit(pos, lineStart2, curLine, radix);
273632
+ errors.invalidDigit(pos, lineStart, curLine, radix);
273633
273633
  val = 0;
273634
273634
  } else if (forceLen) {
273635
273635
  val = 0;
@@ -273652,7 +273652,7 @@ function readInt2(input, pos, lineStart2, curLine, radix, len, forceLen, allowNu
273652
273652
  pos
273653
273653
  };
273654
273654
  }
273655
- function readCodePoint2(input, pos, lineStart2, curLine, throwOnInvalid, errors) {
273655
+ function readCodePoint2(input, pos, lineStart, curLine, throwOnInvalid, errors) {
273656
273656
  const ch = input.charCodeAt(pos);
273657
273657
  let code2;
273658
273658
  if (ch === 123) {
@@ -273660,11 +273660,11 @@ function readCodePoint2(input, pos, lineStart2, curLine, throwOnInvalid, errors)
273660
273660
  ({
273661
273661
  code: code2,
273662
273662
  pos
273663
- } = readHexChar2(input, pos, lineStart2, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
273663
+ } = readHexChar2(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
273664
273664
  ++pos;
273665
273665
  if (code2 !== null && code2 > 1114111) {
273666
273666
  if (throwOnInvalid) {
273667
- errors.invalidCodePoint(pos, lineStart2, curLine);
273667
+ errors.invalidCodePoint(pos, lineStart, curLine);
273668
273668
  } else {
273669
273669
  return {
273670
273670
  code: null,
@@ -273676,15 +273676,15 @@ function readCodePoint2(input, pos, lineStart2, curLine, throwOnInvalid, errors)
273676
273676
  ({
273677
273677
  code: code2,
273678
273678
  pos
273679
- } = readHexChar2(input, pos, lineStart2, curLine, 4, false, throwOnInvalid, errors));
273679
+ } = readHexChar2(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
273680
273680
  }
273681
273681
  return {
273682
273682
  code: code2,
273683
273683
  pos
273684
273684
  };
273685
273685
  }
273686
- function buildPosition(pos, lineStart2, curLine) {
273687
- return new Position(curLine, pos - lineStart2, pos);
273686
+ function buildPosition(pos, lineStart, curLine) {
273687
+ return new Position(curLine, pos - lineStart, pos);
273688
273688
  }
273689
273689
  var VALID_REGEX_FLAGS = /* @__PURE__ */ new Set([103, 109, 115, 105, 121, 117, 100, 118]);
273690
273690
  var Token = class {
@@ -274517,10 +274517,10 @@ var Tokenizer = class extends CommentsParser {
274517
274517
  str,
274518
274518
  pos,
274519
274519
  curLine,
274520
- lineStart: lineStart2
274520
+ lineStart
274521
274521
  } = readStringContents2(quote === 34 ? "double" : "single", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_string);
274522
274522
  this.state.pos = pos + 1;
274523
- this.state.lineStart = lineStart2;
274523
+ this.state.lineStart = lineStart;
274524
274524
  this.state.curLine = curLine;
274525
274525
  this.finishToken(133, str);
274526
274526
  }
@@ -274538,10 +274538,10 @@ var Tokenizer = class extends CommentsParser {
274538
274538
  firstInvalidLoc,
274539
274539
  pos,
274540
274540
  curLine,
274541
- lineStart: lineStart2
274541
+ lineStart
274542
274542
  } = readStringContents2("template", this.input, this.state.pos + 1, this.state.lineStart, this.state.curLine, this.errorHandlers_readStringContents_template);
274543
274543
  this.state.pos = pos + 1;
274544
- this.state.lineStart = lineStart2;
274544
+ this.state.lineStart = lineStart;
274545
274545
  this.state.curLine = curLine;
274546
274546
  if (firstInvalidLoc) {
274547
274547
  this.state.firstInvalidTemplateEscapePos = new Position(firstInvalidLoc.curLine, firstInvalidLoc.pos - firstInvalidLoc.lineStart, this.sourceToOffsetPos(firstInvalidLoc.pos));
@@ -274662,13 +274662,13 @@ var Tokenizer = class extends CommentsParser {
274662
274662
  }
274663
274663
  }
274664
274664
  errorBuilder(error) {
274665
- return (pos, lineStart2, curLine) => {
274666
- this.raise(error, buildPosition(pos, lineStart2, curLine));
274665
+ return (pos, lineStart, curLine) => {
274666
+ this.raise(error, buildPosition(pos, lineStart, curLine));
274667
274667
  };
274668
274668
  }
274669
274669
  errorHandlers_readInt = {
274670
- invalidDigit: (pos, lineStart2, curLine, radix) => {
274671
- this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart2, curLine), {
274670
+ invalidDigit: (pos, lineStart, curLine, radix) => {
274671
+ this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), {
274672
274672
  radix
274673
274673
  });
274674
274674
  },
@@ -274682,18 +274682,18 @@ var Tokenizer = class extends CommentsParser {
274682
274682
  };
274683
274683
  errorHandlers_readStringContents_string = {
274684
274684
  ...this.errorHandlers_readCodePoint,
274685
- strictNumericEscape: (pos, lineStart2, curLine) => {
274686
- this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart2, curLine));
274685
+ strictNumericEscape: (pos, lineStart, curLine) => {
274686
+ this.recordStrictModeErrors(Errors.StrictNumericEscape, buildPosition(pos, lineStart, curLine));
274687
274687
  },
274688
- unterminated: (pos, lineStart2, curLine) => {
274689
- throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart2, curLine));
274688
+ unterminated: (pos, lineStart, curLine) => {
274689
+ throw this.raise(Errors.UnterminatedString, buildPosition(pos - 1, lineStart, curLine));
274690
274690
  }
274691
274691
  };
274692
274692
  errorHandlers_readStringContents_template = {
274693
274693
  ...this.errorHandlers_readCodePoint,
274694
274694
  strictNumericEscape: this.errorBuilder(Errors.StrictNumericEscape),
274695
- unterminated: (pos, lineStart2, curLine) => {
274696
- throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart2, curLine));
274695
+ unterminated: (pos, lineStart, curLine) => {
274696
+ throw this.raise(Errors.UnterminatedTemplate, buildPosition(pos, lineStart, curLine));
274697
274697
  }
274698
274698
  };
274699
274699
  };
@@ -288230,7 +288230,6 @@ init_define_globalThis_DIAGONAL_SDK_RUNTIME();
288230
288230
 
288231
288231
  // scripts/lib/runtime-build/resource-references.mjs
288232
288232
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
288233
- import { basename as basename2, extname } from "node:path";
288234
288233
 
288235
288234
  // app/pages/resources/js/pageRuntime/sdk/generatedNames.ts
288236
288235
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -288272,6 +288271,34 @@ function memberPathSegments(node) {
288272
288271
  return null;
288273
288272
  }
288274
288273
 
288274
+ // scripts/lib/runtime-build/resource-paths.mjs
288275
+ init_define_globalThis_DIAGONAL_SDK_RUNTIME();
288276
+ var CHILD_KINDS = Object.freeze({
288277
+ fields: "resource_field",
288278
+ policies: "resource_policy",
288279
+ records: "resource_record"
288280
+ });
288281
+ var DEFINITION_PATH = /^resources\/([^/]+)\/resource\.ts$/;
288282
+ var CHILD_PATH = /^resources\/([^/]+)\/(fields|policies|records)\/([^/]+)\.ts$/;
288283
+ var LEGACY_PATH = /^resources\/([^/]+)\.ts$/;
288284
+ function isResourcePath(path) {
288285
+ return DEFINITION_PATH.test(path);
288286
+ }
288287
+ function resourceChildOf(path) {
288288
+ const match = CHILD_PATH.exec(path);
288289
+ if (match === null) {
288290
+ return null;
288291
+ }
288292
+ const [, folder, directory, key] = match;
288293
+ return { folder, kind: CHILD_KINDS[directory], key, definitionPath: `resources/${folder}/resource.ts` };
288294
+ }
288295
+ function resourceFolderOf(path) {
288296
+ return DEFINITION_PATH.exec(path)?.[1] ?? null;
288297
+ }
288298
+ function legacyResourceFolder(path) {
288299
+ return LEGACY_PATH.exec(path)?.[1] ?? null;
288300
+ }
288301
+
288275
288302
  // scripts/lib/runtime-build/source-module.mjs
288276
288303
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
288277
288304
 
@@ -289226,7 +289253,7 @@ function cssReferences(source) {
289226
289253
  let composing = false;
289227
289254
  let nextNewline = source.indexOf("\n");
289228
289255
  let line = 1;
289229
- let lineStart2 = 0;
289256
+ let lineStart = 0;
289230
289257
  const skipSpace = () => {
289231
289258
  while (offset < source.length) {
289232
289259
  if (/\s/.test(source[offset])) {
@@ -289252,10 +289279,10 @@ function cssReferences(source) {
289252
289279
  const add = (value, start) => {
289253
289280
  while (nextNewline !== -1 && nextNewline < start) {
289254
289281
  line++;
289255
- lineStart2 = nextNewline + 1;
289256
- nextNewline = source.indexOf("\n", lineStart2);
289282
+ lineStart = nextNewline + 1;
289283
+ nextNewline = source.indexOf("\n", lineStart);
289257
289284
  }
289258
- const column = start - lineStart2 + 1;
289285
+ const column = start - lineStart + 1;
289259
289286
  (importing ? imports : urls).push({ value, line, column });
289260
289287
  importing = false;
289261
289288
  };
@@ -289337,7 +289364,7 @@ function diagnostic(path, line, column, message, { stage = BUILD_STAGE, severity
289337
289364
  }
289338
289365
  function diagnosticAt(path, node, message, options) {
289339
289366
  const start = node?.loc?.start;
289340
- return diagnostic(path, start ? start.line : 1, start ? start.column + 1 : 1, message, options);
289367
+ return diagnostic(node?.loc?.filename ?? path, start ? start.line : 1, start ? start.column + 1 : 1, message, options);
289341
289368
  }
289342
289369
  function hasErrors(diagnostics) {
289343
289370
  return diagnostics.some((diagnostic2) => diagnostic2.severity === "error");
@@ -289356,11 +289383,12 @@ function diagnosticFromError(path, error) {
289356
289383
  }
289357
289384
  throw error;
289358
289385
  }
289359
- function parseSource(source, { jsx: jsx2 }) {
289386
+ function parseSource(source, { jsx: jsx2, path }) {
289360
289387
  return parse2(source, {
289361
289388
  sourceType: "module",
289362
289389
  plugins: jsx2 ? ["typescript", "jsx"] : ["typescript"],
289363
- errorRecovery: false
289390
+ errorRecovery: false,
289391
+ ...path === void 0 ? {} : { sourceFilename: path }
289364
289392
  });
289365
289393
  }
289366
289394
  function isTypeOnlyStatement(statement2) {
@@ -302061,6 +302089,7 @@ function scriptWorkspaceDeclarations(resources, builtInResources = [], notificat
302061
302089
  var traverse4 = traverse3.default ?? traverse3;
302062
302090
  var GENERATED_RESOURCES_PATH = "generated/resources.ts";
302063
302091
  var GENERATED_RESOURCES_MODULE = "@app/generated/resources";
302092
+ var GENERATED_RESOURCE_FOLDERS_PATH = "generated/resource-folders.ts";
302064
302093
  var RESOURCES_EXPORT = "Resources";
302065
302094
  var WORKFLOW_MODULE = "@diagonal/workflow";
302066
302095
  var WORKFLOW_PACKAGE = "@diagonal-hq/workflows";
@@ -302100,20 +302129,23 @@ function resourceNames(files, diagnostics) {
302100
302129
  namesBySlug.set(slug, studlyName(slug));
302101
302130
  }
302102
302131
  for (const { path, slug: declared = null, node = null, problem: problem2 = null } of files) {
302103
- const fileName = basename2(path, extname(path));
302132
+ const fileName = resourceFolderOf(path);
302133
+ if (fileName === null) {
302134
+ throw new Error(`resourceNames() takes the resources/<folder>/resource.ts path of each resource, not ${path}`);
302135
+ }
302104
302136
  if (BUILT_IN_RESOURCE_SLUGS.has(fileName)) {
302105
302137
  diagnostics.push(
302106
302138
  diagnosticAt(
302107
302139
  path,
302108
302140
  null,
302109
- "Delete this file. The build always generates Resources.Roles and Resources.Permissions."
302141
+ "Delete this folder. The build always generates Resources.Roles and Resources.Permissions."
302110
302142
  )
302111
302143
  );
302112
302144
  continue;
302113
302145
  }
302114
302146
  if (!RESOURCE_SLUG_PATTERN.test(fileName)) {
302115
302147
  const role = declared === null ? "is the resource slug" : "gives the Resources name of the resource";
302116
- diagnostics.push(diagnosticAt(path, null, `The file name "${fileName}" ${role}, so it must ${SLUG_RULE}`));
302148
+ diagnostics.push(diagnosticAt(path, null, `The folder name "${fileName}" ${role}, so it must ${SLUG_RULE}`));
302117
302149
  continue;
302118
302150
  }
302119
302151
  if (problem2 !== null) {
@@ -302141,7 +302173,7 @@ function resourceNames(files, diagnostics) {
302141
302173
  const otherName = pathsByName.get(name);
302142
302174
  if (otherName === void 0 && slugsByName.has(name)) {
302143
302175
  diagnostics.push(
302144
- diagnosticAt(path, null, `The file name "${fileName}" has the name Resources.${name} of a built-in resource. Rename the file`)
302176
+ diagnosticAt(path, null, `The folder name "${fileName}" has the name Resources.${name} of a built-in resource. Rename the folder`)
302145
302177
  );
302146
302178
  continue;
302147
302179
  }
@@ -302150,7 +302182,7 @@ function resourceNames(files, diagnostics) {
302150
302182
  diagnosticAt(
302151
302183
  path,
302152
302184
  null,
302153
- `The file names "${basename2(otherName, extname(otherName))}" and "${fileName}" both have the name Resources.${name}. Rename one of the files`,
302185
+ `The folder names "${resourceFolderOf(otherName)}" and "${fileName}" both have the name Resources.${name}. Rename one of the folders`,
302154
302186
  { relatedPath: otherName }
302155
302187
  )
302156
302188
  );
@@ -302162,7 +302194,7 @@ function resourceNames(files, diagnostics) {
302162
302194
  diagnosticAt(
302163
302195
  path,
302164
302196
  node,
302165
- `The resource files ${otherSlug} and ${path} have the same slug "${slug}". Change the slug of one of them`,
302197
+ `The resources ${otherSlug} and ${path} have the same slug "${slug}". Change the slug of one of them`,
302166
302198
  { relatedPath: otherSlug }
302167
302199
  )
302168
302200
  );
@@ -302186,15 +302218,15 @@ function staticRecordValues(resource, record) {
302186
302218
  }
302187
302219
  return values;
302188
302220
  }
302189
- function policyKey(name) {
302190
- const key = studlyName(name);
302221
+ function policyKey(fileKey) {
302222
+ const key = studlyName(fileKey);
302191
302223
  return /^[0-9]/.test(key) ? `Policy${key}` : key;
302192
302224
  }
302193
302225
  function policyKeys(policies) {
302194
302226
  const policiesByKey = /* @__PURE__ */ new Map();
302195
302227
  const unnamed = [];
302196
302228
  for (const policy of policies) {
302197
- const key = policyKey(policy.name);
302229
+ const key = policyKey(policy.key);
302198
302230
  if (key === "" || policiesByKey.has(key)) {
302199
302231
  unnamed.push({ policy, key });
302200
302232
  continue;
@@ -302209,8 +302241,11 @@ function policyKeyWarnings(resources, { namesBySlug }) {
302209
302241
  const name = namesBySlug.get(resource.slug);
302210
302242
  const { policiesByKey, unnamed } = policyKeys(resource.policies ?? []);
302211
302243
  for (const { policy, key } of unnamed) {
302212
- const message = key === "" ? `The policy "${policy.name}" has no key in Resources.${name}.policies, because its name has no letters or digits` : `The policies "${policiesByKey.get(key).name}" and "${policy.name}" both have the key Resources.${name}.policies.${key}, so it names "${policiesByKey.get(key).name}". Rename one of them to give "${policy.name}" a key`;
302213
- diagnostics.push(diagnosticAt(resource.path, null, message, { severity: "warning" }));
302244
+ const first = policiesByKey.get(key);
302245
+ const message = first === void 0 ? `The policy file "${policy.key}" has no key in Resources.${name}.policies, because its name has no letters or digits. Rename the file` : `The policy files "${first.key}" and "${policy.key}" both have the key Resources.${name}.policies.${key}, so it names "${first.key}". Rename one of the files`;
302246
+ diagnostics.push(
302247
+ diagnosticAt(policy.path, null, message, first === void 0 ? { severity: "warning" } : { severity: "warning", relatedPath: first.path })
302248
+ );
302214
302249
  }
302215
302250
  }
302216
302251
  return diagnostics;
@@ -302292,6 +302327,23 @@ function generatedResourcesSource(names2, resources, { workflowPackageDeclared =
302292
302327
  workflowPackageDeclared
302293
302328
  });
302294
302329
  }
302330
+ function generatedResourceFoldersSource(names2, resources) {
302331
+ const folders = resources.filter((resource) => names2.namesBySlug.has(resource.slug)).map((resource) => {
302332
+ const folder = resourceFolderOf(resource.path);
302333
+ return ` ${IDENTIFIER_KEY.test(folder) ? folder : quoted(folder)}: typeof ${RESOURCES_EXPORT}.${names2.namesBySlug.get(resource.slug)};`;
302334
+ });
302335
+ return [
302336
+ GENERATED_HEADER,
302337
+ `import type { ${RESOURCES_EXPORT} } from './resources';`,
302338
+ "",
302339
+ `declare module '${AUTHORING_MODULE}' {`,
302340
+ " interface WorkspaceResourceFolders {",
302341
+ ...folders,
302342
+ " }",
302343
+ "}",
302344
+ ""
302345
+ ].join("\n");
302346
+ }
302295
302347
  function generatedWorkflowTypesSource(name, entries, declarations, { augment, workflowPackageDeclared }) {
302296
302348
  const modules = [WORKFLOW_MODULE, ...workflowPackageDeclared ? [WORKFLOW_PACKAGE] : []];
302297
302349
  const augmentations = modules.map((module) => augment(module)).join("");
@@ -302310,7 +302362,13 @@ export const ${name} = ${printLiteral(entries, 0)} as const;
302310
302362
  `;
302311
302363
  }
302312
302364
  function resourceValues(entries) {
302313
- return { entries, exportName: RESOURCES_EXPORT, noun: "resource", directory: "resources/" };
302365
+ return {
302366
+ entries,
302367
+ exportName: RESOURCES_EXPORT,
302368
+ noun: "resource",
302369
+ directory: "resources/",
302370
+ unknownName: (path, key, depth) => depth === 0 ? `Unknown resource "${path}.${key}". Each name in ${path} is a folder in resources/ with a resource.ts` : null
302371
+ };
302314
302372
  }
302315
302373
  function inlineGeneratedValues(source, ast, generatedModuleOf, { typescript: typescript2 = false, typeChecked = false } = {}) {
302316
302374
  const mode = typescript2 ? typeChecked ? "call" : "cast" : null;
@@ -302479,8 +302537,8 @@ function offsetOf(text2, line, column) {
302479
302537
  }
302480
302538
  function positionOf(text2, offset) {
302481
302539
  const before = text2.slice(0, offset);
302482
- const lineStart2 = before.lastIndexOf("\n") + 1;
302483
- return { line: before.split("\n").length, column: offset - lineStart2 + 1 };
302540
+ const lineStart = before.lastIndexOf("\n") + 1;
302541
+ return { line: before.split("\n").length, column: offset - lineStart + 1 };
302484
302542
  }
302485
302543
  function memberName(node, object) {
302486
302544
  if ((node?.type === "MemberExpression" || node?.type === "OptionalMemberExpression") && node.object === object && !node.computed && node.property.type === "Identifier") {
@@ -302766,7 +302824,7 @@ function camelKey(name) {
302766
302824
  return `${name.charAt(0).toLowerCase()}${name.slice(1)}`;
302767
302825
  }
302768
302826
  var GENERATED_REFERENCES = [
302769
- { option: "resources", values: "slugsByName", noun: "resource", directory: "resources/", property: "slug" },
302827
+ { option: "resources", values: "slugsByName", noun: "resource", directory: "resources/", names: "is a folder in resources/ with a resource.ts", property: "slug" },
302770
302828
  {
302771
302829
  option: "assets",
302772
302830
  values: "keysByName",
@@ -303242,8 +303300,8 @@ export default defineAssets({
303242
303300
  }
303243
303301
  const multiline = last2.loc.end.line < definition.loc.end.line;
303244
303302
  if (multiline) {
303245
- const lineStart2 = source.lastIndexOf("\n", last2.start - 1) + 1;
303246
- const indent = source.slice(lineStart2, last2.start).match(/^[\t ]*/)[0];
303303
+ const lineStart = source.lastIndexOf("\n", last2.start - 1) + 1;
303304
+ const indent = source.slice(lineStart, last2.start).match(/^[\t ]*/)[0];
303247
303305
  if (!trailingComma) {
303248
303306
  edits.push({ start: last2.end, text: "," });
303249
303307
  }
@@ -303387,7 +303445,7 @@ ${ASSETS_UPLOAD_USAGE}
303387
303445
  assetId = lookup.body.asset.id;
303388
303446
  }
303389
303447
  const form = new FormData();
303390
- form.append("file", new Blob([bytes]), basename3(file2));
303448
+ form.append("file", new Blob([bytes]), basename2(file2));
303391
303449
  const uploaded = await request(target, "POST", "/api/files/uploads", form, stderr);
303392
303450
  if (uploaded === null) return 1;
303393
303451
  const result = await request(
@@ -303524,7 +303582,7 @@ init_define_globalThis_DIAGONAL_SDK_RUNTIME();
303524
303582
  // scripts/lib/runtime-build/record-bindings.mjs
303525
303583
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
303526
303584
  import { readFileSync as readFileSync2 } from "node:fs";
303527
- import { basename as basename4, join as join4 } from "node:path";
303585
+ import { basename as basename3, join as join4 } from "node:path";
303528
303586
 
303529
303587
  // scripts/lib/runtime-build/definition-uid.mjs
303530
303588
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -303654,8 +303712,8 @@ function readUid(object, { version = null } = {}) {
303654
303712
  }
303655
303713
  function locationAt(source, offset) {
303656
303714
  const before = source.slice(0, offset);
303657
- const lineStart2 = before.lastIndexOf("\n") + 1;
303658
- return { loc: { start: { line: before.split("\n").length, column: offset - lineStart2 } } };
303715
+ const lineStart = before.lastIndexOf("\n") + 1;
303716
+ return { loc: { start: { line: before.split("\n").length, column: offset - lineStart } } };
303659
303717
  }
303660
303718
  function readFrontMatterUid(source, { map, offset }) {
303661
303719
  const pair = map.items.find((item) => (0, import_yaml.isScalar)(item.key) && item.key.value === "uid") ?? null;
@@ -303738,9 +303796,9 @@ function uidInsertion(source, object, uid2) {
303738
303796
  if (anchor.loc.start.line === object.loc.start.line) {
303739
303797
  return { start: anchor.start, end: anchor.start, text: `${property}, ` };
303740
303798
  }
303741
- const lineStart2 = source.lastIndexOf("\n", anchor.start - 1) + 1;
303742
- const indent = source.slice(lineStart2, anchor.start);
303743
- const newline = source[lineStart2 - 2] === "\r" ? "\r\n" : "\n";
303799
+ const lineStart = source.lastIndexOf("\n", anchor.start - 1) + 1;
303800
+ const indent = source.slice(lineStart, anchor.start);
303801
+ const newline = source[lineStart - 2] === "\r" ? "\r\n" : "\n";
303744
303802
  return { start: anchor.start, end: anchor.start, text: `${property},${newline}${indent}` };
303745
303803
  }
303746
303804
  function frontMatterUidInsertion(source, { map, offset }, uid2) {
@@ -303888,7 +303946,7 @@ function readRecordBindings(root, paths, names2, resources, diagnostics, { write
303888
303946
  throw new SourceError(`Unknown record binding option "${key2}"`, node);
303889
303947
  }
303890
303948
  }
303891
- const key = studlyName(basename4(path, ".ts"));
303949
+ const key = studlyName(basename3(path, ".ts"));
303892
303950
  if (!/^[A-Za-z][A-Za-z0-9_]*$/.test(key)) {
303893
303951
  throw new SourceError(`Invalid RecordBindings name "${key}". Rename the file`, node);
303894
303952
  }
@@ -304013,7 +304071,7 @@ function recordBindingUsages(root, paths, entries) {
304013
304071
 
304014
304072
  // scripts/lib/runtime-build/build-workspace.mjs
304015
304073
  import { existsSync as existsSync9, mkdirSync as mkdirSync3, readFileSync as readFileSync14, writeFileSync as writeFileSync5 } from "node:fs";
304016
- import { basename as basename14, dirname as dirname9, extname as extname3, join as join18 } from "node:path";
304074
+ import { basename as basename13, dirname as dirname9, extname as extname2, join as join18 } from "node:path";
304017
304075
 
304018
304076
  // scripts/lib/runtime-build/brand-kit.mjs
304019
304077
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -308309,8 +308367,27 @@ function composePackages(root) {
308309
308367
  dependencies: [...packageDependencies].toSorted()
308310
308368
  });
308311
308369
  }
308370
+ diagnostics.push(...resourceOwnershipProblems(files));
308312
308371
  return { packages, files, dependencies, diagnostics };
308313
308372
  }
308373
+ function resourceOwnershipProblems(files) {
308374
+ const diagnostics = [];
308375
+ for (const [path, { name, source }] of files) {
308376
+ const child = resourceChildOf(path);
308377
+ if (child === null || child.kind === "resource_field" || files.get(child.definitionPath)?.name === name) {
308378
+ continue;
308379
+ }
308380
+ const kind = child.kind === "resource_policy" ? "policy" : "record";
308381
+ diagnostics.push(
308382
+ diagnosticAt(
308383
+ source,
308384
+ null,
308385
+ `The package "${name}" does not provide ${child.definitionPath}, so it cannot add a ${kind} to that resource. A package adds only fields to a resource of another tree`
308386
+ )
308387
+ );
308388
+ }
308389
+ return diagnostics;
308390
+ }
308314
308391
  function materializePackages(root, plan) {
308315
308392
  for (const [path, { source }] of plan.files) {
308316
308393
  const target = join7(root, path);
@@ -308551,7 +308628,7 @@ function refuseUnknownOptions(value, options, node, owner) {
308551
308628
 
308552
308629
  // scripts/lib/runtime-build/migrations.mjs
308553
308630
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
308554
- import { basename as basename12 } from "node:path";
308631
+ import { basename as basename11 } from "node:path";
308555
308632
 
308556
308633
  // scripts/lib/runtime-build/migration-file.mjs
308557
308634
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -310816,7 +310893,7 @@ function fieldTypeList(fieldTypes) {
310816
310893
 
310817
310894
  // scripts/lib/runtime-build/workflow-references.mjs
310818
310895
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
310819
- import { basename as basename5 } from "node:path";
310896
+ import { basename as basename4 } from "node:path";
310820
310897
 
310821
310898
  // scripts/lib/workflow-script/constants.mjs
310822
310899
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -310851,7 +310928,7 @@ function workflowNames(paths, diagnostics) {
310851
310928
  for (const path of paths.toSorted(byteOrder2)) {
310852
310929
  const name = pathName(
310853
310930
  path,
310854
- basename5(path, ".ts"),
310931
+ basename4(path, ".ts"),
310855
310932
  { exportName: WORKFLOWS_EXPORT, label: "workflow", showText: false, severity: "warning" },
310856
310933
  diagnostics
310857
310934
  );
@@ -310879,7 +310956,7 @@ function workflowEntries({ pathsByName }, metadataByPath) {
310879
310956
  const entries = /* @__PURE__ */ Object.create(null);
310880
310957
  for (const name of [...pathsByName.keys()].toSorted(byteOrder2)) {
310881
310958
  const path = pathsByName.get(name);
310882
- const { uid: uid2 = null, slug = basename5(path, ".ts"), ...metadata } = metadataByPath.get(path) ?? {};
310959
+ const { uid: uid2 = null, slug = basename4(path, ".ts"), ...metadata } = metadataByPath.get(path) ?? {};
310883
310960
  entries[name] = { uid: uid2, slug, ...metadata };
310884
310961
  }
310885
310962
  return entries;
@@ -311039,7 +311116,7 @@ function pageWorkflowReferenceDiagnostics(path, ast, entries, options = {}) {
311039
311116
  const pathError = workflowPathError(
311040
311117
  path,
311041
311118
  value,
311042
- (workflowPath) => namesBySlug.get(basename5(workflowPath, ".ts")) ?? null,
311119
+ (workflowPath) => namesBySlug.get(basename4(workflowPath, ".ts")) ?? null,
311043
311120
  options
311044
311121
  );
311045
311122
  if (pathError !== null) {
@@ -311791,7 +311868,7 @@ var import_typescript2 = __toESM(require_typescript(), 1);
311791
311868
  import { spawnSync } from "node:child_process";
311792
311869
  import { mkdirSync as mkdirSync2, mkdtempSync as mkdtempSync2, realpathSync as realpathSync2, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "node:fs";
311793
311870
  import { tmpdir as tmpdir2 } from "node:os";
311794
- import { basename as basename10, dirname as dirname5, join as join13, relative as relative5 } from "node:path";
311871
+ import { basename as basename9, dirname as dirname5, join as join13, relative as relative5 } from "node:path";
311795
311872
 
311796
311873
  // scripts/lib/runtime-build/app-modules.mjs
311797
311874
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -311813,6 +311890,8 @@ __export(cli_exports, {
311813
311890
  defineNotificationType: () => defineNotificationType,
311814
311891
  definePage: () => definePage,
311815
311892
  definePermission: () => definePermission,
311893
+ definePolicy: () => definePolicy,
311894
+ defineRecord: () => defineRecord,
311816
311895
  defineRecordBinding: () => defineRecordBinding,
311817
311896
  defineRedirects: () => defineRedirects,
311818
311897
  defineResource: () => defineResource,
@@ -311916,6 +311995,8 @@ var defineWorkspaceField = (field2) => field2;
311916
311995
  var definePermission = (permission) => permission;
311917
311996
  var defineRole = (role) => role;
311918
311997
  var defineResource = (resource) => resource;
311998
+ var definePolicy = (policy) => policy;
311999
+ var defineRecord = (record) => record;
311919
312000
  var definePage = (page, _component) => page;
311920
312001
  var text = {
311921
312002
  template: (template, values) => ({ $type: "text.template", template, values })
@@ -311952,7 +312033,7 @@ function sha256(value) {
311952
312033
 
311953
312034
  // scripts/lib/runtime-build/permission-references.mjs
311954
312035
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
311955
- import { basename as basename6, extname as extname2 } from "node:path";
312036
+ import { basename as basename5, extname } from "node:path";
311956
312037
  var PERMISSIONS_DIRECTORY = "permissions";
311957
312038
  var LEGACY_PERMISSIONS_PATH = "permissions.ts";
311958
312039
  var GENERATED_PERMISSIONS_PATH = "generated/permissions.ts";
@@ -311974,7 +312055,7 @@ function isDefinitionSlug(slug) {
311974
312055
  return SLUG_PATTERN2.test(slug) && slug.length <= MAX_LENGTH;
311975
312056
  }
311976
312057
  function definitionFileSlug(path, definition, { noun, exportName }) {
311977
- const fileName = basename6(path, extname2(path));
312058
+ const fileName = basename5(path, extname(path));
311978
312059
  const declared = declaredSlug(definition);
311979
312060
  if (declared.problem !== null) {
311980
312061
  throw new SourceError(declared.problem, declared.node);
@@ -312384,7 +312465,7 @@ function roleValues(entries) {
312384
312465
 
312385
312466
  // scripts/lib/runtime-build/skill-references.mjs
312386
312467
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
312387
- import { basename as basename7 } from "node:path";
312468
+ import { basename as basename6 } from "node:path";
312388
312469
  var GENERATED_SKILLS_PATH = "generated/skills.ts";
312389
312470
  var SKILLS_EXPORT = "Skills";
312390
312471
  function skillNames(paths, diagnostics) {
@@ -312392,7 +312473,7 @@ function skillNames(paths, diagnostics) {
312392
312473
  for (const path of paths.toSorted(byteOrder2)) {
312393
312474
  const name = pathName(
312394
312475
  path,
312395
- basename7(path, ".md"),
312476
+ basename6(path, ".md"),
312396
312477
  { exportName: SKILLS_EXPORT, label: "skill", showText: false, severity: "warning" },
312397
312478
  diagnostics
312398
312479
  );
@@ -312632,12 +312713,12 @@ function objectExpressions(node) {
312632
312713
 
312633
312714
  // scripts/lib/runtime-build/workspace-field-references.mjs
312634
312715
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
312635
- import { basename as basename9 } from "node:path";
312716
+ import { basename as basename8 } from "node:path";
312636
312717
 
312637
312718
  // scripts/lib/runtime-build/workspace-fields.mjs
312638
312719
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
312639
312720
  import { readFileSync as readFileSync5 } from "node:fs";
312640
- import { basename as basename8, join as join8 } from "node:path";
312721
+ import { basename as basename7, join as join8 } from "node:path";
312641
312722
 
312642
312723
  // packages/cli/workspace-settings-catalog.json
312643
312724
  var workspace_settings_catalog_default = {
@@ -312899,7 +312980,7 @@ function readWorkspaceFields(root, paths, diagnostics, { write = false, recordBi
312899
312980
  const ast = parseSource(source, { jsx: false });
312900
312981
  const argument = defineWorkspaceFieldArgument(ast);
312901
312982
  const declared = declaredSlug(argument, "key");
312902
- keysByPath.set(path, declared.slug ?? basename8(path, ".ts"));
312983
+ keysByPath.set(path, declared.slug ?? basename7(path, ".ts"));
312903
312984
  const field2 = readWorkspaceField(path, argument, declared, diagnostics, recordBindingsBinding(ast, recordBindingEntries));
312904
312985
  read2.push({ field: field2, uidDefinition: { type: "workspace field", path, source, node: argument } });
312905
312986
  } catch (error) {
@@ -312921,7 +313002,7 @@ function isWorkspaceFieldFileName(name) {
312921
313002
  return FIELD_KEY_PATTERN.test(name);
312922
313003
  }
312923
313004
  function workspaceFieldKeyProblem(path, key, declared) {
312924
- const fileName = basename8(path, ".ts");
313005
+ const fileName = basename7(path, ".ts");
312925
313006
  if (!isWorkspaceFieldFileName(fileName)) {
312926
313007
  const suggestion = fileName.toLowerCase().replaceAll("-", "_");
312927
313008
  const hint = isWorkspaceFieldFileName(suggestion) ? `. Rename the file to ${suggestion}.ts` : "";
@@ -312940,7 +313021,7 @@ function readWorkspaceField(path, argument, declared, diagnostics, generatedEntr
312940
313021
  if (declared.problem !== null) {
312941
313022
  throw new SourceError(declared.problem, declared.node);
312942
313023
  }
312943
- const key = declared.slug ?? basename8(path, ".ts");
313024
+ const key = declared.slug ?? basename7(path, ".ts");
312944
313025
  const keyProblem = workspaceFieldKeyProblem(path, key, declared.slug !== null);
312945
313026
  if (keyProblem !== null) {
312946
313027
  throw new SourceError(keyProblem, declared.node);
@@ -313090,7 +313171,7 @@ function workspaceFieldNames(paths, keysByPath, diagnostics) {
313090
313171
  const pathsByName = /* @__PURE__ */ new Map();
313091
313172
  const pathsByKey = /* @__PURE__ */ new Map();
313092
313173
  for (const path of paths.toSorted(byteOrder2)) {
313093
- const fileName = basename9(path, ".ts");
313174
+ const fileName = basename8(path, ".ts");
313094
313175
  if (!isWorkspaceFieldFileName(fileName)) {
313095
313176
  continue;
313096
313177
  }
@@ -314187,7 +314268,7 @@ function importDiagnostics(test, scriptNames, workspaceRoot, subject) {
314187
314268
  }
314188
314269
  function compiledScriptModule(script) {
314189
314270
  const prefix2 = sandboxPrefix(script.path);
314190
- const source = JSON.stringify(`./${basename10(script.path, ".ts")}.mjs`);
314271
+ const source = JSON.stringify(`./${basename9(script.path, ".ts")}.mjs`);
314191
314272
  return [
314192
314273
  `import * as script from ${source};`,
314193
314274
  `import { registerCompiledScript } from ${JSON.stringify(`${prefix2}sdk/quickjs-testing.js`)};`,
@@ -314411,7 +314492,7 @@ function runScriptTests({
314411
314492
 
314412
314493
  // scripts/lib/runtime-build/workflows.mjs
314413
314494
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
314414
- import { basename as basename11 } from "node:path";
314495
+ import { basename as basename10 } from "node:path";
314415
314496
 
314416
314497
  // scripts/lib/workflow-script/compile.mjs
314417
314498
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -314830,7 +314911,7 @@ function buildWorkflows({
314830
314911
  entry: {
314831
314912
  path,
314832
314913
  uid: uidsByPath.get(path) ?? null,
314833
- slug: config?.slug ?? basename11(path, ".ts"),
314914
+ slug: config?.slug ?? basename10(path, ".ts"),
314834
314915
  title: config?.title ?? null,
314835
314916
  description: config?.description ?? null,
314836
314917
  type: config?.type ?? null,
@@ -314883,7 +314964,7 @@ function buildMigrations({ migrations, ...input }) {
314883
314964
  const diagnostics = [];
314884
314965
  const timestamps = /* @__PURE__ */ new Map();
314885
314966
  for (const { path, ast } of migrations) {
314886
- const id = basename12(path, ".ts");
314967
+ const id = basename11(path, ".ts");
314887
314968
  const timestamp = migrationTimestamp(id);
314888
314969
  const slug = declaredSlug(workflowConfigObject(ast));
314889
314970
  if (slug.node !== null) {
@@ -314948,7 +315029,7 @@ function buildMigrations({ migrations, ...input }) {
314948
315029
  }
314949
315030
  }
314950
315031
  return {
314951
- migrations: built.workflows.map((workflow) => ({ ...workflow, id: basename12(workflow.path, ".ts") })).toSorted((left, right) => left.id.localeCompare(right.id)),
315032
+ migrations: built.workflows.map((workflow) => ({ ...workflow, id: basename11(workflow.path, ".ts") })).toSorted((left, right) => left.id.localeCompare(right.id)),
314952
315033
  migrationTests: built.workflowTests,
314953
315034
  diagnostics
314954
315035
  };
@@ -316901,7 +316982,7 @@ var SUCRASE_OPTIONS = {
316901
316982
  function authoringColumns(code2) {
316902
316983
  const { tokens } = (0, import_parser4.parse)(code2, true, true, false);
316903
316984
  const columns = [];
316904
- let lineStart2 = 0;
316985
+ let lineStart = 0;
316905
316986
  let scanned = 0;
316906
316987
  for (let index3 = 0; index3 < tokens.length; index3 += 1) {
316907
316988
  if (tokens[index3].type !== import_types.TokenType.jsxTagStart) {
@@ -316914,11 +316995,11 @@ function authoringColumns(code2) {
316914
316995
  const { start } = tokens[index3];
316915
316996
  while (scanned < start) {
316916
316997
  if (code2.charCodeAt(scanned) === 10) {
316917
- lineStart2 = scanned + 1;
316998
+ lineStart = scanned + 1;
316918
316999
  }
316919
317000
  scanned += 1;
316920
317001
  }
316921
- columns.push(start - lineStart2);
317002
+ columns.push(start - lineStart);
316922
317003
  }
316923
317004
  return columns;
316924
317005
  }
@@ -316926,7 +317007,7 @@ function addAuthoringColumns(transformed, columns, trackInsertions) {
316926
317007
  let sourceIndex = 0;
316927
317008
  let scannedOffset = 0;
316928
317009
  let line = 0;
316929
- let lineStart2 = 0;
317010
+ let lineStart = 0;
316930
317011
  const insertions = [];
316931
317012
  const code2 = transformed.replace(
316932
317013
  /(__source:\s*\{fileName:\s*_jsxFileName,\s*lineNumber:\s*\d+)(\})/g,
@@ -316937,11 +317018,11 @@ function addAuthoringColumns(transformed, columns, trackInsertions) {
316937
317018
  while (scannedOffset < insertionOffset) {
316938
317019
  if (transformed.charCodeAt(scannedOffset) === 10) {
316939
317020
  line += 1;
316940
- lineStart2 = scannedOffset + 1;
317021
+ lineStart = scannedOffset + 1;
316941
317022
  }
316942
317023
  scannedOffset += 1;
316943
317024
  }
316944
- insertions.push({ line, column: insertionOffset - lineStart2, length: insertion.length });
317025
+ insertions.push({ line, column: insertionOffset - lineStart, length: insertion.length });
316945
317026
  }
316946
317027
  return `${source}${insertion}${closingBrace}`;
316947
317028
  }
@@ -320335,8 +320416,8 @@ function propertyValue2(objectNode, property) {
320335
320416
  }
320336
320417
  }
320337
320418
  function lineIndent(source, offset) {
320338
- const lineStart2 = source.lastIndexOf("\n", offset - 1) + 1;
320339
- return /^[ \t]*/.exec(source.slice(lineStart2))[0];
320419
+ const lineStart = source.lastIndexOf("\n", offset - 1) + 1;
320420
+ return /^[ \t]*/.exec(source.slice(lineStart))[0];
320340
320421
  }
320341
320422
  function removalEnd(property, next) {
320342
320423
  const comments = (next.leadingComments ?? []).filter(
@@ -320606,15 +320687,18 @@ var RESOURCE_KEYS = /* @__PURE__ */ new Set([
320606
320687
  "displayField",
320607
320688
  "searchableFields",
320608
320689
  "fieldOrder",
320609
- "fields",
320610
320690
  "indexes",
320611
320691
  "embeddings",
320612
320692
  "dataApi",
320613
320693
  "static",
320614
- "records",
320615
- "policies",
320616
320694
  "capabilities"
320617
320695
  ]);
320696
+ var CHILD_OPTIONS = {
320697
+ fields: "Move each field to fields/<key>.ts in the folder of the resource, as export default field.<type>({...})",
320698
+ policies: "Move each policy to policies/<key>.ts in the folder of the resource, as export default definePolicy({...})",
320699
+ records: "Move each record to records/<key>.ts in the folder of the resource, as export default defineRecord({...})"
320700
+ };
320701
+ var RESOURCE_FILE_IMPORTS = [GENERATED_RESOURCES_MODULE, GENERATED_PAGES_MODULE, GENERATED_RECORD_BINDINGS_MODULE];
320618
320702
  var INDEX_KEYS = /* @__PURE__ */ new Set(["fields", "unique"]);
320619
320703
  var EMBEDDINGS_KEYS = /* @__PURE__ */ new Set(["enabled", "fields"]);
320620
320704
  var DEFAULT_SEARCHABLE_TYPES = /* @__PURE__ */ new Set(["text", "markdown"]);
@@ -320673,12 +320757,17 @@ function buildIndexes(indexes, node, fieldsByKey) {
320673
320757
  return { fields: index3.fields, unique: index3.unique ?? false };
320674
320758
  });
320675
320759
  }
320676
- function orderFields(fields, fieldOrder, node) {
320760
+ function orderFields(declared, fieldOrder, node) {
320761
+ if (fieldOrder !== void 0) {
320762
+ stringList(fieldOrder, "fieldOrder", node);
320763
+ }
320764
+ const unlisted = declared.filter(({ field: field2 }) => fieldOrder === void 0 || !fieldOrder.includes(field2.key)).toSorted(
320765
+ (left, right) => Number(left.uid === null) - Number(right.uid === null) || byteOrder3(left.uid ?? "", right.uid ?? "") || byteOrder3(left.field.key, right.field.key)
320766
+ ).map(({ field: field2 }) => field2);
320677
320767
  if (fieldOrder === void 0) {
320678
- return fields;
320768
+ return unlisted;
320679
320769
  }
320680
- stringList(fieldOrder, "fieldOrder", node);
320681
- const fieldsByKey = new Map(fields.map((field2) => [field2.key, field2]));
320770
+ const fieldsByKey = new Map(declared.map(({ field: field2 }) => [field2.key, field2]));
320682
320771
  fieldOrder.forEach((key, position) => {
320683
320772
  if (!fieldsByKey.has(key)) {
320684
320773
  throw new SourceError(
@@ -320687,11 +320776,10 @@ function orderFields(fields, fieldOrder, node) {
320687
320776
  );
320688
320777
  }
320689
320778
  });
320690
- const missing = fields.find((field2) => !fieldOrder.includes(field2.key));
320691
- if (missing !== void 0) {
320692
- throw new SourceError(`fieldOrder must list every field. "${missing.key}" is missing`, node);
320693
- }
320694
- return fieldOrder.map((key) => fieldsByKey.get(key));
320779
+ return [...fieldOrder.map((key) => fieldsByKey.get(key)), ...unlisted];
320780
+ }
320781
+ function byteOrder3(left, right) {
320782
+ return left < right ? -1 : left > right ? 1 : 0;
320695
320783
  }
320696
320784
  function defaultSearchableFields(fields, displayField) {
320697
320785
  const keys2 = /* @__PURE__ */ new Set();
@@ -320893,31 +320981,25 @@ function staticRelationValue(key, field2, value, valueNode) {
320893
320981
  function isEmptyValue(value) {
320894
320982
  return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
320895
320983
  }
320896
- function buildStaticRecords(value, nodes, definitionNode, fields) {
320984
+ function buildStaticRecords(value, nodes, fields) {
320897
320985
  if (value.static !== true) {
320898
- if (value.records !== void 0) {
320899
- throw new SourceError('"records" needs "static: true". Only a static resource declares its records', nodes.records);
320986
+ if (Object.keys(value.records).length > 0) {
320987
+ throw new SourceError(
320988
+ 'A record file needs "static: true" in resource.ts. Only a static resource declares its records',
320989
+ nodes.records.value.properties[0]
320990
+ );
320900
320991
  }
320901
320992
  return null;
320902
320993
  }
320903
- if (value.records === void 0) {
320904
- throw new SourceError(
320905
- 'A static resource declares all of its records in "records". Use "records: {}" for a resource with no records',
320906
- nodes.static ?? definitionNode
320907
- );
320908
- }
320909
320994
  if (value.capabilities !== void 0 && Object.keys(value.capabilities ?? {}).length > 0) {
320910
320995
  throw new SourceError("A static resource cannot have capabilities, because they write to its records", nodes.capabilities);
320911
320996
  }
320912
320997
  for (const field2 of fields) {
320913
320998
  if (field2.key === "uid") {
320914
- throw new SourceError('A static resource cannot have a field with the key "uid". Each record uses "uid" for its id', nodes.fields);
320999
+ throw new SourceError('A static resource cannot have a field with the key "uid". Each record uses "uid" for its id', nodes.fieldNodes.get(field2.key));
320915
321000
  }
320916
321001
  }
320917
321002
  const recordsNode = nodes.records.value;
320918
- if (recordsNode.type !== "ObjectExpression" || !isPlainObject2(value.records)) {
320919
- throw new SourceError('"records" must be an object literal of records, keyed by record key', nodes.records);
320920
- }
320921
321003
  const fieldsByKey = new Map(fields.map((field2) => [field2.key, field2]));
320922
321004
  const entryNodes = new Map(recordsNode.properties.map((property) => [propertyKey2(property), property]));
320923
321005
  return Object.entries(value.records).map(([key, entry]) => {
@@ -320963,9 +321045,39 @@ function buildStaticRecords(value, nodes, definitionNode, fields) {
320963
321045
  });
320964
321046
  }
320965
321047
  function defineResourceArgument(ast) {
320966
- const { declaration } = defaultExportOf(ast, { extraImports: [GENERATED_RESOURCES_MODULE, GENERATED_PAGES_MODULE, GENERATED_RECORD_BINDINGS_MODULE] });
321048
+ const { declaration } = defaultExportOf(ast, { extraImports: RESOURCE_FILE_IMPORTS });
320967
321049
  return expectDefineCall(declaration, "defineResource", 1)[0];
320968
321050
  }
321051
+ function folderTypeArgumentProblem(ast, folder) {
321052
+ const { declaration } = defaultExportOf(ast, { extraImports: RESOURCE_FILE_IMPORTS });
321053
+ const typeArguments = declaration?.typeArguments ?? declaration?.typeParameters;
321054
+ if (typeArguments === void 0 || typeArguments === null) {
321055
+ return null;
321056
+ }
321057
+ const [argument] = typeArguments.params;
321058
+ const named = argument?.type === "TSLiteralType" && argument.literal.type === "StringLiteral" ? argument.literal.value : null;
321059
+ if (typeArguments.params.length === 1 && named === folder) {
321060
+ return null;
321061
+ }
321062
+ const define2 = declaration.callee?.name ?? "define";
321063
+ return {
321064
+ node: typeArguments,
321065
+ message: `The type argument names another folder, so the editor types this file with the fields of that resource. Use ${define2}<'${folder}'>(...)`
321066
+ };
321067
+ }
321068
+ function resourceChildArgument(kind, ast) {
321069
+ const { declaration } = defaultExportOf(ast, { extraImports: RESOURCE_FILE_IMPORTS });
321070
+ switch (kind) {
321071
+ case "resource_field":
321072
+ return declaration;
321073
+ case "resource_policy":
321074
+ return expectDefineCall(declaration, "definePolicy", 1)[0];
321075
+ case "resource_record":
321076
+ return expectDefineCall(declaration, "defineRecord", 1)[0];
321077
+ default:
321078
+ throw new Error(`Unknown resource file kind "${kind}"`);
321079
+ }
321080
+ }
320969
321081
  function resourceSlugOption(ast) {
320970
321082
  try {
320971
321083
  return declaredSlug(defineResourceArgument(ast));
@@ -320976,8 +321088,8 @@ function resourceSlugOption(ast) {
320976
321088
  throw error;
320977
321089
  }
320978
321090
  }
320979
- function buildResource(path, definitionNode, { slug, resources, pages = null, generatedEntries = [] }) {
320980
- const { value, nodes } = staticObject(definitionNode, { fieldBuilders: true, resources, pages, generatedEntries });
321091
+ function buildResource(path, definitionNode, { slug, resources, pages = null, generatedEntries = [], children = [] }) {
321092
+ const { value, nodes } = staticObject(definitionNode, { fieldBuilders: false, resources, pages, generatedEntries });
320981
321093
  if (Object.hasOwn(value, "platform")) {
320982
321094
  throw new SourceError(
320983
321095
  "Platform resource files are no longer supported. Declare the resource with its fields, or delete the file.",
@@ -320988,25 +321100,25 @@ function buildResource(path, definitionNode, { slug, resources, pages = null, ge
320988
321100
  if (key === "id") {
320989
321101
  throw new SourceError('Remove "id". The platform gives each resource its id', nodes.id);
320990
321102
  }
321103
+ if (Object.hasOwn(CHILD_OPTIONS, key)) {
321104
+ throw new SourceError(`Remove "${key}" from resource.ts. ${CHILD_OPTIONS[key]}`, nodes[key]);
321105
+ }
320991
321106
  if (!RESOURCE_KEYS.has(key)) {
320992
321107
  throw new SourceError(`Unknown resource option "${key}"`, nodes[key]);
320993
321108
  }
320994
321109
  }
320995
321110
  const name = requireString(value, "name", nodes.name ?? definitionNode);
320996
321111
  const singularName = requireString(value, "singularName", nodes.singularName ?? definitionNode);
320997
- if (value.fields === null || typeof value.fields !== "object" || Array.isArray(value.fields)) {
320998
- throw new SourceError(
320999
- '"fields" must be an object of field.<type>(...) calls',
321000
- nodes.fields ?? definitionNode
321001
- );
321002
- }
321003
- const fieldsNode = nodes.fields.value;
321004
- const fieldKeyNodes = new Map(
321005
- fieldsNode.type === "ObjectExpression" ? fieldsNode.properties.map((property) => [property.key.name ?? property.key.value, property]) : []
321006
- );
321007
- const declaredFields = Object.entries(value.fields).map(
321008
- ([key, builder]) => buildField(key, builder, fieldKeyNodes.get(key) ?? fieldsNode)
321009
- );
321112
+ const ordered = children.toSorted((left, right) => byteOrder3(left.path, right.path));
321113
+ const fieldNodes = /* @__PURE__ */ new Map();
321114
+ const declaredFields = ordered.filter((child) => child.kind === "resource_field").map((child) => {
321115
+ const builder = staticValue(child.node, { ...child.bindings, fieldBuilders: true });
321116
+ fieldNodes.set(child.key, child.node);
321117
+ return {
321118
+ field: { ...buildField(child.key, builder, child.node), path: child.path },
321119
+ uid: typeof builder?.options?.uid === "string" ? builder.options.uid : null
321120
+ };
321121
+ });
321010
321122
  const fields = orderFields(declaredFields, value.fieldOrder, nodes.fieldOrder);
321011
321123
  const fieldsByKey = new Map(fields.map((field2) => [field2.key, field2]));
321012
321124
  const displayField = requireString(value, "displayField", nodes.displayField, { optional: true });
@@ -321021,7 +321133,37 @@ function buildResource(path, definitionNode, { slug, resources, pages = null, ge
321021
321133
  }
321022
321134
  const searchableFields = value.searchableFields === void 0 ? defaultSearchableFields(fields, displayField) : stringList(value.searchableFields, "searchableFields", nodes.searchableFields);
321023
321135
  const embeddings = buildEmbeddings(value.embeddings, nodes.embeddings);
321024
- const records = buildStaticRecords(value, nodes, definitionNode, fields);
321136
+ const recordFiles = ordered.filter((child) => child.kind === "resource_record");
321137
+ const records = buildStaticRecords(
321138
+ {
321139
+ static: value.static,
321140
+ capabilities: value.capabilities,
321141
+ records: Object.fromEntries(
321142
+ recordFiles.map((child) => [child.key, staticValue(child.node, { ...child.bindings, fieldBuilders: false })])
321143
+ )
321144
+ },
321145
+ {
321146
+ ...nodes,
321147
+ fieldNodes,
321148
+ records: {
321149
+ value: {
321150
+ type: "ObjectExpression",
321151
+ properties: recordFiles.map((child) => ({
321152
+ type: "ObjectProperty",
321153
+ key: { type: "Identifier", name: child.key, loc: child.node.loc },
321154
+ value: child.node,
321155
+ loc: child.node.loc
321156
+ }))
321157
+ }
321158
+ }
321159
+ },
321160
+ fields
321161
+ );
321162
+ const policyFiles = ordered.filter((child) => child.kind === "resource_policy");
321163
+ const policies = buildPolicies(
321164
+ policyFiles.map((child) => staticValue(child.node, { ...child.bindings, fieldBuilders: false })),
321165
+ { type: "ArrayExpression", elements: policyFiles.map((child) => child.node) }
321166
+ ).map((policy, position) => ({ ...policy, key: policyFiles[position].key, path: policyFiles[position].path }));
321025
321167
  return {
321026
321168
  path,
321027
321169
  slug,
@@ -321035,7 +321177,7 @@ function buildResource(path, definitionNode, { slug, resources, pages = null, ge
321035
321177
  data_api: buildDataApi(value.dataApi, nodes.dataApi),
321036
321178
  static: value.static ?? false,
321037
321179
  records,
321038
- policies: buildPolicies(value.policies, nodes.policies),
321180
+ policies,
321039
321181
  capabilities: readCapabilities(value.capabilities, nodes.capabilities),
321040
321182
  pathNodes: {
321041
321183
  searchableFields: value.searchableFields === void 0 ? null : nodes.searchableFields,
@@ -321058,8 +321200,8 @@ function addInverseFields(resources, diagnostics) {
321058
321200
  }
321059
321201
  const existing = target.fields.find((item) => item.key === inverse.key);
321060
321202
  if (existing !== void 0) {
321061
- const owner = existing.inverse_of === void 0 ? `${target.path}` : `another relation`;
321062
- const ownerPath = existing.inverse_of === void 0 ? target.path : resourcesBySlug.get(existing.inverse_of.resource).path;
321203
+ const owner = existing.inverse_of === void 0 ? existing.path : "another relation";
321204
+ const ownerPath = existing.path;
321063
321205
  diagnostics.push(
321064
321206
  diagnosticAt(
321065
321207
  resource.path,
@@ -321104,7 +321246,8 @@ function addInverseFields(resources, diagnostics) {
321104
321246
  computed: null,
321105
321247
  guard: [],
321106
321248
  settings,
321107
- inverse_of: { resource: resource.slug, key: field2.key }
321249
+ inverse_of: { resource: resource.slug, key: field2.key },
321250
+ path: field2.path
321108
321251
  });
321109
321252
  }
321110
321253
  }
@@ -321174,9 +321317,9 @@ function withoutBuildNodes(resource) {
321174
321317
  const { pathNodes: _pathNodes, ...rest } = resource;
321175
321318
  return {
321176
321319
  ...rest,
321177
- fields: rest.fields.map(({ relationNode: _relationNode, ...field2 }) => field2),
321320
+ fields: rest.fields.map(({ relationNode: _relationNode, path: _path, ...field2 }) => field2),
321178
321321
  records: rest.records?.map(({ uidLiteral: _uidLiteral, valueNodes: _valueNodes, ...record }) => record) ?? rest.records,
321179
- policies: rest.policies.map(({ resourceNode: _resourceNode, ...policy }) => policy)
321322
+ policies: rest.policies.map(({ resourceNode: _resourceNode, path: _path, ...policy }) => policy)
321180
321323
  };
321181
321324
  }
321182
321325
 
@@ -321388,7 +321531,7 @@ function checkSkillFiles(files, { root = null, write = false } = {}) {
321388
321531
 
321389
321532
  // scripts/lib/runtime-build/test-suites.mjs
321390
321533
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
321391
- import { basename as basename13, dirname as dirname8 } from "node:path";
321534
+ import { basename as basename12, dirname as dirname8 } from "node:path";
321392
321535
 
321393
321536
  // scripts/lib/test-code/embedded-files.mjs
321394
321537
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -321628,7 +321771,7 @@ function readSuite(file2, report) {
321628
321771
  }
321629
321772
  const read2 = readConfig(
321630
321773
  node,
321631
- { allowed: SUITE_PROPERTIES, noun: "test suite", fallbackName: basename13(dirname8(file2.path)) },
321774
+ { allowed: SUITE_PROPERTIES, noun: "test suite", fallbackName: basename12(dirname8(file2.path)) },
321632
321775
  report
321633
321776
  );
321634
321777
  if (read2 === null) {
@@ -322260,7 +322403,7 @@ function isTypeOnlySpecifier(statement2, specifier) {
322260
322403
  function importedName(specifier) {
322261
322404
  return specifier.imported.type === "StringLiteral" ? specifier.imported.value : specifier.imported.name;
322262
322405
  }
322263
- function foreignBindingText(statement2, { lint: lint2, resolve: resolve8 }) {
322406
+ function foreignBindingText(statement2, { lint: lint2, resolve: resolve7 }) {
322264
322407
  const specifier = statement2.source.value;
322265
322408
  const kind = importKind(specifier);
322266
322409
  const statements2 = [];
@@ -322306,7 +322449,7 @@ function foreignBindingText(statement2, { lint: lint2, resolve: resolve8 }) {
322306
322449
  );
322307
322450
  continue;
322308
322451
  }
322309
- const value = kind === "package" ? packageExpression(specifier) : kind === "style_module" ? styleModuleExpression(resolve8(specifier)) : null;
322452
+ const value = kind === "package" ? packageExpression(specifier) : kind === "style_module" ? styleModuleExpression(resolve7(specifier)) : null;
322310
322453
  if (value === null) {
322311
322454
  statements2.push(`const ${local} = undefined;`);
322312
322455
  } else if (item.type === "ImportSpecifier") {
@@ -322338,12 +322481,12 @@ function foreignTypeAliases(statement2) {
322338
322481
  return `type ${local} = ${SDK_TYPE_DECLARATIONS[local] ?? "any"};`;
322339
322482
  });
322340
322483
  }
322341
- function foreignBindings(source, ast, imports, resolve8) {
322484
+ function foreignBindings(source, ast, imports, resolve7) {
322342
322485
  return ast.program.body.filter((statement2) => statement2.type === "ImportDeclaration").filter((statement2) => !imports.some((item) => item.statement === statement2)).filter((statement2) => !isAuthoringModule(statement2.source.value)).map((statement2) => ({
322343
322486
  start: statement2.start,
322344
322487
  end: statement2.end,
322345
- text: foreignBindingText(statement2, { lint: false, resolve: resolve8 }),
322346
- lintText: foreignBindingText(statement2, { lint: true, resolve: resolve8 }),
322488
+ text: foreignBindingText(statement2, { lint: false, resolve: resolve7 }),
322489
+ lintText: foreignBindingText(statement2, { lint: true, resolve: resolve7 }),
322347
322490
  original: sliceOf(source, statement2)
322348
322491
  })).filter((binding) => binding.text !== "" || binding.lintText !== "");
322349
322492
  }
@@ -322842,14 +322985,14 @@ var ENTRY_TYPES = /* @__PURE__ */ new Map([
322842
322985
  var MODULE_ENTITY_EXTENSIONS = /* @__PURE__ */ new Set([".tsx", ".ts", ".jsx", ".js"]);
322843
322986
  function moduleEntityType(path) {
322844
322987
  const type = MODULE_ENTITY_TYPES[topDirectory(path)] ?? null;
322845
- if (type === null || !MODULE_ENTITY_EXTENSIONS.has(extname3(path)) || /\.(test|spec|d)\.[a-z]+$/.test(path)) {
322988
+ if (type === null || !MODULE_ENTITY_EXTENSIONS.has(extname2(path)) || /\.(test|spec|d)\.[a-z]+$/.test(path)) {
322846
322989
  return null;
322847
322990
  }
322848
322991
  return type;
322849
322992
  }
322850
322993
  function moduleUidDefinition(type, path, source) {
322851
322994
  try {
322852
- const ast = parseSource(source, { jsx: extname3(path) === ".tsx" || extname3(path) === ".jsx" });
322995
+ const ast = parseSource(source, { jsx: extname2(path) === ".tsx" || extname2(path) === ".jsx" });
322853
322996
  return { type, path, source, program: ast.program, optional: true };
322854
322997
  } catch (error) {
322855
322998
  if (error instanceof SourceError || error instanceof SyntaxError) {
@@ -322866,7 +323009,7 @@ function isDirectChild(path, directory) {
322866
323009
  return path.startsWith(`${directory}/`) && !path.slice(directory.length + 1).includes("/");
322867
323010
  }
322868
323011
  function stem(path) {
322869
- return basename14(path, extname3(path));
323012
+ return basename13(path, extname2(path));
322870
323013
  }
322871
323014
  function buildConfig(ast, resources, pages, pagesByUid, assetEntries2, domainReferences, diagnostics, recordBindingEntries) {
322872
323015
  const { declaration } = defaultExportOf(ast, {
@@ -322984,7 +323127,7 @@ function checkMenuModule(ast) {
322984
323127
  }
322985
323128
  }
322986
323129
  function isUnitSupportFile(path) {
322987
- const extension = extname3(path).toLowerCase();
323130
+ const extension = extname2(path).toLowerCase();
322988
323131
  return extension === ".ts" || extension === ".css";
322989
323132
  }
322990
323133
  function classify(path) {
@@ -323001,13 +323144,21 @@ function classify(path) {
323001
323144
  return "config";
323002
323145
  }
323003
323146
  const directory = topDirectory(path);
323004
- const extension = extname3(path);
323147
+ const extension = extname2(path);
323005
323148
  if (directory === "pages" && isUnitSupportFile(path)) {
323006
323149
  return "ignored";
323007
323150
  }
323008
323151
  switch (directory) {
323009
- case "resources":
323010
- return isDirectChild(path, directory) && extension === ".ts" ? "resource" : "unknown";
323152
+ case "resources": {
323153
+ if (isResourcePath(path)) {
323154
+ return "resource";
323155
+ }
323156
+ const child = resourceChildOf(path);
323157
+ if (child !== null) {
323158
+ return child.kind;
323159
+ }
323160
+ return legacyResourceFolder(path) === null ? "unknown" : "legacy_resource";
323161
+ }
323011
323162
  case PERMISSIONS_DIRECTORY:
323012
323163
  return isDirectChild(path, directory) && extension === ".ts" ? "permission" : "unknown";
323013
323164
  case ROLES_DIRECTORY:
@@ -323444,63 +323595,38 @@ function withoutTypeAssertions(node) {
323444
323595
  }
323445
323596
  return current;
323446
323597
  }
323447
- function fieldUidNodes(definition) {
323448
- const fields = withoutTypeAssertions(objectProperty2(definition, "fields")?.value);
323449
- if (fields?.type !== "ObjectExpression") {
323598
+ function fieldUidNodes(field2, definition) {
323599
+ const call = withoutTypeAssertions(definition);
323600
+ if (call?.type !== "CallExpression") {
323450
323601
  return [];
323451
323602
  }
323452
- const nodes = [];
323453
- for (const property of fields.properties) {
323454
- if (property.type !== "ObjectProperty") {
323455
- continue;
323456
- }
323457
- const call = withoutTypeAssertions(property.value);
323458
- if (call.type !== "CallExpression") {
323459
- continue;
323460
- }
323461
- const field2 = propertyKey2(property);
323462
- const [argument] = call.arguments;
323463
- if (argument === void 0) {
323464
- nodes.push({ type: "field", node: call, field: field2, inverse: false });
323465
- continue;
323466
- }
323467
- const options = withoutTypeAssertions(argument);
323468
- if (options.type !== "ObjectExpression") {
323469
- continue;
323470
- }
323471
- nodes.push({ type: "field", node: options, field: field2, inverse: false });
323472
- const settings = withoutTypeAssertions(objectProperty2(options, "settings")?.value);
323473
- const inverse = settings?.type === "ObjectExpression" ? withoutTypeAssertions(objectProperty2(settings, "inverse")?.value) : void 0;
323474
- if (inverse?.type === "ObjectExpression") {
323475
- nodes.push({ type: "field", node: inverse, field: field2, inverse: true });
323476
- }
323603
+ const [argument] = call.arguments;
323604
+ if (argument === void 0) {
323605
+ return [{ type: "field", node: call, field: field2, inverse: false }];
323477
323606
  }
323478
- return nodes;
323479
- }
323480
- function policyUidNodes(definition) {
323481
- const policies = withoutTypeAssertions(objectProperty2(definition, "policies")?.value);
323482
- if (policies?.type !== "ArrayExpression") {
323607
+ const options = withoutTypeAssertions(argument);
323608
+ if (options.type !== "ObjectExpression") {
323483
323609
  return [];
323484
323610
  }
323485
- return policies.elements.flatMap((element, position) => {
323486
- const node = withoutTypeAssertions(element);
323487
- return node?.type === "ObjectExpression" ? [{ type: "policy", node, policy: position }] : [];
323488
- });
323489
- }
323490
- function policyUidPosition(path, position) {
323491
- return `${path}\0${position}`;
323611
+ const nodes = [{ type: "field", node: options, field: field2, inverse: false }];
323612
+ const settings = withoutTypeAssertions(objectProperty2(options, "settings")?.value);
323613
+ const inverse = settings?.type === "ObjectExpression" ? withoutTypeAssertions(objectProperty2(settings, "inverse")?.value) : void 0;
323614
+ if (inverse?.type === "ObjectExpression") {
323615
+ nodes.push({ type: "field", node: inverse, field: field2, inverse: true });
323616
+ }
323617
+ return nodes;
323492
323618
  }
323493
323619
  function fieldUidPosition(path, field2, inverse) {
323494
323620
  return `${path}\0${field2}\0${inverse ? "inverse" : "field"}`;
323495
323621
  }
323496
- function checkInverseFieldUids(resources, pathsBySlug, diagnostics) {
323622
+ function checkInverseFieldUids(resources, fieldPaths, diagnostics) {
323497
323623
  for (const resource of resources) {
323498
323624
  const firstByUid = /* @__PURE__ */ new Map();
323499
- for (const field2 of resource.fields) {
323625
+ for (const [position, field2] of resource.fields.entries()) {
323500
323626
  if (field2.uid === null) {
323501
323627
  continue;
323502
323628
  }
323503
- const path = field2.inverse_of === void 0 ? resource.path : pathsBySlug.get(field2.inverse_of.resource);
323629
+ const path = fieldPaths.get(resource.path)[position];
323504
323630
  const first = firstByUid.get(field2.uid);
323505
323631
  if (first === void 0) {
323506
323632
  firstByUid.set(field2.uid, { field: field2, path });
@@ -323520,17 +323646,6 @@ function checkInverseFieldUids(resources, pathsBySlug, diagnostics) {
323520
323646
  }
323521
323647
  }
323522
323648
  }
323523
- function staticRecordNodes(definition) {
323524
- const records = definition.properties.find(
323525
- (property) => property.type === "ObjectProperty" && propertyKey2(property) === "records"
323526
- );
323527
- if (records?.value.type !== "ObjectExpression") {
323528
- return [];
323529
- }
323530
- return records.value.properties.filter(
323531
- (property) => property.type === "ObjectProperty" && property.value.type === "ObjectExpression"
323532
- ).map((property) => ({ key: propertyKey2(property), node: property.value }));
323533
- }
323534
323649
  function uidDefinitionNodes(kind, path, ast) {
323535
323650
  switch (kind) {
323536
323651
  case "resource": {
@@ -323538,23 +323653,29 @@ function uidDefinitionNodes(kind, path, ast) {
323538
323653
  if (node.type !== "ObjectExpression") {
323539
323654
  return [{ type: "resource", node }];
323540
323655
  }
323541
- if (objectProperty2(node, "platform") !== null || BUILT_IN_RESOURCE_SLUGS.has(stem(path))) {
323656
+ if (objectProperty2(node, "platform") !== null || BUILT_IN_RESOURCE_SLUGS.has(resourceFolderOf(path))) {
323542
323657
  return [];
323543
323658
  }
323544
- return [
323545
- { type: "resource", node },
323546
- ...fieldUidNodes(node).map((field2) => ({
323659
+ return [{ type: "resource", node }];
323660
+ }
323661
+ case "resource_field":
323662
+ case "resource_policy":
323663
+ case "resource_record": {
323664
+ const { folder, key, definitionPath } = resourceChildOf(path);
323665
+ if (BUILT_IN_RESOURCE_SLUGS.has(folder)) {
323666
+ return [];
323667
+ }
323668
+ const node = resourceChildArgument(kind, ast);
323669
+ if (kind === "resource_field") {
323670
+ return fieldUidNodes(key, node).map((field2) => ({
323547
323671
  ...field2,
323548
- scope: field2.inverse ? fieldUidPosition(path, field2.field, true) : path
323549
- })),
323550
- ...policyUidNodes(node).map((policy) => ({ ...policy, scope: path })),
323551
- ...staticRecordNodes(node).map(({ key, node: recordNode }) => ({
323552
- type: "static record",
323553
- node: recordNode,
323554
- recordKey: key,
323555
- version: 7
323556
- }))
323557
- ];
323672
+ scope: field2.inverse ? fieldUidPosition(definitionPath, key, true) : definitionPath
323673
+ }));
323674
+ }
323675
+ if (node.type !== "ObjectExpression") {
323676
+ return [];
323677
+ }
323678
+ return kind === "resource_policy" ? [{ type: "policy", node, scope: definitionPath }] : [{ type: "static record", node, recordKey: key, version: 7 }];
323558
323679
  }
323559
323680
  case "permission":
323560
323681
  return [{ type: "permission", node: definePermissionArgument(ast), version: 7 }];
@@ -323592,6 +323713,7 @@ function uidPositionKey(path, recordKey = null) {
323592
323713
  return recordKey === null ? path : `${path}\0${recordKey}`;
323593
323714
  }
323594
323715
  var ENTITY_UID_TYPES = /* @__PURE__ */ new Set(["page", "workflow", "layout", "component", NOTIFICATION_DEFINITIONS.email_layout.type]);
323716
+ var RESOURCE_FILE_KINDS = /* @__PURE__ */ new Set(["resource", "resource_field", "resource_policy", "resource_record"]);
323595
323717
  function buildWorkspace(root, options = {}) {
323596
323718
  const plan = composePackages(root);
323597
323719
  return plan.files.size > 0 ? buildComposedCheckout(root, plan, options, buildMaterializedWorkspace) : buildMaterializedWorkspace(root, plan, options);
@@ -323656,17 +323778,38 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
323656
323778
  );
323657
323779
  }
323658
323780
  const resourceSources = /* @__PURE__ */ new Map();
323659
- for (const path of files.filter((item) => classify(item) === "resource")) {
323781
+ const resourceChildren = /* @__PURE__ */ new Map();
323782
+ for (const path of files.filter((item) => RESOURCE_FILE_KINDS.has(classify(item)))) {
323660
323783
  const source = readFileSync14(join18(root, path), "utf8");
323661
323784
  let ast = null;
323662
323785
  try {
323663
- ast = parseSource(source, { jsx: false });
323786
+ ast = parseSource(source, { jsx: false, path });
323664
323787
  } catch (error) {
323665
323788
  if (!(error instanceof SourceError || error instanceof SyntaxError)) {
323666
323789
  throw error;
323667
323790
  }
323791
+ if (classify(path) !== "resource") {
323792
+ diagnostics.push(diagnosticFromError(path, error));
323793
+ }
323794
+ }
323795
+ if (classify(path) === "resource") {
323796
+ resourceSources.set(path, { source, ast });
323797
+ continue;
323798
+ }
323799
+ const child = resourceChildOf(path);
323800
+ const children = resourceChildren.get(child.definitionPath) ?? [];
323801
+ children.push({ ...child, path, source, ast });
323802
+ resourceChildren.set(child.definitionPath, children);
323803
+ }
323804
+ for (const [definitionPath, children] of resourceChildren) {
323805
+ if (resourceSources.has(definitionPath)) {
323806
+ continue;
323807
+ }
323808
+ for (const { path } of children) {
323809
+ diagnostics.push(
323810
+ diagnosticAt(path, null, `This file belongs to a resource, so its folder needs ${definitionPath}. Add the file, or move this file`)
323811
+ );
323668
323812
  }
323669
- resourceSources.set(path, { source, ast });
323670
323813
  }
323671
323814
  const names2 = resourceNames(
323672
323815
  [...resourceSources].map(
@@ -323692,7 +323835,7 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
323692
323835
  diagnosticAt(
323693
323836
  path,
323694
323837
  null,
323695
- BINARY_EXTENSIONS.has(extname3(path).toLowerCase()) ? BINARY_FILE_MESSAGE : "The build does not know this file. Move or rename it"
323838
+ BINARY_EXTENSIONS.has(extname2(path).toLowerCase()) ? BINARY_FILE_MESSAGE : "The build does not know this file. Move or rename it"
323696
323839
  )
323697
323840
  );
323698
323841
  return;
@@ -323700,6 +323843,20 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
323700
323843
  if (kind === "skill" || NOTIFICATION_KINDS.has(kind)) {
323701
323844
  return;
323702
323845
  }
323846
+ if (RESOURCE_FILE_KINDS.has(kind) && kind !== "resource") {
323847
+ return;
323848
+ }
323849
+ if (kind === "legacy_resource") {
323850
+ const folder = legacyResourceFolder(path);
323851
+ diagnostics.push(
323852
+ diagnosticAt(
323853
+ path,
323854
+ null,
323855
+ `A resource is a folder. Move the settings of this file to resources/${folder}/resource.ts, and each field, policy, and record to a file of its own in resources/${folder}/fields/, policies/, and records/`
323856
+ )
323857
+ );
323858
+ return;
323859
+ }
323703
323860
  if (kind === "legacy_authorization") {
323704
323861
  diagnostics.push(
323705
323862
  diagnosticAt(
@@ -323713,7 +323870,7 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
323713
323870
  const parsed = resourceSources.get(path);
323714
323871
  const source = parsed?.source ?? readFileSync14(join18(root, path), "utf8");
323715
323872
  try {
323716
- const ast = parsed?.ast ?? parseSource(source, { jsx: extname3(path) === ".tsx" });
323873
+ const ast = parsed?.ast ?? parseSource(source, { jsx: extname2(path) === ".tsx" });
323717
323874
  if (kind === "page") {
323718
323875
  diagnostics.push(...rowMenuReads(path, ast));
323719
323876
  }
@@ -323753,32 +323910,70 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
323753
323910
  if (slug === void 0) {
323754
323911
  break;
323755
323912
  }
323913
+ const childFiles = resourceChildren.get(path) ?? [];
323914
+ const children = [];
323915
+ for (const child of childFiles) {
323916
+ if (child.ast === null) {
323917
+ continue;
323918
+ }
323919
+ try {
323920
+ const typeProblem2 = child.kind === "resource_field" ? null : folderTypeArgumentProblem(child.ast, child.folder);
323921
+ if (typeProblem2 !== null) {
323922
+ diagnostics.push(diagnosticAt(child.path, typeProblem2.node, typeProblem2.message, { severity: "warning" }));
323923
+ }
323924
+ children.push({
323925
+ path: child.path,
323926
+ kind: child.kind,
323927
+ key: child.key,
323928
+ ast: child.ast,
323929
+ source: child.source,
323930
+ node: resourceChildArgument(child.kind, child.ast),
323931
+ bindings: {
323932
+ resources: resourcesBinding(child.ast, names2),
323933
+ pages: pagesBinding(child.ast, generatedPages.entries, generatedPages.pathsByName),
323934
+ generatedEntries: recordBindingsBinding(child.ast, recordBindings.entries)
323935
+ }
323936
+ });
323937
+ } catch (error) {
323938
+ diagnostics.push(diagnosticFromError(child.path, error));
323939
+ }
323940
+ }
323941
+ if (children.length !== childFiles.length) {
323942
+ break;
323943
+ }
323944
+ const typeProblem = folderTypeArgumentProblem(ast, resourceFolderOf(path));
323945
+ if (typeProblem !== null) {
323946
+ diagnostics.push(diagnosticAt(path, typeProblem.node, typeProblem.message, { severity: "warning" }));
323947
+ }
323756
323948
  const definition = defineResourceArgument(ast);
323757
323949
  const resource = buildResource(path, definition, {
323758
323950
  slug,
323759
323951
  resources: resourcesBinding(ast, names2),
323760
323952
  pages: pagesBinding(ast, generatedPages.entries, generatedPages.pathsByName),
323761
- generatedEntries: recordBindingsBinding(ast, recordBindings.entries)
323953
+ generatedEntries: recordBindingsBinding(ast, recordBindings.entries),
323954
+ children
323762
323955
  });
323763
323956
  output.resources.push(resource);
323764
- for (const {
323765
- type,
323766
- scope: scope2,
323767
- node,
323768
- field: field2,
323769
- inverse,
323770
- policy,
323771
- recordKey,
323772
- version
323773
- } of uidDefinitionNodes(kind, path, ast)) {
323957
+ for (const { type, scope: scope2, node, version } of uidDefinitionNodes(kind, path, ast)) {
323774
323958
  const position = resourceUidDefinitions.push({ type, scope: scope2, path, source, node, version }) - 1;
323775
- if (field2 !== void 0) {
323776
- fieldUidPositions.set(fieldUidPosition(path, field2, inverse), position);
323777
- } else if (policy !== void 0) {
323778
- policyUidPositions.set(policyUidPosition(path, policy), position);
323779
- } else {
323780
- resourceUidPositions.set(uidPositionKey(path, recordKey ?? null), position);
323959
+ resourceUidPositions.set(uidPositionKey(path), position);
323960
+ }
323961
+ for (const child of children) {
323962
+ for (const { type, scope: scope2, node, field: field2, inverse, recordKey, version } of uidDefinitionNodes(
323963
+ child.kind,
323964
+ child.path,
323965
+ child.ast
323966
+ )) {
323967
+ const position = resourceUidDefinitions.push({ type, scope: scope2, path: child.path, source: child.source, node, version }) - 1;
323968
+ if (field2 !== void 0) {
323969
+ fieldUidPositions.set(fieldUidPosition(path, field2, inverse), position);
323970
+ } else if (child.kind === "resource_policy") {
323971
+ policyUidPositions.set(child.path, position);
323972
+ } else {
323973
+ resourceUidPositions.set(uidPositionKey(path, recordKey), position);
323974
+ }
323781
323975
  }
323976
+ diagnostics.push(...slugStringWarnings(child.path, child.node, names2));
323782
323977
  }
323783
323978
  diagnostics.push(...slugStringWarnings(path, definition, names2));
323784
323979
  break;
@@ -323863,7 +324058,7 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
323863
324058
  const resourceFiles = files.filter((path) => topDirectory(path) === "resources");
323864
324059
  const assetPaths = files.filter((path) => classify(path) === "assets");
323865
324060
  const otherFiles = files.filter(
323866
- (path) => !["resource", "permission", "role", "config"].includes(classify(path)) && !assetPaths.includes(path)
324061
+ (path) => topDirectory(path) !== "resources" && !["permission", "role", "config"].includes(classify(path)) && !assetPaths.includes(path)
323867
324062
  );
323868
324063
  for (const path of resourceFiles) {
323869
324064
  buildFile(path);
@@ -323884,6 +324079,9 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
323884
324079
  );
323885
324080
  checkPolicyResources(output.resources, BUILT_IN_RESOURCE_SLUGS, names2, diagnostics);
323886
324081
  }
324082
+ diagnostics.push(...policyKeyWarnings(output.resources, names2));
324083
+ const policyPaths = new Map(output.resources.map((resource) => [resource.path, resource.policies.map((policy) => policy.path)]));
324084
+ const fieldPaths = new Map(output.resources.map((resource) => [resource.path, resource.fields.map((field2) => field2.path)]));
323887
324085
  output.resources = output.resources.map(withoutBuildNodes);
323888
324086
  const resourceUidCheck = checkDefinitionUids(root, resourceUidDefinitions, {
323889
324087
  write: writeSource
@@ -323904,11 +324102,10 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
323904
324102
  record.uid = resourceUidCheck.uids[resourceUidPositions.get(uidPositionKey(resource.path, record.key))] ?? null;
323905
324103
  }
323906
324104
  resource.policies.forEach((policy, position) => {
323907
- policy.uid = resourceUidCheck.uids[policyUidPositions.get(policyUidPosition(resource.path, position))] ?? null;
324105
+ policy.uid = resourceUidCheck.uids[policyUidPositions.get(policyPaths.get(resource.path)[position])] ?? null;
323908
324106
  });
323909
324107
  }
323910
- checkInverseFieldUids(output.resources, pathsBySlug, diagnostics);
323911
- diagnostics.push(...policyKeyWarnings(output.resources, names2));
324108
+ checkInverseFieldUids(output.resources, fieldPaths, diagnostics);
323912
324109
  const workflowPackageDeclared = Object.hasOwn(sdkPackages(packageFiles), "@diagonal-hq/workflows");
323913
324110
  writeGeneratedModule(
323914
324111
  root,
@@ -323916,6 +324113,7 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
323916
324113
  generatedResourcesSource(names2, output.resources, { workflowPackageDeclared }),
323917
324114
  true
323918
324115
  );
324116
+ writeGeneratedModule(root, GENERATED_RESOURCE_FOLDERS_PATH, generatedResourceFoldersSource(names2, output.resources), output.resources.length > 0);
323919
324117
  const entries = resourceEntries(names2, output.resources);
323920
324118
  for (const path of assetPaths) {
323921
324119
  buildFile(path);
@@ -324269,597 +324467,10 @@ function buildMaterializedWorkspace(root, plan, { assetCatalog = null, writeSour
324269
324467
  };
324270
324468
  }
324271
324469
 
324272
- // scripts/lib/runtime-build/git-cli.mjs
324273
- init_define_globalThis_DIAGONAL_SDK_RUNTIME();
324274
- import { spawnSync as spawnSync3 } from "node:child_process";
324275
- import { readFileSync as readFileSync15, writeFileSync as writeFileSync6 } from "node:fs";
324276
- import { join as join19, resolve as resolve6 } from "node:path";
324277
-
324278
- // scripts/lib/runtime-build/resource-merge.mjs
324279
- init_define_globalThis_DIAGONAL_SDK_RUNTIME();
324280
- var KEYED_PROPERTIES = /* @__PURE__ */ new Set(["fields", "records"]);
324281
- var CLOSING_TOKENS = /* @__PURE__ */ new Set(["}", "]", ")"]);
324282
- var RESOURCE_PATH = /^resources\/[^/]+\.ts$/;
324283
- function isResourceFilePath(path) {
324284
- return RESOURCE_PATH.test(path);
324285
- }
324286
- function tokenLabel(token) {
324287
- return typeof token.type === "string" ? token.type : token.type.label;
324288
- }
324289
- function isComment(token) {
324290
- return token.type === "CommentLine" || token.type === "CommentBlock";
324291
- }
324292
- function firstTokenAt(tokens, position) {
324293
- let low = 0;
324294
- let high = tokens.length;
324295
- while (low < high) {
324296
- const middle = low + high >> 1;
324297
- if (tokens[middle].start < position) {
324298
- low = middle + 1;
324299
- } else {
324300
- high = middle;
324301
- }
324302
- }
324303
- return low;
324304
- }
324305
- function nextCodeToken(tokens, index3) {
324306
- for (let next = index3 + 1; next < tokens.length; next++) {
324307
- if (!isComment(tokens[next])) {
324308
- return tokens[next];
324309
- }
324310
- }
324311
- return null;
324312
- }
324313
- function normalizedText(side, start, end) {
324314
- const { tokens, source } = side;
324315
- const parts = [];
324316
- for (let index3 = firstTokenAt(tokens, start); index3 < tokens.length; index3++) {
324317
- const token = tokens[index3];
324318
- if (token.end > end) {
324319
- break;
324320
- }
324321
- const label = tokenLabel(token);
324322
- if (label === "eof") {
324323
- continue;
324324
- }
324325
- if (label === ",") {
324326
- const next = nextCodeToken(tokens, index3);
324327
- if (next === null || next.end > end || CLOSING_TOKENS.has(tokenLabel(next))) {
324328
- continue;
324329
- }
324330
- }
324331
- const text2 = source.slice(token.start, token.end);
324332
- parts.push(isComment(token) ? text2.replace(/\s+/g, " ") : text2);
324333
- }
324334
- return parts.join(" ");
324335
- }
324336
- function lineStart(source, position) {
324337
- return source.lastIndexOf("\n", position - 1) + 1;
324338
- }
324339
- function lineIndent2(source, position) {
324340
- const start = lineStart(source, position);
324341
- return /^[ \t]*/.exec(source.slice(start, position))[0];
324342
- }
324343
- function insideValueToken(tokens, position) {
324344
- const token = tokens[firstTokenAt(tokens, position) - 1];
324345
- return token !== void 0 && !isComment(token) && token.end > position;
324346
- }
324347
- function reindent(ctx, entry, indent) {
324348
- const { source, tokens, unit: step } = entry.side;
324349
- const from = lineIndent2(source, entry.start);
324350
- const lines = source.slice(entry.start, entry.end).split("\n");
324351
- let position = entry.start;
324352
- return lines.map((raw, index3) => {
324353
- const start = position;
324354
- position += raw.length + 1;
324355
- const line = index3 < lines.length - 1 && raw.endsWith("\r") ? raw.slice(0, -1) : raw;
324356
- if (index3 === 0 || !line.startsWith(from) || insideValueToken(tokens, start)) {
324357
- return line;
324358
- }
324359
- let rest = line.slice(from.length);
324360
- let steps = 0;
324361
- while (rest.startsWith(step)) {
324362
- rest = rest.slice(step.length);
324363
- steps++;
324364
- }
324365
- return `${indent}${ctx.unit.repeat(steps)}${rest}`;
324366
- }).join(ctx.newline);
324367
- }
324368
- function readKey(element) {
324369
- if (element.type !== "ObjectProperty" && element.type !== "ObjectMethod") {
324370
- return null;
324371
- }
324372
- try {
324373
- return propertyKey2(element);
324374
- } catch (error) {
324375
- if (error instanceof SourceError) {
324376
- return null;
324377
- }
324378
- throw error;
324379
- }
324380
- }
324381
- function readPolicyUid(element) {
324382
- if (element.type !== "ObjectExpression") {
324383
- return null;
324384
- }
324385
- const property = element.properties.find(
324386
- (candidate) => candidate.type === "ObjectProperty" && !candidate.computed && readKey(candidate) === "uid"
324387
- );
324388
- return property?.value.type === "StringLiteral" ? property.value.value : null;
324389
- }
324390
- var KEY_READERS = {
324391
- keyed: readKey,
324392
- strings: (element) => element.type === "StringLiteral" ? element.value : null,
324393
- uids: readPolicyUid
324394
- };
324395
- function tokenAfter(side, position, label) {
324396
- for (let index3 = firstTokenAt(side.tokens, position); index3 < side.tokens.length; index3++) {
324397
- const token = side.tokens[index3];
324398
- if (tokenLabel(token) === label) {
324399
- return token;
324400
- }
324401
- if (!isComment(token)) {
324402
- return null;
324403
- }
324404
- }
324405
- return null;
324406
- }
324407
- function containerOf(side, node, keyOf) {
324408
- const elements = node.type === "ObjectExpression" ? node.properties : node.elements;
324409
- const entries = [];
324410
- const seen = /* @__PURE__ */ new Set();
324411
- let boundary = node.start + 1;
324412
- let boundaryLine = node.loc.start.line;
324413
- for (const [index3, element] of elements.entries()) {
324414
- if (element === null) {
324415
- return null;
324416
- }
324417
- const key = keyOf(element);
324418
- if (key === null || seen.has(key)) {
324419
- return null;
324420
- }
324421
- seen.add(key);
324422
- if (index3 > 0) {
324423
- const comma2 = tokenAfter(side, elements[index3 - 1].end, ",");
324424
- if (comma2 === null) {
324425
- return null;
324426
- }
324427
- boundary = comma2.end;
324428
- boundaryLine = comma2.loc.start.line;
324429
- }
324430
- const leading = (element.leadingComments ?? []).find(
324431
- (comment) => comment.start >= boundary && comment.loc.start.line > boundaryLine
324432
- );
324433
- entries.push({
324434
- side,
324435
- key,
324436
- index: index3,
324437
- value: element.type === "ObjectProperty" ? element.value : null,
324438
- start: leading?.start ?? element.start,
324439
- end: element.end
324440
- });
324441
- }
324442
- return { side, node, entries };
324443
- }
324444
- function readSide(source) {
324445
- let ast;
324446
- try {
324447
- ast = parse2(source, { sourceType: "module", plugins: ["typescript"], errorRecovery: false, tokens: true });
324448
- } catch (error) {
324449
- if (error instanceof SyntaxError) {
324450
- return null;
324451
- }
324452
- throw error;
324453
- }
324454
- const exports = ast.program.body.filter((statement2) => statement2.type === "ExportDefaultDeclaration");
324455
- if (exports.length !== 1) {
324456
- return null;
324457
- }
324458
- const call = exports[0].declaration;
324459
- if (call.type !== "CallExpression" || call.callee.type !== "Identifier" || call.callee.name !== "defineResource" || call.arguments.length !== 1 || call.arguments[0].type !== "ObjectExpression") {
324460
- return null;
324461
- }
324462
- const side = { source, tokens: ast.tokens, object: call.arguments[0], container: null, unit: " " };
324463
- side.container = containerOf(side, side.object, KEY_READERS.keyed);
324464
- if (side.container === null) {
324465
- return null;
324466
- }
324467
- side.unit = indentUnit(side);
324468
- return side;
324469
- }
324470
- function nestedKind(key, values) {
324471
- if (KEYED_PROPERTIES.has(key)) {
324472
- return values.every((value) => value?.type === "ObjectExpression") ? "keyed" : null;
324473
- }
324474
- if (!values.every((value) => value?.type === "ArrayExpression")) {
324475
- return null;
324476
- }
324477
- const elements = values.flatMap((value) => value.elements);
324478
- if (elements.length === 0) {
324479
- return null;
324480
- }
324481
- if (elements.every((element) => element?.type === "StringLiteral")) {
324482
- return "strings";
324483
- }
324484
- return elements.every((element) => element !== null && readPolicyUid(element) !== null) ? "uids" : null;
324485
- }
324486
- function decide(base, ours, theirs, same) {
324487
- if (ours !== void 0 && theirs !== void 0) {
324488
- if (same(ours, theirs)) {
324489
- return "ours";
324490
- }
324491
- if (base !== void 0 && same(ours, base)) {
324492
- return "theirs";
324493
- }
324494
- return base !== void 0 && same(theirs, base) ? "ours" : "conflict";
324495
- }
324496
- if (ours !== void 0) {
324497
- if (base === void 0) {
324498
- return "ours";
324499
- }
324500
- return same(ours, base) ? "delete" : "conflict";
324501
- }
324502
- if (theirs !== void 0) {
324503
- if (base === void 0) {
324504
- return "theirs";
324505
- }
324506
- return same(theirs, base) ? "delete" : "conflict";
324507
- }
324508
- return "delete";
324509
- }
324510
- function entryText(entry) {
324511
- return entry.side.source.slice(entry.start, entry.end);
324512
- }
324513
- function entryIndent(entry) {
324514
- return lineIndent2(entry.side.source, entry.start);
324515
- }
324516
- function isMultiline(container) {
324517
- const [first] = container.entries;
324518
- return first !== void 0 && container.side.source.slice(container.node.start, first.start).includes("\n");
324519
- }
324520
- function containerLayout(ctx, ours, theirs) {
324521
- const { source } = ours.side;
324522
- const { node, entries } = ours;
324523
- const isObject = node.type === "ObjectExpression";
324524
- if (entries.length === 0) {
324525
- const multiline2 = isMultiline(theirs);
324526
- const outer = lineIndent2(source, node.start);
324527
- const indent2 = multiline2 ? `${outer}${ctx.unit}` : outer;
324528
- const padding = isObject ? " " : "";
324529
- return {
324530
- indent: indent2,
324531
- first: multiline2 ? `${ctx.newline}${indent2}` : padding,
324532
- last: multiline2 ? `${ctx.newline}${outer}` : padding,
324533
- between: [],
324534
- separator: multiline2 ? `,${ctx.newline}${indent2}` : ", "
324535
- };
324536
- }
324537
- const multiline = isMultiline(ours);
324538
- const indent = multiline ? entryIndent(entries[0]) : lineIndent2(source, node.start);
324539
- const between = entries.map((entry, index3) => index3 === 0 ? null : source.slice(entries[index3 - 1].end, entry.start));
324540
- return {
324541
- indent,
324542
- first: source.slice(node.start + 1, entries[0].start),
324543
- last: source.slice(entries.at(-1).end, node.end - 1),
324544
- between,
324545
- separator: multiline ? `,${ctx.newline}${indent}` : ", "
324546
- };
324547
- }
324548
- function conflictBlock(ctx, { ours, base, hasBase, theirs }) {
324549
- const lines = [`<<<<<<< ${ctx.labels.ours}`];
324550
- if (ours !== null) {
324551
- lines.push(ours);
324552
- }
324553
- if (hasBase) {
324554
- lines.push(`||||||| ${ctx.labels.base}`);
324555
- if (base !== null) {
324556
- lines.push(base);
324557
- }
324558
- }
324559
- lines.push("=======");
324560
- if (theirs !== null) {
324561
- lines.push(theirs);
324562
- }
324563
- lines.push(`>>>>>>> ${ctx.labels.theirs}`);
324564
- return lines.join(ctx.newline);
324565
- }
324566
- function renderContainer(ctx, ours, layout, items) {
324567
- const { source } = ours.side;
324568
- const { node, entries } = ours;
324569
- if (items.length === 0) {
324570
- return entries.length === 0 ? source.slice(node.start, node.end) : `${source[node.start]}${source[node.end - 1]}`;
324571
- }
324572
- let text2 = source[node.start];
324573
- let separator = layout.first;
324574
- for (const [position, item] of items.entries()) {
324575
- if (item.type === "conflict") {
324576
- text2 += separator.replace(/[ \t]+$/, "");
324577
- if (!text2.endsWith("\n")) {
324578
- text2 += ctx.newline;
324579
- }
324580
- text2 += item.text;
324581
- } else {
324582
- text2 += `${separator}${item.text}`;
324583
- }
324584
- if (position === items.length - 1) {
324585
- separator = layout.last;
324586
- } else if (item.index !== null && item.index < entries.length - 1) {
324587
- separator = layout.between[item.index + 1];
324588
- } else {
324589
- separator = layout.separator;
324590
- }
324591
- if (item.type === "conflict") {
324592
- separator = separator.replace(",", "");
324593
- if (!/^[ \t]*\r?\n/.test(separator)) {
324594
- separator = `${ctx.newline}${separator.replace(/^[ \t]+/, "")}`;
324595
- }
324596
- }
324597
- }
324598
- return `${text2}${separator}${source[node.end - 1]}`;
324599
- }
324600
- function mergeContainer(ctx, { base, ours, theirs }, { label, same, nested = () => null }) {
324601
- const byKey = (container) => new Map((container?.entries ?? []).map((entry) => [entry.key, entry]));
324602
- const baseEntries = byKey(base);
324603
- const oursEntries = byKey(ours);
324604
- const theirsEntries = byKey(theirs);
324605
- const layout = containerLayout(ctx, ours, theirs);
324606
- const section = (entry) => `${layout.indent}${reindent(ctx, entry, layout.indent)},`;
324607
- const items = /* @__PURE__ */ new Map();
324608
- for (const key of /* @__PURE__ */ new Set([...oursEntries.keys(), ...theirsEntries.keys()])) {
324609
- const baseEntry = baseEntries.get(key);
324610
- const oursEntry = oursEntries.get(key);
324611
- const theirsEntry = theirsEntries.get(key);
324612
- const decision = decide(baseEntry, oursEntry, theirsEntry, same);
324613
- const index3 = oursEntry?.index ?? null;
324614
- if (decision === "ours") {
324615
- items.set(key, { type: "entry", index: index3, text: entryText(oursEntry) });
324616
- } else if (decision === "theirs") {
324617
- items.set(key, { type: "entry", index: index3, text: reindent(ctx, theirsEntry, layout.indent) });
324618
- } else if (decision === "conflict") {
324619
- const merged = oursEntry !== void 0 && theirsEntry !== void 0 ? nested(key, baseEntry, oursEntry, theirsEntry) : null;
324620
- if (merged !== null) {
324621
- items.set(key, { type: "entry", index: index3, text: merged });
324622
- continue;
324623
- }
324624
- ctx.conflicts.push(label(key));
324625
- items.set(key, {
324626
- type: "conflict",
324627
- index: index3,
324628
- text: conflictBlock(ctx, {
324629
- ours: oursEntry === void 0 ? null : section(oursEntry),
324630
- hasBase: baseEntry !== void 0,
324631
- base: baseEntry === void 0 ? null : section(baseEntry),
324632
- theirs: theirsEntry === void 0 ? null : section(theirsEntry)
324633
- })
324634
- });
324635
- }
324636
- }
324637
- const order = ours.entries.map((entry) => entry.key).filter((key) => items.has(key));
324638
- for (const [position, entry] of theirs.entries.entries()) {
324639
- if (oursEntries.has(entry.key) || !items.has(entry.key)) {
324640
- continue;
324641
- }
324642
- let at = 0;
324643
- for (let previous = position - 1; previous >= 0; previous--) {
324644
- const found2 = order.indexOf(theirs.entries[previous].key);
324645
- if (found2 !== -1) {
324646
- at = found2 + 1;
324647
- break;
324648
- }
324649
- }
324650
- while (at < order.length && !theirsEntries.has(order[at])) {
324651
- at++;
324652
- }
324653
- order.splice(at, 0, entry.key);
324654
- }
324655
- return renderContainer(
324656
- ctx,
324657
- ours,
324658
- layout,
324659
- order.map((key) => items.get(key))
324660
- );
324661
- }
324662
- function sameEntryText() {
324663
- const cache2 = /* @__PURE__ */ new Map();
324664
- const text2 = (entry) => {
324665
- if (!cache2.has(entry)) {
324666
- cache2.set(entry, normalizedText(entry.side, entry.start, entry.end));
324667
- }
324668
- return cache2.get(entry);
324669
- };
324670
- return (left, right) => text2(left) === text2(right);
324671
- }
324672
- function mergeNestedOption(ctx, sides, key, baseEntry, oursEntry, theirsEntry) {
324673
- const values = [baseEntry?.value, oursEntry.value, theirsEntry.value].filter((value) => value !== void 0);
324674
- const kind = nestedKind(key, values);
324675
- if (kind === null) {
324676
- return null;
324677
- }
324678
- const keyOf = KEY_READERS[kind];
324679
- const containers = {
324680
- base: baseEntry === void 0 ? null : containerOf(sides.base, baseEntry.value, keyOf),
324681
- ours: containerOf(sides.ours, oursEntry.value, keyOf),
324682
- theirs: containerOf(sides.theirs, theirsEntry.value, keyOf)
324683
- };
324684
- if (containers.ours === null || containers.theirs === null || baseEntry !== void 0 && containers.base === null) {
324685
- return null;
324686
- }
324687
- const same = kind === "strings" ? () => true : sameEntryText();
324688
- const merged = mergeContainer(ctx, containers, { label: (entryKey) => `${key}.${entryKey}`, same });
324689
- const { source } = sides.ours;
324690
- return `${source.slice(oursEntry.start, oursEntry.value.start)}${merged}${source.slice(oursEntry.value.end, oursEntry.end)}`;
324691
- }
324692
- function mergeOutside(ctx, sides, range, label) {
324693
- const versions = {};
324694
- for (const name of ["base", "ours", "theirs"]) {
324695
- const side = sides[name];
324696
- if (side !== null) {
324697
- const [start, end] = range(side);
324698
- versions[name] = { text: side.source.slice(start, end), normalized: normalizedText(side, start, end) };
324699
- }
324700
- }
324701
- const decision = decide(versions.base, versions.ours, versions.theirs, (left, right) => left.normalized === right.normalized);
324702
- if (decision === "ours") {
324703
- return { text: versions.ours.text, conflict: false };
324704
- }
324705
- if (decision === "theirs") {
324706
- return { text: versions.theirs.text, conflict: false };
324707
- }
324708
- ctx.conflicts.push(label);
324709
- const trimmed = (version) => version.text.replace(/\r?\n$/, "");
324710
- return {
324711
- text: conflictBlock(ctx, {
324712
- ours: trimmed(versions.ours),
324713
- hasBase: versions.base !== void 0,
324714
- base: versions.base === void 0 ? null : trimmed(versions.base),
324715
- theirs: trimmed(versions.theirs)
324716
- }),
324717
- conflict: true
324718
- };
324719
- }
324720
- function indentUnit(side) {
324721
- const { container, source } = side;
324722
- if (!isMultiline(container)) {
324723
- return " ";
324724
- }
324725
- const outer = lineIndent2(source, container.node.start);
324726
- const inner = entryIndent(container.entries[0]);
324727
- return inner.startsWith(outer) && inner.length > outer.length ? inner.slice(outer.length) : " ";
324728
- }
324729
- function mergeResourceSource({ base, ours, theirs }, { oursLabel = "branch", baseLabel = "base", theirsLabel = "main" } = {}) {
324730
- if (ours === theirs || base === theirs) {
324731
- return { status: "merged", content: ours };
324732
- }
324733
- if (base === ours) {
324734
- return { status: "merged", content: theirs };
324735
- }
324736
- const sides = { base: base === null ? null : readSide(base), ours: readSide(ours), theirs: readSide(theirs) };
324737
- if (sides.ours === null || sides.theirs === null || base !== null && sides.base === null) {
324738
- return { status: "unsupported" };
324739
- }
324740
- const ctx = {
324741
- conflicts: [],
324742
- labels: { ours: oursLabel, base: baseLabel, theirs: theirsLabel },
324743
- newline: ours.includes("\r\n") ? "\r\n" : "\n",
324744
- unit: sides.ours.unit
324745
- };
324746
- const containers = { base: sides.base?.container ?? null, ours: sides.ours.container, theirs: sides.theirs.container };
324747
- const before = mergeOutside(ctx, sides, (side) => [0, side.object.start], "module code before defineResource");
324748
- const object = mergeContainer(ctx, containers, {
324749
- label: (key) => key,
324750
- same: sameEntryText(),
324751
- nested: (key, baseEntry, oursEntry, theirsEntry) => mergeNestedOption(ctx, sides, key, baseEntry, oursEntry, theirsEntry)
324752
- });
324753
- const after = mergeOutside(ctx, sides, (side) => [side.object.end, side.source.length], "module code after defineResource");
324754
- const content = [
324755
- before.conflict ? `${before.text}${ctx.newline}` : before.text,
324756
- object,
324757
- after.conflict ? `${ctx.newline}${after.text}${ctx.newline}` : after.text
324758
- ].join("");
324759
- if (ctx.conflicts.length > 0) {
324760
- return { status: "conflict", content, conflicts: ctx.conflicts };
324761
- }
324762
- return readSide(content) === null ? { status: "unsupported" } : { status: "merged", content };
324763
- }
324764
-
324765
- // scripts/lib/runtime-build/git-cli.mjs
324766
- var MERGE_DRIVER_USAGE = "Usage: diagonal merge-driver <base> <ours> <theirs> [path]";
324767
- var GIT_SETUP_USAGE = "Usage: diagonal git setup";
324768
- var DRIVER = "diagonal-resource";
324769
- var DRIVER_COMMAND = "npx --no-install diagonal merge-driver %O %A %B %P";
324770
- var ATTRIBUTES_LINE = `resources/*.ts merge=${DRIVER}`;
324771
- var LABELS = { oursLabel: "branch", baseLabel: "base", theirsLabel: "main" };
324772
- function git(args, cwd) {
324773
- return spawnSync3("git", args, { cwd, encoding: "utf8" });
324774
- }
324775
- function lineMerge(base, ours, theirs, { cwd, stderr }) {
324776
- const result = git(
324777
- ["merge-file", "--diff3", "-L", LABELS.oursLabel, "-L", LABELS.baseLabel, "-L", LABELS.theirsLabel, ours, base, theirs],
324778
- cwd
324779
- );
324780
- if (result.error !== void 0 || result.status === null) {
324781
- stderr.write(`git merge-file did not run: ${result.error?.message ?? result.signal}
324782
- `);
324783
- return 2;
324784
- }
324785
- return result.status;
324786
- }
324787
- function mergeDriver(args, { cwd, stderr }) {
324788
- if (args.length < 3 || args.length > 4) {
324789
- stderr.write(`${MERGE_DRIVER_USAGE}
324790
- `);
324791
- return 2;
324792
- }
324793
- const [base, ours, theirs] = args.slice(0, 3).map((file2) => resolve6(cwd, file2));
324794
- const path = args[3];
324795
- if (path === void 0 || !isResourceFilePath(path)) {
324796
- return lineMerge(base, ours, theirs, { cwd, stderr });
324797
- }
324798
- const baseSource = readFileSync15(base, "utf8");
324799
- const result = mergeResourceSource(
324800
- { base: baseSource === "" ? null : baseSource, ours: readFileSync15(ours, "utf8"), theirs: readFileSync15(theirs, "utf8") },
324801
- LABELS
324802
- );
324803
- if (result.status === "unsupported") {
324804
- return lineMerge(base, ours, theirs, { cwd, stderr });
324805
- }
324806
- writeFileSync6(ours, result.content);
324807
- if (result.status === "conflict") {
324808
- stderr.write(`${path}: conflict in ${result.conflicts.join(", ")}
324809
- `);
324810
- return 1;
324811
- }
324812
- return 0;
324813
- }
324814
- function gitSetup(args, { cwd, stdout, stderr }) {
324815
- if (args.length > 0) {
324816
- stderr.write(`${GIT_SETUP_USAGE}
324817
- `);
324818
- return 2;
324819
- }
324820
- const topLevel = git(["rev-parse", "--show-toplevel"], cwd);
324821
- if (topLevel.status !== 0) {
324822
- stderr.write("Run this command in a git repository.\n");
324823
- return 2;
324824
- }
324825
- const root = topLevel.stdout.trim();
324826
- for (const [key, value] of [
324827
- [`merge.${DRIVER}.name`, "Diagonal resource merge"],
324828
- [`merge.${DRIVER}.driver`, DRIVER_COMMAND]
324829
- ]) {
324830
- const result = git(["config", key, value], root);
324831
- if (result.status !== 0) {
324832
- stderr.write(`git config ${key} failed: ${result.stderr.trim()}
324833
- `);
324834
- return 1;
324835
- }
324836
- }
324837
- const attributesPath = join19(root, ".gitattributes");
324838
- let attributes = "";
324839
- try {
324840
- attributes = readFileSync15(attributesPath, "utf8");
324841
- } catch (error) {
324842
- if (error.code !== "ENOENT") {
324843
- throw error;
324844
- }
324845
- }
324846
- stdout.write(`Registered the ${DRIVER} merge driver in the git config.
324847
- `);
324848
- if (attributes.split(/\r?\n/).some((line) => line.trim() === ATTRIBUTES_LINE)) {
324849
- return 0;
324850
- }
324851
- const separator = attributes === "" || attributes.endsWith("\n") ? "" : "\n";
324852
- writeFileSync6(attributesPath, `${attributes}${separator}${ATTRIBUTES_LINE}
324853
- `);
324854
- stdout.write(`Added "${ATTRIBUTES_LINE}" to .gitattributes. Commit .gitattributes.
324855
- `);
324856
- return 0;
324857
- }
324858
-
324859
324470
  // scripts/lib/runtime-build/migration-cli.mjs
324860
324471
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
324861
- import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, statSync as statSync5, writeFileSync as writeFileSync7 } from "node:fs";
324862
- import { join as join20 } from "node:path";
324472
+ import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, statSync as statSync5, writeFileSync as writeFileSync6 } from "node:fs";
324473
+ import { join as join19 } from "node:path";
324863
324474
  var MIGRATION_USAGE = "Usage: diagonal make:migration <name>";
324864
324475
  var NAME = /^[a-z0-9][a-z0-9_]{0,84}$/;
324865
324476
  function makeMigration(args, { cwd, stdout, stderr }) {
@@ -324871,12 +324482,12 @@ ${MIGRATION_USAGE}
324871
324482
  );
324872
324483
  return 2;
324873
324484
  }
324874
- if (!statSync5(join20(cwd, "diagonal.config.ts"), { throwIfNoEntry: false })?.isFile()) {
324485
+ if (!statSync5(join19(cwd, "diagonal.config.ts"), { throwIfNoEntry: false })?.isFile()) {
324875
324486
  stderr.write("Run this command in a workspace directory with diagonal.config.ts.\n");
324876
324487
  return 2;
324877
324488
  }
324878
324489
  const name = args[0];
324879
- const directory = join20(cwd, "migrations");
324490
+ const directory = join19(cwd, "migrations");
324880
324491
  mkdirSync4(directory, { recursive: true });
324881
324492
  const used = new Set(
324882
324493
  readdirSync4(directory).filter((file2) => file2.endsWith(".ts") && !file2.endsWith(".test.ts")).map((file2) => migrationTimestamp(file2.slice(0, -3))).filter((timestamp2) => timestamp2 !== null)
@@ -324900,7 +324511,7 @@ export default defineWorkflow(
324900
324511
  async () => {}
324901
324512
  );
324902
324513
  `;
324903
- writeFileSync7(join20(cwd, path), source, { flag: "wx" });
324514
+ writeFileSync6(join19(cwd, path), source, { flag: "wx" });
324904
324515
  stdout.write(`Created ${path}
324905
324516
  `);
324906
324517
  return 0;
@@ -324916,9 +324527,7 @@ var USAGE = [
324916
324527
  RUN_USAGE,
324917
324528
  LOGS_USAGE,
324918
324529
  ASSETS_UPLOAD_USAGE,
324919
- ASSETS_LIST_USAGE,
324920
- MERGE_DRIVER_USAGE,
324921
- GIT_SETUP_USAGE
324530
+ ASSETS_LIST_USAGE
324922
324531
  ].join("\n");
324923
324532
  function plural(count, word) {
324924
324533
  return `${count} ${word}${count === 1 ? "" : "s"}`;
@@ -324952,7 +324561,7 @@ ${CHECK_USAGE}
324952
324561
  `);
324953
324562
  return 2;
324954
324563
  }
324955
- const root = resolve7(cwd, parsed.dir);
324564
+ const root = resolve6(cwd, parsed.dir);
324956
324565
  if (!statSync6(root, { throwIfNoEntry: false })?.isDirectory()) {
324957
324566
  stderr.write(`Not a directory: ${root}
324958
324567
  `);
@@ -324990,15 +324599,6 @@ async function main(argv, io) {
324990
324599
  if (subcommand === "list") return listAssets(assetArgs, io);
324991
324600
  io.stderr.write(`${ASSETS_UPLOAD_USAGE}
324992
324601
  ${ASSETS_LIST_USAGE}
324993
- `);
324994
- return 2;
324995
- }
324996
- case "merge-driver":
324997
- return mergeDriver(args, io);
324998
- case "git": {
324999
- const [subcommand, ...gitArgs] = args;
325000
- if (subcommand === "setup") return gitSetup(gitArgs, io);
325001
- io.stderr.write(`${GIT_SETUP_USAGE}
325002
324602
  `);
325003
324603
  return 2;
325004
324604
  }