import { Crypto, Data, Effect, Option, PlatformError, Result, Schema, Stream } from "effect"; //#region src/JsoncNode.d.ts /** * A single path segment: a `string` for object property keys or a `number` * for array indices. * * @public */ type JsoncSegment = string | number; /** * An ordered sequence of {@link JsoncSegment} values describing a location * within a JSONC document tree. * * @public */ type JsoncPath = ReadonlyArray; /** * Discriminator values for JSONC AST node types: the JSON value types * (`string`/`number`/`boolean`/`null`), the structural types * (`object`/`array`) and the `property` key-value pair type. * * @public */ declare const JsoncNodeType: Schema.Literals; /** * The union of all JSONC AST node type string literals. * * @public */ type JsoncNodeType = typeof JsoncNodeType.Type; declare const JsoncNode_base: Schema.Class; readonly offset: Schema.Number; readonly length: Schema.Number; readonly value: Schema.optionalKey; readonly colonOffset: Schema.optionalKey; readonly children: Schema.optionalKey>>>; }>, {}>; /** * An immutable JSONC AST node produced by `Jsonc.parseTree`. * * The `parent` field present in Microsoft's `jsonc-parser` is intentionally * omitted: circular references would break structural equality, serialization * and Schema encode/decode. Child relationships are expressed via `children`, * and the recursive type is handled with `Schema.suspend`. * * - `type` — the `JsoncNodeType` discriminator. * - `offset` / `length` — the node's span in the source (tight token-end * discipline: spans never swallow trailing whitespace or comments). * - `value` — the decoded JS value for leaf nodes; omitted for structural nodes. * - `colonOffset` — for `property` nodes, the offset of the `:` separator. * - `children` — child nodes for `object`, `array` and `property` nodes. * * Construct via `JsoncNode.make(...)`, never `new JsoncNode(...)`. * * @public */ declare class JsoncNode extends JsoncNode_base { /** * Find a descendant node by path. String segments navigate object * properties; number segments navigate array indices. Returns * `Option.none()` when any segment cannot be resolved. Pure. * * @param path - The path to resolve, relative to this node. * @returns The descendant node, or `Option.none()` when `path` cannot be * resolved. */ find(path: JsoncPath): Option.Option; /** * Find the innermost node whose span covers `offset`, or `Option.none()` * if the offset is outside this subtree. Pure. * * @param offset - The zero-based character offset to locate. * @returns The innermost covering node, or `Option.none()` when `offset` * falls outside this subtree. */ findAtOffset(offset: number): Option.Option; /** * Return the JSON path to the innermost node covering `offset`, or * `Option.none()` if the offset is outside this subtree. The inverse of * {@link JsoncNode.find}. Pure. * * @param offset - The zero-based character offset to locate. * @returns The path to the innermost covering node, or `Option.none()` * when `offset` falls outside this subtree. */ pathAt(offset: number): Option.Option; /** * Reconstruct the plain JavaScript value represented by this subtree. Pure * and total — never fails, so no `Effect` wrapper. * * @returns The plain JavaScript value (object, array, string, number, * boolean or `null`) this subtree represents. */ toValue(): unknown; } //#endregion //#region src/Jsonc.d.ts /** * The single public parse-error code vocabulary, appearing as the `code` field * of {@link JsoncParseErrorDetail}. * * @public */ declare const JsoncParseErrorCode: Schema.Literals; /** * The union of all JSONC parse-error code string literals. * * @public */ type JsoncParseErrorCode = typeof JsoncParseErrorCode.Type; declare const JsoncParseErrorDetail_base: Schema.Class; readonly offset: Schema.Number; readonly length: Schema.Number; readonly line: Schema.Number; readonly character: Schema.Number; }>, {}>; /** * One recovered parse error: its `JsoncParseErrorCode` and its exact * position (`offset`/`length`, plus zero-based `line`/`character`). A single * {@link JsoncParseError} reports a batch of these. * * @public */ declare class JsoncParseErrorDetail extends JsoncParseErrorDetail_base {} declare const JsoncParseError_base: Schema.Class; readonly input: Schema.String; }>, import("effect/Cause").YieldableError>; /** * Error-recovery parse failure: aggregates every {@link JsoncParseErrorDetail} * encountered, so a single failure reports the whole batch. Raised by * {@link Jsonc.parse}, {@link Jsonc.parseTree} and the decode direction of the * schema factories. * * @public */ declare class JsoncParseError extends JsoncParseError_base { get message(): string; } declare const JsoncParseOptions_base: Schema.Class; readonly allowTrailingComma: Schema.optionalKey; readonly allowEmptyContent: Schema.optionalKey; }>, {}>; /** * Options controlling parse behavior. All fields are omissible. * * - `disallowComments` — reject line and block comments as a parse error * instead of the JSONC default of allowing them. Defaults to `false`. * - `allowTrailingComma` — accept a trailing comma before a closing `}`/`]`. * Defaults to `true` — the deliberate JSONC-convention default, differing * from Microsoft's parser (which defaults to `false`). * - `allowEmptyContent` — treat empty or whitespace/comment-only input as * valid, yielding `Option.none()` from {@link Jsonc.parseTree} instead of a * `ValueExpected` parse error. Defaults to `false`. * * @public */ declare class JsoncParseOptions extends JsoncParseOptions_base {} /** * The public stringify-error code vocabulary, appearing as the `code` field of * {@link JsoncStringifyError}: * * - `CircularReference` — the value contains a reference cycle, so no finite * JSON text exists for it. * - `BigIntValue` — the value contains a `bigint` (anywhere, top-level or * nested), which JSON cannot represent. * - `TopLevelUnrepresentable` — the top-level value (`undefined`, a function * or a symbol) serializes to no output at all. * * @public */ declare const JsoncStringifyErrorCode: Schema.Literals; /** * The union of all JSONC stringify-error code string literals. * * @public */ type JsoncStringifyErrorCode = typeof JsoncStringifyErrorCode.Type; declare const JsoncStringifyOptions_base: Schema.Class; readonly insertSpaces: Schema.optionalKey; }>, {}>; /** * Options controlling stringify behavior. All fields are omissible; the * vocabulary matches `JsoncFormattingOptions`. * * - `tabSize` — the indent width in spaces when `insertSpaces` is `true`. * Defaults to `2`; `0` produces compact single-line output. * - `insertSpaces` — indent with spaces (`tabSize` of them) when `true`, or a * single tab character when `false`. Defaults to `true`. * * @public */ declare class JsoncStringifyOptions extends JsoncStringifyOptions_base {} declare const JsoncStringifyError_base: Schema.Class; readonly detail: Schema.String; readonly value: Schema.Unknown; }>, import("effect/Cause").YieldableError>; /** * Stringification failure: a `JsoncStringifyErrorCode` naming the * failure mode, a human-readable `detail` (the engine's message for thrown * cases — on V8 the circular-reference message includes the offending property * path), and the offending `value`. Raised by {@link Jsonc.stringify}, * {@link Jsonc.stringifyResult} and the encode direction of the schema * factories. * * @public */ declare class JsoncStringifyError extends JsoncStringifyError_base { get message(): string; } /** * A domain codec pre-bound to its two directions, returned by * {@link Jsonc.bind}: the composed `schema` (what {@link Jsonc.schema} * returns) plus `decode` and `encode` functions derived from it once, so * callers need no generic `Schema` machinery at the use site. * * @public */ interface JsoncBoundCodec { /** The composed codec decoding a JSONC `string` straight into `T`. */ readonly schema: Schema.Codec; /** Decode JSONC text into a validated `T`. */ readonly decode: (text: string) => Effect.Effect; /** Encode a `T` back to JSON text (default 2-space indent). */ readonly encode: (value: T) => Effect.Effect; } /** * Static entry points for JSONC parsing, editing-adjacent utilities and the * schema factories. Not instantiable. * * @example * ```ts * import { Jsonc } from "@effected/jsonc"; * import { Effect } from "effect"; * * const program = Effect.gen(function* () { * const value = yield* Jsonc.parse('{ "port": 3000 // dev\n }'); * return value; // { port: 3000 } * }); * ``` * * @public */ declare class Jsonc { private constructor(); /** * Parse JSONC into a plain JavaScript value, synchronously, returning a * `Result` instead of an `Effect`. Same error-recovery semantics as * {@link Jsonc.parse}: every parse error is collected and the failure side * carries one aggregate {@link JsoncParseError}. Pure — parsing is * fundamentally synchronous, so non-Effect consumers (a plain config * loader, a build script) can call this directly instead of wrapping * `Effect.runSync(Effect.result(Jsonc.parse(text)))`. * * @remarks * {@link Jsonc.parse} is defined in terms of this function; the two never * diverge. Reach for the `Effect` variant inside Effect code — it carries * the `Jsonc.parse` tracing span — and for this one at synchronous * boundaries. * * @example * ```ts * import { Jsonc } from "@effected/jsonc"; * import { Result } from "effect"; * * const ok = Jsonc.parseResult('{ "port": 3000 // dev\n }'); * if (Result.isSuccess(ok)) { * console.log(ok.success); // => { port: 3000 } * } * * const bad = Jsonc.parseResult("{ bad }"); * if (Result.isFailure(bad)) { * console.log(bad.failure._tag); // => "JsoncParseError" * } * ``` * * @param text - The JSONC source to parse. * @param options - Optional {@link JsoncParseOptions}; defaults apply for * omitted fields. * @returns A `Result` succeeding with the decoded value (`unknown`, never * `any`), or failing with the aggregate {@link JsoncParseError}. */ static parseResult(text: string, options?: JsoncParseOptions): Result.Result; /** * Parse JSONC into a plain JavaScript value. Error-recovery parsing: * collects every parse error and fails once with the aggregate * {@link JsoncParseError}. Returns `unknown`, never `any`. Defined in terms * of {@link Jsonc.parseResult} — synchronous callers can use that variant * directly. * * @param text - The JSONC source to parse. * @param options - Optional {@link JsoncParseOptions}; defaults apply for * omitted fields. * @returns An `Effect` that succeeds with the decoded value, or fails with * the aggregate {@link JsoncParseError}. */ static readonly parse: (text: string, options?: JsoncParseOptions | undefined) => Effect.Effect; /** * Parse JSONC into an immutable {@link JsoncNode} AST, synchronously, * returning a `Result` instead of an `Effect`. `Option.none()` for empty * input (with `allowEmptyContent`); the aggregate {@link JsoncParseError} * for malformed input. Pure — parsing is fundamentally synchronous, so * non-Effect consumers (a plain config loader, a build script) can call * this directly instead of wrapping * `Effect.runSync(Effect.result(Jsonc.parseTree(text)))`. * * @remarks * {@link Jsonc.parseTree} is defined in terms of this function; the two * never diverge. Reach for the `Effect` variant inside Effect code — it * carries the `Jsonc.parseTree` tracing span — and for this one at * synchronous boundaries. * * @example * ```ts * import { Jsonc } from "@effected/jsonc"; * import { Option, Result } from "effect"; * * const ok = Jsonc.parseTreeResult('{ "port": 3000 // dev\n }'); * if (Result.isSuccess(ok) && Option.isSome(ok.success)) { * console.log(ok.success.value.type); // => "object" * } * * const bad = Jsonc.parseTreeResult("{ bad }"); * if (Result.isFailure(bad)) { * console.log(bad.failure._tag); // => "JsoncParseError" * } * ``` * * @param text - The JSONC source to parse. * @param options - Optional {@link JsoncParseOptions}; defaults apply for * omitted fields. * @returns A `Result` succeeding with `Option.some(root)` (or * `Option.none()` for empty input), or failing with the aggregate * {@link JsoncParseError}. */ static parseTreeResult(text: string, options?: JsoncParseOptions): Result.Result, JsoncParseError>; /** * Parse JSONC into an immutable {@link JsoncNode} AST. `Option.none()` for * empty input (with `allowEmptyContent`); the aggregate * {@link JsoncParseError} for malformed input. Defined in terms of * {@link Jsonc.parseTreeResult} — synchronous callers can use that variant * directly. * * @param text - The JSONC source to parse. * @param options - Optional {@link JsoncParseOptions}; defaults apply for * omitted fields. * @returns An `Effect` that succeeds with `Option.some(root)` (or * `Option.none()` for empty input), or fails with the aggregate * {@link JsoncParseError}. */ static readonly parseTree: (text: string, options?: JsoncParseOptions | undefined) => Effect.Effect, JsoncParseError, never>; /** * Stringify a plain JavaScript value as JSON text, synchronously, returning * a `Result` instead of an `Effect`. With no options the output is * byte-identical to `JSON.stringify(value, null, 2)`. * * Plain JSON emission: JSONC comments exist only in the document/edit layer * (`JsoncNode`, `JsoncEdit`, `JsoncFormatter`), so no comment survives — or * can be produced by — value-level stringification. * * Nested unrepresentable values follow `JSON.stringify`'s documented * semantics: `undefined`, functions and symbols are dropped from objects and * become `null` in arrays. The typed failure channel covers only the cases * where output would be absent or an exception thrown — see * `JsoncStringifyErrorCode`. A throwing `toJSON` method or getter is * caller code failing and rethrows as a defect, never a typed error. * * @remarks * {@link Jsonc.stringify} is defined in terms of this function; the two * never diverge. Reach for the `Effect` variant inside Effect code — it * carries the `Jsonc.stringify` tracing span — and for this one at * synchronous boundaries. * * @example * ```ts * import { Jsonc } from "@effected/jsonc"; * import { Result } from "effect"; * * const ok = Jsonc.stringifyResult({ port: 3000 }); * if (Result.isSuccess(ok)) { * console.log(ok.success); // => '{\n "port": 3000\n}' * } * * const bad = Jsonc.stringifyResult(0n); * if (Result.isFailure(bad)) { * console.log(bad.failure.code); // => "BigIntValue" * } * ``` * * @param value - The plain JavaScript value to stringify. * @param options - Optional {@link JsoncStringifyOptions}; defaults apply * for omitted fields. * @returns A `Result` succeeding with the JSON text, or failing with a * {@link JsoncStringifyError}. */ static stringifyResult(value: unknown, options?: JsoncStringifyOptions): Result.Result; /** * Stringify a plain JavaScript value as JSON text. With no options the * output is byte-identical to `JSON.stringify(value, null, 2)`. Fails with * {@link JsoncStringifyError} on circular references, `bigint` values and a * top-level value with no JSON representation; nested `undefined`, functions * and symbols follow `JSON.stringify`'s documented semantics (dropped from * objects, `null` in arrays). Comments are a document/edit-layer concern — * value-level stringification never emits them. Defined in terms of * {@link Jsonc.stringifyResult} — synchronous callers can use that variant * directly. * * @param value - The plain JavaScript value to stringify. * @param options - Optional {@link JsoncStringifyOptions}; defaults apply * for omitted fields. * @returns An `Effect` that succeeds with the JSON text, or fails with a * {@link JsoncStringifyError}. */ static readonly stringify: (value: unknown, options?: JsoncStringifyOptions | undefined) => Effect.Effect; /** * Remove all comments from JSONC, producing valid JSON. Pass a `replaceCh` * (e.g. `" "`) to replace each comment character instead of deleting it, * keeping all offsets stable (line breaks inside block comments are kept). * Pure and total. * * @param text - The JSONC source to strip. * @param replaceCh - Optional single character replacing each stripped * comment character (offset-preserving); when omitted, comments are * deleted outright and offsets shift. * @returns The comment-free text. */ static stripComments(text: string, replaceCh?: string): string; /** * Compare two JSONC strings for semantic equality: comments, whitespace, * formatting and object key order are ignored; array order is significant. * Malformed input is never equal to anything — parse errors on either side * yield `false` rather than comparing recovery-parser artifacts. Pure and * total. * * @param a - The first JSONC source. * @param b - The second JSONC source. * @returns `true` when `a` and `b` decode to structurally equal values. */ static equals(a: string, b: string): boolean; /** * Compare a JSONC string against an existing JavaScript value with the same * semantics as {@link Jsonc.equals}: malformed `text` yields `false`. Pure * and total. * * @param text - The JSONC source to decode and compare. * @param value - The plain JavaScript value to compare against. * @returns `true` when `text` decodes to a value structurally equal to * `value`. */ static equalsValue(text: string, value: unknown): boolean; /** * A `Schema` decoding JSONC with the given `options` * (defaults when omitted). Encoding is {@link Jsonc.stringifyResult} with * default options (2-space indent, byte-identical to * `JSON.stringify(value, null, 2)`), so comments do not survive a * round-trip encode; a {@link JsoncStringifyError} on the encode side * surfaces as a schema issue. * * @remarks * Schema-producing: each call returns a fresh schema whose derivation caches * are not shared across calls. Bind the result to a `const` on hot paths; * for the default-options case use {@link Jsonc.JsoncFromString}. * * @param options - Optional {@link JsoncParseOptions} controlling the * decode direction. * @returns A codec decoding JSONC `string` to `unknown`, failing the decode * direction with the aggregate {@link JsoncParseError} wrapped as a * schema issue. */ static fromString(options?: JsoncParseOptions): Schema.Codec; /** * The zero-config `Schema` — `Jsonc.fromString()` with * default options, pre-bound so the common case needs no memoization * discipline. */ static readonly JsoncFromString: Schema.Codec; /** * Compose {@link Jsonc.fromString} with a target schema, yielding a * `Schema` that decodes JSONC straight into a validated domain * value — the reason an Effect-native JSONC library exists. * * @remarks * Schema-producing: bind the result to a `const` on hot paths (see * {@link Jsonc.fromString}). * * @param target - The domain schema decoded values must satisfy. * @param options - Optional {@link JsoncParseOptions} controlling the JSONC * decode step. * @returns A codec decoding a JSONC `string` straight into `T`. */ static schema(target: Schema.Codec, options?: JsoncParseOptions): Schema.Codec; /** * Bind a target schema to the JSONC codec once, yielding the composed * schema plus pre-derived `decode`/`encode` directions — the * {@link Jsonc.schema} composition without the generic `Schema` machinery * at every use site. Binds the plain form only: default * {@link JsoncParseOptions} on decode, default stringify options on encode. * * Both directions fail with `Schema.SchemaError`, exactly as * `Schema.decodeEffect`/`Schema.encodeEffect` over {@link Jsonc.schema} * would; the target's decoding/encoding service requirements flow through. * * @remarks * Schema-producing: each call composes a fresh schema and derives both * directions from it. Bind the result to a `const` — that single binding is * the point. * * @example * ```ts * import { Jsonc } from "@effected/jsonc"; * import { Effect, Schema } from "effect"; * * const Config = Schema.Struct({ port: Schema.Number }); * const config = Jsonc.bind(Config); * * const program = Effect.gen(function* () { * const value = yield* config.decode('{ "port": 3000 // dev\n }'); * const text = yield* config.encode(value); * return [value, text] as const; * }); * ``` * * @param target - The domain schema decoded values must satisfy. * @returns A {@link JsoncBoundCodec} carrying the composed schema and its * two pre-bound directions. */ static bind(target: Schema.Codec): JsoncBoundCodec; } //#endregion //#region src/JsoncEdit.d.ts declare const JsoncRange_base: Schema.Class, {}>; /** * A range within a JSONC document, expressed as a zero-based character * `offset` and a `length` in UTF-16 code units. Pass to `JsoncFormatter.format` * to restrict formatting to a region. * * @public */ declare class JsoncRange extends JsoncRange_base {} declare const JsoncFormattingOptions_base: Schema.Class; readonly insertSpaces: Schema.optionalKey; readonly eol: Schema.optionalKey; readonly insertFinalNewline: Schema.optionalKey; readonly keepLines: Schema.optionalKey; }>, {}>; /** * Options controlling JSONC formatting. All fields are omissible. * * - `tabSize` — the indent width in columns when `insertSpaces` is `true`. * Defaults to `2`. * - `insertSpaces` — indent with spaces (`tabSize` of them) when `true`, or a * single tab character when `false`. Defaults to `true`. * - `eol` — the line-ending string inserted between formatted tokens. * Defaults to `"\n"`. * - `insertFinalNewline` — append `eol` at the end of the document if it * doesn't already end with one. Defaults to `false`. * - `keepLines` — preserve existing line breaks (including blank lines) * between tokens instead of collapsing each gap to the canonical single * `eol`. Defaults to `false`. * * @public */ declare class JsoncFormattingOptions extends JsoncFormattingOptions_base {} /** * Formatting options accepted at call sites: either a * {@link JsoncFormattingOptions} instance or a plain literal with the same * fields (the two are structurally interchangeable — only the option fields * are read). Mirrors the `YamlRangeLike` posture in `@effected/yaml`, so a * caller can pass `{ insertSpaces: false, tabSize: 2 }` without constructing * the class. `JsoncFormattingOptions` remains the canonical decoded form. * * @public */ type JsoncFormattingOptionsLike = JsoncFormattingOptions | { readonly tabSize?: number; readonly insertSpaces?: boolean; readonly eol?: string; readonly insertFinalNewline?: boolean; readonly keepLines?: boolean; }; declare const JsoncEdit_base: Schema.Class, {}>; /** * A non-mutating text edit: replace the span `[offset, offset + length)` with * `content`. Set `length` to `0` to insert, `content` to `""` to delete. * * @public */ declare class JsoncEdit extends JsoncEdit_base { /** * Apply `edits` to `text`, producing a new string. Edits are applied in * reverse-offset order so earlier offsets stay valid; the input `edits` * array is not mutated. Overlapping edits are a programmer error and throw * as a defect — `JsoncFormatter` never produces them. * * @param text - The source text to edit. * @param edits - The edits to apply, in any order. * @returns The edited text. */ static applyAll(text: string, edits: ReadonlyArray): string; } //#endregion //#region src/JsoncFingerprint.d.ts /** * The public canonicalize-error code vocabulary, appearing as the `code` field * of {@link JsoncCanonicalizeError}: * * - `UnrepresentableValue` — an `undefined`, function or symbol anywhere in * the value. Unlike `Jsonc.stringify` (which follows `JSON.stringify`'s * drop/null semantics for nested cases), canonicalization refuses to alter * the document, so these fail typed at any position. Array holes read as * `undefined` and fail here too, carrying the hole's index in `path`. A * property getter that throws during the read also fails here, at the * member's path — a benign getter's value canonicalizes normally, matching * `JSON.stringify`'s accessor semantics. * - `BigIntValue` — a `bigint` (anywhere), which JSON cannot represent. * - `NonFiniteNumber` — `NaN`, `Infinity` or `-Infinity`, which RFC 8785 * forbids (`JSON.stringify` would silently rewrite them to `null`). * - `LoneSurrogate` — a string value or object member key containing an * unpaired UTF-16 surrogate. RFC 8785 requires I-JSON (RFC 7493) input, * which malformed Unicode is not (`JSON.stringify` would silently emit a * `\udxxx` escape). * - `NonPlainObject` — an object that is neither an array nor a plain object * (a `Date`, `Map`, class instance, …). `toJSON` methods are deliberately * ignored; encode domain values to plain JSON (e.g. via `Schema`) first. * - `NestingDepthExceeded` — the value nests deeper than the package * hardening cap, which also intercepts cyclic values before they can * recurse forever. * * @public */ declare const JsoncCanonicalizeErrorCode: Schema.Literals; /** * The union of all canonicalize-error code string literals. * * @public */ type JsoncCanonicalizeErrorCode = typeof JsoncCanonicalizeErrorCode.Type; declare const JsoncCanonicalizeError_base: Schema.Class; readonly path: Schema.String; readonly detail: Schema.String; }>, import("effect/Cause").YieldableError>; /** * Canonicalization failure: a `JsoncCanonicalizeErrorCode` naming the * failure mode, the JSON-pointer `path` to the offending value (`""` is the * document root) and a human-readable `detail`. Raised by * {@link JsoncFingerprint.canonicalize}, * {@link JsoncFingerprint.canonicalizeResult} and * {@link JsoncFingerprint.hash}. * * @public */ declare class JsoncCanonicalizeError extends JsoncCanonicalizeError_base { get message(): string; } declare const JsoncTextHashOptions_base: Schema.Class; }>, {}>; /** * Options controlling {@link JsoncFingerprint.hashText}. All fields are * omissible. * * - `normalizeEol` — normalize `\r\n` and bare `\r` line endings to `\n` * before hashing, so the same file content fingerprints identically across * checkout line-ending settings. Defaults to `false` — by default the bytes * hashed are exactly the UTF-8 encoding of the text given. * * @public */ declare class JsoncTextHashOptions extends JsoncTextHashOptions_base {} /** * Static entry points for canonical JSON serialization (RFC 8785, the JSON * Canonicalization Scheme) and SHA-256 content fingerprints. Not instantiable. * * Canonicalization is pure; the two hashing statics require core's * `Crypto.Crypto` service in `R` and own no backend — provide * `@effect/platform-node`'s `NodeCrypto.layer` (or any `Crypto` layer, e.g. * one built with `Crypto.make` over WebCrypto) at the application edge. * * @example * ```ts * import { JsoncFingerprint } from "@effected/jsonc"; * import { Effect } from "effect"; * * const program = Effect.gen(function* () { * // Key order never matters: both values fingerprint identically. * const a = yield* JsoncFingerprint.hash({ b: 2, a: 1 }); * const b = yield* JsoncFingerprint.hash({ a: 1, b: 2 }); * return a === b; // true * }); * // Provide a Crypto layer at the edge, e.g. NodeCrypto.layer from * // "@effect/platform-node". * ``` * * @public */ declare class JsoncFingerprint { private constructor(); /** * Serialize a JSON value to its RFC 8785 canonical text, synchronously, * returning a `Result` instead of an `Effect`: compact output (no * whitespace), object keys sorted lexicographically by UTF-16 code units, * ECMAScript number serialization and `JSON.stringify` string escaping. * Equal JSON values canonicalize to equal strings. * * Unlike {@link Jsonc.stringify} — which follows `JSON.stringify`'s * documented drop/null semantics for nested unrepresentables — every * non-JSON value fails typed here, carrying the JSON-pointer path to fix: * a fingerprint of a silently altered document would be a lie. * * @remarks * {@link JsoncFingerprint.canonicalize} is defined in terms of this * function; the two never diverge. Reach for the `Effect` variant inside * Effect code — it carries the `JsoncFingerprint.canonicalize` tracing * span — and for this one at synchronous boundaries. * * @example * ```ts * import { JsoncFingerprint } from "@effected/jsonc"; * import { Result } from "effect"; * * const ok = JsoncFingerprint.canonicalizeResult({ b: 2, a: 1 }); * if (Result.isSuccess(ok)) { * console.log(ok.success); // => '{"a":1,"b":2}' * } * * const bad = JsoncFingerprint.canonicalizeResult({ a: { b: undefined } }); * if (Result.isFailure(bad)) { * console.log(bad.failure.code); // => "UnrepresentableValue" * console.log(bad.failure.path); // => "/a/b" * } * ``` * * @param value - The plain JSON value (`null`, booleans, finite numbers, * strings, arrays, plain objects) to serialize. * @returns A `Result` succeeding with the canonical JSON text, or failing * with a {@link JsoncCanonicalizeError}. */ static canonicalizeResult(value: unknown): Result.Result; /** * Serialize a JSON value to its RFC 8785 canonical text. Fails with * {@link JsoncCanonicalizeError} on any non-JSON value (`undefined`, * functions, symbols, `bigint`, non-finite numbers, strings or member keys * with unpaired surrogates, non-plain objects) and * on nesting past the hardening cap (which also intercepts cycles). * Defined in terms of {@link JsoncFingerprint.canonicalizeResult} — * synchronous callers can use that variant directly. * * @param value - The plain JSON value to serialize. * @returns An `Effect` that succeeds with the canonical JSON text, or * fails with a {@link JsoncCanonicalizeError}. */ static readonly canonicalize: (value: unknown) => Effect.Effect; /** * Normalize line endings for hashing: `\r\n` and bare `\r` become `\n`. * Pure and total — exactly the normalization * {@link JsoncFingerprint.hashText} applies when its `normalizeEol` option * is set, exposed so split/inspect flows can share it. * * @param text - The text to normalize. * @returns The text with all line endings as `\n`. */ static normalizeEol(text: string): string; /** * The content fingerprint of a JSON value: the lowercase-hex SHA-256 of * the UTF-8 bytes of its RFC 8785 canonical serialization. Values that * differ only in object key order fingerprint identically; any non-JSON * value fails with the same typed errors as * {@link JsoncFingerprint.canonicalize}. * * Requires core's `Crypto.Crypto` service — provide * `@effect/platform-node`'s `NodeCrypto.layer` (or any `Crypto` layer) at * the application edge. The digest itself can fail with the platform's * `PlatformError`, passed through untranslated. * * The output format is a guarantee: exactly 64 lowercase hexadecimal * characters, with no `sha256:` (or other) algorithm prefix — the digest * vocabulary `@effected/sbom`'s `Sha256Digest` schema decodes, so * fingerprints flow into attestation subjects downstream without this * package taking any edge on `sbom`. * * @param value - The plain JSON value to fingerprint. * @returns An `Effect` requiring `Crypto.Crypto` that succeeds with the * 64-character lowercase-hex SHA-256, or fails with a * {@link JsoncCanonicalizeError} (or the platform's `PlatformError`). */ static readonly hash: (value: unknown) => Effect.Effect; /** * The content fingerprint of raw text: the lowercase-hex SHA-256 of its * UTF-8 bytes, with opt-in line-ending normalization (`\r\n`/`\r` → `\n`) * for file content that must fingerprint identically across checkout * line-ending settings. * * Requires core's `Crypto.Crypto` service — provide * `@effect/platform-node`'s `NodeCrypto.layer` (or any `Crypto` layer) at * the application edge. * * The output format is a guarantee: exactly 64 lowercase hexadecimal * characters, with no `sha256:` (or other) algorithm prefix — the digest * vocabulary `@effected/sbom`'s `Sha256Digest` schema decodes, so * fingerprints flow into attestation subjects downstream without this * package taking any edge on `sbom`. * * @example * ```ts * import { JsoncFingerprint, JsoncTextHashOptions } from "@effected/jsonc"; * import { Effect } from "effect"; * * const program = Effect.gen(function* () { * const options = JsoncTextHashOptions.make({ normalizeEol: true }); * const a = yield* JsoncFingerprint.hashText("line one\r\nline two", options); * const b = yield* JsoncFingerprint.hashText("line one\nline two", options); * return a === b; // true * }); * ``` * * @param text - The text content to fingerprint. * @param options - Optional {@link JsoncTextHashOptions}; defaults apply * for omitted fields. * @returns An `Effect` requiring `Crypto.Crypto` that succeeds with the * 64-character lowercase-hex SHA-256, or fails with the platform's * `PlatformError` if the digest itself fails. */ static readonly hashText: (text: string, options?: JsoncTextHashOptions | undefined) => Effect.Effect; } //#endregion //#region src/JsoncFormatter.d.ts /** * Pure JSONC formatting statics. Not instantiable. * * @public */ declare class JsoncFormatter { private constructor(); /** * Compute formatting edits for a JSONC document. Non-mutating — apply the * result with `JsoncEdit.applyAll`. Pure and total. * * @param text - The JSONC source to format. * @param range - Optional sub-range; only edits within it are returned. * @param options - Optional {@link JsoncFormattingOptions}; absent fields use * defaults (tabSize 2, spaces, `"\n"`, no final newline, reflow). * @returns The edits that bring `text` (or `range`) to canonical shape; * apply them with `JsoncEdit.applyAll`. */ static format(text: string, range?: JsoncRange, options?: JsoncFormattingOptions): ReadonlyArray; /** * Format `text` and apply the resulting edits in one step * (`applyAll ∘ format`). The sole surviving convenience from v3's * `formatAndApply`. Pure and total. * * @param text - The JSONC source to format. * @param range - Optional sub-range; only edits within it are applied. * @param options - Optional {@link JsoncFormattingOptions}; see * {@link JsoncFormatter.format} for defaults. * @returns The formatted text. */ static formatToString(text: string, range?: JsoncRange, options?: JsoncFormattingOptions): string; } //#endregion //#region src/JsoncModifier.d.ts declare const JsoncModificationError_base: Schema.Class>; readonly expected: Schema.Literals; readonly depth: Schema.Number; readonly offset: Schema.optionalKey; }>, import("effect/Cause").YieldableError>; /** * Raised when `JsoncModifier.modify` cannot navigate the requested path: the * value at `depth` is not the container kind (`expected`) the next path segment * requires. * * - `path` — the full path that was passed to `JsoncModifier.modify`. * - `expected` — the container kind (`"object"` or `"array"`) the segment at * `depth` required. * - `depth` — the 1-based index into `path` where navigation failed. * - `offset` — reserved for a future source-position annotation; currently * always omitted (navigation reports the mismatch structurally, without a * text offset). * * @remarks * Follows the structure-preserving-errors house rule — the mismatch's * discriminating data is carried as typed fields (`path`, `expected`, `depth`, * optional `offset`), not collapsed into a `reason: string`. This mirrors * `YamlModificationError`'s posture (its fields differ because the underlying * failures differ; the jsonc/yaml parity convention binds `Edit`/`Range`/`Path`, * not this error). * * @public */ declare class JsoncModificationError extends JsoncModificationError_base { get message(): string; } /** * Options for `JsoncModifier.modify`: formatting controls for generated text. * * @public */ interface JsoncModifyOptions { /** * Formatting applied to inserted/replaced content (indentation, EOL, * spacing). Accepts a `JsoncFormattingOptions` instance or a plain literal * (e.g. `{ insertSpaces: false, tabSize: 2 }`) — see * {@link JsoncFormattingOptionsLike}. */ readonly formattingOptions?: JsoncFormattingOptionsLike; } /** * Structural JSONC modification statics. Not instantiable. * * @public */ declare class JsoncModifier { private constructor(); /** * Compute the edits that set, replace or delete `value` at `path` in `text`. * * Passing `value === undefined` deletes the target property or element * (including its surrounding comma). A missing insertion target appends after * the last property/element. Fails with {@link JsoncModificationError} on a * structural mismatch. * * @param text - The JSONC source to modify. * @param path - The location to set, replace or delete; `[]` replaces the * whole document. * @param value - The plain JavaScript value to write, serialized with * `JSON.stringify`; `undefined` deletes the target instead. * @param options - Optional {@link JsoncModifyOptions} controlling * formatting of generated content. * @returns An `Effect` that succeeds with the edits to apply (via * `JsoncEdit.applyAll`), or fails with {@link JsoncModificationError} when * `path` cannot be navigated. */ static readonly modify: (text: string, path: JsoncPath, value: unknown, options?: JsoncModifyOptions | undefined) => Effect.Effect; } //#endregion //#region src/JsoncVisitor.d.ts /** * The discriminated union of JSONC visitor events. Every variant carries * `offset` and `length`; `ObjectBegin`, `ArrayBegin`, `ObjectProperty` and * `LiteralValue` also carry `path` context (the location being entered). * * - `ObjectBegin` / `ObjectEnd` — an object's opening `{` / closing `}`. * - `ObjectProperty` — an object key, ahead of its value; `property` is the * key string. * - `ArrayBegin` / `ArrayEnd` — an array's opening `[` / closing `]`. * - `LiteralValue` — a scalar value (`string`/`number`/`boolean`/`null`); * `value` is the decoded JS value. * - `Separator` — a `,` or `:` token; `character` is which one. * - `Comment` — a line or block comment span. * - `Error` — a recovered parse error; `code` is its `JsoncParseErrorCode`. * * @public */ type JsoncVisitorEvent = Data.TaggedEnum<{ ObjectBegin: { readonly offset: number; readonly length: number; readonly path: JsoncPath; }; ObjectEnd: { readonly offset: number; readonly length: number; }; ObjectProperty: { readonly property: string; readonly offset: number; readonly length: number; readonly path: JsoncPath; }; ArrayBegin: { readonly offset: number; readonly length: number; readonly path: JsoncPath; }; ArrayEnd: { readonly offset: number; readonly length: number; }; LiteralValue: { readonly value: unknown; readonly offset: number; readonly length: number; readonly path: JsoncPath; }; Separator: { readonly character: string; readonly offset: number; readonly length: number; }; Comment: { readonly offset: number; readonly length: number; }; Error: { readonly code: JsoncParseErrorCode; readonly offset: number; readonly length: number; }; }>; /** * Constructors and matchers for the `JsoncVisitorEvent` union (e.g. * `JsoncVisitorEvent.ObjectBegin({ offset, length, path })`, * `JsoncVisitorEvent.$is("LiteralValue")`). * * @public */ declare const JsoncVisitorEvent: { readonly $is: (tag: Tag) => (u: unknown) => u is Extract<{ readonly _tag: "ArrayBegin"; readonly offset: number; readonly length: number; readonly path: JsoncPath; }, { readonly _tag: Tag; }> | Extract<{ readonly _tag: "ArrayEnd"; readonly offset: number; readonly length: number; }, { readonly _tag: Tag; }> | Extract<{ readonly _tag: "Comment"; readonly offset: number; readonly length: number; }, { readonly _tag: Tag; }> | Extract<{ readonly _tag: "Error"; readonly code: JsoncParseErrorCode; readonly offset: number; readonly length: number; }, { readonly _tag: Tag; }> | Extract<{ readonly _tag: "LiteralValue"; readonly value: unknown; readonly offset: number; readonly length: number; readonly path: JsoncPath; }, { readonly _tag: Tag; }> | Extract<{ readonly _tag: "ObjectBegin"; readonly offset: number; readonly length: number; readonly path: JsoncPath; }, { readonly _tag: Tag; }> | Extract<{ readonly _tag: "ObjectEnd"; readonly offset: number; readonly length: number; }, { readonly _tag: Tag; }> | Extract<{ readonly _tag: "ObjectProperty"; readonly property: string; readonly offset: number; readonly length: number; readonly path: JsoncPath; }, { readonly _tag: Tag; }> | Extract<{ readonly _tag: "Separator"; readonly character: string; readonly offset: number; readonly length: number; }, { readonly _tag: Tag; }>; readonly $match: { any; readonly ArrayEnd: (args: { readonly _tag: "ArrayEnd"; readonly offset: number; readonly length: number; }) => any; readonly Comment: (args: { readonly _tag: "Comment"; readonly offset: number; readonly length: number; }) => any; readonly Error: (args: { readonly _tag: "Error"; readonly code: JsoncParseErrorCode; readonly offset: number; readonly length: number; }) => any; readonly LiteralValue: (args: { readonly _tag: "LiteralValue"; readonly value: unknown; readonly offset: number; readonly length: number; readonly path: JsoncPath; }) => any; readonly ObjectBegin: (args: { readonly _tag: "ObjectBegin"; readonly offset: number; readonly length: number; readonly path: JsoncPath; }) => any; readonly ObjectEnd: (args: { readonly _tag: "ObjectEnd"; readonly offset: number; readonly length: number; }) => any; readonly ObjectProperty: (args: { readonly _tag: "ObjectProperty"; readonly property: string; readonly offset: number; readonly length: number; readonly path: JsoncPath; }) => any; readonly Separator: (args: { readonly _tag: "Separator"; readonly character: string; readonly offset: number; readonly length: number; }) => any; }>(cases: Cases): (value: { readonly _tag: "ArrayBegin"; readonly offset: number; readonly length: number; readonly path: JsoncPath; } | { readonly _tag: "ArrayEnd"; readonly offset: number; readonly length: number; } | { readonly _tag: "Comment"; readonly offset: number; readonly length: number; } | { readonly _tag: "Error"; readonly code: JsoncParseErrorCode; readonly offset: number; readonly length: number; } | { readonly _tag: "LiteralValue"; readonly value: unknown; readonly offset: number; readonly length: number; readonly path: JsoncPath; } | { readonly _tag: "ObjectBegin"; readonly offset: number; readonly length: number; readonly path: JsoncPath; } | { readonly _tag: "ObjectEnd"; readonly offset: number; readonly length: number; } | { readonly _tag: "ObjectProperty"; readonly property: string; readonly offset: number; readonly length: number; readonly path: JsoncPath; } | { readonly _tag: "Separator"; readonly character: string; readonly offset: number; readonly length: number; }) => import("effect/Unify").Unify>; any; readonly ArrayEnd: (args: { readonly _tag: "ArrayEnd"; readonly offset: number; readonly length: number; }) => any; readonly Comment: (args: { readonly _tag: "Comment"; readonly offset: number; readonly length: number; }) => any; readonly Error: (args: { readonly _tag: "Error"; readonly code: JsoncParseErrorCode; readonly offset: number; readonly length: number; }) => any; readonly LiteralValue: (args: { readonly _tag: "LiteralValue"; readonly value: unknown; readonly offset: number; readonly length: number; readonly path: JsoncPath; }) => any; readonly ObjectBegin: (args: { readonly _tag: "ObjectBegin"; readonly offset: number; readonly length: number; readonly path: JsoncPath; }) => any; readonly ObjectEnd: (args: { readonly _tag: "ObjectEnd"; readonly offset: number; readonly length: number; }) => any; readonly ObjectProperty: (args: { readonly _tag: "ObjectProperty"; readonly property: string; readonly offset: number; readonly length: number; readonly path: JsoncPath; }) => any; readonly Separator: (args: { readonly _tag: "Separator"; readonly character: string; readonly offset: number; readonly length: number; }) => any; }>(value: { readonly _tag: "ArrayBegin"; readonly offset: number; readonly length: number; readonly path: JsoncPath; } | { readonly _tag: "ArrayEnd"; readonly offset: number; readonly length: number; } | { readonly _tag: "Comment"; readonly offset: number; readonly length: number; } | { readonly _tag: "Error"; readonly code: JsoncParseErrorCode; readonly offset: number; readonly length: number; } | { readonly _tag: "LiteralValue"; readonly value: unknown; readonly offset: number; readonly length: number; readonly path: JsoncPath; } | { readonly _tag: "ObjectBegin"; readonly offset: number; readonly length: number; readonly path: JsoncPath; } | { readonly _tag: "ObjectEnd"; readonly offset: number; readonly length: number; } | { readonly _tag: "ObjectProperty"; readonly property: string; readonly offset: number; readonly length: number; readonly path: JsoncPath; } | { readonly _tag: "Separator"; readonly character: string; readonly offset: number; readonly length: number; }, cases: Cases): import("effect/Unify").Unify>; }; readonly ArrayBegin: Data.TaggedEnum.ConstructorFrom<{ readonly _tag: "ArrayBegin"; readonly offset: number; readonly length: number; readonly path: JsoncPath; }, "_tag">; readonly ArrayEnd: Data.TaggedEnum.ConstructorFrom<{ readonly _tag: "ArrayEnd"; readonly offset: number; readonly length: number; }, "_tag">; readonly Comment: Data.TaggedEnum.ConstructorFrom<{ readonly _tag: "Comment"; readonly offset: number; readonly length: number; }, "_tag">; readonly Error: Data.TaggedEnum.ConstructorFrom<{ readonly _tag: "Error"; readonly code: JsoncParseErrorCode; readonly offset: number; readonly length: number; }, "_tag">; readonly LiteralValue: Data.TaggedEnum.ConstructorFrom<{ readonly _tag: "LiteralValue"; readonly value: unknown; readonly offset: number; readonly length: number; readonly path: JsoncPath; }, "_tag">; readonly ObjectBegin: Data.TaggedEnum.ConstructorFrom<{ readonly _tag: "ObjectBegin"; readonly offset: number; readonly length: number; readonly path: JsoncPath; }, "_tag">; readonly ObjectEnd: Data.TaggedEnum.ConstructorFrom<{ readonly _tag: "ObjectEnd"; readonly offset: number; readonly length: number; }, "_tag">; readonly ObjectProperty: Data.TaggedEnum.ConstructorFrom<{ readonly _tag: "ObjectProperty"; readonly property: string; readonly offset: number; readonly length: number; readonly path: JsoncPath; }, "_tag">; readonly Separator: Data.TaggedEnum.ConstructorFrom<{ readonly _tag: "Separator"; readonly character: string; readonly offset: number; readonly length: number; }, "_tag">; }; /** * SAX-style JSONC visitor statics. Not instantiable. * * @public */ declare class JsoncVisitor { private constructor(); /** * Create a lazy `Stream` of `JsoncVisitorEvent` from JSONC text. Events * are produced on demand, so combining with `Stream.take` allows efficient * partial scans of large documents. * * @param text - The JSONC source to visit. * @param options - Optional {@link JsoncParseOptions}; only comment handling * is consulted. * @returns A lazy `Stream` of `JsoncVisitorEvent`, infallible at the type * level — malformed input surfaces as in-band `Error` events rather than * failing the stream. */ static visit(text: string, options?: JsoncParseOptions): Stream.Stream; } //#endregion export { Jsonc, type JsoncBoundCodec, JsoncCanonicalizeError, JsoncCanonicalizeErrorCode, JsoncEdit, JsoncFingerprint, JsoncFormatter, JsoncFormattingOptions, type JsoncFormattingOptionsLike, JsoncModificationError, JsoncModifier, type JsoncModifyOptions, JsoncNode, JsoncNodeType, JsoncParseError, JsoncParseErrorCode, JsoncParseErrorDetail, JsoncParseOptions, type JsoncPath, JsoncRange, type JsoncSegment, JsoncStringifyError, JsoncStringifyErrorCode, JsoncStringifyOptions, JsoncTextHashOptions, JsoncVisitor, JsoncVisitorEvent }; //# sourceMappingURL=index.d.ts.map