@pipelex/mthds-ui 0.24.0 → 0.25.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.
@@ -1,4 +1,4 @@
1
- import { C as ConceptInfo, P as PipeBlueprintUnion, a as PresenceMarker, b as GraphSpec, V as ValidationIssue } from '../types-Cn2FttBC.js';
1
+ import { C as ConceptInfo, P as PipeBlueprintUnion, a as PresenceMarker, b as GraphSpec, V as ValidationIssue } from '../types-Bcsh7Z0U.js';
2
2
  export { P as ParsedPipeRef, m as makePipeRef, p as parsePipeRef } from '../pipeRefs-BQJO5nh5.js';
3
3
 
4
4
  type DiagnosticSeverity = "error" | "warning";
@@ -164,4 +164,82 @@ declare function buildStaticGraphSpecFromToml(tomlTexts: string | string[], opti
164
164
  */
165
165
  declare function staticDiagnosticsToValidationIssues(diagnostics: Diagnostic[]): ValidationIssue[];
166
166
 
167
- export { type ConceptRefParts, type Diagnostic, type DiagnosticCode, type DiagnosticSeverity, type DomainNamespace, type InputSlotParts, type MergedMethodSet, NATIVE_CONCEPT_CODES, NATIVE_DOMAIN, type ParseMthdsBundleResult, type ParsedBundle, type StaticGraphOptions, type StaticGraphResult, UNKNOWN_DOMAIN, buildStaticGraphSpec, buildStaticGraphSpecFromToml, mergeBundles, parseConceptRef, parseInputSlot, parseMthdsBundle, staticDiagnosticsToValidationIssues };
167
+ /**
168
+ * One `.mthds` file of a method: the name it goes by and its TOML text. The
169
+ * same shape as an `mthds_sources[]` entry on the hosted API, so a host holding
170
+ * one can pass it straight through.
171
+ */
172
+ interface MthdsSource {
173
+ /**
174
+ * File name, or a path ending in one. The whole string is the file's
175
+ * identity: a `preferred` file is matched against it exactly, and an embed
176
+ * lists each name once. Only the `bundle.mthds` tie-break reads the last
177
+ * segment alone.
178
+ */
179
+ name: string;
180
+ /** The file's `.mthds` TOML text. */
181
+ content: string;
182
+ }
183
+ /** The file name that breaks a tie when several files declare `main_pipe`. */
184
+ declare const DEFAULT_BUNDLE_FILE_NAME = "bundle.mthds";
185
+ /**
186
+ * Whether a file declares `main_pipe` at the top level, before its first table.
187
+ *
188
+ * A line scan rather than a TOML parse, on purpose: an editor asks this about
189
+ * a file the author is in the middle of writing, and a syntax error further
190
+ * down must not demote the file that plainly declares the entry point. The
191
+ * scan stops at the first table header, because a `main_pipe` key inside a
192
+ * table is not the bundle's.
193
+ */
194
+ declare function hasTopLevelMainPipe(content: string): boolean;
195
+ /**
196
+ * The file a method's graph is anchored on.
197
+ *
198
+ * `preferred` is the file the host is looking at, such as the one open in an
199
+ * editor; it leads whenever it declares `main_pipe` itself. Otherwise the file
200
+ * declaring a top-level `main_pipe` leads, `bundle.mthds` when several do and
201
+ * the first of them in the given order when none is named so. When no file
202
+ * declares one, `preferred` leads, or else the first file. Returns `undefined`
203
+ * only for an empty list.
204
+ *
205
+ * `preferred` is matched against `sources` by `name`, and the listed entry is
206
+ * what is read and returned, so a host may pass its own object for the open
207
+ * file rather than the list's: the result is always a member of `sources`,
208
+ * because the merge reads the list and not `preferred`. That is also why
209
+ * `preferred` is a plain `MthdsSource`: it cannot narrow the result's type and
210
+ * strip the fields a host's own list entries carry. A `preferred` whose
211
+ * name is not listed is ignored: it cannot lead a list it is not in, and the
212
+ * answer is then the one given no `preferred` at all.
213
+ */
214
+ declare function selectPrimaryMthdsSource<T extends MthdsSource>(sources: readonly T[], preferred?: MthdsSource): T | undefined;
215
+ /**
216
+ * The files in the order the static builder should merge them: the primary
217
+ * file (see {@link selectPrimaryMthdsSource}, which also says how `preferred`
218
+ * is matched) first, then the rest in the order given. The rest keep their
219
+ * order so a host that wants a deterministic merge only has to list its files
220
+ * deterministically. Returns a new array.
221
+ */
222
+ declare function orderMthdsSources<T extends MthdsSource>(sources: readonly T[], preferred?: MthdsSource): T[];
223
+
224
+ /** The id of the `<script type="application/json">` element carrying the files. */
225
+ declare const MTHDS_SOURCES_EMBED_ID = "mthds-sources";
226
+ /**
227
+ * The text a host places inside `<script type="application/json"
228
+ * id="mthds-sources">`: the files as a JSON array of `{ name, content }`,
229
+ * checked against the embed contract, with every `<` written as `\u003c`.
230
+ *
231
+ * The escape is what makes the text safe inside the element. `JSON.parse`
232
+ * reads it back as `<`, while the HTML parser never meets one, so no method
233
+ * text can end the element early, whichever spelling of `</script` it uses, or
234
+ * switch the element into the states a `<!--` opens. A prompt quoting a line of
235
+ * HTML is enough to need it. Neither `JSON.stringify` nor any platform API has
236
+ * an HTML-safe mode, which is why this function exists.
237
+ *
238
+ * Only `name` and `content` are written, whatever else a host's objects carry,
239
+ * and the files keep the order given, because the bundle puts them in merge
240
+ * order itself. Throws on a list the bundle would refuse, naming the entry at
241
+ * fault.
242
+ */
243
+ declare function serializeMthdsSourcesEmbed(sources: readonly MthdsSource[]): string;
244
+
245
+ export { type ConceptRefParts, DEFAULT_BUNDLE_FILE_NAME, type Diagnostic, type DiagnosticCode, type DiagnosticSeverity, type DomainNamespace, type InputSlotParts, MTHDS_SOURCES_EMBED_ID, type MergedMethodSet, type MthdsSource, NATIVE_CONCEPT_CODES, NATIVE_DOMAIN, type ParseMthdsBundleResult, type ParsedBundle, type StaticGraphOptions, type StaticGraphResult, UNKNOWN_DOMAIN, buildStaticGraphSpec, buildStaticGraphSpecFromToml, hasTopLevelMainPipe, mergeBundles, orderMthdsSources, parseConceptRef, parseInputSlot, parseMthdsBundle, selectPrimaryMthdsSource, serializeMthdsSourcesEmbed, staticDiagnosticsToValidationIssues };
@@ -4,7 +4,7 @@ import {
4
4
  } from "../chunk-2N65P32H.js";
5
5
  import {
6
6
  KNOWN_PIPE_TYPES
7
- } from "../chunk-RJVEDP7M.js";
7
+ } from "../chunk-F3GBNU2I.js";
8
8
  import {
9
9
  __spreadProps,
10
10
  __spreadValues
@@ -1425,18 +1425,90 @@ function staticDiagnosticsToValidationIssues(diagnostics) {
1425
1425
  origin: "static"
1426
1426
  }, targetFromPath(diagnostic.path, diagnostic.domain_code)));
1427
1427
  }
1428
+
1429
+ // src/static-graph/sourceOrder.ts
1430
+ var DEFAULT_BUNDLE_FILE_NAME = "bundle.mthds";
1431
+ var MAIN_PIPE_LINE = /^\s*main_pipe\s*=\s*(["'])[^"']+\1\s*(?:#.*)?$/;
1432
+ var TABLE_HEADER_LINE = /^\s*\[/;
1433
+ function hasTopLevelMainPipe(content) {
1434
+ for (const line of content.split(/\r\n|\r|\n/)) {
1435
+ if (TABLE_HEADER_LINE.test(line)) return false;
1436
+ if (MAIN_PIPE_LINE.test(line)) return true;
1437
+ }
1438
+ return false;
1439
+ }
1440
+ function isDefaultBundle(source) {
1441
+ const baseName = source.name.replace(/^.*[\\/]/, "");
1442
+ return baseName.toLowerCase() === DEFAULT_BUNDLE_FILE_NAME;
1443
+ }
1444
+ function selectPrimaryMthdsSource(sources, preferred) {
1445
+ var _a, _b, _c;
1446
+ const listed = preferred === void 0 ? void 0 : sources.find((source) => source.name === preferred.name);
1447
+ if (listed !== void 0 && hasTopLevelMainPipe(listed.content)) return listed;
1448
+ const withMainPipe = sources.filter((source) => hasTopLevelMainPipe(source.content));
1449
+ return (_c = (_b = (_a = withMainPipe.find(isDefaultBundle)) != null ? _a : withMainPipe[0]) != null ? _b : listed) != null ? _c : sources[0];
1450
+ }
1451
+ function orderMthdsSources(sources, preferred) {
1452
+ const primary = selectPrimaryMthdsSource(sources, preferred);
1453
+ const index = primary === void 0 ? -1 : sources.indexOf(primary);
1454
+ if (index <= 0) return [...sources];
1455
+ return [sources[index], ...sources.slice(0, index), ...sources.slice(index + 1)];
1456
+ }
1457
+
1458
+ // src/static-graph/mthdsSourcesEmbed.ts
1459
+ var MTHDS_SOURCES_EMBED_ID = "mthds-sources";
1460
+ function describeEntry(index) {
1461
+ return `<script id="${MTHDS_SOURCES_EMBED_ID}"> entry ${index}`;
1462
+ }
1463
+ function parseMthdsSourcesEmbed(raw) {
1464
+ if (!Array.isArray(raw)) {
1465
+ throw new Error(
1466
+ `<script id="${MTHDS_SOURCES_EMBED_ID}"> must hold a JSON array of { "name", "content" } objects, one per .mthds file.`
1467
+ );
1468
+ }
1469
+ if (raw.length === 0) {
1470
+ throw new Error(`<script id="${MTHDS_SOURCES_EMBED_ID}"> lists no .mthds file.`);
1471
+ }
1472
+ const seen = /* @__PURE__ */ new Set();
1473
+ return raw.map((entry, index) => {
1474
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) {
1475
+ throw new Error(`${describeEntry(index)} is not a { "name", "content" } object.`);
1476
+ }
1477
+ const { name, content } = entry;
1478
+ if (typeof name !== "string" || name.trim() === "") {
1479
+ throw new Error(`${describeEntry(index)} has no "name" string.`);
1480
+ }
1481
+ if (typeof content !== "string") {
1482
+ throw new Error(`${describeEntry(index)} ("${name}") has no "content" string.`);
1483
+ }
1484
+ if (seen.has(name)) {
1485
+ throw new Error(`${describeEntry(index)} repeats the name "${name}".`);
1486
+ }
1487
+ seen.add(name);
1488
+ return { name, content };
1489
+ });
1490
+ }
1491
+ function serializeMthdsSourcesEmbed(sources) {
1492
+ return JSON.stringify(parseMthdsSourcesEmbed(sources)).replace(/</g, "\\u003c");
1493
+ }
1428
1494
  export {
1495
+ DEFAULT_BUNDLE_FILE_NAME,
1496
+ MTHDS_SOURCES_EMBED_ID,
1429
1497
  NATIVE_CONCEPT_CODES,
1430
1498
  NATIVE_DOMAIN,
1431
1499
  UNKNOWN_DOMAIN,
1432
1500
  buildStaticGraphSpec,
1433
1501
  buildStaticGraphSpecFromToml,
1502
+ hasTopLevelMainPipe,
1434
1503
  makePipeRef,
1435
1504
  mergeBundles,
1505
+ orderMthdsSources,
1436
1506
  parseConceptRef,
1437
1507
  parseInputSlot,
1438
1508
  parseMthdsBundle,
1439
1509
  parsePipeRef,
1510
+ selectPrimaryMthdsSource,
1511
+ serializeMthdsSourcesEmbed,
1440
1512
  staticDiagnosticsToValidationIssues
1441
1513
  };
1442
1514
  //# sourceMappingURL=index.js.map