@dallaylaen/ski-interpreter 2.8.1 → 2.9.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.
@@ -1686,6 +1686,8 @@ var Quest = class {
1686
1686
  this.intro = list2str(options.intro);
1687
1687
  this.id = options.id;
1688
1688
  this.meta = meta;
1689
+ if (meta.created_at)
1690
+ this.created = new Date(meta.created_at);
1689
1691
  for (const c of cases ?? [])
1690
1692
  this.add(...c);
1691
1693
  }
@@ -1833,10 +1835,9 @@ var Quest = class {
1833
1835
  findings[field] = found;
1834
1836
  }
1835
1837
  if (options.date) {
1836
- const date = new Date(this.meta?.created_at);
1837
- if (isNaN(date.getTime()))
1838
+ if (!this.created || isNaN(this.created.getTime()))
1838
1839
  findings.date = "invalid date format: " + this.meta?.created_at;
1839
- else if (date.getTime() < (/* @__PURE__ */ new Date("2024-07-15")).getTime() || date.getTime() > (/* @__PURE__ */ new Date()).getTime())
1840
+ else if (this.created < /* @__PURE__ */ new Date("2024-07-15") || this.created > /* @__PURE__ */ new Date())
1840
1841
  findings.date = "date out of range: " + this.meta?.created_at;
1841
1842
  }
1842
1843
  return findings;
@@ -2130,7 +2131,7 @@ function deepFormat(obj, options = {}) {
2130
2131
  out[key] = deepFormat(obj[key], options);
2131
2132
  return out;
2132
2133
  }
2133
- function search(seed, options, predicate) {
2134
+ function* search(seed, options, predicate) {
2134
2135
  const {
2135
2136
  depth = 16,
2136
2137
  infer = true,
@@ -2141,57 +2142,70 @@ function search(seed, options, predicate) {
2141
2142
  let total = 0;
2142
2143
  let probed = 0;
2143
2144
  const seen = {};
2145
+ const parseResult = (raw) => {
2146
+ if (raw === null || raw === void 0)
2147
+ return {};
2148
+ if (typeof raw === "number")
2149
+ return raw > 0 ? { found: true, stop: true } : raw < 0 ? { offset: -1 } : {};
2150
+ return raw;
2151
+ };
2144
2152
  const maybeProbe = (term) => {
2145
2153
  total++;
2146
2154
  const props = infer ? term.infer({ max: options.max, maxArgs: options.maxArgs }) : null;
2147
2155
  if (hasSeen && props && props.expr) {
2148
2156
  const key = String(props.expr);
2149
2157
  if (seen[key])
2150
- return { res: -1, props };
2158
+ return { res: { offset: -1 }, props };
2151
2159
  seen[key] = true;
2152
2160
  }
2153
2161
  probed++;
2154
- const res = predicate(term, props);
2162
+ const res = parseResult(predicate(term, props));
2155
2163
  return { res, props };
2156
2164
  };
2157
2165
  for (const term of seed) {
2158
- const { res = 0 } = maybeProbe(term);
2159
- if (res > 0)
2160
- return { expr: term, total, probed, gen: 1 };
2161
- else if (res < 0)
2162
- continue;
2163
- cache[0].push(term);
2166
+ const { res } = maybeProbe(term);
2167
+ if (res.found)
2168
+ yield { expr: term, found: true, step: false, gen: 0, total, probed, cache };
2169
+ if (res.stop)
2170
+ return;
2171
+ if ((res.offset ?? 0) >= 0)
2172
+ cache[0].push(term);
2164
2173
  }
2165
2174
  let lastProgress = 0;
2166
2175
  for (let gen = 1; gen < depth; gen++) {
2167
- if (options.progress) {
2168
- options.progress({ gen, total, probed, step: true });
2169
- lastProgress = total;
2170
- }
2176
+ yield { found: false, step: true, gen, total, probed, cache };
2177
+ lastProgress = total;
2171
2178
  for (let i = 0; i < gen; i++) {
2172
2179
  for (const a of cache[gen - i - 1] || []) {
2173
2180
  for (const b of cache[i] || []) {
2174
- if (total >= (options.tries ?? Infinity))
2175
- return { total, probed, gen, ...options.retain ? { cache } : {} };
2176
- if (options.progress && total - lastProgress >= progressInterval) {
2177
- options.progress({ gen, total, probed, step: false });
2181
+ if (total >= (options.tries ?? Infinity)) {
2182
+ yield { found: false, step: false, gen, total, probed, cache };
2183
+ return;
2184
+ }
2185
+ if (total - lastProgress >= progressInterval) {
2186
+ yield { found: false, step: false, gen, total, probed, cache };
2178
2187
  lastProgress = total;
2179
2188
  }
2180
2189
  const term = a.apply(b);
2181
2190
  const { res, props } = maybeProbe(term);
2182
- if ((res ?? 0) > 0)
2183
- return { expr: term, total, probed, gen, ...options.retain ? { cache } : {} };
2184
- else if ((res ?? 0) < 0)
2191
+ if (res.found)
2192
+ yield { expr: term, found: true, step: false, gen, total, probed, cache };
2193
+ if (res.stop) {
2194
+ yield { found: false, step: false, gen, total, probed, cache };
2195
+ return;
2196
+ }
2197
+ if ((res.offset ?? 0) < 0)
2185
2198
  continue;
2186
- const offset = infer && props ? (props.expr ? 0 : 3) + (props.dup ? 1 : 0) + (props.proper ? 0 : 1) : 0;
2187
- if (!cache[gen + offset])
2188
- cache[gen + offset] = [];
2189
- cache[gen + offset].push(term);
2199
+ const autoOffset = infer && props ? (props.expr ? 0 : 3) + (props.dup ? 1 : 0) + (props.proper ? 0 : 1) : 0;
2200
+ const finalOffset = res.offset ?? autoOffset;
2201
+ if (!cache[gen + finalOffset])
2202
+ cache[gen + finalOffset] = [];
2203
+ cache[gen + finalOffset].push(term);
2190
2204
  }
2191
2205
  }
2192
2206
  }
2193
2207
  }
2194
- return { total, probed, gen: depth, ...options.retain ? { cache } : {} };
2208
+ yield { found: false, step: false, gen: depth, total, probed, cache };
2195
2209
  }
2196
2210
  function isStringPair(x) {
2197
2211
  return Array.isArray(x) && x.length === 2 && typeof x[0] === "string" && typeof x[1] === "string" ? void 0 : "must be a pair of strings";