@openclaw/firecrawl-plugin 2026.9.6 → 2026.9.7

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.
Files changed (54) hide show
  1. package/assets/icon.png +0 -0
  2. package/dist/.setup/{firecrawl-client-hBjAoE8s.mjs → firecrawl-client-S2gdb9zo.mjs} +15 -23
  3. package/dist/.setup/{firecrawl-fetch-provider-DH8FdBjV.mjs → firecrawl-fetch-provider-Cq_h8okw.mjs} +1 -1
  4. package/dist/.setup/{firecrawl-search-provider-8H0Cu9l0.mjs → firecrawl-search-provider-DzEHIoq7.mjs} +1 -1
  5. package/dist/api.js +1 -1
  6. package/dist/index.js +3 -3
  7. package/dist/web-fetch-contract-api.js +1 -1
  8. package/dist/web-fetch-provider.js +1 -1
  9. package/dist/web-search-contract-api.js +1 -1
  10. package/dist/web-search-provider.js +1 -1
  11. package/node_modules/typebox/build/compile/code.mjs +1 -2
  12. package/node_modules/typebox/build/compile/validator.mjs +5 -1
  13. package/node_modules/typebox/build/format/iri.mjs +16 -9
  14. package/node_modules/typebox/build/guard/emit.mjs +2 -2
  15. package/node_modules/typebox/build/guard/guard.d.mts +7 -5
  16. package/node_modules/typebox/build/guard/guard.mjs +14 -9
  17. package/node_modules/typebox/build/guard/index.mjs +6 -0
  18. package/node_modules/typebox/build/guard/unicode/unicode.d.mts +6 -0
  19. package/node_modules/typebox/build/guard/unicode/unicode.mjs +35 -0
  20. package/node_modules/typebox/build/guard/{string.mjs → unicode/unicode_segment.mjs} +16 -19
  21. package/node_modules/typebox/build/schema/build.mjs +2 -3
  22. package/node_modules/typebox/build/schema/engine/_pathing.d.mts +1 -0
  23. package/node_modules/typebox/build/schema/engine/_pathing.mjs +11 -0
  24. package/node_modules/typebox/build/schema/engine/_refine.mjs +13 -5
  25. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +2 -1
  26. package/node_modules/typebox/build/schema/engine/dependencies.mjs +2 -1
  27. package/node_modules/typebox/build/schema/engine/dependentSchemas.mjs +2 -1
  28. package/node_modules/typebox/build/schema/engine/dynamicRef.d.mts +1 -1
  29. package/node_modules/typebox/build/schema/engine/dynamicRef.mjs +2 -2
  30. package/node_modules/typebox/build/schema/engine/format.mjs +9 -2
  31. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +3 -2
  32. package/node_modules/typebox/build/schema/engine/properties.mjs +3 -2
  33. package/node_modules/typebox/build/schema/engine/propertyNames.mjs +2 -1
  34. package/node_modules/typebox/build/schema/engine/recursiveRef.d.mts +1 -1
  35. package/node_modules/typebox/build/schema/engine/recursiveRef.mjs +2 -2
  36. package/node_modules/typebox/build/schema/engine/ref.d.mts +1 -1
  37. package/node_modules/typebox/build/schema/engine/ref.mjs +2 -2
  38. package/node_modules/typebox/build/schema/engine/schema.mjs +24 -24
  39. package/node_modules/typebox/build/schema/parse.mjs +3 -0
  40. package/node_modules/typebox/build/schema/pointer/pointer.d.mts +1 -6
  41. package/node_modules/typebox/build/schema/pointer/pointer.mjs +47 -64
  42. package/node_modules/typebox/build/system/settings/internal.d.mts +2 -0
  43. package/node_modules/typebox/build/system/settings/internal.mjs +20 -0
  44. package/node_modules/typebox/build/system/settings/settings.d.mts +11 -0
  45. package/node_modules/typebox/build/system/settings/settings.mjs +14 -0
  46. package/node_modules/typebox/build/type/extends/inference.d.mts +1 -1
  47. package/node_modules/typebox/build/type/extends/inference.mjs +15 -2
  48. package/node_modules/typebox/build/type/extends/tuple.d.mts +2 -1
  49. package/node_modules/typebox/build/type/extends/tuple.mjs +21 -1
  50. package/node_modules/typebox/build/value/parse/parse.mjs +10 -4
  51. package/node_modules/typebox/package.json +1 -1
  52. package/node_modules/typebox/readme.md +3 -1
  53. package/package.json +5 -5
  54. /package/node_modules/typebox/build/guard/{string.d.mts → unicode/unicode_segment.d.mts} +0 -0
package/assets/icon.png CHANGED
Binary file
@@ -1,11 +1,11 @@
1
1
  import { resolveSiteName } from "openclaw/plugin-sdk/provider-web-search";
2
- import { parseDateStringTimestampMs, parseFiniteNumber } from "openclaw/plugin-sdk/number-runtime";
2
+ import { asNonNegativeFiniteNumber, asPositiveFiniteNumber, parseDateStringTimestampMs, parseFiniteNumber, resolveIntegerOption } from "openclaw/plugin-sdk/number-runtime";
3
3
  import { ProviderHttpError, readProviderJsonObjectResponse } from "openclaw/plugin-sdk/provider-http";
4
4
  import { DEFAULT_CACHE_TTL_MINUTES, markdownToText, normalizeCacheKey, readCache, readResponseText, resolveCacheTtlMs, resolvePositiveTimeoutSeconds, withSelfHostedWebToolsEndpoint, withStrictWebToolsEndpoint, writeCache } from "openclaw/plugin-sdk/provider-web-fetch";
5
5
  import { normalizeSecretInput } from "openclaw/plugin-sdk/secret-input";
6
6
  import { truncateSanitizedExternalContent, wrapExternalContent, wrapWebContent } from "openclaw/plugin-sdk/security-runtime";
7
7
  import { SsrFBlockedError, isBlockedHostnameOrIp, isPrivateIpAddress, resolvePinnedHostnameWithPolicy } from "openclaw/plugin-sdk/ssrf-runtime";
8
- import { asOptionalRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
8
+ import { asOptionalObjectRecord, asOptionalRecord, asRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
9
9
  import { z } from "zod";
10
10
  import { resolveReadOnlyEnvSecretRef } from "openclaw/plugin-sdk/secret-ref-readonly";
11
11
  //#region \0rolldown/runtime.js
@@ -24,12 +24,12 @@ const DEFAULT_FIRECRAWL_SCRAPE_TIMEOUT_SECONDS = 60;
24
24
  const DEFAULT_FIRECRAWL_MAX_AGE_MS = 1728e5;
25
25
  const FIRECRAWL_API_KEY_ENV_VAR = "FIRECRAWL_API_KEY";
26
26
  function resolveFirecrawlSearchConfig(cfg) {
27
- const pluginWebSearch = (cfg?.plugins?.entries?.firecrawl?.config)?.webSearch;
28
- if (pluginWebSearch && typeof pluginWebSearch === "object" && !Array.isArray(pluginWebSearch)) return pluginWebSearch;
27
+ const pluginConfig = cfg?.plugins?.entries?.firecrawl?.config;
28
+ return asOptionalRecord(pluginConfig?.webSearch);
29
29
  }
30
30
  function resolveFirecrawlFetchConfig(cfg) {
31
- const pluginWebFetch = (cfg?.plugins?.entries?.firecrawl?.config)?.webFetch;
32
- if (pluginWebFetch && typeof pluginWebFetch === "object" && !Array.isArray(pluginWebFetch)) return pluginWebFetch;
31
+ const pluginConfig = cfg?.plugins?.entries?.firecrawl?.config;
32
+ return asOptionalRecord(pluginConfig?.webFetch);
33
33
  }
34
34
  function resolveConfiguredSecret(value, path, cfg) {
35
35
  return resolveReadOnlyEnvSecretRef({
@@ -71,10 +71,7 @@ function resolveFirecrawlOnlyMainContent(cfg, override) {
71
71
  return true;
72
72
  }
73
73
  function resolveFirecrawlMaxAgeMs(cfg, override) {
74
- if (typeof override === "number" && Number.isFinite(override) && override >= 0) return Math.floor(override);
75
- const fetch = resolveFirecrawlFetchConfig(cfg);
76
- if (typeof fetch?.maxAgeMs === "number" && Number.isFinite(fetch.maxAgeMs) && fetch.maxAgeMs >= 0) return Math.floor(fetch.maxAgeMs);
77
- return DEFAULT_FIRECRAWL_MAX_AGE_MS;
74
+ return Math.floor(asNonNegativeFiniteNumber(override) ?? asNonNegativeFiniteNumber(resolveFirecrawlFetchConfig(cfg)?.maxAgeMs) ?? DEFAULT_FIRECRAWL_MAX_AGE_MS);
78
75
  }
79
76
  function resolveFirecrawlScrapeTimeoutSeconds(cfg, override) {
80
77
  const fetch = resolveFirecrawlFetchConfig(cfg);
@@ -177,7 +174,7 @@ async function postFirecrawlJson(params, parse) {
177
174
  try {
178
175
  const body = await readResponseText(jsonResponse, { maxBytes: 64e3 });
179
176
  const payload = JSON.parse(body.text);
180
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : null;
177
+ return asOptionalRecord(payload) ?? null;
181
178
  } catch {
182
179
  return null;
183
180
  }
@@ -310,7 +307,10 @@ async function runFirecrawlSearch(params) {
310
307
  const providerId = keyless ? "firecrawl-free" : "firecrawl";
311
308
  const apiKey = keyless ? void 0 : resolveFirecrawlApiKey(params.cfg);
312
309
  if (!apiKey && !keyless) throw new Error("web_search (firecrawl) needs a Firecrawl API key. Set FIRECRAWL_API_KEY in the Gateway environment, or configure plugins.entries.firecrawl.config.webSearch.apiKey.");
313
- const count = typeof params.count === "number" && Number.isFinite(params.count) ? Math.max(1, Math.min(100, Math.floor(params.count))) : DEFAULT_SEARCH_COUNT;
310
+ const count = resolveIntegerOption(params.count, DEFAULT_SEARCH_COUNT, {
311
+ min: 1,
312
+ max: 100
313
+ });
314
314
  const timeoutSeconds = resolveFirecrawlSearchTimeoutSeconds(params.timeoutSeconds);
315
315
  const scrapeResults = params.scrapeResults === true;
316
316
  const sources = Array.isArray(params.sources) ? params.sources.filter(Boolean) : [];
@@ -384,14 +384,9 @@ async function runFirecrawlSearch(params) {
384
384
  writeCache(SEARCH_CACHE, cacheKey, result, cacheTtlMs);
385
385
  return result;
386
386
  }
387
- function resolveScrapeData(payload) {
388
- const data = payload.data;
389
- if (data && typeof data === "object") return data;
390
- return {};
391
- }
392
387
  function parseFirecrawlScrapePayload(params) {
393
- const data = resolveScrapeData(params.payload);
394
- const metadata = data.metadata && typeof data.metadata === "object" ? data.metadata : void 0;
388
+ const data = asRecord(params.payload.data);
389
+ const metadata = asOptionalObjectRecord(data.metadata);
395
390
  const rawStatus = parseFiniteNumber(metadata?.statusCode) ?? parseFiniteNumber(data.statusCode);
396
391
  const status = rawStatus === void 0 ? void 0 : Math.floor(rawStatus);
397
392
  if (status !== void 0 && (status < 200 || status >= 300)) throw new Error(`Firecrawl fetch failed (${status}): target returned an unsuccessful HTTP status.`);
@@ -446,10 +441,7 @@ async function runFirecrawlScrape(params) {
446
441
  const maxAgeMs = resolveFirecrawlMaxAgeMs(params.cfg, params.maxAgeMs);
447
442
  const proxy = params.proxy ?? "auto";
448
443
  const storeInCache = params.storeInCache ?? true;
449
- const configuredMaxCharsCap = params.cfg?.tools?.web?.fetch?.maxCharsCap;
450
- const maxCharsCap = typeof configuredMaxCharsCap === "number" && Number.isFinite(configuredMaxCharsCap) && configuredMaxCharsCap > 0 ? Math.floor(configuredMaxCharsCap) : DEFAULT_SCRAPE_MAX_CHARS;
451
- const requestedMaxChars = typeof params.maxChars === "number" && Number.isFinite(params.maxChars) && params.maxChars > 0 ? Math.floor(params.maxChars) : DEFAULT_SCRAPE_MAX_CHARS;
452
- const maxChars = Math.min(requestedMaxChars, maxCharsCap);
444
+ const maxChars = Math.floor(Math.min(asPositiveFiniteNumber(params.maxChars) ?? DEFAULT_SCRAPE_MAX_CHARS, asPositiveFiniteNumber(params.cfg?.tools?.web?.fetch?.maxCharsCap) ?? DEFAULT_SCRAPE_MAX_CHARS));
453
445
  const endpoint = await resolveEndpoint(baseUrl, "/v2/scrape");
454
446
  return parseFirecrawlScrapePayload({
455
447
  payload: await postFirecrawlJson({
@@ -51,7 +51,7 @@ const FIRECRAWL_WEB_FETCH_PROVIDER_SHARED = {
51
51
  };
52
52
  //#endregion
53
53
  //#region extensions/firecrawl/src/firecrawl-fetch-provider.ts
54
- const loadFirecrawlClientModule = createLazyRuntimeModule(() => import("./firecrawl-client-hBjAoE8s.mjs").then((n) => n.t));
54
+ const loadFirecrawlClientModule = createLazyRuntimeModule(() => import("./firecrawl-client-S2gdb9zo.mjs").then((n) => n.t));
55
55
  function createFirecrawlWebFetchProvider() {
56
56
  return {
57
57
  ...FIRECRAWL_WEB_FETCH_PROVIDER_SHARED,
@@ -4,7 +4,7 @@ import { asOptionalRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
4
4
  import { createWebSearchProviderContractFields, enablePluginInConfig } from "openclaw/plugin-sdk/provider-web-search-contract";
5
5
  //#region extensions/firecrawl/src/firecrawl-search-provider.ts
6
6
  const FIRECRAWL_CREDENTIAL_PATH = "plugins.entries.firecrawl.config.webSearch.apiKey";
7
- const loadFirecrawlClientModule = createLazyRuntimeModule(() => import("./firecrawl-client-hBjAoE8s.mjs").then((n) => n.t));
7
+ const loadFirecrawlClientModule = createLazyRuntimeModule(() => import("./firecrawl-client-S2gdb9zo.mjs").then((n) => n.t));
8
8
  const GenericFirecrawlSearchSchema = {
9
9
  type: "object",
10
10
  properties: {
package/dist/api.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as runFirecrawlScrape } from "./.setup/firecrawl-client-hBjAoE8s.mjs";
1
+ import { n as runFirecrawlScrape } from "./.setup/firecrawl-client-S2gdb9zo.mjs";
2
2
  import { readStringValue } from "openclaw/plugin-sdk/string-coerce-runtime";
3
3
  //#region extensions/firecrawl/api.ts
4
4
  async function fetchFirecrawlContent(params) {
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { n as runFirecrawlScrape, r as runFirecrawlSearch } from "./.setup/firecrawl-client-hBjAoE8s.mjs";
2
- import { t as createFirecrawlWebFetchProvider } from "./.setup/firecrawl-fetch-provider-DH8FdBjV.mjs";
3
- import { n as createFirecrawlWebSearchProvider, t as createFirecrawlFreeWebSearchProvider } from "./.setup/firecrawl-search-provider-8H0Cu9l0.mjs";
1
+ import { n as runFirecrawlScrape, r as runFirecrawlSearch } from "./.setup/firecrawl-client-S2gdb9zo.mjs";
2
+ import { t as createFirecrawlWebFetchProvider } from "./.setup/firecrawl-fetch-provider-Cq_h8okw.mjs";
3
+ import { n as createFirecrawlWebSearchProvider, t as createFirecrawlFreeWebSearchProvider } from "./.setup/firecrawl-search-provider-DzEHIoq7.mjs";
4
4
  import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
5
5
  import { optionalStringEnum } from "openclaw/plugin-sdk/channel-actions";
6
6
  import { jsonResult, readNonNegativeIntegerParam, readPositiveIntegerParam, readStringArrayParam, readStringParam } from "openclaw/plugin-sdk/provider-web-search";
@@ -1,3 +1,3 @@
1
- import { t as createFirecrawlWebFetchProvider } from "./.setup/firecrawl-fetch-provider-DH8FdBjV.mjs";
1
+ import { t as createFirecrawlWebFetchProvider } from "./.setup/firecrawl-fetch-provider-Cq_h8okw.mjs";
2
2
  import "./web-fetch-provider.js";
3
3
  export { createFirecrawlWebFetchProvider };
@@ -1,2 +1,2 @@
1
- import { t as createFirecrawlWebFetchProvider } from "./.setup/firecrawl-fetch-provider-DH8FdBjV.mjs";
1
+ import { t as createFirecrawlWebFetchProvider } from "./.setup/firecrawl-fetch-provider-Cq_h8okw.mjs";
2
2
  export { createFirecrawlWebFetchProvider };
@@ -1,3 +1,3 @@
1
- import { n as createFirecrawlWebSearchProvider, t as createFirecrawlFreeWebSearchProvider } from "./.setup/firecrawl-search-provider-8H0Cu9l0.mjs";
1
+ import { n as createFirecrawlWebSearchProvider, t as createFirecrawlFreeWebSearchProvider } from "./.setup/firecrawl-search-provider-DzEHIoq7.mjs";
2
2
  import "./web-search-provider.js";
3
3
  export { createFirecrawlFreeWebSearchProvider, createFirecrawlWebSearchProvider };
@@ -1,2 +1,2 @@
1
- import { n as createFirecrawlWebSearchProvider, t as createFirecrawlFreeWebSearchProvider } from "./.setup/firecrawl-search-provider-8H0Cu9l0.mjs";
1
+ import { n as createFirecrawlWebSearchProvider, t as createFirecrawlFreeWebSearchProvider } from "./.setup/firecrawl-search-provider-DzEHIoq7.mjs";
2
2
  export { createFirecrawlFreeWebSearchProvider, createFirecrawlWebSearchProvider };
@@ -16,9 +16,8 @@ function Separator() {
16
16
  function ImportSection(build) {
17
17
  const context = build.UseUnevaluated() ? [`import { CheckContext } from "typebox/schema"`] : [];
18
18
  const hashing = `import { Hashing } from "typebox/system"`;
19
- const format = `import { Format } from "typebox/format"`;
20
19
  const guard = `import { Guard } from "typebox/guard"`;
21
- return [...context, hashing, format, guard];
20
+ return [...context, hashing, guard];
22
21
  }
23
22
  // ------------------------------------------------------------------
24
23
  // ExternalSection
@@ -1,4 +1,5 @@
1
1
  // deno-fmt-ignore-file
2
+ import { EnableParseErrors, DisableParseErrors } from '../system/settings/internal.mjs';
2
3
  import { Settings } from '../system/settings/index.mjs';
3
4
  import { Errors, Clean, Convert, Create, Default, Decode, Encode, HasCodec, Parser, ParseError } from '../value/index.mjs';
4
5
  import { Build } from '../schema/index.mjs';
@@ -51,7 +52,10 @@ export class Validator {
51
52
  return value;
52
53
  if (Settings.Get().correctiveParse)
53
54
  return Parser(this.Context(), this.Type(), value);
54
- throw new ParseError(value, this.Errors(value));
55
+ EnableParseErrors();
56
+ const errors = this.Errors(value);
57
+ DisableParseErrors();
58
+ throw new ParseError(value, errors);
55
59
  }
56
60
  /** Returns an array of validation errors for the given value. */
57
61
  Errors(value) {
@@ -1,9 +1,10 @@
1
1
  // deno-lint-ignore-file no-control-regex
2
- const IpvFutureMatchMaxLength = 2048;
3
- const IpvFutureMatch = /\[[vV][0-9a-fA-F]+\.[^\]]+\]/; // Guarded By IpvFutureMatchMaxLength
4
- const InvalidIriChars = /[\x00-\x20<>\^`{|}\\]/;
5
- const InvalidPercentEncoding = /%(?![0-9a-fA-F]{2})/;
6
2
  // ------------------------------------------------------------------
3
+ //
4
+ // Removed by the following PR
5
+ //
6
+ // https://github.com/json-schema-org/JSON-Schema-Test-Suite/pull/1176
7
+ //
7
8
  // NarrowIpvFuture
8
9
  //
9
10
  // Substitutes an IPvFuture address with a standard IPv6 loopback
@@ -13,12 +14,18 @@ const InvalidPercentEncoding = /%(?![0-9a-fA-F]{2})/;
13
14
  // be expensive on large strings, this operation is strictly
14
15
  // limited to inputs under a defined length threshold.
15
16
  //
16
- // (review-optimization)
17
+ // ------------------------------------------------------------------
18
+ //
19
+ // const IpvFutureMatchMaxLength = 2048
20
+ // const IpvFutureMatch = /\[[vV][0-9a-fA-F]+\.[^\]]+\]/ // Guarded By IpvFutureMatchMaxLength
21
+ //
22
+ // function NarrowIpvFuture(value: string): string {
23
+ // return value.length < IpvFutureMatchMaxLength ? value.replace(IpvFutureMatch, '[::1]') : value
24
+ // }
17
25
  //
18
26
  // ------------------------------------------------------------------
19
- function NarrowIpvFuture(value) {
20
- return value.length < IpvFutureMatchMaxLength ? value.replace(IpvFutureMatch, '[::1]') : value;
21
- }
27
+ const InvalidIriChars = /[\x00-\x20<>\^`{|}\\]/;
28
+ const InvalidPercentEncoding = /%(?![0-9a-fA-F]{2})/;
22
29
  /**
23
30
  * Returns true if the value is a valid Internationalized Resource Identifier.
24
31
  * @specification https://datatracker.ietf.org/doc/html/rfc3987
@@ -31,5 +38,5 @@ export function IsIri(value) {
31
38
  if (InvalidPercentEncoding.test(value))
32
39
  return false;
33
40
  // 3. Delegate to the native URL parser, patching the IPvFuture edge case beforehand.
34
- return URL.canParse(NarrowIpvFuture(value));
41
+ return URL.canParse(value);
35
42
  }
@@ -97,10 +97,10 @@ export function IsGreaterEqualThan(left, right) {
97
97
  // String
98
98
  // --------------------------------------------------------------------------
99
99
  export function IsMinLength(value, length) {
100
- return `Guard.IsMinLength(${value}, ${length})`;
100
+ return `(${value}.length >= ${(+length) << 1} || (${value}.length >= ${length} && Guard.CodePointCount(${value}) >= ${length}))`;
101
101
  }
102
102
  export function IsMaxLength(value, length) {
103
- return `Guard.IsMaxLength(${value}, ${length})`;
103
+ return `(${value}.length <= ${length} || (${value}.length <= ${(+length) << 1} && Guard.CodePointCount(${value}) <= ${length}))`;
104
104
  }
105
105
  // --------------------------------------------------------------------------
106
106
  // Array
@@ -33,12 +33,14 @@ export declare function IsMultipleOf(dividend: bigint | number, divisor: bigint
33
33
  /** Returns true if the value appears to be an instance of a class. */
34
34
  export declare function IsClassInstance(value: unknown): boolean;
35
35
  export declare function IsValueLike(value: unknown): value is bigint | boolean | null | number | string | undefined;
36
- /** Returns the number of grapheme clusters in the string */
36
+ /** Returns the total number of visual grapheme clusters in the string. */
37
37
  export declare function GraphemeCount(value: string): number;
38
- /** Returns true if the string has at most the given number of graphemes */
39
- export declare function IsMaxLength(value: string, length: number): boolean;
40
- /** Returns true if the string has at least the given number of graphemes */
41
- export declare function IsMinLength(value: string, length: number): boolean;
38
+ /** Returns the total number of Unicode code points in the string. */
39
+ export declare function CodePointCount(value: string): number;
40
+ /** Returns true if the string length in Unicode code points does not exceed maxLength */
41
+ export declare function IsMaxLength(value: string, maxLength: number): boolean;
42
+ /** Returns true if the string length in Unicode code points is at least minLength */
43
+ export declare function IsMinLength(value: string, minLength: number): boolean;
42
44
  /** Returns true if every element from offset satisfies the callback, short-circuiting on the first failure */
43
45
  export declare function Every<T>(value: T[], offset: number, callback: (value: T, index: number) => boolean): boolean;
44
46
  /** Returns true if every element from offset satisfies the callback, using exhaustive enumeration */
@@ -1,5 +1,6 @@
1
1
  // deno-fmt-ignore-file
2
- import * as String from './string.mjs';
2
+ import * as UnicodeSegmentGuard from './unicode/unicode_segment.mjs';
3
+ import * as UnicodeGuard from './unicode/unicode.mjs';
3
4
  // --------------------------------------------------------------------------
4
5
  // Guards
5
6
  // --------------------------------------------------------------------------
@@ -123,17 +124,21 @@ export function IsValueLike(value) {
123
124
  // --------------------------------------------------------------------------
124
125
  // String
125
126
  // --------------------------------------------------------------------------
126
- /** Returns the number of grapheme clusters in the string */
127
+ /** Returns the total number of visual grapheme clusters in the string. */
127
128
  export function GraphemeCount(value) {
128
- return String.GraphemeCount(value);
129
+ return UnicodeSegmentGuard.GraphemeCount(value);
129
130
  }
130
- /** Returns true if the string has at most the given number of graphemes */
131
- export function IsMaxLength(value, length) {
132
- return String.IsMaxLength(value, length);
131
+ /** Returns the total number of Unicode code points in the string. */
132
+ export function CodePointCount(value) {
133
+ return UnicodeGuard.CodePointCount(value);
133
134
  }
134
- /** Returns true if the string has at least the given number of graphemes */
135
- export function IsMinLength(value, length) {
136
- return String.IsMinLength(value, length);
135
+ /** Returns true if the string length in Unicode code points does not exceed maxLength */
136
+ export function IsMaxLength(value, maxLength) {
137
+ return UnicodeGuard.IsMaxLength(value, maxLength);
138
+ }
139
+ /** Returns true if the string length in Unicode code points is at least minLength */
140
+ export function IsMinLength(value, minLength) {
141
+ return UnicodeGuard.IsMinLength(value, minLength);
137
142
  }
138
143
  // --------------------------------------------------------------------------
139
144
  // Array
@@ -1,6 +1,12 @@
1
+ // ------------------------------------------------------------------
2
+ // Guards
3
+ // ------------------------------------------------------------------
1
4
  export * as EmitGuard from './emit.mjs';
2
5
  export * as GlobalsGuard from './globals.mjs';
3
6
  export * as NativeGuard from './native.mjs';
7
+ // ------------------------------------------------------------------
8
+ // Default
9
+ // ------------------------------------------------------------------
4
10
  import * as Guard from './guard.mjs';
5
11
  export * as Guard from './guard.mjs';
6
12
  export default Guard;
@@ -0,0 +1,6 @@
1
+ /** Returns the total number of Unicode code points in the string */
2
+ export declare function CodePointCount(value: string): number;
3
+ /** Returns true if the string length in Unicode code points is less than or equal to maxLength */
4
+ export declare function IsMaxLength(value: string, maxLength: number): boolean;
5
+ /** Returns true if the string length in Unicode code points is greater than or equal to minLength */
6
+ export declare function IsMinLength(value: string, minLength: number): boolean;
@@ -0,0 +1,35 @@
1
+ // ------------------------------------------------------------------
2
+ // CodePointCount (10-bit Shift Branchless)
3
+ //
4
+ // Counts code points by enumerating UTF-16 sequences and incrementing
5
+ // when not within a high/low pairing. Because surrogate blocks are
6
+ // 1024 (2^10) wide and aligned, by shifting right by (0xA), we can
7
+ // collapse each unit to a constant per block (high: 0x36, low: 0x37)
8
+ // and shift again into a packed (0x3637) for comparison. Fetch calls
9
+ // to charCodeAt(...) are kept to one call per iteration.
10
+ //
11
+ // ------------------------------------------------------------------
12
+ /** Returns the total number of Unicode code points in the string */
13
+ export function CodePointCount(value) {
14
+ let result = 0, index = 0, prev = 0;
15
+ while (index < value.length) {
16
+ const next = value.charCodeAt(index++) >> 0xA; // shift (10-bits into high/low)
17
+ result += +(((prev << 8) | next) !== 0x3637); // packed (or +!(prev === 0x36 && next === 0x37))
18
+ prev = next;
19
+ }
20
+ return result;
21
+ }
22
+ // ------------------------------------------------------------------
23
+ // IsMaxLength
24
+ // ------------------------------------------------------------------
25
+ /** Returns true if the string length in Unicode code points is less than or equal to maxLength */
26
+ export function IsMaxLength(value, maxLength) {
27
+ return value.length <= maxLength || (value.length <= (maxLength << 1) && CodePointCount(value) <= maxLength);
28
+ }
29
+ // ------------------------------------------------------------------
30
+ // IsMinLength
31
+ // ------------------------------------------------------------------
32
+ /** Returns true if the string length in Unicode code points is greater than or equal to minLength */
33
+ export function IsMinLength(value, minLength) {
34
+ return value.length >= (minLength << 1) || (value.length >= minLength && CodePointCount(value) >= minLength);
35
+ }
@@ -91,26 +91,12 @@ function IsGraphemeCodePoint(value) {
91
91
  IsZeroWidthJoiner(value)));
92
92
  }
93
93
  // --------------------------------------------------------------------------
94
- // GraphemeCount
95
- // --------------------------------------------------------------------------
96
- /** Returns the number of grapheme clusters in a string */
97
- export function GraphemeCount(value) {
98
- let count = 0;
99
- let index = 0;
100
- while (index < value.length) {
101
- index = NextGraphemeClusterIndex(value, index);
102
- count++;
103
- }
104
- return count;
105
- }
106
- // --------------------------------------------------------------------------
107
94
  // IsMinLengthSegmented
108
95
  // --------------------------------------------------------------------------
109
96
  /** Checks if a string has at least a minimum number of grapheme clusters */
110
97
  function IsMinLengthSegmented(value, minLength) {
111
98
  // if (minLength === 0) return true // 0-length (unreachable)
112
- let count = 0;
113
- let index = 0;
99
+ let count = 0, index = 0;
114
100
  while (index < value.length) {
115
101
  index = NextGraphemeClusterIndex(value, index);
116
102
  if ((++count) >= minLength)
@@ -123,8 +109,7 @@ function IsMinLengthSegmented(value, minLength) {
123
109
  // --------------------------------------------------------------------------
124
110
  /** Checks if a string has at most a maximum number of grapheme clusters */
125
111
  function IsMaxLengthSegmented(value, maxLength) {
126
- let count = 0;
127
- let index = 0;
112
+ let count = 0, index = 0;
128
113
  while (index < value.length) {
129
114
  index = NextGraphemeClusterIndex(value, index);
130
115
  if ((++count) > maxLength)
@@ -133,7 +118,19 @@ function IsMaxLengthSegmented(value, maxLength) {
133
118
  return true;
134
119
  }
135
120
  // --------------------------------------------------------------------------
136
- // IsMinLengthFast
121
+ // GraphemeCount
122
+ // --------------------------------------------------------------------------
123
+ /** Returns the number of grapheme clusters in a string */
124
+ export function GraphemeCount(value) {
125
+ let count = 0, index = 0;
126
+ while (index < value.length) {
127
+ index = NextGraphemeClusterIndex(value, index);
128
+ count++;
129
+ }
130
+ return count;
131
+ }
132
+ // --------------------------------------------------------------------------
133
+ // IsMinLength
137
134
  // --------------------------------------------------------------------------
138
135
  /** Fast check for minimum grapheme length, falls back to full check if needed */
139
136
  export function IsMinLength(value, minLength) {
@@ -151,7 +148,7 @@ export function IsMinLength(value, minLength) {
151
148
  }
152
149
  }
153
150
  // --------------------------------------------------------------------------
154
- // IsMaxLengthFast
151
+ // IsMaxLength
155
152
  // --------------------------------------------------------------------------
156
153
  /** Fast check for maximum grapheme length, falls back to full check if needed */
157
154
  export function IsMaxLength(value, maxLength) {
@@ -4,7 +4,6 @@ import { Arguments } from '../system/arguments/index.mjs';
4
4
  import { Environment } from '../system/environment/index.mjs';
5
5
  import { Hashing } from '../system/hashing/index.mjs';
6
6
  import { Guard } from '../guard/index.mjs';
7
- import { Format } from '../format/index.mjs';
8
7
  import * as Engine from './engine/index.mjs';
9
8
  // ------------------------------------------------------------------
10
9
  // CreateCode
@@ -20,8 +19,8 @@ function CreateCode(build) {
20
19
  // CreateEvaluatedCheck
21
20
  // ------------------------------------------------------------------
22
21
  function CreateEvaluatedCheck(build, code) {
23
- const factory = Environment.Evaluate('CheckContext', 'Guard', 'Format', 'Hashing', build.External().identifier, code);
24
- return factory(Engine.CheckContext, Guard, Format, Hashing, build.External().variables);
22
+ const factory = Environment.Evaluate('CheckContext', 'Guard', 'Hashing', build.External().identifier, code);
23
+ return factory(Engine.CheckContext, Guard, Hashing, build.External().variables);
25
24
  }
26
25
  // ------------------------------------------------------------------
27
26
  // CreateDynamicCheck
@@ -0,0 +1 @@
1
+ export declare function EncodeFragment(fragment: string): string;
@@ -0,0 +1,11 @@
1
+ // ------------------------------------------------------------------
2
+ // EncodeFragment
3
+ //
4
+ // We use this function to encode instancePath and schemaPath path
5
+ // fragments for errors. We need this encoding such that callers
6
+ // can use Pointer to deref error targets. We should consider adding
7
+ // this to the Pointer module as Pointer.Encode(...) (review)
8
+ // ------------------------------------------------------------------
9
+ export function EncodeFragment(fragment) {
10
+ return fragment.replace(/~/g, '~0').replace(/\//g, '~1');
11
+ }
@@ -4,9 +4,18 @@ import { EmitGuard as E, Guard as G } from '../../guard/index.mjs';
4
4
  // ------------------------------------------------------------------
5
5
  // Build
6
6
  // ------------------------------------------------------------------
7
+ function BuildRefineMultiple(_stack, _context, schema, value) {
8
+ const external = Externals.CreateVariable(schema['~refine']);
9
+ return E.Every(external, E.Constant(0), ['refinement', '_'], E.Call(E.Member('refinement', 'check'), [value]));
10
+ }
11
+ function BuildRefineSingle(_stack, _context, schema, value) {
12
+ const external = Externals.CreateVariable(schema['~refine'][0]);
13
+ return E.Call(E.Member(external, 'check'), [value]);
14
+ }
7
15
  export function BuildRefine(_stack, _context, schema, value) {
8
- const refinements = Externals.CreateVariable(schema['~refine'].map((refinement) => refinement));
9
- return E.Every(refinements, E.Constant(0), ['refinement', '_'], E.Call(E.Member('refinement', 'check'), [value]));
16
+ return G.IsEqual(schema['~refine'].length, 1)
17
+ ? BuildRefineSingle(_stack, _context, schema, value)
18
+ : BuildRefineMultiple(_stack, _context, schema, value);
10
19
  }
11
20
  // ------------------------------------------------------------------
12
21
  // Check
@@ -19,8 +28,7 @@ export function CheckRefine(_stack, _context, schema, value) {
19
28
  // ------------------------------------------------------------------
20
29
  export function ErrorRefine(_stack, context, schemaPath, instancePath, schema, value) {
21
30
  return G.EveryAll(schema['~refine'], 0, (refinement, index) => {
22
- return refinement.check(value) || context.AddError('~refine', schemaPath, instancePath, {
23
- index, message: refinement.error(value)
24
- });
31
+ return refinement.check(value) ||
32
+ context.AddError('~refine', schemaPath, instancePath, { index, message: refinement.error(value) });
25
33
  });
26
34
  }
@@ -1,6 +1,7 @@
1
1
  // deno-fmt-ignore-file
2
2
  import * as Schema from '../types/index.mjs';
3
3
  import * as Externals from './_externals.mjs';
4
+ import * as Pathing from './_pathing.mjs';
4
5
  import { Unique } from './_unique.mjs';
5
6
  import { UnicodeRegExp } from './_regexp.mjs';
6
7
  import { EmitGuard as E, Guard as G } from '../../guard/index.mjs';
@@ -107,7 +108,7 @@ export function ErrorAdditionalProperties(stack, context, schemaPath, instancePa
107
108
  const additionalProperties = [];
108
109
  const isAdditionalProperties = G.EveryAll(G.Keys(value), 0, (key, _index) => {
109
110
  const nextSchemaPath = `${schemaPath}/additionalProperties`;
110
- const nextInstancePath = `${instancePath}/${key}`;
111
+ const nextInstancePath = `${instancePath}/${Pathing.EncodeFragment(key)}`;
111
112
  const isAdditionalProperty = regexp.test(key) ||
112
113
  (ErrorSchemaPushStack(stack, context, nextSchemaPath, nextInstancePath, schema.additionalProperties, value[key]) && context.AddKey(key));
113
114
  if (!isAdditionalProperty)
@@ -1,4 +1,5 @@
1
1
  // deno-fmt-ignore-file
2
+ import * as Pathing from './_pathing.mjs';
2
3
  import { EmitGuard as E, Guard as G } from '../../guard/index.mjs';
3
4
  import { BuildSchema, CheckSchema, ErrorSchema } from './schema.mjs';
4
5
  // ------------------------------------------------------------------
@@ -32,7 +33,7 @@ export function CheckDependencies(stack, context, schema, value) {
32
33
  export function ErrorDependencies(stack, context, schemaPath, instancePath, schema, value) {
33
34
  const isLength = G.IsEqual(G.Keys(value).length, 0);
34
35
  const isEvery = G.EveryAll(G.Entries(schema.dependencies), 0, ([key, schema]) => {
35
- const nextSchemaPath = `${schemaPath}/dependencies/${key}`;
36
+ const nextSchemaPath = `${schemaPath}/dependencies/${Pathing.EncodeFragment(key)}`;
36
37
  return !G.HasPropertyKey(value, key) || (G.IsArray(schema)
37
38
  ? schema.every((dependency) => G.HasPropertyKey(value, dependency) ||
38
39
  context.AddError('dependencies', schemaPath, instancePath, { property: key, dependencies: schema }))
@@ -1,4 +1,5 @@
1
1
  // deno-fmt-ignore-file
2
+ import * as Pathing from './_pathing.mjs';
2
3
  import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
3
4
  import { BuildSchema, CheckSchema, ErrorSchema } from './schema.mjs';
4
5
  // ------------------------------------------------------------------
@@ -30,7 +31,7 @@ export function CheckDependentSchemas(stack, context, schema, value) {
30
31
  export function ErrorDependentSchemas(stack, context, schemaPath, instancePath, schema, value) {
31
32
  const isLength = G.IsEqual(G.Keys(value).length, 0);
32
33
  const isEvery = G.EveryAll(G.Entries(schema.dependentSchemas), 0, ([key, schema]) => {
33
- const nextSchemaPath = `${schemaPath}/dependentSchemas/${key}`;
34
+ const nextSchemaPath = `${schemaPath}/dependentSchemas/${Pathing.EncodeFragment(key)}`;
34
35
  return !G.HasPropertyKey(value, key) ||
35
36
  ErrorSchema(stack, context, nextSchemaPath, instancePath, schema, value);
36
37
  });
@@ -3,4 +3,4 @@ import * as Stack from './_stack.mjs';
3
3
  import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
4
4
  export declare function BuildDynamicRef(stack: Stack.XStack, context: BuildContext, schema: Schema.XDynamicRef, value: string): string;
5
5
  export declare function CheckDynamicRef(stack: Stack.XStack, context: CheckContext, schema: Schema.XDynamicRef, value: unknown): boolean;
6
- export declare function ErrorDynamicRef(stack: Stack.XStack, context: ErrorContext, _schemaPath: string, instancePath: string, schema: Schema.XDynamicRef, value: unknown): boolean;
6
+ export declare function ErrorDynamicRef(stack: Stack.XStack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XDynamicRef, value: unknown): boolean;
@@ -22,8 +22,8 @@ export function CheckDynamicRef(stack, context, schema, value) {
22
22
  // ------------------------------------------------------------------
23
23
  // Error
24
24
  // ------------------------------------------------------------------
25
- export function ErrorDynamicRef(stack, context, _schemaPath, instancePath, schema, value) {
25
+ export function ErrorDynamicRef(stack, context, schemaPath, instancePath, schema, value) {
26
26
  const target = Resolve.DynamicRef(stack, schema) ?? false;
27
27
  const nextStack = target ? { ...stack, pendingResource: true } : stack;
28
- return (Schema.IsSchema(target) && ErrorSchema(nextStack, context, '#', instancePath, target, value));
28
+ return (Schema.IsSchema(target) && ErrorSchema(nextStack, context, schemaPath, instancePath, target, value));
29
29
  }
@@ -1,11 +1,18 @@
1
1
  // deno-fmt-ignore-file
2
+ import * as Externals from './_externals.mjs';
2
3
  import { Format } from '../../format/index.mjs';
3
4
  import { EmitGuard as E } from '../../guard/index.mjs';
4
5
  // ------------------------------------------------------------------
5
- // Build
6
+ // Build (Remote)
7
+ // ------------------------------------------------------------------
8
+ // export function BuildFormat(_stack: Stack.XStack, _context: BuildContext, schema: Schema.XFormat, value: string): string {
9
+ // return E.Call(E.Member('Format', 'Test'), [E.Constant(schema.format), value])
10
+ // }
11
+ // ------------------------------------------------------------------
12
+ // Build (Inline)
6
13
  // ------------------------------------------------------------------
7
14
  export function BuildFormat(_stack, _context, schema, value) {
8
- return E.Call(E.Member('Format', 'Test'), [E.Constant(schema.format), value]);
15
+ return Format.Has(schema.format) ? E.Call(Externals.CreateVariable(Format.Get(schema.format)), [value]) : E.Constant(true);
9
16
  }
10
17
  // ------------------------------------------------------------------
11
18
  // Check
@@ -1,5 +1,6 @@
1
1
  // deno-fmt-ignore-file
2
2
  import * as Externals from './_externals.mjs';
3
+ import * as Pathing from './_pathing.mjs';
3
4
  import { Unique } from './_unique.mjs';
4
5
  import { UnicodeRegExp } from './_regexp.mjs';
5
6
  import { BuildSchemaPushStack, CheckSchemaPushStack, ErrorSchemaPushStack } from './schema.mjs';
@@ -34,10 +35,10 @@ export function CheckPatternProperties(stack, context, schema, value) {
34
35
  // ------------------------------------------------------------------
35
36
  export function ErrorPatternProperties(stack, context, schemaPath, instancePath, schema, value) {
36
37
  return G.EveryAll(G.Entries(schema.patternProperties), 0, ([pattern, schema]) => {
37
- const nextSchemaPath = `${schemaPath}/patternProperties/${pattern}`;
38
+ const nextSchemaPath = `${schemaPath}/patternProperties/${Pathing.EncodeFragment(pattern)}`;
38
39
  const regexp = UnicodeRegExp(pattern);
39
40
  return G.EveryAll(G.Entries(value), 0, ([key, value]) => {
40
- const nextInstancePath = `${instancePath}/${key}`;
41
+ const nextInstancePath = `${instancePath}/${Pathing.EncodeFragment(key)}`;
41
42
  const notKey = !regexp.test(key);
42
43
  return notKey || ErrorSchemaPushStack(stack, context, nextSchemaPath, nextInstancePath, schema, value) && context.AddKey(key);
43
44
  });