diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d1e8f751..52f086e9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ history. ## Unreleased +- **BREAKING CHANGES:** `fjs/types/bit_vec` migrates from authored TypeScript + (`.f.ts`) to JSDoc-typed JavaScript (`.f.mjs`) under the stage-1 + TypeScript-to-mjs migration — importers must use the `.f.mjs` specifier + [#1460](https://github.com/functionalscript/functionalscript/pull/1460) - **BREAKING CHANGES:** `fjs/types/list`, `fjs/types/result`, `fjs/common/monoid`, `fjs/types/bigint`, and `fjs/types/nominal` migrate from authored TypeScript (`.f.ts`) to JSDoc-typed JavaScript (`.f.mjs`) under the diff --git a/fjs/asn.1/module.f.ts b/fjs/asn.1/module.f.ts index 68902a95d..4c280d173 100644 --- a/fjs/asn.1/module.f.ts +++ b/fjs/asn.1/module.f.ts @@ -16,7 +16,7 @@ import { vec8, type Unpacked, type Vec -} from "../types/bit_vec/module.f.ts" +} from "../types/bit_vec/module.f.mjs" import { identity } from "../types/function/module.f.mjs" import { max } from "../types/function/compare/module.f.mjs" import { encode as b128encode, decode as b128decode } from "../basen/base128/module.f.ts" diff --git a/fjs/asn.1/proof.f.ts b/fjs/asn.1/proof.f.ts index ffe2781d5..4d6b0ea58 100644 --- a/fjs/asn.1/proof.f.ts +++ b/fjs/asn.1/proof.f.ts @@ -1,4 +1,4 @@ -import { empty, isVec, length, msb, uint, unpack, vec, vec8, type Vec } from "../types/bit_vec/module.f.ts" +import { empty, isVec, length, msb, uint, unpack, vec, vec8, type Vec } from "../types/bit_vec/module.f.mjs" import { asBase } from "../types/nominal/module.f.mjs" import { decodeRaw, diff --git a/fjs/base_n/module.f.ts b/fjs/base_n/module.f.ts index 4770aeb00..a2ce32363 100644 --- a/fjs/base_n/module.f.ts +++ b/fjs/base_n/module.f.ts @@ -11,7 +11,7 @@ * * @module */ -import { msb, lsb, type Vec, vec, chunkList, unpack } from '../types/bit_vec/module.f.ts' +import { msb, lsb, type Vec, vec, chunkList, unpack } from '../types/bit_vec/module.f.mjs' import { fold, type List } from '../types/list/module.f.mjs' import { compose } from '../types/function/module.f.mjs' import type { Nullable } from '../types/nullable/module.f.mjs' diff --git a/fjs/base_n/proof.f.ts b/fjs/base_n/proof.f.ts index 1a371e7fc..f365b938e 100644 --- a/fjs/base_n/proof.f.ts +++ b/fjs/base_n/proof.f.ts @@ -1,5 +1,5 @@ import { assertEq } from '../asserts/module.f.mjs' -import { empty, maxLength, vec, length } from '../types/bit_vec/module.f.ts' +import { empty, maxLength, vec, length } from '../types/bit_vec/module.f.mjs' import { baseN } from './module.f.ts' const hex = baseN(4n, '0123456789abcdef') diff --git a/fjs/basen/base128/module.f.ts b/fjs/basen/base128/module.f.ts index 741327baf..848c2a3a8 100644 --- a/fjs/basen/base128/module.f.ts +++ b/fjs/basen/base128/module.f.ts @@ -3,7 +3,7 @@ * * @module */ -import { vec8, type Vec, msb, empty } from '../../types/bit_vec/module.f.ts' +import { vec8, type Vec, msb, empty } from '../../types/bit_vec/module.f.mjs' const { concat, popFront } = msb diff --git a/fjs/basen/base128/proof.f.ts b/fjs/basen/base128/proof.f.ts index 8c838cee8..63a328088 100644 --- a/fjs/basen/base128/proof.f.ts +++ b/fjs/basen/base128/proof.f.ts @@ -1,4 +1,4 @@ -import { empty, vec, vec8, type Vec } from '../../types/bit_vec/module.f.ts' +import { empty, vec, vec8, type Vec } from '../../types/bit_vec/module.f.mjs' import { asBase } from '../../types/nominal/module.f.mjs' import { encode, decode } from './module.f.ts' diff --git a/fjs/basen/base64/module.f.ts b/fjs/basen/base64/module.f.ts index 0e4194c9a..66dfc2abe 100644 --- a/fjs/basen/base64/module.f.ts +++ b/fjs/basen/base64/module.f.ts @@ -3,7 +3,7 @@ * * @module */ -import { msb, type Vec, length, vec, maxLength } from "../../types/bit_vec/module.f.ts" +import { msb, type Vec, length, vec, maxLength } from "../../types/bit_vec/module.f.mjs" import type { Nullable } from "../../types/nullable/module.f.mjs" import { baseN } from "../../base_n/module.f.ts" diff --git a/fjs/basen/base64/proof.f.ts b/fjs/basen/base64/proof.f.ts index 0e151562b..933528004 100644 --- a/fjs/basen/base64/proof.f.ts +++ b/fjs/basen/base64/proof.f.ts @@ -1,5 +1,5 @@ import { assertEq } from '../../asserts/module.f.mjs' -import { empty, vec, repeat, vec8, maxLength, type Vec } from "../../types/bit_vec/module.f.ts" +import { empty, vec, repeat, vec8, maxLength, type Vec } from "../../types/bit_vec/module.f.mjs" import { encode, decode } from "./module.f.ts" const check = (s: string, v: Vec) => { diff --git a/fjs/basen/cbase32/module.f.ts b/fjs/basen/cbase32/module.f.ts index 8a019337a..327a2f8d3 100644 --- a/fjs/basen/cbase32/module.f.ts +++ b/fjs/basen/cbase32/module.f.ts @@ -3,7 +3,7 @@ * * @module */ -import { msb, lsb, type Vec, length, vec, empty } from "../../types/bit_vec/module.f.ts" +import { msb, lsb, type Vec, length, vec, empty } from "../../types/bit_vec/module.f.mjs" import type { Nullable } from "../../types/nullable/module.f.mjs" import { baseN } from "../../base_n/module.f.ts" diff --git a/fjs/basen/cbase32/proof.f.ts b/fjs/basen/cbase32/proof.f.ts index 1dbf40325..f485d991f 100644 --- a/fjs/basen/cbase32/proof.f.ts +++ b/fjs/basen/cbase32/proof.f.ts @@ -1,4 +1,4 @@ -import { empty, vec, type Vec } from "../../types/bit_vec/module.f.ts" +import { empty, vec, type Vec } from "../../types/bit_vec/module.f.mjs" import { cBase32ToVec, cBase32ToVec5x, vec5xToCBase32, vecToCBase32 } from "./module.f.ts" import { assertEq } from '../../asserts/module.f.mjs' diff --git a/fjs/cas/cli/proof.f.ts b/fjs/cas/cli/proof.f.ts index 68dae2f8c..445def475 100644 --- a/fjs/cas/cli/proof.f.ts +++ b/fjs/cas/cli/proof.f.ts @@ -1,6 +1,6 @@ import { commands } from './module.f.ts' import { computeSync, sha256 } from '../../crypto/sha2/module.f.ts' -import { maxLength, vec, vec8 } from '../../types/bit_vec/module.f.ts' +import { maxLength, vec, vec8 } from '../../types/bit_vec/module.f.mjs' import { defaultNodeProgramOptions, emptyState, virtual } from '../../effects/node/virtual/module.f.ts' import { type NodeProgramOptions } from '../../effects/node/module.f.ts' import { dispatch } from '../../cli/module.f.ts' diff --git a/fjs/cas/evo/module.f.ts b/fjs/cas/evo/module.f.ts index 497976979..ceea8b2bb 100644 --- a/fjs/cas/evo/module.f.ts +++ b/fjs/cas/evo/module.f.ts @@ -54,7 +54,7 @@ import { ok, error, type Ok, type Result } from '../../types/result/module.f.mjs import { nonEmpty, empty as elEmpty } from '../../effects/list/module.f.ts' import { at, definedEntries, type StringMap } from '../../types/object/module.f.ts' import { unwrap } from '../../types/nullable/module.f.mjs' -import type { Vec } from '../../types/bit_vec/module.f.ts' +import type { Vec } from '../../types/bit_vec/module.f.mjs' import { isNotFound, type IoResult } from '../../effects/node/module.f.ts' /** A cBase32 content hash, as accepted/returned by `Cas`. */ diff --git a/fjs/cas/evo/proof.f.ts b/fjs/cas/evo/proof.f.ts index 84c0075ac..b18e8d621 100644 --- a/fjs/cas/evo/proof.f.ts +++ b/fjs/cas/evo/proof.f.ts @@ -3,7 +3,7 @@ import { pure } from '../../effects/module.f.ts' import { fileCas, type Cas } from '../module.f.ts' import { sha256 } from '../../crypto/sha2/module.f.ts' import { emptyState, virtual } from '../../effects/node/virtual/module.f.ts' -import { vec, vec8, type Vec } from '../../types/bit_vec/module.f.ts' +import { vec, vec8, type Vec } from '../../types/bit_vec/module.f.mjs' import { cBase32ToVec, vecToCBase32 } from '../../basen/cbase32/module.f.ts' import { unwrap } from '../../types/nullable/module.f.mjs' import { ok, error, type Ok } from '../../types/result/module.f.mjs' diff --git a/fjs/cas/module.f.ts b/fjs/cas/module.f.ts index db58170f9..209e8d68d 100644 --- a/fjs/cas/module.f.ts +++ b/fjs/cas/module.f.ts @@ -5,7 +5,7 @@ */ import { sha256, type Sha2, type State as Sha2State } from '../crypto/sha2/module.f.ts' import { join, normalize, parse } from '../path/module.f.ts' -import { empty, length, maxLength, maxLengthBytes, msb, vec, type Vec } from '../types/bit_vec/module.f.ts' +import { empty, length, maxLength, maxLengthBytes, msb, vec, type Vec } from '../types/bit_vec/module.f.mjs' import { cBase32ToVec, vecToCBase32 } from '../basen/cbase32/module.f.ts' import { foldStep, forEachStep, history, historyStep, okStep, pure, step, type Effect, type Operation } from '../effects/module.f.ts' import { eff } from '../effects/eff/module.f.ts' diff --git a/fjs/cas/proof.f.ts b/fjs/cas/proof.f.ts index 60762dbc0..5b8a8ea3e 100644 --- a/fjs/cas/proof.f.ts +++ b/fjs/cas/proof.f.ts @@ -1,4 +1,4 @@ -import { length, maxLength, msb, vec, vec8, type Vec } from '../types/bit_vec/module.f.ts' +import { length, maxLength, msb, vec, vec8, type Vec } from '../types/bit_vec/module.f.mjs' import { cBase32ToVec, vecToCBase32 } from '../basen/cbase32/module.f.ts' import { computeSync, sha256 } from '../crypto/sha2/module.f.ts' import { fileCas, casAddFile, collectRead, type FileCasOperation, casUpload } from './module.f.ts' diff --git a/fjs/ci/proof.f.ts b/fjs/ci/proof.f.ts index cb21c889c..e8920456f 100644 --- a/fjs/ci/proof.f.ts +++ b/fjs/ci/proof.f.ts @@ -3,7 +3,7 @@ import { functionalscript, node } from './config/module.f.ts' import { nodeNixJobs } from './node/module.f.ts' import { coverageInclude } from './deno/module.f.ts' import { utf8, utf8ToString } from '../text/module.f.ts' -import { empty as emptyVec, isVec } from '../types/bit_vec/module.f.ts' +import { empty as emptyVec } from '../types/bit_vec/module.f.mjs' import { type MetaStep, type Os, test, ubuntu, type GitHubAction, parseGitHubAction } from './common/module.f.ts' import { assert, assertEq } from '../asserts/module.f.mjs' import type { State } from '../effects/node/virtual/module.f.ts' diff --git a/fjs/crypto/hmac/module.f.ts b/fjs/crypto/hmac/module.f.ts index 097313fee..ed69c6315 100644 --- a/fjs/crypto/hmac/module.f.ts +++ b/fjs/crypto/hmac/module.f.ts @@ -18,7 +18,7 @@ * ``` */ -import { length, type Vec, msb, vec, vec8, type Reduce, repeat } from '../../types/bit_vec/module.f.ts' +import { length, type Vec, msb, vec, vec8, type Reduce, repeat } from '../../types/bit_vec/module.f.mjs' import { computeSync, type Sha2 } from '../sha2/module.f.ts' const { concat, xor } = msb diff --git a/fjs/crypto/hmac/proof.f.ts b/fjs/crypto/hmac/proof.f.ts index be620c3db..fe053d237 100644 --- a/fjs/crypto/hmac/proof.f.ts +++ b/fjs/crypto/hmac/proof.f.ts @@ -1,6 +1,6 @@ import { assertEq } from '../../asserts/module.f.mjs' import { utf8 } from '../../text/module.f.ts' -import { uint, vec } from '../../types/bit_vec/module.f.ts' +import { uint, vec } from '../../types/bit_vec/module.f.mjs' import { sha256, sha384, sha512 } from '../sha2/module.f.ts' import { hmac } from './module.f.ts' diff --git a/fjs/crypto/pow/module.f.ts b/fjs/crypto/pow/module.f.ts index 6ba6c9990..5eb48d9ad 100644 --- a/fjs/crypto/pow/module.f.ts +++ b/fjs/crypto/pow/module.f.ts @@ -5,7 +5,7 @@ * @module */ import { mask } from '../../types/bigint/module.f.mjs' -import { type Vec, uint } from '../../types/bit_vec/module.f.ts' +import { type Vec, uint } from '../../types/bit_vec/module.f.mjs' import type { Nullable } from '../../types/nullable/module.f.mjs' import { computeSync, sha256, type Sha2 } from '../sha2/module.f.ts' diff --git a/fjs/crypto/pow/proof.f.ts b/fjs/crypto/pow/proof.f.ts index b21454b50..ac0b99b62 100644 --- a/fjs/crypto/pow/proof.f.ts +++ b/fjs/crypto/pow/proof.f.ts @@ -1,5 +1,5 @@ import { utf8 } from '../../text/module.f.ts' -import { empty, uint } from '../../types/bit_vec/module.f.ts' +import { empty, uint } from '../../types/bit_vec/module.f.mjs' import { computeSync, sha224, sha256 } from '../sha2/module.f.ts' import { bitcoinPow, genesisNBits, genesisTarget, pow, sha256Pow, targetFromNBits } from './module.f.ts' import { assert, assertEq, assertNotNullish } from '../../asserts/module.f.mjs' diff --git a/fjs/crypto/sha2/module.f.ts b/fjs/crypto/sha2/module.f.ts index 101f73117..d8c0862a8 100644 --- a/fjs/crypto/sha2/module.f.ts +++ b/fjs/crypto/sha2/module.f.ts @@ -13,7 +13,7 @@ import { chunkList, uint, type Vec -} from '../../types/bit_vec/module.f.ts' +} from '../../types/bit_vec/module.f.mjs' import type { Fold } from '../../types/function/operator/module.f.mjs' import { fold, type List } from '../../types/list/module.f.mjs' diff --git a/fjs/crypto/sha2/proof.f.ts b/fjs/crypto/sha2/proof.f.ts index 92d06a365..3e590d083 100644 --- a/fjs/crypto/sha2/proof.f.ts +++ b/fjs/crypto/sha2/proof.f.ts @@ -1,5 +1,5 @@ import { utf8 } from '../../text/module.f.ts' -import { repeat, uint, vec } from '../../types/bit_vec/module.f.ts' +import { repeat, uint, vec } from '../../types/bit_vec/module.f.mjs' import { flip } from '../../types/function/module.f.mjs' import { assertEq } from '../../asserts/module.f.mjs' import { map } from '../../types/list/module.f.mjs' diff --git a/fjs/crypto/sign/module.f.ts b/fjs/crypto/sign/module.f.ts index 95951d522..78855d790 100644 --- a/fjs/crypto/sign/module.f.ts +++ b/fjs/crypto/sign/module.f.ts @@ -6,7 +6,7 @@ import { assertNotNullish } from '../../asserts/module.f.mjs' import type { Tuple } from '../../types/array/module.f.mjs' import { bitLength, divUp8, roundUp8 } from '../../types/bigint/module.f.mjs' -import { empty, length, msb, repeat, unpack, vec, vec8, type Vec } from '../../types/bit_vec/module.f.ts' +import { empty, length, msb, repeat, unpack, vec, vec8, type Vec } from '../../types/bit_vec/module.f.mjs' import { hmac } from '../hmac/module.f.ts' import type { Curve } from '../secp/module.f.ts' import { computeSync, type Sha2 } from '../sha2/module.f.ts' diff --git a/fjs/crypto/sign/proof.f.ts b/fjs/crypto/sign/proof.f.ts index ead93ced6..95ec7254c 100644 --- a/fjs/crypto/sign/proof.f.ts +++ b/fjs/crypto/sign/proof.f.ts @@ -1,6 +1,6 @@ import { utf8 } from "../../text/module.f.ts" import type { Tuple } from "../../types/array/module.f.mjs" -import { empty, msb, repeat, vec, vec8, type Vec } from "../../types/bit_vec/module.f.ts" +import { empty, msb, repeat, vec, vec8, type Vec } from "../../types/bit_vec/module.f.mjs" import { hmac } from "../hmac/module.f.ts" import { secp192r1, secp256r1, secp384r1, secp521r1, type Curve } from "../secp/module.f.ts" import { computeSync, sha224, sha256, sha384, sha512, type Sha2 } from "../sha2/module.f.ts" diff --git a/fjs/djs/proof.f.ts b/fjs/djs/proof.f.ts index e13f11e82..0094b9903 100644 --- a/fjs/djs/proof.f.ts +++ b/fjs/djs/proof.f.ts @@ -1,7 +1,7 @@ import { compile } from './module.f.ts' import { virtual, emptyState } from '../effects/node/virtual/module.f.ts' import { utf8, utf8ToString } from '../text/module.f.ts' -import type { Vec } from '../types/bit_vec/module.f.ts' +import type { Vec } from '../types/bit_vec/module.f.mjs' import { assert, assertEq } from '../asserts/module.f.mjs' const readOutput = (root: typeof emptyState.root, path: string): string => { diff --git a/fjs/effects/node/module.f.ts b/fjs/effects/node/module.f.ts index a9218a71a..15a65f161 100644 --- a/fjs/effects/node/module.f.ts +++ b/fjs/effects/node/module.f.ts @@ -12,7 +12,7 @@ import { utf8, utf8ToString } from '../../text/module.f.ts' import { toCodePointList } from '../../text/utf8/module.f.ts' import { codePointListToString } from '../../text/utf16/module.f.ts' import { reverse, type List as EffectList } from '../../types/list/module.f.mjs' -import { length, type Vec } from '../../types/bit_vec/module.f.ts' +import { length, type Vec } from '../../types/bit_vec/module.f.mjs' import type { MemOp } from '../memory/module.f.ts' import type { Nominal } from '../../types/nominal/module.f.mjs' import { ok, error as resultError, mapOk, type Result } from '../../types/result/module.f.mjs' diff --git a/fjs/effects/node/module.ts b/fjs/effects/node/module.ts index 15e3207e2..3d724e460 100644 --- a/fjs/effects/node/module.ts +++ b/fjs/effects/node/module.ts @@ -43,7 +43,7 @@ import { error, ok, type Result } from '../../types/result/module.f.mjs' import { asyncTryCatch } from '../../types/result/module.ts' import { fromVec, listToVec, toVec } from '../../types/uint8array/module.f.ts' import type { StringMap } from '../../types/object/module.f.ts' -import { maxLengthBytes } from '../../types/bit_vec/module.f.ts' +import { maxLengthBytes } from '../../types/bit_vec/module.f.mjs' type Server = { readonly listen: (port: number) => void diff --git a/fjs/effects/node/proof.f.ts b/fjs/effects/node/proof.f.ts index cee527613..c96316cb1 100644 --- a/fjs/effects/node/proof.f.ts +++ b/fjs/effects/node/proof.f.ts @@ -1,4 +1,4 @@ -import { empty, isVec, uint, vec, vec8, type Vec } from "../../types/bit_vec/module.f.ts" +import { empty, isVec, uint, vec, vec8, type Vec } from "../../types/bit_vec/module.f.mjs" import { utf8, utf8ToString } from "../../text/module.f.ts" import { match, pure, step } from "../module.f.ts" import { both, fetch, mkdir, now, readdir, readFile, readUtf8File, rm, sandbox, writeFile, writeUtf8File, rename, readBytes, randomInt, writeFromStream, usesInlineTestContext, versionLessThan, type IoResult, type ReadFile } from "./module.f.ts" diff --git a/fjs/effects/node/virtual/module.f.ts b/fjs/effects/node/virtual/module.f.ts index 895c4c9f6..336299526 100644 --- a/fjs/effects/node/virtual/module.f.ts +++ b/fjs/effects/node/virtual/module.f.ts @@ -6,7 +6,7 @@ import { todo } from '../../../asserts/module.f.mjs' import { isProperPrefix, join, parse } from '../../../path/module.f.ts' import { utf8ToString } from '../../../text/module.f.ts' -import { empty, length, maxLengthBytes, msb, vec, type Vec } from '../../../types/bit_vec/module.f.ts' +import { empty, length, maxLengthBytes, msb, vec, type Vec } from '../../../types/bit_vec/module.f.mjs' import { error, ok } from '../../../types/result/module.f.mjs' import { run, type MemOperationMap, type RunInstance } from '../../mock/module.f.ts' import { asBase, asNominal, type Key } from '../../memory/module.f.ts' diff --git a/fjs/effects/node/virtual/proof.f.ts b/fjs/effects/node/virtual/proof.f.ts index 6fb8c0afb..60a4e1f0d 100644 --- a/fjs/effects/node/virtual/proof.f.ts +++ b/fjs/effects/node/virtual/proof.f.ts @@ -1,6 +1,6 @@ import { assert, assertEq } from '../../../asserts/module.f.mjs' import { access, awaitIfPromise, fetch, rm, writeFile, readFile, readdir, import_, rename, readBytes, writeBytes } from '../module.f.ts' -import { maxLengthBytes, vec, vec8 } from '../../../types/bit_vec/module.f.ts' +import { maxLengthBytes, vec, vec8 } from '../../../types/bit_vec/module.f.mjs' import { emptyState, virtual, type Dir, type JsModule } from './module.f.ts' export const proof = { diff --git a/fjs/mcp/cas/module.f.ts b/fjs/mcp/cas/module.f.ts index a467b136e..eeaca1c74 100644 --- a/fjs/mcp/cas/module.f.ts +++ b/fjs/mcp/cas/module.f.ts @@ -111,7 +111,7 @@ import { tryUtf8 } from '../../text/module.f.ts' import { detectStream } from '../../media/type/module.f.ts' import { detect } from '../../media/module.f.ts' import { revisionDialect } from '../../media/revision/module.f.ts' -import { maxLengthBytes, type Vec } from '../../types/bit_vec/module.f.ts' +import { maxLengthBytes, type Vec } from '../../types/bit_vec/module.f.mjs' import { ok, type Ok } from '../../types/result/module.f.mjs' import { toolEntry, errorResult, okResult, diff --git a/fjs/mcp/evo/proof.f.ts b/fjs/mcp/evo/proof.f.ts index a5582f897..42016b483 100644 --- a/fjs/mcp/evo/proof.f.ts +++ b/fjs/mcp/evo/proof.f.ts @@ -2,7 +2,7 @@ import { assert, assertEq } from '../../asserts/module.f.mjs' import { fileCas } from '../../cas/module.f.ts' import { sha256 } from '../../crypto/sha2/module.f.ts' import { emptyState, virtual } from '../../effects/node/virtual/module.f.ts' -import { vec8 } from '../../types/bit_vec/module.f.ts' +import { vec8 } from '../../types/bit_vec/module.f.mjs' import { vecToCBase32 } from '../../basen/cbase32/module.f.ts' import { initEvo, evo, type Evo } from '../../cas/evo/module.f.ts' import { evoToolRegistry } from './module.f.ts' diff --git a/fjs/mcp/proof.f.ts b/fjs/mcp/proof.f.ts index 89f828183..91ef53a06 100644 --- a/fjs/mcp/proof.f.ts +++ b/fjs/mcp/proof.f.ts @@ -5,7 +5,7 @@ import { parse as parseJson, type Unknown } from '../media/json/module.f.ts' import { number as rttiNumber, option, string as rttiString } from '../types/rtti/module.f.ts' import { parse as rttiParse } from '../types/rtti/parse/module.f.ts' import type { Response } from '../protocol/json_rpc/module.f.ts' -import { msb, u8ListToVec, vec8, repeat, length, type Vec, maxLengthBytes } from '../types/bit_vec/module.f.ts' +import { msb, u8ListToVec, vec8, repeat, length, type Vec, maxLengthBytes } from '../types/bit_vec/module.f.mjs' import { vecToCBase32 } from '../basen/cbase32/module.f.ts' import { encode as base64Encode } from '../basen/base64/module.f.ts' import { utf8 } from '../text/module.f.ts' diff --git a/fjs/media/html/module.f.ts b/fjs/media/html/module.f.ts index 332530cea..2669449dd 100644 --- a/fjs/media/html/module.f.ts +++ b/fjs/media/html/module.f.ts @@ -10,7 +10,7 @@ import { definedEntries, type Entry, type StringMap } from '../../types/object/m import { compose } from '../../types/function/module.f.mjs' import { stringToList } from '../../text/utf16/module.f.ts' import { includes } from '../../types/array/module.f.mjs' -import { type Vec } from '../../types/bit_vec/module.f.ts' +import { type Vec } from '../../types/bit_vec/module.f.mjs' import { utf8 } from '../../text/module.f.ts' import { quotationMark, ampersand, lessThanSign, greaterThanSign } from '../../text/ascii/module.f.ts' diff --git a/fjs/media/module.f.ts b/fjs/media/module.f.ts index b50c588a0..1b6248eae 100644 --- a/fjs/media/module.f.ts +++ b/fjs/media/module.f.ts @@ -41,7 +41,7 @@ * * @module */ -import type { Vec } from '../types/bit_vec/module.f.ts' +import type { Vec } from '../types/bit_vec/module.f.mjs' import { fromVec } from '../text/utf8/module.f.ts' import { detectVec, type DetectMeta } from './type/module.f.ts' import { parse } from './json/module.f.ts' diff --git a/fjs/media/proof.f.ts b/fjs/media/proof.f.ts index 17b8f3cd2..6cdb4de87 100644 --- a/fjs/media/proof.f.ts +++ b/fjs/media/proof.f.ts @@ -1,5 +1,5 @@ import { assertEq } from '../asserts/module.f.mjs' -import { msb, u8ListToVec, repeat, vec8, type Vec } from '../types/bit_vec/module.f.ts' +import { msb, u8ListToVec, repeat, vec8, type Vec } from '../types/bit_vec/module.f.mjs' import { detect, dialectEntry, type DialectEntry } from './module.f.ts' import { dialect, revisionDialect } from './revision/module.f.ts' import { number, string } from '../types/rtti/module.f.ts' diff --git a/fjs/media/type/module.f.ts b/fjs/media/type/module.f.ts index 7810e2546..61112d38c 100644 --- a/fjs/media/type/module.f.ts +++ b/fjs/media/type/module.f.ts @@ -32,7 +32,7 @@ * * @module */ -import { msb, fromSentinel, length, u8List, type Vec } from '../../types/bit_vec/module.f.ts' +import { msb, fromSentinel, length, u8List, type Vec } from '../../types/bit_vec/module.f.mjs' import { iterable } from '../../types/list/module.f.mjs' import type { Nullable } from '../../types/nullable/module.f.mjs' import { pure, step, type Effect, type Operation } from '../../effects/module.f.ts' diff --git a/fjs/media/type/proof.f.ts b/fjs/media/type/proof.f.ts index 2ea232553..99f9fa44a 100644 --- a/fjs/media/type/proof.f.ts +++ b/fjs/media/type/proof.f.ts @@ -1,5 +1,5 @@ import { assert, assertEq } from '../../asserts/module.f.mjs' -import { msb, u8ListToVec, vec8, repeat, empty, type Vec } from '../../types/bit_vec/module.f.ts' +import { msb, u8ListToVec, vec8, repeat, empty, type Vec } from '../../types/bit_vec/module.f.mjs' import { runPure } from '../../effects/module.f.ts' import { nonEmpty, empty as emptyList, type List } from '../../effects/list/module.f.ts' import { ok, type Result } from '../../types/result/module.f.mjs' diff --git a/fjs/protocol/mcp/stdio/proof.f.ts b/fjs/protocol/mcp/stdio/proof.f.ts index 8c0035fa8..a2bb0164a 100644 --- a/fjs/protocol/mcp/stdio/proof.f.ts +++ b/fjs/protocol/mcp/stdio/proof.f.ts @@ -5,7 +5,7 @@ import type { Unknown } from '../../../media/json/module.f.ts' import { stringify } from '../../../media/json/module.f.ts' import { utf8 } from '../../../text/module.f.ts' import { fromVec } from '../../../types/uint8array/module.f.ts' -import { maxLengthBytes } from '../../../types/bit_vec/module.f.ts' +import { maxLengthBytes } from '../../../types/bit_vec/module.f.mjs' import { sort } from '../../../types/object/module.f.ts' import { internalError, jsonrpc, parseError, type Id, type Response } from '../../json_rpc/module.f.ts' import { stdioTransport, type Step } from './module.f.ts' diff --git a/fjs/sul/id/module.f.ts b/fjs/sul/id/module.f.ts index 519a3ff2a..b6060cee1 100644 --- a/fjs/sul/id/module.f.ts +++ b/fjs/sul/id/module.f.ts @@ -15,7 +15,7 @@ import { unpack, vec, type Vec -} from '../../types/bit_vec/module.f.ts' +} from '../../types/bit_vec/module.f.mjs' import { assertEq } from '../../asserts/module.f.mjs' import { utf8 } from '../../text/module.f.ts' import { secp256r1, type Point2D } from '../../crypto/secp/module.f.ts' diff --git a/fjs/sul/id/proof.f.ts b/fjs/sul/id/proof.f.ts index 8e9ec7355..4fc219201 100644 --- a/fjs/sul/id/proof.f.ts +++ b/fjs/sul/id/proof.f.ts @@ -1,6 +1,6 @@ import { assert, assertEq } from '../../asserts/module.f.mjs' import { mask } from '../../types/bigint/module.f.mjs' -import { vec } from '../../types/bit_vec/module.f.ts' +import { vec } from '../../types/bit_vec/module.f.mjs' import { compress, hashId, isHash, isRaw, level3Id, rawId } from './module.f.ts' import { asBase } from '../../types/nominal/module.f.mjs' diff --git a/fjs/sul/level/literal/module.f.ts b/fjs/sul/level/literal/module.f.ts index e65c1bf61..a6b8bc3a3 100644 --- a/fjs/sul/level/literal/module.f.ts +++ b/fjs/sul/level/literal/module.f.ts @@ -6,7 +6,7 @@ */ import { log2 } from '../../../types/bigint/module.f.mjs' -import { msb, vec, type Vec } from '../../../types/bit_vec/module.f.ts' +import { msb, vec, type Vec } from '../../../types/bit_vec/module.f.mjs' import type { Func } from '../../../types/function/module.f.mjs' import { strictEqual, type Equal, type StateScan } from '../../../types/function/operator/module.f.mjs' import { equal, map, type List } from '../../../types/list/module.f.mjs' diff --git a/fjs/sul/level/literal/proof.f.ts b/fjs/sul/level/literal/proof.f.ts index 96ee6283b..36709b43d 100644 --- a/fjs/sul/level/literal/proof.f.ts +++ b/fjs/sul/level/literal/proof.f.ts @@ -1,4 +1,4 @@ -import { chunkList, msb, vec, type Vec } from '../../../types/bit_vec/module.f.ts' +import { chunkList, msb, vec, type Vec } from '../../../types/bit_vec/module.f.mjs' import { assert, assertEq } from '../../../asserts/module.f.mjs' import { map, stateScan, toArray } from '../../../types/list/module.f.mjs' import { diff --git a/fjs/text/module.f.ts b/fjs/text/module.f.ts index 17d450ed2..66700cc7f 100644 --- a/fjs/text/module.f.ts +++ b/fjs/text/module.f.ts @@ -5,7 +5,7 @@ * * @module */ -import { msb, tryU8ListToVec, u8List, type Vec } from '../types/bit_vec/module.f.ts' +import { msb, tryU8ListToVec, u8List, type Vec } from '../types/bit_vec/module.f.mjs' import { flatMap, type List } from '../types/list/module.f.mjs' import { fromCodePointList, toCodePointList } from './utf8/module.f.ts' import { stringToCodePointList, codePointListToString } from './utf16/module.f.ts' diff --git a/fjs/text/proof.f.ts b/fjs/text/proof.f.ts index 665b7304c..2fdf6029e 100644 --- a/fjs/text/proof.f.ts +++ b/fjs/text/proof.f.ts @@ -1,7 +1,7 @@ import { assertEq, assertNotNullish } from '../asserts/module.f.mjs' import { flat, utf8, utf8ToString, tryUtf8, type Block } from './module.f.ts' import { join } from '../types/string/module.f.ts' -import { empty, maxLengthBytes } from '../types/bit_vec/module.f.ts' +import { empty, maxLengthBytes } from '../types/bit_vec/module.f.mjs' const overflowStr = 'a'.repeat(Number(maxLengthBytes) + 1) diff --git a/fjs/text/utf8/module.f.ts b/fjs/text/utf8/module.f.ts index fb5b7d513..15722fcb1 100644 --- a/fjs/text/utf8/module.f.ts +++ b/fjs/text/utf8/module.f.ts @@ -7,7 +7,7 @@ import { flatMap, toArray, type List, type Thunk } from '../../types/list/module import type { StateScan } from '../../types/function/operator/module.f.mjs' import type { Tuple } from '../../types/array/module.f.mjs' import { decoder, errorMask, isValidCodePoint } from '../code_point/module.f.ts' -import { msb, u8List, length, type Vec } from '../../types/bit_vec/module.f.ts' +import { msb, u8List, length, type Vec } from '../../types/bit_vec/module.f.mjs' import { codePointListToString } from '../utf16/module.f.ts' /** diff --git a/fjs/text/utf8/proof.f.ts b/fjs/text/utf8/proof.f.ts index 4378b4c97..822397935 100644 --- a/fjs/text/utf8/proof.f.ts +++ b/fjs/text/utf8/proof.f.ts @@ -2,7 +2,7 @@ import { toCodePointList, fromCodePointList, fromVec, utf8ByteToCodePointOp } fr import { stringify as jsonStringify } from '../../media/json/module.f.ts' import { sort } from '../../types/object/module.f.ts' import { toArray } from '../../types/list/module.f.mjs' -import { msb, u8ListToVec, vec } from '../../types/bit_vec/module.f.ts' +import { msb, u8ListToVec, vec } from '../../types/bit_vec/module.f.mjs' import { assertEq } from '../../asserts/module.f.mjs' const stringify = jsonStringify(sort) diff --git a/fjs/types/bit_vec/module.f.ts b/fjs/types/bit_vec/module.f.mjs similarity index 54% rename from fjs/types/bit_vec/module.f.ts rename to fjs/types/bit_vec/module.f.mjs index 5756f5c37..c3b18da2e 100644 --- a/fjs/types/bit_vec/module.f.ts +++ b/fjs/types/bit_vec/module.f.mjs @@ -21,22 +21,35 @@ * * @module */ -import { bitLength, divUp, mask, maxLength, xor, type Reduce as BigintReduce } from '../bigint/module.f.mjs' + +import { bitLength, divUp, mask, maxLength, xor } from '../bigint/module.f.mjs' +/** @import { Reduce as BigintReduce } from '../bigint/module.f.mjs' */ + import { flip, identity } from '../function/module.f.mjs' -import type { Binary, Fold, Reduce as OpReduce } from '../function/operator/module.f.mjs' -import { map, tryFold, type Accumulator, type List, type Thunk } from '../list/module.f.mjs' -import { asBase, asNominal, type Nominal } from '../nominal/module.f.mjs' + +/** @import { Binary, Fold, Reduce as OpReduce } from '../function/operator/module.f.mjs' */ + +import { map, tryFold } from '../list/module.f.mjs' +/** @import { Accumulator, List, Thunk } from '../list/module.f.mjs' */ + +import { asBase, asNominal } from '../nominal/module.f.mjs' +/** @import { Nominal } from '../nominal/module.f.mjs' */ + import { repeat as mRepeat } from '../../common/monoid/module.f.mjs' -import { cmp, max, min, type Sign } from '../function/compare/module.f.mjs' -import { mapUnwrap, type Nullable } from '../nullable/module.f.mjs' + +import { cmp, max, min } from '../function/compare/module.f.mjs' +/** @import { Sign } from '../function/compare/module.f.mjs' */ + +import { mapUnwrap } from '../nullable/module.f.mjs' +/** @import { Nullable } from '../nullable/module.f.mjs' */ + +/** @typedef {'1a23a4336197e6158b6936cad34e90d146cd84b9b40ff7ab75a17c6d79e31d89'} Revision */ /** * A vector of bits represented as a signed `bigint`. + * + * @typedef {Nominal<'bit_vec', Revision, bigint>} Vec */ -export type Vec = Nominal< - 'bit_vec', - '1a23a4336197e6158b6936cad34e90d146cd84b9b40ff7ab75a17c6d79e31d89', - bigint> /** * Maximum length of a bit vector in bits (1_048_576 = 0x10_0000). @@ -49,13 +62,17 @@ export const maxLengthBytes = maxLength >> 3n /** * An empty vector of bits. + * + * @type {Vec} */ -export const empty: Vec = asNominal(0n) +export const empty = asNominal(0n) /** * Calculates the length of the given vector of bits. + * + * @type {(v: Vec) => bigint} */ -export const length = (v: Vec): bigint => bitLength(asBase(v)) +export const length = v => bitLength(asBase(v)) const lazyEmpty = () => empty @@ -69,8 +86,10 @@ const lazyEmpty = () => empty * const v0 = vec4(5n) // -0xDn = -0b1101 * const v1 = vec4(0x5FEn) // 0xEn = 0b1110 * ``` + * + * @type {(len: bigint) => (ui: bigint) => Vec} */ -export const vec = (len: bigint): (ui: bigint) => Vec => { +export const vec = len => { if (len <= 0n) { return lazyEmpty } const m = mask(len) const last = len - 1n @@ -88,7 +107,7 @@ export const vec = (len: bigint): (ui: bigint) => Vec => { /** * Creates an 8-bit vector from an unsigned integer. */ -export const vec8: (ui: bigint) => Vec = vec(8n) +export const vec8 = vec(8n) /** * Builds a vector from a bigint whose most-significant set bit is a sentinel @@ -106,8 +125,10 @@ export const vec8: (ui: bigint) => Vec = vec(8n) * length(fromSentinel(0x1_89_50n)) // 16n — the two data bytes, sentinel gone * fromSentinel(0x1_00_05n) // a 16-bit vector holding 0x0005 * ``` + * + * @type {(raw: bigint) => Vec} */ -export const fromSentinel = (raw: bigint): Vec => vec(bitLength(raw) - 1n)(raw) +export const fromSentinel = raw => vec(bitLength(raw) - 1n)(raw) /** * Returns the unsigned integer representation of the vector by clearing the stop bit. @@ -118,8 +139,10 @@ export const fromSentinel = (raw: bigint): Vec => vec(bitLength(raw) - 1n)(raw) * const vector = vec(8n)(0x5n) // -0x85n * const result = uint(vector); // result is 0x5n * ``` + * + * @type {(v: Vec) => bigint} */ -export const uint = (v: Vec): bigint => { +export const uint = v => { const b = asBase(v) if (b >= 0n) { return b } const u = -b @@ -129,38 +152,49 @@ export const uint = (v: Vec): bigint => { /** * Structure describing the unpacked view of a vector. + * @typedef {{ + * readonly length: bigint + * readonly uint: bigint + * }} Unpacked */ -export type Unpacked = { - readonly length: bigint - readonly uint: bigint -} /** * Extracts the logical length and unsigned integer from the vector. + * + * @type {(v: Vec) => Unpacked} */ -export const unpack = (v: Vec): Unpacked => ({ +export const unpack = v => ({ length: length(v), uint: uint(v), }) /** * Packs an unpacked representation back into a vector. + * + * @type {({ length, uint }: Unpacked) => Vec} */ -export const pack = ({ length, uint }: Unpacked): Vec => vec(length)(uint) +export const pack = ({ length, uint }) => vec(length)(uint) -export const unpackedUint = ({ uint }: Unpacked): bigint => uint +/** @type {({ uint }: Unpacked) => bigint} */ +export const unpackedUint = ({ uint }) => uint -type Norm = (len: bigint) => { - readonly a: bigint - readonly b: bigint -} +/** + * @typedef {(len: bigint) => { + * readonly a: bigint + * readonly b: bigint + * }} Norm + */ -type NormOp = Binary +/** @typedef {Binary} NormOp */ + +/** @typedef {OpReduce} Reduce */ /** * Normalizes two vectors to the same length before applying a bigint reducer. + * + * @type {(norm: NormOp) => (op: BigintReduce) => Reduce} */ -const op = (norm: NormOp) => (op: BigintReduce): Reduce => ap => bp => { +const op = norm => op => ap => bp => { const au = unpack(ap) const bu = unpack(bp) const len = max(au.length)(bu.length) @@ -168,151 +202,59 @@ const op = (norm: NormOp) => (op: BigintReduce): Reduce => ap => bp => { return vec(len)(op(a)(b)) } -export type Reduce = OpReduce - -export type PopFront = (len: bigint) => (u: T) => readonly [bigint, T] +/** + * @template T + * @typedef {(len: bigint) => (u: T) => readonly [bigint, T]} PopFront + */ /** * Represents operations for handling bit vectors with a specific bit order. * * https://en.wikipedia.org/wiki/Bit_numbering + * + * @typedef {{ + * readonly front: (len: bigint) => (v: Vec) => bigint + * readonly removeFront: (len: bigint) => (v: Vec) => Vec + * readonly popFront: PopFront + * readonly concat: Reduce + * readonly tryListToVec: (list: List) => Nullable + * readonly listToVec: (list: List) => Vec + * readonly xor: Reduce + * readonly unpackPopFront: PopFront + * readonly norm: NormOp + * readonly cmp: (a: Vec) => (b: Vec) => Sign + * readonly unpackSplit: (len: bigint) => (u: Unpacked) => readonly[bigint, bigint] + * readonly unpackConcat: UnpackConcat + * readonly startsWith: (prefix: Vec) => (v: Vec) => boolean + * }} BitOrder */ -export type BitOrder = { - /** - * Retrieves the first unsigned integer of the specified length from the given vector. - * - * @param len - The number of bits to read from the start of the vector. - * @returns A function that takes a vector and returns the extracted unsigned integer. - * - * @example - * - * ```js - * const vector = vec(8n)(0xF5n) - * - * const resultL0 = lsb.front(4n)(vector) // 5n - * const resultL1 = lsb.front(16n)(vector) // 0xF5n - * - * const resultM0 = msb.front(4n)(vector) // 0xFn - * const resultM1 = msb.front(16n)(vector) // 0xF500n - * ``` - */ - readonly front: (len: bigint) => (v: Vec) => bigint - /** - * Removes a specified number of bits from the start of the given vector. - * - * @param len - The number of bits to remove from the vector. - * @returns A function that takes a vector and returns the remaining vector. - * - * @example - * - * ```js - * const v = vec(16n)(0x3456n) - * - * const rL0 = lsb.removeFront(4n)(v) // uint(rL0) is 0x345n - * const rL1 = lsb.removeFront(24n)(v) // rL1 === empty - * - * const rM0 = msb.removeFront(4n)(v) // uint(rM0) is 0x456n - * const rM1 = msb.removeFront(24n)(v) // rM1 === empty - * ``` - */ - readonly removeFront: (len: bigint) => (v: Vec) => Vec - /** - * Removes a specified number of bits from the start of the vector and returns - * the removed bits and the remaining vector. - * - * @param len - The number of bits to remove from the vector. - * @returns A function that takes a vector and returns - * a tuple containing the removed bits as an unsigned integer and the remaining vector. - * - * @example - * - * ```js - * const vector = vec(8n)(0xF5n) - * - * const [uL0, rL0] = lsb.popFront(4n)(vector) // [5n, uint(rL0) is 0xFn] - * const [uL1, rL1] = lsb.popFront(16n)(vector) // [0xF5n, rL1 === empty] - * - * const [uM0, rM0] = msb.popFront(4n)(vector) // [0xFn, uint(rM0) is 0x5n] - * const [uM1, rM1] = msb.popFront(16n)(vector) // [0xF500n, rM1 === empty] - * ``` - */ - readonly popFront: PopFront - /** - * Concatenates two vectors. - * - * @returns A function that takes a second vector and returns the concatenated vector. - * - * @example - * - * ```js - * const u8 = vec(8n) - * const a = u8(0x45n) - * const b = u8(0x89n) - * - * const abL = lsb.concat(a)(b) // uint(abL) is 0x8945n - * const abM = msb.concat(a)(b) // uint(abM) is 0x4589n - * ``` - */ - readonly concat: Reduce - /** - * Folds a list of vectors into a single vector in this bit order, like - * `listToVec`, but returns `null` instead of throwing when the combined - * length would exceed `maxLength`. - */ - readonly tryListToVec: (list: List) => Nullable - /** - * Folds a list of vectors into a single vector in this bit order. - * - * Unlike `concat`, which joins exactly two vectors, this joins a whole list. - * - * @returns The concatenation of every vector in the list, or `empty` when the - * list is empty. - */ - readonly listToVec: (list: List) => Vec - /** - * Computes the bitwise exclusive OR of two vectors after normalizing their lengths. - * - * @returns A function that takes a second vector and returns the XOR result. - */ - readonly xor: Reduce - readonly unpackPopFront: PopFront - readonly norm: NormOp - /** - * Lexically compares two vectors. - * - * a < b => -1 - * a > b => 1 - * a === b => 0 - */ - readonly cmp: (a: Vec) => (b: Vec) => Sign - readonly unpackSplit: (len: bigint) => (u: Unpacked) => readonly[bigint, bigint] - readonly unpackConcat: UnpackConcat - readonly startsWith: (prefix: Vec) => (v: Vec) => boolean -} -type Base = { - readonly front: (len: bigint) => (v: Vec) => bigint - readonly removeFront: (len: bigint) => (v: Vec) => Vec - readonly norm: NormOp - readonly uintCmp: (a: bigint) => (b: bigint) => Sign - readonly unpackSplit: (len: bigint) => (u: Unpacked) => readonly[bigint, bigint] - readonly unpackConcatUint: (a: Unpacked) => (b: Unpacked) => bigint -} +/** + * @typedef {{ + * readonly front: (len: bigint) => (v: Vec) => bigint + * readonly removeFront: (len: bigint) => (v: Vec) => Vec + * readonly norm: NormOp + * readonly uintCmp: (a: bigint) => (b: bigint) => Sign + * readonly unpackSplit: (len: bigint) => (u: Unpacked) => readonly[bigint, bigint] + * readonly unpackConcatUint: (a: Unpacked) => (b: Unpacked) => bigint + * }} Base + */ -const unpackEmpty = { length: 0n, uint: 0n } as const +const unpackEmpty = /** @type {const} */{ length: 0n, uint: 0n } -type UnpackConcat = (a: Unpacked) => (b: Unpacked) => Unpacked +/** @typedef {(a: Unpacked) => (b: Unpacked) => Unpacked} UnpackConcat */ -type ListToVecState = { - readonly len: bigint - readonly stack: readonly Unpacked[] -} +/** + * @typedef {{ + * readonly len: bigint + * readonly stack: readonly Unpacked[] + * }} ListToVecState + */ -type ListToVecOp = Accumulator +/** @typedef {Accumulator} ListToVecOp */ -const listToVecOp = - (unpackConcat: UnpackConcat): ListToVecOp => -({ +/** @type {(unpackConcat: UnpackConcat) => ListToVecOp} */ +const listToVecOp = unpackConcat => ({ init: { len: 0n, stack: [] }, update: (v, {len, stack}) => { len += v.length @@ -356,35 +298,44 @@ const listToVecOp = * This is the bit-vector analogue of a builder that accumulates appended pieces * and materializes the combined result on demand, such as `StringBuilder` * (Java, C#) or `strings.Builder` (Go). + * + * @param {UnpackConcat} unpackConcat */ -const unpackListToVec = (unpackConcat: UnpackConcat) => tryFold(listToVecOp(unpackConcat)) +const unpackListToVec = unpackConcat => tryFold(listToVecOp(unpackConcat)) -const bo = ({ front, removeFront, norm, uintCmp, unpackSplit, unpackConcatUint }: Base): BitOrder => { - const unpackPopFront = (len: bigint) => { +/** @type {(base: Base) => BitOrder} */ +const bo = ({ front, removeFront, norm, uintCmp, unpackSplit, unpackConcatUint }) => { + /** @param {bigint} len */ + const unpackPopFront = len => { const m = mask(len) const us = unpackSplit(len) - return (v: Unpacked) => { + /** @param {Unpacked} v */ + return v => { const [uint, rest] = us(v) - return [uint & m, { length: v.length - len, uint: rest }] as const + return /** @type {const} */([uint & m, { length: v.length - len, uint: rest }]) } } - const unpackConcat: UnpackConcat = a => b => ({ + /** @type {UnpackConcat} */ + const unpackConcat = a => b => ({ length: a.length + b.length, uint: unpackConcatUint(a)(b) }) - const popFront: PopFront = len => { + /** @type {PopFront} */ + const popFront = len => { const f = unpackPopFront(len) return v => { const [uint, u] = f(unpack(v)) return [uint, pack(u)] } } - const concat: Reduce = a => b => { + /** @type {Reduce} */ + const concat = a => b => { const au = unpack(a) const bu = unpack(b) return pack(unpackConcat(au)(bu)) } - const tryListToVec = (list: List) => + /** @param {List} list */ + const tryListToVec = list => unpackListToVec(unpackConcat)(map(unpack)(list)) return { front, @@ -414,7 +365,9 @@ const bo = ({ front, removeFront, norm, uintCmp, unpackSplit, unpackConcatUint } } } -const lsbUnpackConcatUint = ({ uint: a, length }: Unpacked) => ({ uint: b }: Unpacked) => (b << length) | a +const lsbUnpackConcatUint = + (/** @type {Unpacked} */{ uint: a, length }) => + (/** @type {Unpacked} */{ uint: b }) => (b << length) | a /** * Implements operations for handling vectors in a least-significant-bit (LSb) first order. @@ -423,7 +376,7 @@ const lsbUnpackConcatUint = ({ uint: a, length }: Unpacked) => ({ uint: b }: Unp * * Usually associated with Little-Endian (LE) byte order. */ -export const lsb: BitOrder = bo({ +export const lsb = bo({ front: len => { const m = mask(len) return v => uint(v) & m @@ -449,7 +402,7 @@ export const lsb: BitOrder = bo({ * * Usually associated with Big-Endian (BE) byte order. */ -export const msb: BitOrder = bo({ +export const msb = bo({ front: len => { const m = mask(len) return v => { @@ -473,30 +426,29 @@ export const msb: BitOrder = bo({ * bit order, like `u8ListToVec`, but returns `null` instead of throwing when the * result would exceed `maxLength`. * - * @param bo The bit order for the conversion - * @param list The list of unsigned 8-bit integers to be converted. - * @returns The resulting vector, or `null` if it would exceed `maxLength`. + * @type {(_: BitOrder) => (list: List) => Nullable} */ -export const tryU8ListToVec = ({ unpackConcat }: BitOrder) => (list: List): Nullable => +export const tryU8ListToVec = ({ unpackConcat }) => list => unpackListToVec(unpackConcat)( - map((b: number): Unpacked => ({ length: 8n, uint: BigInt(b) }))(list)) + map(/** @type {(_: number) => Unpacked} */b => ({ length: 8n, uint: BigInt(b) }))(list)) /** * Converts a list of unsigned 8-bit integers to a bit vector using the provided bit order. * - * @param bo The bit order for the conversion + * @param {BitOrder} bo The bit order for the conversion * @param list The list of unsigned 8-bit integers to be converted. * @returns The resulting vector based on the provided bit order. */ -export const u8ListToVec = (bo: BitOrder) => +export const u8ListToVec = bo => mapUnwrap(tryU8ListToVec(bo)) -const unpackChunkList = ({ unpackSplit }: BitOrder) => (n: bigint): (u: Unpacked) => Thunk => { +/** @type {({ unpackSplit }: BitOrder) => (n: bigint) => (u: Unpacked) => Thunk} */ +const unpackChunkList = ({ unpackSplit }) => n => { const divUpN2 = divUp(n << 1n) return u => { if (u.length === 0n) { return () => null } - type Stack = readonly[Unpacked, Stack | undefined] - const f = (stack: Stack) => () => { + /** @typedef {readonly[Unpacked, Stack | undefined]} Stack */ + const f = (/** @type {Stack} */stack) => () => { while (true) { const [first, rest] = stack const { length } = first @@ -516,39 +468,41 @@ const unpackChunkList = ({ unpackSplit }: BitOrder) => (n: bigint): (u: Unpacked } } -const mappedChunkList = (g: (i: I) => Unpacked) => (f: (u: Unpacked) => O) => - (bo: BitOrder) => (n: bigint): (i: I) => Thunk => { - const ucl = unpackChunkList(bo)(n) - const mf = map(f) - return i => mf(ucl(g(i))) - } +/** + * @type {(g: (i: I) => Unpacked) => + * (f: (u: Unpacked) => O) => + * (bo: BitOrder) => + * (n: bigint) => + * (i: I) => + * Thunk + * } + */ +const mappedChunkList = g => f => bo => n => { + const ucl = unpackChunkList(bo)(n) + const mf = map(f) + return i => mf(ucl(g(i))) +} /** * Chunks an unpacked vector into fixed-size pieces of `n` bits using the provided bit order, * returning each chunk as an unsigned integer. * The last chunk may be smaller than `n` bits if the vector length is not a multiple of `n`. * - * @param bitOrder The bit order for the conversion. - * @param n The chunk size in bits. - * @param u The unpacked vector to be chunked. - * @returns A thunk that produces a list of unsigned integers, each representing one chunk. + * @type {(bo: BitOrder) => (n: bigint) => (u: Unpacked) => Thunk} */ -export const uintChunkList: (bo: BitOrder) => (n: bigint) => (u: Unpacked) => Thunk - = mappedChunkList(identity)(unpackedUint) +export const uintChunkList + = mappedChunkList(identity/**/)(unpackedUint) /** * Chunks a bit vector into fixed-size pieces of `n` bits using the provided bit order. * The last chunk may be smaller than `n` bits if the vector length is not a multiple of `n`. * - * @param bitOrder The bit order for the conversion. - * @param n The chunk size in bits. - * @param v The vector to be chunked. - * @returns A thunk that produces a list of bit vectors, each representing one chunk. + * @type {(bo: BitOrder) => (n: bigint) => (v: Vec) => Thunk} */ -export const chunkList: (bo: BitOrder) => (n: bigint) => (v: Vec) => Thunk - = mappedChunkList(unpack)(pack) +export const chunkList = mappedChunkList(unpack)(pack) -const vecToU8 = ({ unpackSplit }: BitOrder): (chunk: Vec) => number => { +/** @type {({ unpackSplit }: BitOrder) => (chunk: Vec) => number} */ +const vecToU8 = ({ unpackSplit }) => { const unpackSplit8 = unpackSplit(8n) return chunk => { const u = unpack(chunk) @@ -559,18 +513,23 @@ const vecToU8 = ({ unpackSplit }: BitOrder): (chunk: Vec) => number => { /** * Converts a bit vector to a list of unsigned 8-bit integers based on the provided bit order. * - * @param bitOrder The bit order for the conversion. - * @param v The vector to be converted. - * @returns A thunk that produces a list of unsigned 8-bit integers. + * @type {(bo: BitOrder) => (v: Vec) => Thunk} */ -export const u8List = (bo: BitOrder) => (v: Vec): Thunk => +export const u8List = bo => v => map(vecToU8(bo))(chunkList(bo)(8n)(v)) /** * Repeats a vector to create a padded block of the desired length. + * + * @type {Fold} */ -export const repeat: Fold = +export const repeat = mRepeat({ identity: empty, operation: lsb.concat }) -export const isVec = (v: Vec | T): v is Vec => - typeof v === 'bigint' +export const isVec = + /** + * @template T + * @param {Vec | T} v + * @return {v is Vec} + */ + v => typeof v === 'bigint' diff --git a/fjs/types/bit_vec/proof.f.ts b/fjs/types/bit_vec/proof.f.ts index e91954bfb..41c2209c4 100644 --- a/fjs/types/bit_vec/proof.f.ts +++ b/fjs/types/bit_vec/proof.f.ts @@ -2,7 +2,7 @@ import { assert, assertEq } from '../../asserts/module.f.mjs' import { mask } from '../bigint/module.f.mjs' import type { Sign } from '../function/compare/module.f.mjs' import { asBase, asNominal } from '../nominal/module.f.mjs' -import { length, empty, uint, type Vec, vec, lsb, msb, type BitOrder, repeat, vec8, maxLength, u8ListToVec, tryU8ListToVec, u8List, chunkList, fromSentinel } from './module.f.ts' +import { length, empty, uint, type Vec, vec, lsb, msb, type BitOrder, repeat, vec8, maxLength, u8ListToVec, tryU8ListToVec, u8List, chunkList, fromSentinel } from './module.f.mjs' import { repeat as listRepeat, toArray, type List } from '../list/module.f.mjs' const unsafeVec = (a: bigint): Vec => asNominal(a) diff --git a/fjs/types/uint8array/module.f.ts b/fjs/types/uint8array/module.f.ts index 985fb90cd..e03edecff 100644 --- a/fjs/types/uint8array/module.f.ts +++ b/fjs/types/uint8array/module.f.ts @@ -11,7 +11,7 @@ */ import { assert, assertNotNullish } from '../../asserts/module.f.mjs' import { utf8, utf8ToString } from '../../text/module.f.ts' -import { maxLengthBytes, msb, tryU8ListToVec, u8List, u8ListToVec, type Vec } from '../bit_vec/module.f.ts' +import { maxLengthBytes, msb, tryU8ListToVec, u8List, u8ListToVec, type Vec } from '../bit_vec/module.f.mjs' import { compose } from '../function/module.f.mjs' import { flat, fromArrayLike, iterable, map, type List } from '../list/module.f.mjs' diff --git a/fjs/types/uint8array/proof.f.ts b/fjs/types/uint8array/proof.f.ts index 86bd1b782..64314cf3c 100644 --- a/fjs/types/uint8array/proof.f.ts +++ b/fjs/types/uint8array/proof.f.ts @@ -1,4 +1,4 @@ -import { maxLength, maxLengthBytes, vec } from '../bit_vec/module.f.ts' +import { maxLengthBytes, vec } from '../bit_vec/module.f.mjs' import { toVec, fromVec, listToVec, decodeUtf8, encodeUtf8 } from './module.f.ts' import { strictEqual } from '../function/operator/module.f.mjs' import { equal, fromArrayLike } from '../list/module.f.mjs' diff --git a/fjs/website/module.f.ts b/fjs/website/module.f.ts index 34693a4bd..67030cbbb 100644 --- a/fjs/website/module.f.ts +++ b/fjs/website/module.f.ts @@ -6,7 +6,7 @@ import { htmlUtf8 } from '../media/html/module.f.ts' import { writeFile, type WriteFile } from '../effects/node/module.f.ts' import { pure, step, type Effect } from '../effects/module.f.ts' -import type { Vec } from '../types/bit_vec/module.f.ts' +import type { Vec } from '../types/bit_vec/module.f.mjs' const html: Vec = htmlUtf8()( ['a',