@riboseinc/anafero-cli 0.0.66 → 0.0.68

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/bootstrap.js CHANGED
@@ -69144,6 +69144,11 @@ schema (${ast._tag}): ${ast}`;
69144
69144
  version: Literal4("0.1"),
69145
69145
  /** The entry point, path to XML of a Metanorma document or collection. */
69146
69146
  entryPoint: String$2.pipe(nonEmptyString3()),
69147
+ /**
69148
+ * Workspace title.
69149
+ * If not provided, “document ID • document title” is used.
69150
+ */
69151
+ workspaceTitle: String$2.pipe(nonEmptyString3()).pipe(optional2),
69147
69152
  /**
69148
69153
  * Which reader modules to use.
69149
69154
  *
@@ -72101,7 +72106,88 @@ schema (${ast._tag}): ${ast}`;
72101
72106
  throw new Error("Requested key does not exist");
72102
72107
  }
72103
72108
  },
72104
- dump: () => cache
72109
+ dump: async (stream2, signal) => {
72110
+ async function* buildKeypaths(obj, currentPath, seen, paths2, signal2) {
72111
+ if (signal2.aborted) {
72112
+ throw new Error("Aborted");
72113
+ }
72114
+ for (const key of Object.keys(Object(obj))) {
72115
+ const val = obj[key];
72116
+ if (typeof val === "string" || Object.keys(Object(val)).length === 0) {
72117
+ yield [...currentPath, key];
72118
+ } else {
72119
+ const complexVal = val;
72120
+ if (!seen.has(complexVal)) {
72121
+ seen.add(complexVal);
72122
+ yield* buildKeypaths(
72123
+ complexVal,
72124
+ [...currentPath, key],
72125
+ seen,
72126
+ paths2,
72127
+ signal2
72128
+ );
72129
+ }
72130
+ }
72131
+ }
72132
+ }
72133
+ async function write(data, end) {
72134
+ return new Promise((resolve) => {
72135
+ if (end) {
72136
+ stream2.end(data, function() {
72137
+ resolve();
72138
+ });
72139
+ } else {
72140
+ stream2.write(data, function() {
72141
+ resolve();
72142
+ });
72143
+ }
72144
+ });
72145
+ }
72146
+ function serializeKeypath(idx2, keyPaths) {
72147
+ const keyPath = keyPaths[idx2];
72148
+ if (keyPath) {
72149
+ const keyString = keyPath.join(".");
72150
+ keyPath.reverse();
72151
+ let valueCursor = cache;
72152
+ while (true) {
72153
+ let part = keyPath.pop();
72154
+ if (part) {
72155
+ valueCursor = valueCursor[part];
72156
+ } else {
72157
+ break;
72158
+ }
72159
+ }
72160
+ return `
72161
+ ${JSON.stringify(keyString)}: ${valueCursor}`;
72162
+ } else {
72163
+ return null;
72164
+ }
72165
+ }
72166
+ const pathGen = buildKeypaths(cache, [], /* @__PURE__ */ new Set(), [], signal);
72167
+ const paths = [];
72168
+ for await (const p of pathGen) {
72169
+ paths.push(p);
72170
+ }
72171
+ await write(`
72172
+ -- starting dumping ${paths.length} paths --`);
72173
+ let idx = 0;
72174
+ const chunkSize = 1e3;
72175
+ let chunk3 = "";
72176
+ while (true) {
72177
+ if (idx > 0 && idx % chunkSize === 0) {
72178
+ await write(chunk3);
72179
+ chunk3 = "";
72180
+ }
72181
+ const nextItem = serializeKeypath(idx, paths);
72182
+ if (nextItem) {
72183
+ chunk3 = chunk3 + nextItem;
72184
+ } else {
72185
+ break;
72186
+ }
72187
+ idx += 1;
72188
+ }
72189
+ return;
72190
+ }
72105
72191
  };
72106
72192
  }
72107
72193
  var init_cache = __esm({
@@ -72214,12 +72300,48 @@ schema (${ast._tag}): ${ast}`;
72214
72300
 
72215
72301
  // ../anafero/search.mts
72216
72302
  function preprocessStringForIndexing(text) {
72217
- return text.normalize("NFKD").replace(/\p{Diacritic}/gu, "").trim();
72303
+ return text.normalize("NFKD").replace(/\p{Diacritic}/gu, "").replace(/[\p{P}$+<=>^`|~]/gu, " ").replace(/[\u200B-\u200D\uFEFF]/g, "").trim();
72218
72304
  }
72219
- function extractRelationsForIndexing(uri, graph, isDefinedSubject) {
72220
- return graph.filter(
72221
- ([s, p, o2]) => p === "hasPart" && (s === uri || s === ROOT_SUBJECT) && !o2.startsWith("data:") && (!isURIString(o2) || !isDefinedSubject(o2))
72305
+ function extractRelationsForIndexing(uri, graph, isIndexable, isAlreadyIndexed, _seen, _log) {
72306
+ const seen = _seen ?? /* @__PURE__ */ new Set();
72307
+ seen.add(uri);
72308
+ const nonData = graph.filter(
72309
+ ([, , o2]) => !o2.startsWith("data:")
72310
+ );
72311
+ const immediateGraph = nonData.filter(
72312
+ ([s, ,]) => s === uri || s === ROOT_SUBJECT
72313
+ );
72314
+ const references = immediateGraph.filter(
72315
+ ([, , o2]) => isURIString(o2)
72222
72316
  );
72317
+ const indexable = immediateGraph.filter(
72318
+ ([s, p, o2]) => !isURIString(o2) && isIndexable([s, p, o2])
72319
+ ).map(([, , o2]) => o2).filter((o2) => o2.trim() !== "");
72320
+ for (const [, , o2] of references) {
72321
+ if (_log) {
72322
+ console.debug(
72323
+ "search: processing triple object",
72324
+ { o: o2, isAlreadyIndexed: isAlreadyIndexed(o2) }
72325
+ );
72326
+ }
72327
+ if (!isAlreadyIndexed(o2) && !seen.has(o2)) {
72328
+ indexable.push(...extractRelationsForIndexing(
72329
+ o2,
72330
+ graph,
72331
+ isIndexable,
72332
+ isAlreadyIndexed,
72333
+ seen,
72334
+ _log
72335
+ ));
72336
+ }
72337
+ }
72338
+ if (_log) {
72339
+ console.debug(
72340
+ "search: obtained indexable from graph",
72341
+ { uri, graph, indexable }
72342
+ );
72343
+ }
72344
+ return indexable;
72223
72345
  }
72224
72346
  var init_search = __esm({
72225
72347
  "../anafero/search.mts"() {
@@ -109636,7 +109758,7 @@ schema (${ast._tag}): ${ast}`;
109636
109758
  const debouncedQueryTrimmed = debouncedQuery.trim();
109637
109759
  if (index && debouncedQueryTrimmed !== "") {
109638
109760
  const normalizedQuery = preprocessStringForIndexing(
109639
- debouncedQuery.replace(/:/g, " ").replace(/\*/g, " ")
109761
+ debouncedQuery.replace(/\*/g, " ")
109640
109762
  );
109641
109763
  const tokens = import_lunr.default.tokenizer(normalizedQuery);
109642
109764
  console.debug("Search: tokens", tokens);