@hawkeyexl/manni 1.0.0 → 1.0.1

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.
@@ -3,7 +3,7 @@
3
3
  // package.json
4
4
  var package_default = {
5
5
  name: "@hawkeyexl/manni",
6
- version: "1.0.0",
6
+ version: "1.0.1",
7
7
  description: "One command line for documentation that is meant to be checked. `manni meta` validates the presence and format of document metadata (Markdown frontmatter and more) against JSON Schema, built for CI. Formerly docmeta.",
8
8
  type: "module",
9
9
  bin: {
@@ -396,6 +396,19 @@ var ToolError = class extends Error {
396
396
  this.name = "ToolError";
397
397
  }
398
398
  };
399
+ function errorMessage(err) {
400
+ if (err instanceof Error) return err.message;
401
+ if (typeof err === "string") return err;
402
+ if (typeof err === "object" && err !== null && "message" in err && typeof err.message === "string") {
403
+ return err.message;
404
+ }
405
+ try {
406
+ const json = JSON.stringify(err);
407
+ if (json !== void 0) return json;
408
+ } catch {
409
+ }
410
+ return String(err);
411
+ }
399
412
 
400
413
  // src/meta/types.ts
401
414
  var DocmetaError = class extends ToolError {
@@ -3113,7 +3126,7 @@ async function requestSchema(ref, timeoutMs, timedOut) {
3113
3126
  } catch (err) {
3114
3127
  if (isAbort(err)) throw timedOut;
3115
3128
  throw new RetryableFetchError(
3116
- `Failed to fetch schema "${ref}": ${err.message}`
3129
+ `Failed to fetch schema "${ref}": ${errorMessage(err)}`
3117
3130
  );
3118
3131
  }
3119
3132
  if (!res.ok) {
@@ -3145,7 +3158,7 @@ async function fetchSchemaBytes(ref, options = {}) {
3145
3158
  if (err instanceof DocmetaError) throw err;
3146
3159
  if (isAbort(err)) throw timedOut;
3147
3160
  throw new DocmetaError(
3148
- `Failed to fetch schema "${ref}": ${err.message}`
3161
+ `Failed to fetch schema "${ref}": ${errorMessage(err)}`
3149
3162
  );
3150
3163
  }
3151
3164
  const raw = stripBom(bytes.toString("utf8"));
@@ -3154,7 +3167,7 @@ async function fetchSchemaBytes(ref, options = {}) {
3154
3167
  parsed2 = JSON.parse(raw);
3155
3168
  } catch (err) {
3156
3169
  throw new DocmetaError(
3157
- `Schema "${ref}" did not return valid JSON: ${err.message}`
3170
+ `Schema "${ref}" did not return valid JSON: ${errorMessage(err)}`
3158
3171
  );
3159
3172
  }
3160
3173
  return { bytes, schema: assertFetchedSchema(ref, parsed2, raw) };
@@ -3267,7 +3280,7 @@ async function loadSchema(ref, options = {}) {
3267
3280
  return JSON.parse(text);
3268
3281
  } catch (err) {
3269
3282
  throw new DocmetaError(
3270
- `Schema file "${ref}" is not valid JSON: ${withoutFileExcerpt(err.message, text)}`
3283
+ `Schema file "${ref}" is not valid JSON: ${withoutFileExcerpt(errorMessage(err), text)}`
3271
3284
  );
3272
3285
  }
3273
3286
  }
@@ -5179,7 +5192,7 @@ function applyXml(original, patch, options = {}) {
5179
5192
  before = readXml(original, options.filePath, { elements: options.elements });
5180
5193
  } catch (err) {
5181
5194
  throw new DocmetaError(
5182
- `Refusing to write metadata: ${err.message}`
5195
+ `Refusing to write metadata: ${errorMessage(err)}`
5183
5196
  );
5184
5197
  }
5185
5198
  const content = before.body;
@@ -5314,7 +5327,7 @@ function verify2(next, before, patch, options) {
5314
5327
  }).data;
5315
5328
  } catch (err) {
5316
5329
  throw new DocmetaError(
5317
- `Refusing to write XML metadata: the rewritten document did not parse (${err.message}).`
5330
+ `Refusing to write XML metadata: the rewritten document did not parse (${errorMessage(err)}).`
5318
5331
  );
5319
5332
  }
5320
5333
  if (!deepEqual(actual, expected)) {
@@ -6253,7 +6266,7 @@ function parseMapping(text, source, opts) {
6253
6266
  try {
6254
6267
  raw = parseYaml(text);
6255
6268
  } catch (err) {
6256
- throw opts.toError(`${source}: invalid YAML: ${err.message}`);
6269
+ throw opts.toError(`${source}: invalid YAML: ${errorMessage(err)}`);
6257
6270
  }
6258
6271
  if (raw == null) return null;
6259
6272
  if (typeof raw !== "object" || Array.isArray(raw)) {
@@ -6365,7 +6378,7 @@ function asElementPaths(value, where, source) {
6365
6378
  try {
6366
6379
  parseElementPath(path);
6367
6380
  } catch (err) {
6368
- throw new DocmetaError(`${source}: ${where} \u2014 ${err.message}`);
6381
+ throw new DocmetaError(`${source}: ${where} \u2014 ${errorMessage(err)}`);
6369
6382
  }
6370
6383
  }
6371
6384
  return list;
@@ -6502,7 +6515,7 @@ function parseConfig(text, source) {
6502
6515
  raw = parseYaml2(text);
6503
6516
  } catch (err) {
6504
6517
  throw new DocmetaError(
6505
- `${source}: invalid YAML: ${err.message}`
6518
+ `${source}: invalid YAML: ${errorMessage(err)}`
6506
6519
  );
6507
6520
  }
6508
6521
  return parseConfigValue(raw, source);
@@ -6564,13 +6577,20 @@ function assertNoMovedKeys(raw, source) {
6564
6577
  }
6565
6578
  }
6566
6579
  }
6567
- function assertOverrideCollections(config, collections, source) {
6580
+ function inSection(message, source, section) {
6581
+ return section === void 0 ? message : withSection(message, source, section);
6582
+ }
6583
+ function assertOverrideCollections(config, collections, source, section) {
6568
6584
  const names = new Set(collections.map((c) => c.name));
6569
6585
  for (const [i, ov] of (config.overrides ?? []).entries()) {
6570
6586
  if (ov.collection === void 0 || names.has(ov.collection)) continue;
6571
6587
  const defined = collections.length === 0 ? "(none)" : collections.map((c) => c.name).join(", ");
6572
6588
  throw new DocmetaError(
6573
- `${source}: overrides[${i}].collection names "${ov.collection}", which collections: does not define. Defined: ${defined}.`
6589
+ inSection(
6590
+ `${source}: overrides[${i}].collection names "${ov.collection}", which collections: does not define. Defined: ${defined}.`,
6591
+ source,
6592
+ section
6593
+ )
6574
6594
  );
6575
6595
  }
6576
6596
  }
@@ -6805,7 +6825,7 @@ async function loadConfig(explicitPath, cwd = process.cwd()) {
6805
6825
  if (file === null) return null;
6806
6826
  const section = file.wrapped ? META_SECTION : void 0;
6807
6827
  const config = parseConfigValue(file.value, file.source, section);
6808
- assertOverrideCollections(config, file.collections, file.source);
6828
+ assertOverrideCollections(config, file.collections, file.source, section);
6809
6829
  return {
6810
6830
  config,
6811
6831
  path: file.path,
@@ -6900,16 +6920,22 @@ function createDocsTable(db, entries, dataColumns) {
6900
6920
  `INSERT INTO docs VALUES (${["?", "?", "?", "?", ...dataColumns.map(() => "?")].join(", ")})`
6901
6921
  );
6902
6922
  db.exec("BEGIN");
6903
- for (const { label, extracted } of entries) {
6904
- insert.run(
6905
- label,
6906
- extracted.format,
6907
- extracted.present ? 1 : 0,
6908
- JSON.stringify(extracted.data),
6909
- ...dataColumns.map((c) => bindValue(extracted.data[c]))
6910
- );
6923
+ let committed = false;
6924
+ try {
6925
+ for (const { label, extracted } of entries) {
6926
+ insert.run(
6927
+ label,
6928
+ extracted.format,
6929
+ extracted.present ? 1 : 0,
6930
+ JSON.stringify(extracted.data),
6931
+ ...dataColumns.map((c) => bindValue(extracted.data[c]))
6932
+ );
6933
+ }
6934
+ db.exec("COMMIT");
6935
+ committed = true;
6936
+ } finally {
6937
+ if (!committed) db.exec("ROLLBACK");
6911
6938
  }
6912
- db.exec("COMMIT");
6913
6939
  }
6914
6940
  function registerLineFor(db, entries) {
6915
6941
  const byLabel = new Map(entries.map((e) => [e.label, e.extracted]));
@@ -7248,7 +7274,7 @@ var Validator = class {
7248
7274
  return ajv.compile(schema);
7249
7275
  } catch (err) {
7250
7276
  throw new DocmetaError(
7251
- `Schema "${ref}" failed to compile: ${err.message}`
7277
+ `Schema "${ref}" failed to compile: ${errorMessage(err)}`
7252
7278
  );
7253
7279
  }
7254
7280
  }
@@ -7389,7 +7415,7 @@ function parseBaseline(text, source) {
7389
7415
  try {
7390
7416
  raw = JSON.parse(stripBom(text));
7391
7417
  } catch (err) {
7392
- bad(source, `invalid JSON: ${err.message}`);
7418
+ bad(source, `invalid JSON: ${errorMessage(err)}`);
7393
7419
  }
7394
7420
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
7395
7421
  bad(source, "top level must be an object.");
@@ -7431,7 +7457,7 @@ async function readBaseline(absPath, source) {
7431
7457
  } catch (err) {
7432
7458
  if (err.code === "ENOENT") return null;
7433
7459
  throw new DocmetaError(
7434
- `Baseline "${source}" could not be read: ${err.message}`
7460
+ `Baseline "${source}" could not be read: ${errorMessage(err)}`
7435
7461
  );
7436
7462
  }
7437
7463
  return parseBaseline(text, source);
@@ -7441,7 +7467,7 @@ async function writeBaselineFile(absPath, baseline, source) {
7441
7467
  await writeFileAtomic(absPath, serializeBaseline(baseline));
7442
7468
  } catch (err) {
7443
7469
  throw new DocmetaError(
7444
- `Baseline "${source}" could not be written: ${err.message}`
7470
+ `Baseline "${source}" could not be written: ${errorMessage(err)}`
7445
7471
  );
7446
7472
  }
7447
7473
  }
@@ -7588,7 +7614,7 @@ async function runChecks(checks, entries, ctx = {}) {
7588
7614
  tokens = collectNamedParameters(check.query);
7589
7615
  } catch (err) {
7590
7616
  throw new DocmetaError(
7591
- `check "${check.name}": ${err.message}`
7617
+ `check "${check.name}": ${errorMessage(err)}`
7592
7618
  );
7593
7619
  }
7594
7620
  if (tokens.length > 0) {
@@ -7604,7 +7630,7 @@ async function runChecks(checks, entries, ctx = {}) {
7604
7630
  columns = stmt.columns().map((c) => c.name);
7605
7631
  rows = stmt.all();
7606
7632
  } catch (err) {
7607
- const message = err.message;
7633
+ const message = errorMessage(err);
7608
7634
  throw new DocmetaError(
7609
7635
  message.includes("attempt to write a readonly database") ? `check "${check.name}": ${message} \u2014 checks are read-only by design; a check is a SELECT over the projection. Edit the corpus with \`manni meta query\` instead.` : `check "${check.name}": ${message}`
7610
7636
  );
@@ -7775,7 +7801,7 @@ async function runValidate(opts) {
7775
7801
  } catch (err) {
7776
7802
  if (err instanceof DocmetaError) throw err;
7777
7803
  results.push(
7778
- parseErrorResult(label, extractor.name, err.message, "parse")
7804
+ parseErrorResult(label, extractor.name, errorMessage(err), "parse")
7779
7805
  );
7780
7806
  return;
7781
7807
  }
@@ -7807,7 +7833,7 @@ async function runValidate(opts) {
7807
7833
  });
7808
7834
  } catch (err) {
7809
7835
  results.push(
7810
- parseErrorResult(label, extractor.name, err.message, "schema")
7836
+ parseErrorResult(label, extractor.name, errorMessage(err), "schema")
7811
7837
  );
7812
7838
  return;
7813
7839
  }
@@ -8734,7 +8760,7 @@ async function prepareDbTarget(resolved, display) {
8734
8760
  var MissingCollectionView = class extends Error {
8735
8761
  };
8736
8762
  function refuseSqlError(err) {
8737
- const message = err.message;
8763
+ const message = errorMessage(err);
8738
8764
  if (message.includes("UNIQUE constraint failed: docs._path")) {
8739
8765
  throw new DocmetaError("That _path already exists in the corpus.");
8740
8766
  }
@@ -8763,7 +8789,7 @@ async function runSql(sql, entries, ctx) {
8763
8789
  db = new DatabaseSync(target ? target.resolved : ":memory:");
8764
8790
  } catch (err) {
8765
8791
  throw new DocmetaError(
8766
- `Cannot open "${target?.display ?? ":memory:"}": ${err.message}`
8792
+ `Cannot open "${target?.display ?? ":memory:"}": ${errorMessage(err)}`
8767
8793
  );
8768
8794
  }
8769
8795
  const dbInfo = target ? {
@@ -8811,7 +8837,7 @@ async function runSql(sql, entries, ctx) {
8811
8837
  stmt = db.prepare(sql);
8812
8838
  columns = stmt.columns().map((c) => c.name);
8813
8839
  } catch (err) {
8814
- const message = err.message;
8840
+ const message = errorMessage(err);
8815
8841
  const missing = missingTableName(message);
8816
8842
  if (missing !== void 0 && !viewsBuilt && namesConfiguredCollection(missing, ctx.declaredCollections)) {
8817
8843
  throw new MissingCollectionView();
@@ -9331,7 +9357,7 @@ async function planSchemaMutation(ops, entries, ctx) {
9331
9357
  onNotice: ctx.onNotice
9332
9358
  });
9333
9359
  } catch (err) {
9334
- throw new DocmetaError(`"${e.label}": ${err.message}`);
9360
+ throw new DocmetaError(`"${e.label}": ${errorMessage(err)}`);
9335
9361
  }
9336
9362
  sources.add(resolved.source);
9337
9363
  if (resolved.overrideIndex !== void 0) {
@@ -10040,7 +10066,9 @@ async function applyChanges(changes, entries, ctx, schemaPlan) {
10040
10066
  path,
10041
10067
  content: extractor.apply("", ops.created, {
10042
10068
  filePath: label,
10043
- elements: resolveElements(label, ctx.config)
10069
+ // The new file's memberships, from its path alone. An INSERT has to
10070
+ // write through the element set a read of that file would use.
10071
+ elements: resolveElements(label, ctx.config, ctx.memberships(label))
10044
10072
  }),
10045
10073
  ensureDir: true
10046
10074
  });
@@ -10088,7 +10116,9 @@ async function applyChanges(changes, entries, ctx, schemaPlan) {
10088
10116
  }
10089
10117
  const applied = entry.extractor.apply(content, ops.patch, {
10090
10118
  filePath: label,
10091
- elements: resolveElements(label, ctx.config),
10119
+ // The memberships the read above used. Without them a collection-scoped
10120
+ // element the read found has nowhere to be written.
10121
+ elements: resolveElements(label, ctx.config, members),
10092
10122
  deletions: ops.deletions
10093
10123
  });
10094
10124
  if (ops.deletions.length > 0) {
@@ -10151,7 +10181,7 @@ async function applyChanges(changes, entries, ctx, schemaPlan) {
10151
10181
  await rename2(r.from, r.to);
10152
10182
  } catch (err) {
10153
10183
  throw new DocmetaError(
10154
- `Cannot move "${r.from}" to "${r.to}": ${err.message}`
10184
+ `Cannot move "${r.from}" to "${r.to}": ${errorMessage(err)}`
10155
10185
  );
10156
10186
  }
10157
10187
  }
@@ -10514,7 +10544,7 @@ async function runFill(opts) {
10514
10544
  provider = construct();
10515
10545
  } catch (err) {
10516
10546
  throw new DocmetaError(
10517
- err instanceof InferenceError ? err.message : `Could not construct the "${providerName}" provider: ${err.message}`
10547
+ err instanceof InferenceError ? err.message : `Could not construct the "${providerName}" provider: ${errorMessage(err)}`
10518
10548
  );
10519
10549
  }
10520
10550
  }
@@ -10564,7 +10594,7 @@ async function runFill(opts) {
10564
10594
  );
10565
10595
  extracted = merged.extracted;
10566
10596
  } catch (err) {
10567
- return errorResult(label, extractor.name, err.message);
10597
+ return errorResult(label, extractor.name, errorMessage(err));
10568
10598
  }
10569
10599
  let resolved;
10570
10600
  try {
@@ -10582,7 +10612,7 @@ async function runFill(opts) {
10582
10612
  onNotice: opts.onNotice
10583
10613
  });
10584
10614
  } catch (err) {
10585
- return errorResult(label, extractor.name, err.message);
10615
+ return errorResult(label, extractor.name, errorMessage(err));
10586
10616
  }
10587
10617
  const schemaSet = resolved.schemas;
10588
10618
  let schemas;
@@ -10636,7 +10666,7 @@ async function runFill(opts) {
10636
10666
  try {
10637
10667
  extractor.apply(content, {}, { filePath: label, elements });
10638
10668
  } catch (err) {
10639
- return errorResult(label, extractor.name, err.message, schemaSet);
10669
+ return errorResult(label, extractor.name, errorMessage(err), schemaSet);
10640
10670
  }
10641
10671
  const cacheKey = buildCacheKey([
10642
10672
  identity.provider,
@@ -10674,7 +10704,7 @@ async function runFill(opts) {
10674
10704
  return errorResult(
10675
10705
  label,
10676
10706
  extractor.name,
10677
- `Could not build a proposal schema from ${schemaSet.join(", ")}: ${err.message}`,
10707
+ `Could not build a proposal schema from ${schemaSet.join(", ")}: ${errorMessage(err)}`,
10678
10708
  schemaSet
10679
10709
  );
10680
10710
  }
@@ -10802,7 +10832,7 @@ async function runFill(opts) {
10802
10832
  return errorResult(
10803
10833
  label,
10804
10834
  extractor.name,
10805
- err.message,
10835
+ errorMessage(err),
10806
10836
  schemaSet,
10807
10837
  fields
10808
10838
  );
@@ -11102,7 +11132,7 @@ async function resolveIdentity(spec) {
11102
11132
  return await resolveProviderIdentityAsync(spec);
11103
11133
  } catch (err) {
11104
11134
  throw new DocmetaError(
11105
- err instanceof InferenceError ? err.message : `Could not resolve provider "${spec.provider}": ${err.message}`
11135
+ err instanceof InferenceError ? err.message : `Could not resolve provider "${spec.provider}": ${errorMessage(err)}`
11106
11136
  );
11107
11137
  }
11108
11138
  }
@@ -11727,6 +11757,7 @@ export {
11727
11757
  palette,
11728
11758
  shouldColor,
11729
11759
  ToolError,
11760
+ errorMessage,
11730
11761
  programName,
11731
11762
  setProgramName,
11732
11763
  externalMetadataUrlProblem,
@@ -11819,4 +11850,4 @@ export {
11819
11850
  renderQuery,
11820
11851
  renderQueryCsv
11821
11852
  };
11822
- //# sourceMappingURL=chunk-L7HN3AWA.js.map
11853
+ //# sourceMappingURL=chunk-IRHWILCO.js.map