functionalscript 0.29.1 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fs/asn.1/module.f.js +18 -22
- package/fs/asn.1/proof.f.d.ts +5 -0
- package/fs/asn.1/proof.f.js +38 -2
- package/fs/base64/module.f.d.ts +9 -0
- package/fs/base64/module.f.js +60 -0
- package/fs/base64/proof.f.d.ts +11 -0
- package/fs/base64/proof.f.js +117 -0
- package/fs/base_n/module.f.d.ts +44 -0
- package/fs/base_n/module.f.js +54 -0
- package/fs/base_n/proof.f.d.ts +10 -0
- package/fs/base_n/proof.f.js +86 -0
- package/fs/bnf/data/module.f.d.ts +4 -9
- package/fs/bnf/data/module.f.js +4 -3
- package/fs/bnf/module.f.d.ts +3 -4
- package/fs/bnf/module.f.js +3 -2
- package/fs/bnf/proof.f.d.ts +9 -0
- package/fs/bnf/proof.f.js +98 -1
- package/fs/cas/mcp/module.f.d.ts +40 -0
- package/fs/cas/mcp/module.f.js +223 -0
- package/fs/cas/mcp/proof.f.d.ts +30 -0
- package/fs/cas/mcp/proof.f.js +310 -0
- package/fs/cas/module.f.d.ts +9 -3
- package/fs/cas/module.f.js +104 -69
- package/fs/cas/proof.f.d.ts +2 -0
- package/fs/cas/proof.f.js +30 -1
- package/fs/cbase32/module.f.d.ts +1 -1
- package/fs/cbase32/module.f.js +19 -40
- package/fs/cbase32/proof.f.d.ts +1 -0
- package/fs/cbase32/proof.f.js +15 -0
- package/fs/ci/bun/module.f.d.ts +2 -2
- package/fs/ci/bun/module.f.js +7 -14
- package/fs/ci/common/module.f.d.ts +3 -1
- package/fs/ci/common/module.f.js +9 -2
- package/fs/ci/config/module.f.d.ts +7 -5
- package/fs/ci/config/module.f.js +11 -5
- package/fs/ci/deno/module.f.d.ts +1 -1
- package/fs/ci/deno/module.f.js +7 -5
- package/fs/ci/module.f.d.ts +6 -3
- package/fs/ci/module.f.js +24 -54
- package/fs/ci/node/module.f.d.ts +3 -3
- package/fs/ci/node/module.f.js +30 -26
- package/fs/ci/playwright/module.f.js +1 -1
- package/fs/ci/proof.f.d.ts +6 -7
- package/fs/ci/proof.f.js +63 -36
- package/fs/ci/rust/module.f.d.ts +2 -1
- package/fs/ci/rust/module.f.js +33 -16
- package/fs/cli/module.f.d.ts +3 -1
- package/fs/cli/module.f.js +22 -12
- package/fs/cli/proof.f.d.ts +5 -0
- package/fs/cli/proof.f.js +76 -0
- package/fs/crypto/hmac/proof.f.d.ts +1 -0
- package/fs/crypto/hmac/proof.f.js +8 -0
- package/fs/crypto/secp/proof.f.d.ts +1 -0
- package/fs/crypto/secp/proof.f.js +10 -0
- package/fs/crypto/sign/module.f.js +1 -4
- package/fs/dev/module.f.d.ts +5 -3
- package/fs/dev/module.f.js +13 -2
- package/fs/dev/package_json/proof.f.d.ts +1 -0
- package/fs/dev/package_json/proof.f.js +5 -0
- package/fs/dev/proof.f.d.ts +1 -0
- package/fs/dev/proof.f.js +12 -1
- package/fs/djs/ast/module.f.d.ts +1 -1
- package/fs/djs/ast/proof.f.d.ts +5 -0
- package/fs/djs/ast/proof.f.js +17 -0
- package/fs/djs/module.f.d.ts +1 -1
- package/fs/djs/module.f.js +2 -3
- package/fs/djs/serializer/module.f.js +24 -11
- package/fs/djs/transpiler/module.f.js +3 -4
- package/fs/effects/memory/module.f.d.ts +37 -0
- package/fs/effects/memory/module.f.js +24 -0
- package/fs/effects/memory/proof.f.d.ts +6 -0
- package/fs/effects/memory/proof.f.js +64 -0
- package/fs/effects/mock/module.f.d.ts +7 -2
- package/fs/effects/mock/module.f.js +12 -8
- package/fs/effects/module.d.ts +1 -1
- package/fs/effects/module.f.d.ts +41 -0
- package/fs/effects/module.f.js +25 -0
- package/fs/effects/module.js +6 -7
- package/fs/effects/node/memory/module.d.ts +20 -0
- package/fs/effects/node/memory/module.js +44 -0
- package/fs/effects/node/memory/proof.d.ts +10 -0
- package/fs/effects/node/memory/proof.js +35 -0
- package/fs/effects/node/module.d.ts +1 -1
- package/fs/effects/node/module.f.d.ts +54 -8
- package/fs/effects/node/module.f.js +55 -4
- package/fs/effects/node/module.js +166 -135
- package/fs/effects/node/proof.f.d.ts +10 -0
- package/fs/effects/node/proof.f.js +88 -21
- package/fs/effects/node/virtual/module.f.d.ts +6 -0
- package/fs/effects/node/virtual/module.f.js +48 -16
- package/fs/effects/node/virtual/proof.f.d.ts +17 -0
- package/fs/effects/node/virtual/proof.f.js +79 -0
- package/fs/effects/proof.f.d.ts +5 -0
- package/fs/effects/proof.f.js +54 -34
- package/fs/emergent_testing/module.f.d.ts +6 -1
- package/fs/emergent_testing/module.f.js +8 -3
- package/fs/emergent_testing/proof.f.d.ts +11 -0
- package/fs/emergent_testing/proof.f.js +52 -16
- package/fs/fjs/module.f.js +2 -2
- package/fs/fjs/proof.f.d.ts +8 -0
- package/fs/fjs/proof.f.js +39 -0
- package/fs/fsc/module.f.d.ts +5 -0
- package/fs/fsc/module.f.js +17 -27
- package/fs/fsc/proof.f.d.ts +8 -0
- package/fs/fsc/proof.f.js +48 -2
- package/fs/fsm/module.f.d.ts +2 -3
- package/fs/fsm/module.f.js +1 -1
- package/fs/html/module.f.d.ts +2 -3
- package/fs/html/module.f.js +7 -6
- package/fs/html/proof.f.d.ts +1 -0
- package/fs/html/proof.f.js +7 -0
- package/fs/js/tokenizer/module.f.js +1 -1
- package/fs/js/tokenizer/proof.f.js +7 -0
- package/fs/json/module.f.d.ts +9 -2
- package/fs/json/module.f.js +9 -7
- package/fs/json/parser/module.f.js +4 -6
- package/fs/json/parser/proof.f.js +19 -10
- package/fs/json/proof.f.d.ts +2 -1
- package/fs/json/proof.f.js +33 -6
- package/fs/json/rpc/module.f.d.ts +5 -0
- package/fs/json/rpc/module.f.js +16 -11
- package/fs/json/schema/module.f.d.ts +15 -14
- package/fs/json/schema/proof.f.d.ts +3 -0
- package/fs/json/schema/proof.f.js +16 -1
- package/fs/mcp/module.f.d.ts +103 -5
- package/fs/mcp/module.f.js +139 -2
- package/fs/mcp/proof.f.d.ts +34 -0
- package/fs/mcp/proof.f.js +207 -0
- package/fs/mcp/stdio/module.f.d.ts +39 -0
- package/fs/mcp/stdio/module.f.js +54 -0
- package/fs/mcp/stdio/proof.f.d.ts +10 -0
- package/fs/mcp/stdio/proof.f.js +92 -0
- package/fs/mime/module.f.d.ts +39 -0
- package/fs/mime/module.f.js +78 -0
- package/fs/mime/proof.f.d.ts +15 -0
- package/fs/mime/proof.f.js +30 -0
- package/fs/path/module.f.d.ts +8 -0
- package/fs/path/module.f.js +10 -3
- package/fs/path/proof.f.d.ts +1 -0
- package/fs/path/proof.f.js +40 -2
- package/fs/text/sgr/proof.f.js +30 -2
- package/fs/text/utf8/module.f.d.ts +7 -0
- package/fs/text/utf8/module.f.js +85 -31
- package/fs/text/utf8/proof.f.d.ts +1 -0
- package/fs/text/utf8/proof.f.js +60 -1
- package/fs/types/bigfloat/module.f.d.ts +3 -0
- package/fs/types/bigfloat/module.f.js +30 -31
- package/fs/types/bigint/module.f.d.ts +24 -2
- package/fs/types/bigint/module.f.js +30 -2
- package/fs/types/bigint/proof.f.d.ts +7 -0
- package/fs/types/bigint/proof.f.js +47 -16
- package/fs/types/bit_vec/module.f.d.ts +18 -0
- package/fs/types/bit_vec/module.f.js +18 -0
- package/fs/types/bit_vec/proof.f.d.ts +1 -0
- package/fs/types/bit_vec/proof.f.js +13 -1
- package/fs/types/function/operator/proof.f.d.ts +2 -0
- package/fs/types/function/operator/proof.f.js +20 -2
- package/fs/types/list/module.f.js +1 -4
- package/fs/types/list/proof.f.d.ts +1 -1
- package/fs/types/list/proof.f.js +14 -6
- package/fs/types/map/proof.f.d.ts +1 -0
- package/fs/types/map/proof.f.js +10 -1
- package/fs/types/nibble_set/module.f.d.ts +13 -0
- package/fs/types/nibble_set/module.f.js +16 -0
- package/fs/types/object/module.f.d.ts +12 -8
- package/fs/types/object/module.f.js +9 -2
- package/fs/types/object/proof.f.d.ts +14 -0
- package/fs/types/object/proof.f.js +4 -0
- package/fs/types/ordered_map/proof.f.d.ts +1 -0
- package/fs/types/ordered_map/proof.f.js +39 -79
- package/fs/types/phantom/module.f.d.ts +22 -0
- package/fs/types/phantom/module.f.js +11 -0
- package/fs/types/prime_field/proof.f.d.ts +7 -0
- package/fs/types/prime_field/proof.f.js +63 -122
- package/fs/types/rtti/common/module.f.d.ts +4 -4
- package/fs/types/rtti/common/module.f.js +1 -1
- package/fs/types/rtti/module.f.d.ts +2 -3
- package/fs/types/rtti/parse/module.f.js +0 -1
- package/fs/types/rtti/ts/module.f.d.ts +26 -32
- package/fs/types/rtti/ts/module.f.js +2 -2
- package/fs/types/rtti/ts/proof.f.js +3 -3
- package/fs/types/rtti/validate/module.f.js +0 -1
- package/fs/types/sorted_list/module.f.d.ts +6 -0
- package/fs/types/sorted_list/module.f.js +11 -0
- package/fs/types/sorted_set/module.f.js +2 -8
- package/fs/types/ts/module.f.d.ts +1 -1
- package/fs/types/ts/module.f.js +3 -1
- package/fs/types/ts/proof.f.js +3 -2
- package/fs/website/proof.f.d.ts +1 -0
- package/fs/website/proof.f.js +8 -1
- package/package.json +3 -3
|
@@ -26,7 +26,7 @@ import type { Primitive, Unknown } from '../../../djs/module.f.ts';
|
|
|
26
26
|
import { type Info0, type Primitive0, type Struct, type Tag1, type Tuple, type Type } from '../module.f.ts';
|
|
27
27
|
import { type Error, type Result as CommonResult } from '../../result/module.f.ts';
|
|
28
28
|
import type { Ts } from '../ts/module.f.ts';
|
|
29
|
-
import { type
|
|
29
|
+
import { type StringMap } from '../../object/module.f.ts';
|
|
30
30
|
/** A path to a sub-value within the validated structure. Each step is an object key or stringified array index. */
|
|
31
31
|
export type Path = readonly string[];
|
|
32
32
|
/** Detailed validation failure: the offending `path` plus a short `message`. */
|
|
@@ -41,7 +41,7 @@ export type Validate<T extends Type> = (value: Unknown) => Result<T>;
|
|
|
41
41
|
/** Builds an error result with empty path and the given message. */
|
|
42
42
|
export declare const verror: (message: string) => Error<ValidationError>;
|
|
43
43
|
/** Prepends `key` to the error's path, used to build the path bottom-up. */
|
|
44
|
-
export declare const prependPath: (key: string, r: Error<ValidationError>) => Error<ValidationError>;
|
|
44
|
+
export declare const prependPath: (key: string, [, r]: Error<ValidationError>) => Error<ValidationError>;
|
|
45
45
|
/** Validates a `Tag0` primitive schema using `typeof`. */
|
|
46
46
|
export declare const primitive0Validate: <K extends Primitive0, T extends Info0<K>>(tag: K) => Validate<T>;
|
|
47
47
|
/**
|
|
@@ -69,11 +69,11 @@ export type Visitor<R> = {
|
|
|
69
69
|
/** Type guard narrowing `Unknown` to a specific container type `C`. */
|
|
70
70
|
export type IsContainer<C extends Unknown> = (value: Unknown) => value is C;
|
|
71
71
|
/** Maps a `Tag1` to its runtime container type. */
|
|
72
|
-
export type Container<K extends Tag1> = K extends 'array' ? ReadonlyArray<Unknown> :
|
|
72
|
+
export type Container<K extends Tag1> = K extends 'array' ? ReadonlyArray<Unknown> : StringMap<string, Unknown>;
|
|
73
73
|
/** `IsContainer` guard for arrays, shared by `validate` and `parse`. */
|
|
74
74
|
export declare const isArray: IsContainer<ReadonlyArray<Unknown>>;
|
|
75
75
|
/** `IsContainer` guard for records/structs, shared by `validate` and `parse`. */
|
|
76
|
-
export declare const isObject: IsContainer<
|
|
76
|
+
export declare const isObject: IsContainer<StringMap<string, Unknown>>;
|
|
77
77
|
/**
|
|
78
78
|
* Visits a schema `Type` by dispatching to the matching handler in `v`.
|
|
79
79
|
*
|
|
@@ -5,7 +5,7 @@ import { isObject as commonIsObject } from "../../object/module.f.js";
|
|
|
5
5
|
/** Builds an error result with empty path and the given message. */
|
|
6
6
|
export const verror = (message) => error({ path: [], message });
|
|
7
7
|
/** Prepends `key` to the error's path, used to build the path bottom-up. */
|
|
8
|
-
export const prependPath = (key, r) => error({ path: [key, ...r
|
|
8
|
+
export const prependPath = (key, [, r]) => error({ path: [key, ...r.path], message: r.message });
|
|
9
9
|
/** Validates a `Tag0` primitive schema using `typeof`. */
|
|
10
10
|
export const primitive0Validate = (tag) => value => typeof value === tag ? ok(value) : verror('unexpected value');
|
|
11
11
|
/**
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { type Includes } from '../array/module.f.ts';
|
|
2
|
+
import type { StringMap } from '../object/module.f.ts';
|
|
2
3
|
/** A constant schema: a primitive literal, a struct object, or a tuple. */
|
|
3
4
|
export type Const = null | boolean | number | string | undefined | bigint | {
|
|
4
5
|
readonly [K in string]: Type;
|
|
5
6
|
} | readonly Type[];
|
|
6
7
|
export type ConstObject = Struct | Tuple;
|
|
7
8
|
/** A struct schema: plain object whose values are nested `Type`s. */
|
|
8
|
-
export type Struct =
|
|
9
|
-
readonly [K in string]: Type;
|
|
10
|
-
};
|
|
9
|
+
export type Struct = StringMap<string, Type>;
|
|
11
10
|
/** A tuple schema: readonly array whose elements are nested `Type`s. */
|
|
12
11
|
export type Tuple = readonly Type[];
|
|
13
12
|
declare const primitive0List: readonly ["bigint", "boolean", "number", "string"];
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
*/
|
|
29
29
|
import {} from "../module.f.js";
|
|
30
30
|
import { ok } from "../../result/module.f.js";
|
|
31
|
-
import {} from "../../object/module.f.js";
|
|
32
31
|
import { find, map as listMap } from "../../list/module.f.js";
|
|
33
32
|
import { constPrimitiveValidate, isArray, isObject, prependPath, primitive0Validate, verror, visit, } from "../common/module.f.js";
|
|
34
33
|
export {} from "../common/module.f.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Tag0, Tag1, Struct, Tuple, Type } from '../module.f.ts';
|
|
2
|
-
import type {
|
|
2
|
+
import type { phantomKey } from '../../phantom/module.f.ts';
|
|
3
|
+
import type { StringMap } from '../../object/module.f.ts';
|
|
3
4
|
/**
|
|
4
5
|
* The set of primitive literal types representable as rtti `Const` values.
|
|
5
6
|
* Defined here rather than imported from `djs` to keep rtti free of djs dependencies
|
|
@@ -19,20 +20,20 @@ export type Unknown = Primitive | Array | Object;
|
|
|
19
20
|
export type Array = readonly Unknown[];
|
|
20
21
|
/** A read-only record of {@link Unknown} values. */
|
|
21
22
|
export type Object = {
|
|
22
|
-
readonly [k in string]
|
|
23
|
+
readonly [k in string]?: Unknown;
|
|
23
24
|
};
|
|
24
25
|
/** Maps a `Tag0` to its TypeScript type. */
|
|
25
26
|
export type Info0Ts<T extends Tag0> = T extends 'boolean' ? boolean : T extends 'number' ? number : T extends 'string' ? string : T extends 'bigint' ? bigint : T extends 'unknown' ? Unknown : never;
|
|
26
27
|
/** Maps a `Const` schema to its TypeScript type. */
|
|
27
|
-
export type ConstTs<T> = T extends readonly Type[] ? TupleTs<T> : T extends
|
|
28
|
-
readonly [k in string]: Type;
|
|
29
|
-
} ? StructTs<T> : T;
|
|
28
|
+
export type ConstTs<T> = T extends readonly Type[] ? TupleTs<T> : T extends StringMap<string, Type> ? StructTs<T> : T;
|
|
30
29
|
/** Maps a `Tag1` and inner type to its TypeScript type. */
|
|
31
30
|
export type Info1Ts<K extends Tag1, T extends Type> = K extends 'array' ? ArrayTs<T> : K extends 'record' ? RecordTs<T> : never;
|
|
32
31
|
/** Maps an array schema `T` to `readonly Ts<T>[]`. */
|
|
33
32
|
export type ArrayTs<T extends Type> = ReadonlyArray<Ts<T>>;
|
|
34
|
-
/** Maps a record schema `T` to `{ readonly[K in string]
|
|
35
|
-
export type RecordTs<T extends Type> =
|
|
33
|
+
/** Maps a record schema `T` to `{ readonly[K in string]?: Ts<T> }`. */
|
|
34
|
+
export type RecordTs<T extends Type> = {
|
|
35
|
+
readonly [K in string]?: Ts<T>;
|
|
36
|
+
};
|
|
36
37
|
/** Maps a tuple schema to a readonly tuple of resolved types. */
|
|
37
38
|
export type TupleTs<T extends Tuple> = {
|
|
38
39
|
readonly [K in keyof T]: Ts<T[K]>;
|
|
@@ -45,33 +46,26 @@ type RequiredFields<T extends Struct> = {
|
|
|
45
46
|
};
|
|
46
47
|
/** Maps a struct schema to a readonly object of resolved types, with optional fields for schemas that include `undefined`. */
|
|
47
48
|
export type StructTs<T extends Struct> = (keyof OptionalFields<T> extends never ? unknown : OptionalFields<T>) & (keyof RequiredFields<T> extends never ? unknown : RequiredFields<T>);
|
|
48
|
-
/**
|
|
49
|
-
* Private unique symbol used as the phantom key in WithOut.
|
|
50
|
-
* A symbol key is excluded from string index signatures ({ readonly [K in string]: Type }),
|
|
51
|
-
* so WithOut<Struct, Out> is valid for any Out regardless of whether Out extends Type.
|
|
52
|
-
*/
|
|
53
|
-
declare const withOutKey: unique symbol;
|
|
54
|
-
/**
|
|
55
|
-
* Attaches a phantom output type `Out` to a schema `S`.
|
|
56
|
-
*
|
|
57
|
-
* `Ts<WithOut<S, Out>>` short-circuits to `Out` via the `withOutKey` branch without
|
|
58
|
-
* recursing through the schema body — solving TS2589 for recursive struct schemas
|
|
59
|
-
* where `StructTs` would otherwise expand infinitely.
|
|
60
|
-
*
|
|
61
|
-
* The `withOutKey` field is phantom: it is `undefined` at runtime and only exists in the
|
|
62
|
-
* type system. Using a unique symbol as the key means it cannot conflict with struct
|
|
63
|
-
* schemas' string index signature (`{ readonly [K in string]: Type }`), so `WithOut`
|
|
64
|
-
* is valid for any schema `S`, not just thunks.
|
|
65
|
-
*/
|
|
66
|
-
export type WithOut<S, Out> = S & {
|
|
67
|
-
readonly [withOutKey]?: Out;
|
|
68
|
-
};
|
|
69
49
|
/**
|
|
70
50
|
* Converts a schema `Type` to its corresponding TypeScript type.
|
|
71
51
|
*
|
|
72
52
|
* - `Thunk` → evaluates the returned `Info` via `InfoTs`
|
|
73
53
|
* - `Const` → resolves via `ConstTs` (primitives map to themselves; structs/tuples recurse)
|
|
74
54
|
*
|
|
55
|
+
* **Recursive schemas and TS2589:** when a schema is self-referential, `StructTs` would
|
|
56
|
+
* expand infinitely and TypeScript raises TS2589. Break the cycle by annotating the
|
|
57
|
+
* schema value with `Phantom<typeof myThunk, MyType>` from `fs/types/phantom/module.f.ts`.
|
|
58
|
+
* `Ts<>` detects the phantom key and returns `MyType` directly without recursing:
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { type Phantom } from '../types/phantom/module.f.ts'
|
|
62
|
+
*
|
|
63
|
+
* type MyType = { readonly self?: MyType }
|
|
64
|
+
* const myThunk = () => ['const', myConst] as const
|
|
65
|
+
* export const my: Phantom<typeof myThunk, MyType> = myThunk
|
|
66
|
+
* // Ts<typeof my> → MyType
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
75
69
|
* @example
|
|
76
70
|
* ```ts
|
|
77
71
|
* type A = Ts<typeof string> // string
|
|
@@ -81,9 +75,9 @@ export type WithOut<S, Out> = S & {
|
|
|
81
75
|
* ```
|
|
82
76
|
*/
|
|
83
77
|
export type Ts<T extends Type> = unknown extends T ? Unknown : T extends {
|
|
84
|
-
readonly [
|
|
78
|
+
readonly [phantomKey]?: infer O;
|
|
85
79
|
} ? Exclude<O, undefined> : T extends () => infer I ? (I extends readonly ['const', infer C] ? ConstTs<C> : I extends readonly ['boolean'] ? boolean : I extends readonly ['number'] ? number : I extends readonly ['string'] ? string : I extends readonly ['bigint'] ? bigint : I extends readonly ['unknown'] ? Unknown : I extends readonly ['array', infer E extends Type] ? readonly Ts<E>[] : I extends readonly ['record', infer E extends Type] ? {
|
|
86
|
-
readonly [
|
|
80
|
+
readonly [k in string]?: Ts<E>;
|
|
87
81
|
} : I extends readonly ['or', ...infer A extends readonly Type[]] ? Ts<A[number]> : never) : ConstTs<T>;
|
|
88
82
|
/**
|
|
89
83
|
* Creates a printer that converts an RTTI schema `Type` to its TypeScript type expression as a string.
|
|
@@ -102,7 +96,7 @@ export type Ts<T extends Type> = unknown extends T ? Unknown : T extends {
|
|
|
102
96
|
* const toTs = printer()
|
|
103
97
|
* toTs(boolean) // 'boolean'
|
|
104
98
|
* toTs(array(number)) // 'readonly(number)[]'
|
|
105
|
-
* toTs(record(string)) // '{readonly[k
|
|
99
|
+
* toTs(record(string)) // '{readonly[k in string]?:string}'
|
|
106
100
|
* toTs(or(string, number)) // 'string|number'
|
|
107
101
|
* toTs(42) // '42'
|
|
108
102
|
* toTs('hello') // '"hello"'
|
|
@@ -111,7 +105,7 @@ export type Ts<T extends Type> = unknown extends T ? Unknown : T extends {
|
|
|
111
105
|
*
|
|
112
106
|
* const toTsMut = printer(true)
|
|
113
107
|
* toTsMut(array(number)) // '(number)[]'
|
|
114
|
-
* toTsMut(record(string)) // '{[k
|
|
108
|
+
* toTsMut(record(string)) // '{[k in string]?:string}'
|
|
115
109
|
* ```
|
|
116
110
|
*/
|
|
117
111
|
export declare const printer: (mut?: true) => (rtti: Type) => string;
|
|
@@ -25,7 +25,7 @@ import { primitive, union, printer as tsPrinter } from "../../ts/module.f.js";
|
|
|
25
25
|
* const toTs = printer()
|
|
26
26
|
* toTs(boolean) // 'boolean'
|
|
27
27
|
* toTs(array(number)) // 'readonly(number)[]'
|
|
28
|
-
* toTs(record(string)) // '{readonly[k
|
|
28
|
+
* toTs(record(string)) // '{readonly[k in string]?:string}'
|
|
29
29
|
* toTs(or(string, number)) // 'string|number'
|
|
30
30
|
* toTs(42) // '42'
|
|
31
31
|
* toTs('hello') // '"hello"'
|
|
@@ -34,7 +34,7 @@ import { primitive, union, printer as tsPrinter } from "../../ts/module.f.js";
|
|
|
34
34
|
*
|
|
35
35
|
* const toTsMut = printer(true)
|
|
36
36
|
* toTsMut(array(number)) // '(number)[]'
|
|
37
|
-
* toTsMut(record(string)) // '{[k
|
|
37
|
+
* toTsMut(record(string)) // '{[k in string]?:string}'
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
40
|
export const printer = (mut) => {
|
|
@@ -29,8 +29,8 @@ export const proof = {
|
|
|
29
29
|
union: () => eq(array(or(number, string)), 'readonly(number|string)[]'),
|
|
30
30
|
},
|
|
31
31
|
record: {
|
|
32
|
-
primitive: () => eq(record(string), '{readonly[k
|
|
33
|
-
nested: () => eq(record(record(number)), '{readonly[k
|
|
32
|
+
primitive: () => eq(record(string), '{readonly[k in string]?:string}'),
|
|
33
|
+
nested: () => eq(record(record(number)), '{readonly[k in string]?:{readonly[k in string]?:number}}'),
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
36
|
const: {
|
|
@@ -68,7 +68,7 @@ export const proof = {
|
|
|
68
68
|
mut: {
|
|
69
69
|
array: () => eqMut(array(number), '(number)[]'),
|
|
70
70
|
nestedArray: () => eqMut(array(array(boolean)), '((boolean)[])[]'),
|
|
71
|
-
record: () => eqMut(record(string), '{[k
|
|
71
|
+
record: () => eqMut(record(string), '{[k in string]?:string}'),
|
|
72
72
|
tuple: () => eqMut([12, true], '[12,true]'),
|
|
73
73
|
struct: () => eqMut({ a: number, b: string }, '{"a":number,"b":string}'),
|
|
74
74
|
},
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {} from "../module.f.js";
|
|
2
2
|
import { ok } from "../../result/module.f.js";
|
|
3
|
-
import {} from "../../object/module.f.js";
|
|
4
3
|
import { constPrimitiveValidate, isArray, isObject, prependPath, primitive0Validate, verror, visit, } from "../common/module.f.js";
|
|
5
4
|
export { constPrimitiveValidate, prependPath, primitive0Validate, verror, } from "../common/module.f.js";
|
|
6
5
|
const { entries } = Object;
|
|
@@ -14,7 +14,13 @@ type MergeReduce<T, S> = {
|
|
|
14
14
|
readonly reduceOp: ReduceOp<T, S>;
|
|
15
15
|
readonly tailReduce: TailReduce<T, S>;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Two-way sorted-list merge.
|
|
19
|
+
* `reduceOp` returns `[output, sign, nextState]` where sign `-1` advances `a`, `1` advances `b`, `0` advances both; `null` output skips emission.
|
|
20
|
+
* `tailReduce` drains the non-exhausted list with current state once the other ends.
|
|
21
|
+
*/
|
|
17
22
|
export declare const genericMerge: <T, S>({ reduceOp, tailReduce }: MergeReduce<T, S>) => (state: S) => (a: List<T>) => (b: List<T>) => List<T>;
|
|
18
23
|
export declare const merge: <T>(cmp: Cmp<T>) => (a: SortedList<T>) => (b: SortedList<T>) => SortedList<T>;
|
|
24
|
+
export declare const intersect: <T>(cmp: Cmp<T>) => (a: SortedList<T>) => (b: SortedList<T>) => SortedList<T>;
|
|
19
25
|
export declare const find: <T>(cmp: Cmp<T>) => (value: T) => (array: SortedArray<T>) => T | null;
|
|
20
26
|
export {};
|
|
@@ -6,6 +6,11 @@
|
|
|
6
6
|
import { bsearch } from "../function/compare/module.f.js";
|
|
7
7
|
import { next } from "../list/module.f.js";
|
|
8
8
|
import { identity } from "../function/module.f.js";
|
|
9
|
+
/**
|
|
10
|
+
* Two-way sorted-list merge.
|
|
11
|
+
* `reduceOp` returns `[output, sign, nextState]` where sign `-1` advances `a`, `1` advances `b`, `0` advances both; `null` output skips emission.
|
|
12
|
+
* `tailReduce` drains the non-exhausted list with current state once the other ends.
|
|
13
|
+
*/
|
|
9
14
|
export const genericMerge = ({ reduceOp, tailReduce }) => {
|
|
10
15
|
const f = (state) => (a) => (b) => () => {
|
|
11
16
|
const aResult = next(a);
|
|
@@ -33,6 +38,12 @@ const cmpReduce = (cmp) => () => a => b => {
|
|
|
33
38
|
return [sign === 1 ? b : a, sign, null];
|
|
34
39
|
};
|
|
35
40
|
const mergeTail = () => identity;
|
|
41
|
+
const tailReduce = () => () => null;
|
|
42
|
+
const intersectReduce = (cmp) => () => a => b => {
|
|
43
|
+
const sign = cmp(a)(b);
|
|
44
|
+
return [sign === 0 ? a : null, sign, null];
|
|
45
|
+
};
|
|
46
|
+
export const intersect = (cmp) => genericMerge({ reduceOp: intersectReduce(cmp), tailReduce })(null);
|
|
36
47
|
export const find = (cmp) => (value) => (array) => {
|
|
37
48
|
const cmpValue = cmp(value);
|
|
38
49
|
const pos = bsearch(array.length)(mid => cmpValue(array[mid]));
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { toArray } from "../list/module.f.js";
|
|
2
|
-
import { merge,
|
|
2
|
+
import { merge, intersect as listIntersect, find } from "../sorted_list/module.f.js";
|
|
3
3
|
export const union = cmp => a => b => toArray(merge(cmp)(a)(b));
|
|
4
|
-
export const intersect = cmp => a => b => toArray(
|
|
5
|
-
const tailReduce = () => () => null;
|
|
6
|
-
const intersectMerge = cmp => genericMerge({ reduceOp: intersectReduce(cmp), tailReduce })(null);
|
|
7
|
-
const intersectReduce = cmp => state => a => b => {
|
|
8
|
-
const sign = cmp(a)(b);
|
|
9
|
-
return [sign === 0 ? a : null, sign, state];
|
|
10
|
-
};
|
|
4
|
+
export const intersect = cmp => a => b => toArray(listIntersect(cmp)(a)(b));
|
|
11
5
|
export const has = cmp => value => set => find(cmp)(value)(set) === value;
|
|
@@ -14,7 +14,7 @@ export type Printer = {
|
|
|
14
14
|
readonly struct: (fields: readonly (readonly [string, string])[]) => string;
|
|
15
15
|
/** Emits an array type: `readonly(T)[]` or `(T)[]` when mutable. */
|
|
16
16
|
readonly array: (type: string) => string;
|
|
17
|
-
/** Emits an index-signature record type: `{readonly[k
|
|
17
|
+
/** Emits an index-signature record type: `{readonly[k in string]?:T}` or `{[k in string]?:T}` when mutable. */
|
|
18
18
|
readonly record: (type: string) => string;
|
|
19
19
|
};
|
|
20
20
|
/** Creates a `Printer`. Pass `true` to emit mutable (non-`readonly`) types. */
|
package/fs/types/ts/module.f.js
CHANGED
|
@@ -7,7 +7,9 @@ export const printer = (mut) => {
|
|
|
7
7
|
tuple: (mut ? complex('[', ']') : complex('readonly[', ']')),
|
|
8
8
|
struct: (fields) => structX(fields.map(([k, v]) => `${ro}${JSON.stringify(k)}:${v}`)),
|
|
9
9
|
array: (type) => `${ro}(${type})[]`,
|
|
10
|
-
|
|
10
|
+
// `[k:string]?:` is invalid TypeScript — optional keys on an infinite
|
|
11
|
+
// key set require mapped-type syntax.
|
|
12
|
+
record: (type) => structX([`${ro}[k in string]?:${type}`]),
|
|
11
13
|
};
|
|
12
14
|
};
|
|
13
15
|
export const primitive = (c) => {
|
package/fs/types/ts/proof.f.js
CHANGED
|
@@ -81,7 +81,7 @@ export const printerReadonlyArray = () => {
|
|
|
81
81
|
};
|
|
82
82
|
export const printerReadonlyRecord = () => {
|
|
83
83
|
const r = ro.record('number');
|
|
84
|
-
if (r !== '{readonly[k
|
|
84
|
+
if (r !== '{readonly[k in string]?:number}') {
|
|
85
85
|
throw r;
|
|
86
86
|
}
|
|
87
87
|
};
|
|
@@ -105,8 +105,9 @@ export const printerMutableArray = () => {
|
|
|
105
105
|
};
|
|
106
106
|
export const printerMutableRecord = () => {
|
|
107
107
|
const r = mut.record('number');
|
|
108
|
-
if (r !== '{[k
|
|
108
|
+
if (r !== '{[k in string]?:number}') {
|
|
109
109
|
throw r;
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
export const proof = { primitiveNull, primitiveBigint, primitiveString, primitiveNumberFinite, primitiveNumberInfinite, primitiveUndefined, primitiveBoolean, unionEmpty, unionSingle, unionMulti, printerReadonlyTuple, printerReadonlyStruct, printerReadonlyArray, printerReadonlyRecord, printerMutableTuple, printerMutableStruct, printerMutableArray, printerMutableRecord };
|
|
113
|
+
// type T4 = {[k:string]?: bigint} //< compilation error.
|
package/fs/website/proof.f.d.ts
CHANGED
package/fs/website/proof.f.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { main } from "./module.f.js";
|
|
2
|
+
import { emptyState, virtual } from "../effects/node/virtual/module.f.js";
|
|
3
|
+
import { assert } from "../asserts/module.f.js";
|
|
2
4
|
export const proof = {
|
|
3
5
|
main: () => {
|
|
4
6
|
const program = main();
|
|
5
7
|
if (program === undefined) {
|
|
6
8
|
throw 'expected a program effect';
|
|
7
9
|
}
|
|
8
|
-
}
|
|
10
|
+
},
|
|
11
|
+
run: () => {
|
|
12
|
+
const state = { ...emptyState, root: { '.github': { workflows: {} } } };
|
|
13
|
+
const [_, result] = virtual(state)(main());
|
|
14
|
+
assert(result === 0, result);
|
|
15
|
+
},
|
|
9
16
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functionalscript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
},
|
|
44
44
|
"homepage": "https://github.com/functionalscript/functionalscript#readme",
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@playwright/test": "1.
|
|
47
|
-
"@types/node": "25.9.
|
|
46
|
+
"@playwright/test": "1.61.0",
|
|
47
|
+
"@types/node": "25.9.3",
|
|
48
48
|
"typescript": "6.0.3"
|
|
49
49
|
}
|
|
50
50
|
}
|