functionalscript 0.42.0 → 0.43.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.
@@ -11,7 +11,7 @@ export type TerminalRange = number;
11
11
  */
12
12
  export type Sequence = readonly string[];
13
13
  /** A variant of rule names. */
14
- export type Variant = StringMap<string, string>;
14
+ export type Variant = StringMap<string>;
15
15
  /**
16
16
  * Grammar rule definition.
17
17
  *
@@ -29,7 +29,7 @@ export type RuleSet = Readonly<Record<string, Rule>>;
29
29
  * variant branch.
30
30
  */
31
31
  export type EmptyTag = string | true | undefined;
32
- type EmptyTagMap = StringMap<string, EmptyTag>;
32
+ type EmptyTagMap = StringMap<EmptyTag>;
33
33
  /**
34
34
  * Computes, for every rule in the set, whether it can match empty input, by
35
35
  * the standard nullable-set fixpoint: a sequence is nullable iff all of its
@@ -26,7 +26,7 @@ type DispatchRuleCollection = {
26
26
  readonly tag: string | undefined;
27
27
  readonly rules: DispatchRuleOrName[];
28
28
  };
29
- type DispatchMap = StringMap<string, DispatchRule>;
29
+ type DispatchMap = StringMap<DispatchRule>;
30
30
  /**
31
31
  * Represents a parsed AST sequence.
32
32
  */
@@ -89,7 +89,7 @@ export declare const range: (ab: string) => TerminalRange;
89
89
  /**
90
90
  * A set of terminal ranges compatible with the `Variant` rule.
91
91
  */
92
- export type RangeVariant = StringMap<string, TerminalRange>;
92
+ export type RangeVariant = StringMap<TerminalRange>;
93
93
  export declare const remove: (range: TerminalRange, v: RangeVariant) => RangeVariant;
94
94
  /**
95
95
  * Returns the complement set of the provided ranges over {@link fullRange}.
@@ -119,7 +119,7 @@ export type SubjectState = {
119
119
  };
120
120
  /** In-memory index: subject → its {@link SubjectState}. */
121
121
  export type Cache = {
122
- readonly bySubject: StringMap<string, SubjectState>;
122
+ readonly bySubject: StringMap<SubjectState>;
123
123
  };
124
124
  /** A cache with no known subjects yet — the starting point for {@link buildCache}. */
125
125
  export declare const emptyCache: Cache;
@@ -10,7 +10,7 @@ export type Module = {
10
10
  readonly proof?: unknown;
11
11
  readonly [k: string]: unknown;
12
12
  };
13
- export type ModuleMap = StringMap<string, Module>;
13
+ export type ModuleMap = StringMap<Module>;
14
14
  /**
15
15
  * Returns `true` if the file should be loaded for proof discovery.
16
16
  *
@@ -109,7 +109,7 @@ export type Stat = readonly ['stat', (path: string) => IoResult<FileStat>];
109
109
  export declare const stat: Func<Stat>;
110
110
  export type Fs = Mkdir | ReadFile | ReadBytes | Readdir | WriteFile | Rm | Rename | Exec | Access | CreateExclusive | WriteBytes | Stat;
111
111
  export type Server = Nominal<'server', `160855c4f69310fece3273c1853ac32de43dee1eb41bf59d821917f8eebe9272`, unknown>;
112
- export type Headers = StringMap<string, string>;
112
+ export type Headers = StringMap<string>;
113
113
  export type IncomingMessage = {
114
114
  readonly method: string;
115
115
  readonly url: string;
@@ -129,7 +129,7 @@ export declare const listen: Func<Listen>;
129
129
  export type Http = CreateServer | Listen;
130
130
  export type Forever = ['forever', () => never];
131
131
  export declare const forever: Func<Forever>;
132
- export type Module = StringMap<string, unknown>;
132
+ export type Module = StringMap<unknown>;
133
133
  export type Import = ['import', (path: string) => IoResult<Module>];
134
134
  export declare const import_: Func<Import>;
135
135
  /** Named output streams accepted by the `Write` effect. */
@@ -9,7 +9,7 @@ import { type ByteSet } from '../types/byte_set/module.f.ts';
9
9
  import { type RangeMapArray } from '../types/range_map/module.f.ts';
10
10
  type Rule = readonly [string, ByteSet, string];
11
11
  export type Grammar = List<Rule>;
12
- type Dfa = StringMap<string, RangeMapArray<string>>;
12
+ type Dfa = StringMap<RangeMapArray<string>>;
13
13
  export declare const toRange: (s: string) => ByteSet;
14
14
  export declare const toUnion: (s: string) => ByteSet;
15
15
  export declare const dfa: (grammar: Grammar) => Dfa;
@@ -17,7 +17,7 @@ type Element2 = readonly [Tag, Attributes, ...Node[]];
17
17
  * - `[tag, attributes, ...children]` for elements with attributes.
18
18
  */
19
19
  export type Element = Element1 | Element2;
20
- type Attributes = StringMap<string, string>;
20
+ type Attributes = StringMap<string>;
21
21
  export type Node = Element | string;
22
22
  /**
23
23
  * Converts a FunctionalScript element into a list of HTML string chunks.
@@ -1,12 +1,35 @@
1
1
  import { type List } from '../list/module.f.ts';
2
2
  import { type Nullable } from '../nullable/module.f.ts';
3
3
  import { type OrderedMap } from '../ordered_map/module.f.ts';
4
- export type Map<T> = StringMap<string, T>;
4
+ /** A record over the keys of `K`, each value possibly missing at runtime. */
5
+ export type OptionalMap<K extends string, T> = {
6
+ readonly [k in K]?: T;
7
+ };
8
+ /**
9
+ * A record over the keys of `K`, each value required.
10
+ *
11
+ * `K` has to be a finite union of string literals: `RequiredMap<string, T>` is
12
+ * `never`, because no object can carry every string as a key. Use `StringMap<T>`
13
+ * for an open key set — its values are optional, which is what such a key set
14
+ * means at runtime.
15
+ *
16
+ * There is no known way to ask TypeScript whether `K` is finite, so the guard
17
+ * approximates it with `string extends K`, which holds exactly when `K` is
18
+ * `string`. Other infinite key sets are not caught: a template literal such as
19
+ * `x-${string}` yields a template index signature instead of `never`, and its
20
+ * reads are typed `T` while the runtime value is `undefined`. Keep `K` a union
21
+ * of string literals.
22
+ */
23
+ export type RequiredMap<K extends string, T> = string extends K ? never : {
24
+ readonly [k in K]: T;
25
+ };
26
+ /** A record with an open key set. Every value can be missing at runtime. */
27
+ export type StringMap<T> = OptionalMap<string, T>;
5
28
  export type Entry<T> = readonly [string, T];
6
- export declare const at: (name: string) => <T>(object: Map<T>) => Nullable<Exclude<T, undefined>>;
29
+ export declare const at: (name: string) => <T>(object: StringMap<T>) => Nullable<Exclude<T, undefined>>;
7
30
  export declare const sort: <T>(e: List<Entry<T>>) => List<Entry<T>>;
8
- export declare const fromEntries: <T>(e: List<Entry<T>>) => Map<T>;
9
- export declare const fromMap: <T>(m: OrderedMap<T>) => Map<T>;
31
+ export declare const fromEntries: <T>(e: List<Entry<T>>) => StringMap<T>;
32
+ export declare const fromMap: <T>(m: OrderedMap<T>) => StringMap<T>;
10
33
  /**
11
34
  * A set of objects with a single key.
12
35
  *
@@ -14,7 +37,7 @@ export declare const fromMap: <T>(m: OrderedMap<T>) => Map<T>;
14
37
  * https://stackoverflow.com/questions/57571664/typescript-type-for-an-object-with-only-one-key-no-union-type-allowed-as-a-key
15
38
  */
16
39
  export type OneKey<K extends string, V> = {
17
- [P in K]: (StringMap<P, V> & Partial<StringMap<Exclude<K, P>, never>>) extends infer O ? {
40
+ [P in K]: (RequiredMap<P, V> & OptionalMap<Exclude<K, P>, never>) extends infer O ? {
18
41
  [Q in keyof O]: O[Q];
19
42
  } : never;
20
43
  }[K];
@@ -24,13 +47,8 @@ export type OneKey<K extends string, V> = {
24
47
  export type NotUnion<T, U = T> = T extends unknown ? [
25
48
  U
26
49
  ] extends [T] ? T : never : never;
27
- export type SingleProperty<T extends StringMap<string, never>> = keyof T extends NotUnion<keyof T> ? T : never;
50
+ export type SingleProperty<T extends StringMap<never>> = keyof T extends NotUnion<keyof T> ? T : never;
28
51
  export declare const isObject: (value: unknown) => value is { readonly [k in string]: unknown; };
29
52
  /** Returns only the defined (non-undefined) values of a partial record. */
30
- export declare const definedValues: <T>(map: StringMap<string, Exclude<T, undefined>>) => readonly Exclude<T, undefined>[];
31
- export type StringMap<K extends string, T> = string extends K ? {
32
- readonly [k in string]?: T;
33
- } : {
34
- readonly [k in K]: T;
35
- };
36
- export declare const definedEntries: <T>(cmd: StringMap<string, Exclude<T, undefined>>) => readonly (readonly [string, Exclude<T, undefined>])[];
53
+ export declare const definedValues: <T>(map: StringMap<Exclude<T, undefined>>) => readonly Exclude<T, undefined>[];
54
+ export declare const definedEntries: <T>(cmd: StringMap<Exclude<T, undefined>>) => readonly (readonly [string, Exclude<T, undefined>])[];
@@ -1,7 +1,8 @@
1
1
  /**
2
- * Plain-object helpers and types: `Map<T>`/`Entry<T>` shapes, safe property
3
- * lookup via `at`, conversions between entries and `OrderedMap`, and the
4
- * `OneKey`/`SingleProperty`/`NotUnion` utility types.
2
+ * Plain-object helpers and types: the `OptionalMap`/`RequiredMap`/`StringMap`
3
+ * record shapes and `Entry<T>`, safe property lookup via `at`, conversions
4
+ * between entries and `OrderedMap`, and the `OneKey`/`SingleProperty`/`NotUnion`
5
+ * utility types.
5
6
  *
6
7
  * @module
7
8
  */
@@ -1,18 +1,4 @@
1
- import type { StringMap } from './module.f.ts';
2
- type E<A, B> = A extends B ? B extends A ? true : false : false;
3
- type _InfiniteIsOptional = E<StringMap<string, bigint>, {
4
- readonly [k in string]?: bigint;
5
- }>;
6
- type _FiniteIsRequired = E<StringMap<'a' | 'b', bigint>, {
7
- readonly a: bigint;
8
- readonly b: bigint;
9
- }>;
10
1
  export declare const proof: {
11
- stringMap: {
12
- infiniteIsOptional: _InfiniteIsOptional;
13
- finiteIsRequired: _FiniteIsRequired;
14
- };
15
2
  ctor: () => void;
16
3
  property: () => void;
17
4
  };
18
- export {};
@@ -1,10 +1,6 @@
1
1
  import { at } from './module.f.js';
2
2
  import { assertEq } from '../../asserts/module.f.js';
3
3
  export const proof = {
4
- stringMap: {
5
- infiniteIsOptional: true,
6
- finiteIsRequired: true,
7
- },
8
4
  ctor: () => {
9
5
  const a = {};
10
6
  const value = at('constructor')(a);
@@ -74,11 +74,11 @@ export type Visitor<R> = {
74
74
  /** Type guard narrowing `Unknown` to a specific container type `C`. */
75
75
  export type IsContainer<C extends Unknown> = (value: Unknown) => value is C;
76
76
  /** Maps a `Tag1` to its runtime container type. */
77
- export type Container<K extends Tag1> = K extends 'array' ? ReadonlyArray<Unknown> : StringMap<string, Unknown>;
77
+ export type Container<K extends Tag1> = K extends 'array' ? ReadonlyArray<Unknown> : StringMap<Unknown>;
78
78
  /** `IsContainer` guard for arrays, shared by `validate` and `parse`. */
79
79
  export declare const isArray: IsContainer<ReadonlyArray<Unknown>>;
80
80
  /** `IsContainer` guard for records/structs, shared by `validate` and `parse`. */
81
- export declare const isObject: IsContainer<StringMap<string, Unknown>>;
81
+ export declare const isObject: IsContainer<StringMap<Unknown>>;
82
82
  /**
83
83
  * Runs `item` over each `[key, value]` entry, bailing out with the first
84
84
  * error, path-prefixed with that entry's key. On success, folds each item's
@@ -6,7 +6,7 @@ export type Const = null | boolean | number | string | undefined | bigint | {
6
6
  } | readonly Type[];
7
7
  export type ConstObject = Struct | Tuple;
8
8
  /** A struct schema: plain object whose values are nested `Type`s. */
9
- export type Struct = StringMap<string, Type>;
9
+ export type Struct = StringMap<Type>;
10
10
  /** A tuple schema: readonly array whose elements are nested `Type`s. */
11
11
  export type Tuple = readonly Type[];
12
12
  declare const primitive0List: readonly ['bigint', 'boolean', 'number', 'string'];
@@ -31,7 +31,7 @@ export type Object = {
31
31
  /** Maps a `Tag0` to its TypeScript type. */
32
32
  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;
33
33
  /** Maps a `Const` schema to its TypeScript type. */
34
- export type ConstTs<T> = T extends readonly Type[] ? TupleTs<T> : T extends StringMap<string, Type> ? StructTs<T> : T;
34
+ export type ConstTs<T> = T extends readonly Type[] ? TupleTs<T> : T extends StringMap<Type> ? StructTs<T> : T;
35
35
  /** Maps a `Tag1` and inner type to its TypeScript type. */
36
36
  export type Info1Ts<K extends Tag1, T extends Type> = K extends 'array' ? ArrayTs<T> : K extends 'record' ? RecordTs<T> : never;
37
37
  /** Maps an array schema `T` to `readonly Ts<T>[]`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.42.0",
3
+ "version": "0.43.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "**/*.js",