functionalscript 0.24.0 → 0.25.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.
Files changed (44) hide show
  1. package/fs/asserts/proof.f.d.ts +8 -0
  2. package/fs/asserts/proof.f.js +51 -0
  3. package/fs/bnf/data/proof.f.js +7 -17
  4. package/fs/bnf/module.f.d.ts +10 -0
  5. package/fs/bnf/module.f.js +10 -0
  6. package/fs/bnf/testlib.f.js +4 -9
  7. package/fs/ci/common/module.f.d.ts +2 -0
  8. package/fs/ci/common/module.f.js +4 -1
  9. package/fs/ci/config/module.f.d.ts +2 -2
  10. package/fs/ci/config/module.f.js +2 -2
  11. package/fs/ci/module.f.d.ts +1 -2
  12. package/fs/ci/module.f.js +10 -8
  13. package/fs/ci/node/module.f.js +4 -2
  14. package/fs/ci/proof.f.js +8 -5
  15. package/fs/crypto/sha2/module.f.js +32 -36
  16. package/fs/crypto/vdf/module.f.d.ts +21 -0
  17. package/fs/crypto/vdf/module.f.js +57 -0
  18. package/fs/crypto/vdf/proof.f.d.ts +32 -0
  19. package/fs/crypto/vdf/proof.f.js +135 -0
  20. package/fs/json/module.f.d.ts +25 -9
  21. package/fs/json/module.f.js +25 -3
  22. package/fs/json/rpc/module.f.d.ts +109 -0
  23. package/fs/json/rpc/module.f.js +84 -0
  24. package/fs/json/rpc/proof.f.d.ts +35 -0
  25. package/fs/json/rpc/proof.f.js +68 -0
  26. package/fs/json/schema/module.f.d.ts +76 -0
  27. package/fs/json/schema/module.f.js +112 -0
  28. package/fs/json/schema/proof.f.d.ts +33 -0
  29. package/fs/json/schema/proof.f.js +71 -0
  30. package/fs/mcp/module.f.d.ts +88 -0
  31. package/fs/mcp/module.f.js +69 -0
  32. package/fs/sul/level/literal/proof.f.d.ts +1 -0
  33. package/fs/sul/level/literal/proof.f.js +6 -0
  34. package/fs/types/array/module.f.d.ts +7 -0
  35. package/fs/types/array/module.f.js +7 -0
  36. package/fs/types/prime_field/module.f.d.ts +8 -0
  37. package/fs/types/prime_field/module.f.js +37 -5
  38. package/fs/types/prime_field/proof.f.d.ts +3 -0
  39. package/fs/types/prime_field/proof.f.js +27 -2
  40. package/fs/types/rtti/parse/module.f.d.ts +28 -0
  41. package/fs/types/rtti/parse/module.f.js +35 -5
  42. package/fs/types/rtti/ts/module.f.d.ts +46 -3
  43. package/fs/types/rtti/validate/module.f.js +5 -0
  44. package/package.json +3 -3
@@ -1,8 +1,28 @@
1
- import type { Unknown as DjsUnknown } from '../../../djs/module.f.ts';
2
1
  import type { Tag0, Tag1, Struct, Tuple, Type } from '../module.f.ts';
3
2
  import type { ReadonlyRecord } from '../../object/module.f.ts';
3
+ /**
4
+ * The set of primitive literal types representable as rtti `Const` values.
5
+ * Defined here rather than imported from `djs` to keep rtti free of djs dependencies
6
+ * (djs depends on rtti, not the other way around — see [i665-rtti-defines-types]).
7
+ */
8
+ export type Primitive = null | boolean | number | string | undefined | bigint;
9
+ /**
10
+ * The TypeScript type that rtti's `unknown` schema validates — any value that
11
+ * an rtti schema can represent: a primitive, an array, or an object.
12
+ *
13
+ * Currently equivalent to `djs.Unknown`, but defined here to keep `rtti` free
14
+ * of `djs` dependencies. May be extended to include functions or other
15
+ * non-JSON-primitives in the future.
16
+ */
17
+ export type Unknown = Primitive | Array | Object;
18
+ /** A read-only array of {@link Unknown} values. */
19
+ export type Array = readonly Unknown[];
20
+ /** A read-only record of {@link Unknown} values. */
21
+ export type Object = {
22
+ readonly [k in string]: Unknown;
23
+ };
4
24
  /** Maps a `Tag0` to its TypeScript type. */
5
- 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' ? DjsUnknown : never;
25
+ 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;
6
26
  /** Maps a `Const` schema to its TypeScript type. */
7
27
  export type ConstTs<T> = T extends readonly Type[] ? TupleTs<T> : T extends {
8
28
  readonly [k in string]: Type;
@@ -25,6 +45,27 @@ type RequiredFields<T extends Struct> = {
25
45
  };
26
46
  /** Maps a struct schema to a readonly object of resolved types, with optional fields for schemas that include `undefined`. */
27
47
  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
+ };
28
69
  /**
29
70
  * Converts a schema `Type` to its corresponding TypeScript type.
30
71
  *
@@ -39,7 +80,9 @@ export type StructTs<T extends Struct> = (keyof OptionalFields<T> extends never
39
80
  * type D = Ts<{ x: typeof boolean }> // { readonly x: boolean }
40
81
  * ```
41
82
  */
42
- export type Ts<T extends Type> = 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'] ? DjsUnknown : I extends readonly ['array', infer E extends Type] ? readonly Ts<E>[] : I extends readonly ['record', infer E extends Type] ? {
83
+ export type Ts<T extends Type> = unknown extends T ? Unknown : T extends {
84
+ readonly [withOutKey]?: infer O;
85
+ } ? 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] ? {
43
86
  readonly [K in string]: Ts<E>;
44
87
  } : I extends readonly ['or', ...infer A extends readonly Type[]] ? Ts<A[number]> : never) : ConstTs<T>;
45
88
  /**
@@ -26,6 +26,8 @@ const containerValidate = (isContainer) => (item) => value => {
26
26
  return prependPath(k, r);
27
27
  }
28
28
  }
29
+ // `value` is Container<K>, but Ts<Info1<K,I>> = readonly Ts<I>[] | Record<string,Ts<I>>.
30
+ // TypeScript can't narrow the container's element types through the validation loop.
29
31
  return ok(value);
30
32
  };
31
33
  const arrayValidate = containerValidate(isArray);
@@ -46,6 +48,8 @@ const constContainerValidate = (isContainer, getItem) => (rtti) => value => {
46
48
  return prependPath(k, r);
47
49
  }
48
50
  }
51
+ // `value` is C (Unknown container), but Ts<T> for T extends Tuple|Struct is not
52
+ // structurally equivalent to C — TypeScript can't narrow element types through the loop.
49
53
  return ok(value);
50
54
  };
51
55
  const tupleValidate = constContainerValidate(isArray, (value, k) => value[Number(k)]);
@@ -54,6 +58,7 @@ const orValidate = (rtti) => {
54
58
  const all = rtti.map(r => validate(r));
55
59
  return value => {
56
60
  for (const i of all) {
61
+ // `i` is Validate<Type>; calling without cast forces Ts<Type> evaluation → TS2589.
57
62
  const r = i(value);
58
63
  if (r[0] === 'ok') {
59
64
  return r;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "**/*.js",
@@ -9,9 +9,9 @@
9
9
  "description": "FunctionalScript is a purely functional subset of JavaScript",
10
10
  "scripts": {
11
11
  "prepack": "tsc --NoEmit false",
12
- "test": "tsc && node --test --experimental-test-coverage --test-coverage-include=**/module.f.ts",
12
+ "test": "tsc && node ./fs/fjs/module.ts t",
13
+ "cov": "node --test --experimental-test-coverage --test-coverage-include=**/module.f.ts",
13
14
  "index": "node ./fs/fjs/module.ts r ./fs/dev/index/module.f.ts",
14
- "fst": "node ./fs/fjs/module.ts t",
15
15
  "start": "node ./fs/fjs/module.ts",
16
16
  "ci-update": "node ./fs/fjs/module.ts r ./fs/ci/module.f.ts",
17
17
  "update": "npm install && npm run index && npm run ci-update",