functionalscript 0.17.0 → 0.19.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 (82) hide show
  1. package/fs/asn.1/module.f.js +7 -8
  2. package/fs/asn.1/test.f.js +11 -12
  3. package/fs/ci/common/module.f.d.ts +4 -5
  4. package/fs/ci/common/module.f.js +4 -4
  5. package/fs/ci/config/module.f.d.ts +5 -5
  6. package/fs/ci/config/module.f.js +5 -5
  7. package/fs/ci/test.f.js +2 -4
  8. package/fs/crypto/sign/module.f.js +3 -3
  9. package/fs/dev/module.f.d.ts +3 -3
  10. package/fs/dev/module.f.js +12 -9
  11. package/fs/dev/tf/module.d.ts +1 -1
  12. package/fs/dev/tf/module.f.d.ts +76 -7
  13. package/fs/dev/tf/module.f.js +166 -87
  14. package/fs/dev/tf/module.js +3 -53
  15. package/fs/dev/tf/scenarios/all.d.ts +1 -0
  16. package/fs/dev/tf/scenarios/all.js +3 -0
  17. package/fs/dev/tf/scenarios/fail.fail.f.d.ts +1 -0
  18. package/fs/dev/tf/scenarios/fail.fail.f.js +1 -0
  19. package/fs/dev/tf/scenarios/return-value.pass.f.d.ts +1 -0
  20. package/fs/dev/tf/scenarios/return-value.pass.f.js +2 -0
  21. package/fs/dev/tf/scenarios/throw.pass.f.d.ts +6 -0
  22. package/fs/dev/tf/scenarios/throw.pass.f.js +3 -0
  23. package/fs/dev/tf/test.f.d.ts +21 -20
  24. package/fs/dev/tf/test.f.js +254 -31
  25. package/fs/djs/module.f.d.ts +2 -2
  26. package/fs/djs/module.f.js +8 -5
  27. package/fs/djs/test.f.js +5 -6
  28. package/fs/djs/tokenizer-new/test.f.js +126 -78
  29. package/fs/djs/transpiler/module.f.js +2 -2
  30. package/fs/djs/transpiler/test.f.js +11 -12
  31. package/fs/fjs/module.f.d.ts +2 -7
  32. package/fs/fjs/module.f.js +16 -22
  33. package/fs/fjs/module.js +2 -2
  34. package/fs/io/module.d.ts +3 -3
  35. package/fs/io/module.f.d.ts +9 -2
  36. package/fs/io/module.f.js +13 -3
  37. package/fs/io/module.js +68 -17
  38. package/fs/path/module.f.d.ts +6 -0
  39. package/fs/path/module.f.js +6 -0
  40. package/fs/path/test.f.d.ts +3 -5
  41. package/fs/path/test.f.js +67 -49
  42. package/fs/sul/id/module.f.js +3 -4
  43. package/fs/sul/level/literal/module.f.js +3 -3
  44. package/fs/text/sgr/module.f.d.ts +9 -1
  45. package/fs/text/sgr/module.f.js +16 -5
  46. package/fs/text/sgr/test.f.js +16 -1
  47. package/fs/types/bit_vec/module.f.d.ts +9 -4
  48. package/fs/types/bit_vec/module.f.js +7 -9
  49. package/fs/types/btree/remove/module.f.d.ts +1 -1
  50. package/fs/types/btree/remove/module.f.js +7 -2
  51. package/fs/types/btree/set/module.f.d.ts +1 -1
  52. package/fs/types/btree/set/module.f.js +7 -2
  53. package/fs/types/btree/types/module.f.d.ts +1 -0
  54. package/fs/types/btree/types/module.f.js +1 -1
  55. package/fs/types/effects/node/module.f.d.ts +30 -17
  56. package/fs/types/effects/node/module.f.js +21 -2
  57. package/fs/types/effects/node/test.f.js +8 -5
  58. package/fs/types/effects/node/virtual/module.f.d.ts +12 -2
  59. package/fs/types/effects/node/virtual/module.f.js +31 -17
  60. package/fs/types/function/compare/module.f.d.ts +12 -0
  61. package/fs/types/function/compare/module.f.js +33 -0
  62. package/fs/types/function/operator/test.f.d.ts +10 -0
  63. package/fs/types/function/operator/test.f.js +81 -0
  64. package/fs/types/nullable/test.f.js +10 -1
  65. package/fs/types/range_map/module.f.js +3 -18
  66. package/fs/types/result/module.f.d.ts +4 -0
  67. package/fs/types/result/module.f.js +4 -0
  68. package/fs/types/result/test.f.d.ts +2 -4
  69. package/fs/types/result/test.f.js +24 -16
  70. package/fs/types/rtti/common/module.f.d.ts +10 -1
  71. package/fs/types/rtti/common/module.f.js +7 -2
  72. package/fs/types/rtti/parse/module.f.js +35 -46
  73. package/fs/types/rtti/validate/module.f.js +9 -12
  74. package/fs/types/sorted_list/module.f.d.ts +1 -2
  75. package/fs/types/sorted_list/module.f.js +8 -21
  76. package/fs/types/sorted_set/module.f.d.ts +1 -3
  77. package/fs/types/ts/test.f.d.ts +18 -0
  78. package/fs/types/ts/test.f.js +111 -0
  79. package/fs/types/uint8array/module.f.js +7 -1
  80. package/fs/types/uint8array/test.f.d.ts +1 -0
  81. package/fs/types/uint8array/test.f.js +5 -1
  82. package/package.json +4 -4
@@ -1,26 +1,26 @@
1
1
  import {} from "../module.f.js";
2
2
  import { ok } from "../../result/module.f.js";
3
- import { isArray as commonIsArray } from "../../array/module.f.js";
4
- import { isObject as commonIsObject } from "../../object/module.f.js";
5
- import { constPrimitiveValidate, prependPath, primitive0Validate, verror, visit, } from "../common/module.f.js";
3
+ import {} from "../../object/module.f.js";
4
+ import { constPrimitiveValidate, isArray, isObject, prependPath, primitive0Validate, verror, visit, } from "../common/module.f.js";
6
5
  export { constPrimitiveValidate, prependPath, primitive0Validate, verror, } from "../common/module.f.js";
6
+ const { entries } = Object;
7
7
  /**
8
8
  * Builds a validator for `array` or `record` schemas.
9
9
  * The inner item validator is instantiated lazily (only when the container is
10
10
  * non-empty) to avoid infinite recursion with recursive schemas.
11
11
  */
12
- const containerValidate = (isContainer, getEntries) => (item) => value => {
12
+ const containerValidate = (isContainer) => (item) => value => {
13
13
  if (!isContainer(value)) {
14
14
  return verror('unexpected value');
15
15
  }
16
- const entries = getEntries(value);
17
- if (entries.length === 0) {
16
+ const e = entries(value);
17
+ if (e.length === 0) {
18
18
  return ok(value);
19
19
  }
20
20
  // Note: we shouldn't instantiate `itemValidate` until we make sure `entries` is not empty.
21
21
  // Otherwise, we can get infinite recursion on empty arrays and objects
22
22
  const itemValidate = validate(item);
23
- for (const [k, v] of entries) {
23
+ for (const [k, v] of e) {
24
24
  const r = itemValidate(v);
25
25
  if (r[0] === 'error') {
26
26
  return prependPath(k, r);
@@ -28,11 +28,8 @@ const containerValidate = (isContainer, getEntries) => (item) => value => {
28
28
  }
29
29
  return ok(value);
30
30
  };
31
- const isArray = value => commonIsArray(value);
32
- const arrayEntries = (value) => value.map((v, i) => [String(i), v]);
33
- const arrayValidate = containerValidate(isArray, arrayEntries);
34
- const isObject = value => commonIsObject(value);
35
- const recordValidate = containerValidate(isObject, Object.entries);
31
+ const arrayValidate = containerValidate(isArray);
32
+ const recordValidate = containerValidate(isObject);
36
33
  /**
37
34
  * Builds a validator for `Tuple` or `Struct` const schemas.
38
35
  * Iterates over the schema's entries and validates each corresponding
@@ -3,12 +3,11 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import type { Sign } from '../function/compare/module.f.ts';
6
+ import { type Sign, type Cmp } from '../function/compare/module.f.ts';
7
7
  import { type List } from '../list/module.f.ts';
8
8
  import type { Nullable } from '../nullable/module.f.ts';
9
9
  export type SortedList<T> = List<T>;
10
10
  type SortedArray<T> = readonly T[];
11
- type Cmp<T> = (a: T) => (b: T) => Sign;
12
11
  export type ReduceOp<T, S> = (state: S) => (a: T) => (b: T) => readonly [Nullable<T>, Sign, S];
13
12
  export type TailReduce<T, S> = (state: S) => (tail: List<T>) => List<T>;
14
13
  type MergeReduce<T, S> = {
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Sorted immutable list helpers and merge operations.
3
+ *
4
+ * @module
5
+ */
6
+ import { bsearch } from "../function/compare/module.f.js";
1
7
  import { next } from "../list/module.f.js";
2
8
  import { identity } from "../function/module.f.js";
3
9
  export const genericMerge = ({ reduceOp, tailReduce }) => {
@@ -29,25 +35,6 @@ const cmpReduce = (cmp) => () => a => b => {
29
35
  const mergeTail = () => identity;
30
36
  export const find = (cmp) => (value) => (array) => {
31
37
  const cmpValue = cmp(value);
32
- let b = 0;
33
- let e = array.length - 1;
34
- while (true) {
35
- const d = e - b;
36
- if (d < 0)
37
- return null;
38
- const mid = b + (d >> 1);
39
- switch (cmpValue(array[mid])) {
40
- case -1: {
41
- e = mid - 1;
42
- break;
43
- }
44
- case 0: {
45
- return value;
46
- }
47
- case 1: {
48
- b = mid + 1;
49
- break;
50
- }
51
- }
52
- }
38
+ const pos = bsearch(array.length)(mid => cmpValue(array[mid]));
39
+ return pos < array.length && cmpValue(array[pos]) === 0 ? value : null;
53
40
  };
@@ -26,10 +26,8 @@
26
26
  * has(cmp)(2)(setA) // false
27
27
  * ```
28
28
  */
29
- import type { Sign } from '../function/compare/module.f.ts';
29
+ import type { Cmp } from '../function/compare/module.f.ts';
30
30
  export type SortedSet<T> = readonly T[];
31
- type Cmp<T> = (a: T) => (b: T) => Sign;
32
31
  export declare const union: <T>(cmp: Cmp<T>) => (a: SortedSet<T>) => (b: SortedSet<T>) => SortedSet<T>;
33
32
  export declare const intersect: <T>(cmp: Cmp<T>) => (a: SortedSet<T>) => (b: SortedSet<T>) => SortedSet<T>;
34
33
  export declare const has: <T>(cmp: Cmp<T>) => (value: T) => (set: SortedSet<T>) => boolean;
35
- export {};
@@ -0,0 +1,18 @@
1
+ export declare const primitiveNull: () => void;
2
+ export declare const primitiveBigint: () => void;
3
+ export declare const primitiveString: () => void;
4
+ export declare const primitiveNumberFinite: () => void;
5
+ export declare const primitiveNumberInfinite: () => void;
6
+ export declare const primitiveUndefined: () => void;
7
+ export declare const primitiveBoolean: () => void;
8
+ export declare const unionEmpty: () => void;
9
+ export declare const unionSingle: () => void;
10
+ export declare const unionMulti: () => void;
11
+ export declare const printerReadonlyTuple: () => void;
12
+ export declare const printerReadonlyStruct: () => void;
13
+ export declare const printerReadonlyArray: () => void;
14
+ export declare const printerReadonlyRecord: () => void;
15
+ export declare const printerMutableTuple: () => void;
16
+ export declare const printerMutableStruct: () => void;
17
+ export declare const printerMutableArray: () => void;
18
+ export declare const printerMutableRecord: () => void;
@@ -0,0 +1,111 @@
1
+ import { printer, primitive, union } from "./module.f.js";
2
+ const ro = printer();
3
+ const mut = printer(true);
4
+ export const primitiveNull = () => {
5
+ const r = primitive(null);
6
+ if (r !== 'null') {
7
+ throw r;
8
+ }
9
+ };
10
+ export const primitiveBigint = () => {
11
+ const r = primitive(42n);
12
+ if (r !== '42n') {
13
+ throw r;
14
+ }
15
+ };
16
+ export const primitiveString = () => {
17
+ const r = primitive('hello');
18
+ if (r !== '"hello"') {
19
+ throw r;
20
+ }
21
+ };
22
+ export const primitiveNumberFinite = () => {
23
+ const r = primitive(3.14);
24
+ if (r !== '3.14') {
25
+ throw r;
26
+ }
27
+ };
28
+ export const primitiveNumberInfinite = () => {
29
+ const r = primitive(Infinity);
30
+ if (r !== 'number') {
31
+ throw r;
32
+ }
33
+ };
34
+ export const primitiveUndefined = () => {
35
+ const r = primitive(undefined);
36
+ if (r !== 'undefined') {
37
+ throw r;
38
+ }
39
+ };
40
+ export const primitiveBoolean = () => {
41
+ const r = primitive(true);
42
+ if (r !== 'true') {
43
+ throw r;
44
+ }
45
+ };
46
+ export const unionEmpty = () => {
47
+ const r = union([]);
48
+ if (r !== 'never') {
49
+ throw r;
50
+ }
51
+ };
52
+ export const unionSingle = () => {
53
+ const r = union(['string']);
54
+ if (r !== 'string') {
55
+ throw r;
56
+ }
57
+ };
58
+ export const unionMulti = () => {
59
+ const r = union(['string', 'number']);
60
+ if (r !== 'string|number') {
61
+ throw r;
62
+ }
63
+ };
64
+ export const printerReadonlyTuple = () => {
65
+ const r = ro.tuple(['string', 'number']);
66
+ if (r !== 'readonly[string,number]') {
67
+ throw r;
68
+ }
69
+ };
70
+ export const printerReadonlyStruct = () => {
71
+ const r = ro.struct([['x', 'number'], ['y', 'string']]);
72
+ if (r !== '{readonly"x":number,readonly"y":string}') {
73
+ throw r;
74
+ }
75
+ };
76
+ export const printerReadonlyArray = () => {
77
+ const r = ro.array('string');
78
+ if (r !== 'readonly(string)[]') {
79
+ throw r;
80
+ }
81
+ };
82
+ export const printerReadonlyRecord = () => {
83
+ const r = ro.record('number');
84
+ if (r !== '{readonly[k:string]:number}') {
85
+ throw r;
86
+ }
87
+ };
88
+ export const printerMutableTuple = () => {
89
+ const r = mut.tuple(['string', 'number']);
90
+ if (r !== '[string,number]') {
91
+ throw r;
92
+ }
93
+ };
94
+ export const printerMutableStruct = () => {
95
+ const r = mut.struct([['x', 'number']]);
96
+ if (r !== '{"x":number}') {
97
+ throw r;
98
+ }
99
+ };
100
+ export const printerMutableArray = () => {
101
+ const r = mut.array('string');
102
+ if (r !== '(string)[]') {
103
+ throw r;
104
+ }
105
+ };
106
+ export const printerMutableRecord = () => {
107
+ const r = mut.record('number');
108
+ if (r !== '{[k:string]:number}') {
109
+ throw r;
110
+ }
111
+ };
@@ -1,5 +1,11 @@
1
1
  /**
2
- * Conversions between Uint8Array values and bit vectors.
2
+ * Conversions between `Uint8Array` values and bit vectors.
3
+ *
4
+ * @deprecated FunctionalScript represents byte data as `bigint`-based bit
5
+ * vectors (`Vec` from `fs/types/bit_vec`). Use `utf8`/`utf8ToString` from
6
+ * `fs/text` for string encoding, and the `bit_vec` module directly for raw
7
+ * byte manipulation. `Uint8Array` interop belongs at Node.js boundaries only
8
+ * (e.g. `fromVec`/`toVec` when reading or writing files).
3
9
  *
4
10
  * @module
5
11
  */
@@ -8,5 +8,6 @@ declare const _default: {
8
8
  decodeUtf8Ascii: () => void;
9
9
  decodeUtf8Multibyte: () => void;
10
10
  utf8RoundTrip: () => void;
11
+ listToVec: () => void;
11
12
  };
12
13
  export default _default;
@@ -1,5 +1,5 @@
1
1
  import { vec } from "../bit_vec/module.f.js";
2
- import { toVec, fromVec, decodeUtf8, encodeUtf8 } from "./module.f.js";
2
+ import { toVec, fromVec, listToVec, decodeUtf8, encodeUtf8 } from "./module.f.js";
3
3
  import { strictEqual } from "../function/operator/module.f.js";
4
4
  import { equal, fromArrayLike } from "../list/module.f.js";
5
5
  const assertEq = (a, b) => {
@@ -54,5 +54,9 @@ export default {
54
54
  const input = 'FunctionalScript 🐝';
55
55
  const output = decodeUtf8(encodeUtf8(input));
56
56
  assertEq(output, input);
57
+ },
58
+ listToVec: () => {
59
+ const result = listToVec([Uint8Array.from([1, 2]), Uint8Array.from([3])]);
60
+ assertArrayEq(fromVec(result), Uint8Array.from([1, 2, 3]));
57
61
  }
58
62
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.17.0",
3
+ "version": "0.19.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "**/*.js",
@@ -9,17 +9,17 @@
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-strip-types --experimental-test-coverage --test-coverage-include=**/module.f.ts",
12
+ "test": "tsc && node --test --experimental-test-coverage --test-coverage-include=**/module.f.ts",
13
13
  "index": "node ./fs/fjs/module.ts r ./fs/dev/index/module.f.ts",
14
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",
18
- "index-html": "node --experimental-strip-types ./fs/fjs/module.ts r ./fs/website/module.f.ts",
18
+ "index-html": "node ./fs/fjs/module.ts r ./fs/website/module.f.ts",
19
19
  "website": "npm run prepack &&npm run index-html"
20
20
  },
21
21
  "engines": {
22
- "node": ">=22"
22
+ "node": ">=24"
23
23
  },
24
24
  "bin": {
25
25
  "fjs": "fs/fjs/module.js"