functionalscript 0.0.592 → 0.1.594
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/.github/workflows/ci.yml +3 -3
- package/README.md +1 -0
- package/com/cpp/{module.f.cjs → module.f.mjs} +22 -21
- package/com/cpp/{test.f.cjs → test.f.mjs} +2 -2
- package/com/cpp/testlib.f.mjs +9 -0
- package/com/cs/{module.f.cjs → module.f.mjs} +20 -19
- package/com/cs/{test.f.cjs → test.f.mjs} +2 -2
- package/com/cs/testlib.f.mjs +10 -0
- package/com/rust/{module.f.cjs → module.f.mjs} +37 -35
- package/com/rust/{test.f.cjs → test.f.mjs} +2 -2
- package/com/rust/testlib.f.mjs +10 -0
- package/com/test/{build.f.cjs → build.f.mjs} +6 -6
- package/com/test/{build.cjs → build.mjs} +16 -8
- package/com/types/{module.f.cjs → module.f.mjs} +9 -8
- package/com/types/{testlib.f.cjs → testlib.f.mjs} +2 -2
- package/commonjs/build/{module.f.cjs → module.f.mjs} +23 -23
- package/commonjs/build/{test.f.cjs → test.f.mjs} +13 -12
- package/commonjs/module/function/{module.f.cjs → module.f.mjs} +4 -4
- package/commonjs/module/{module.f.cjs → module.f.mjs} +3 -5
- package/commonjs/module.f.mjs +11 -0
- package/commonjs/{module.cjs → module.mjs} +8 -6
- package/commonjs/package/dependencies/{module.f.cjs → module.f.mjs} +5 -5
- package/commonjs/package/dependencies/{test.f.cjs → test.f.mjs} +2 -2
- package/commonjs/package/{module.f.cjs → module.f.mjs} +7 -6
- package/commonjs/package/{test.f.cjs → test.f.mjs} +2 -2
- package/commonjs/path/{module.f.cjs → module.f.mjs} +15 -14
- package/commonjs/path/{test.f.cjs → test.f.mjs} +16 -14
- package/commonjs/{test.cjs → test.mjs} +4 -4
- package/dev/{module.f.cjs → module.f.mjs} +1 -1
- package/dev/module.mjs +5 -3
- package/dev/test/{module.f.cjs → module.f.mjs} +21 -9
- package/dev/{test.f.cjs → test.f.mjs} +1 -1
- package/dev/test.mjs +1 -1
- package/djs/{module.f.cjs → module.f.mjs} +18 -15
- package/djs/parser/{module.f.cjs → module.f.mjs} +29 -28
- package/djs/parser/{test.f.cjs → test.f.mjs} +10 -8
- package/djs/{test.f.cjs → test.f.mjs} +7 -5
- package/djs/tokenizer/{module.f.cjs → module.f.mjs} +19 -18
- package/djs/tokenizer/{test.f.cjs → test.f.mjs} +9 -7
- package/fsc/{module.f.cjs → module.f.mjs} +17 -16
- package/fsc/{test.f.cjs → test.f.mjs} +6 -4
- package/fsm/{module.f.cjs → module.f.mjs} +28 -24
- package/fsm/{test.f.cjs → test.f.mjs} +13 -9
- package/html/{module.f.cjs → module.f.mjs} +16 -13
- package/html/{test.f.cjs → test.f.mjs} +5 -5
- package/index.f.mjs +45 -35
- package/issues/README.md +15 -0
- package/js/tokenizer/{module.f.cjs → module.f.mjs} +52 -51
- package/js/tokenizer/{test.f.cjs → test.f.mjs} +9 -7
- package/json/{module.f.cjs → module.f.mjs} +18 -17
- package/json/parser/{module.f.cjs → module.f.mjs} +27 -26
- package/json/parser/{test.f.cjs → test.f.mjs} +10 -8
- package/json/serializer/{module.f.cjs → module.f.mjs} +12 -12
- package/json/serializer/{test.f.cjs → test.f.mjs} +4 -3
- package/json/{test.f.cjs → test.f.mjs} +6 -4
- package/json/tokenizer/{module.f.cjs → module.f.mjs} +16 -15
- package/json/tokenizer/{test.f.cjs → test.f.mjs} +9 -7
- package/jsr.json +1 -1
- package/nodejs/version/main.mjs +5 -0
- package/nodejs/version/{module.f.cjs → module.f.mjs} +2 -2
- package/nodejs/version/{test.f.cjs → test.f.mjs} +5 -5
- package/package.json +3 -3
- package/prime_field/{module.f.cjs → module.f.mjs} +6 -5
- package/prime_field/{test.f.cjs → test.f.mjs} +3 -2
- package/secp/{module.f.cjs → module.f.mjs} +7 -6
- package/secp/{test.f.cjs → test.f.mjs} +6 -6
- package/sha2/{module.f.cjs → module.f.mjs} +5 -5
- package/sha2/{test.f.cjs → test.f.mjs} +7 -6
- package/text/ascii/{module.f.cjs → module.f.mjs} +3 -3
- package/text/ascii/test.f.mjs +14 -0
- package/text/{module.f.cjs → module.f.mjs} +6 -6
- package/text/sgr/{module.f.cjs → module.f.mjs} +1 -1
- package/text/{test.f.cjs → test.f.mjs} +5 -4
- package/text/utf16/{module.f.cjs → module.f.mjs} +16 -14
- package/text/utf16/{test.f.cjs → test.f.mjs} +7 -6
- package/text/utf8/{module.f.cjs → module.f.mjs} +11 -11
- package/text/utf8/{test.f.cjs → test.f.mjs} +6 -5
- package/tsconfig.json +2 -2
- package/types/array/{module.f.cjs → module.f.mjs} +2 -2
- package/types/array/{test.f.cjs → test.f.mjs} +5 -4
- package/types/bigfloat/{module.f.cjs → module.f.mjs} +3 -3
- package/types/bigfloat/{test.f.cjs → test.f.mjs} +3 -2
- package/types/bigint/{module.f.cjs → module.f.mjs} +8 -7
- package/types/bigint/{test.f.cjs → test.f.mjs} +3 -2
- package/types/btree/find/{module.f.cjs → module.f.mjs} +12 -12
- package/types/btree/find/{test.f.cjs → test.f.mjs} +11 -9
- package/types/btree/{module.f.cjs → module.f.mjs} +7 -12
- package/types/btree/remove/{module.f.cjs → module.f.mjs} +17 -16
- package/types/btree/remove/{test.f.cjs → test.f.mjs} +9 -7
- package/types/btree/set/{module.f.cjs → module.f.mjs} +9 -9
- package/types/btree/set/{test.f.cjs → test.f.mjs} +8 -6
- package/types/btree/{test.f.cjs → test.f.mjs} +23 -20
- package/types/btree/types/{module.f.cjs → module.f.mjs} +1 -1
- package/types/byte_set/{module.f.cjs → module.f.mjs} +8 -7
- package/types/byte_set/{test.f.cjs → test.f.mjs} +8 -7
- package/types/function/compare/{module.f.cjs → module.f.mjs} +2 -2
- package/types/function/compare/{test.f.cjs → test.f.mjs} +3 -2
- package/types/function/{module.f.cjs → module.f.mjs} +1 -5
- package/types/function/operator/{module.f.cjs → module.f.mjs} +1 -1
- package/types/function/{test.f.cjs → test.f.mjs} +4 -2
- package/types/list/{module.f.cjs → module.f.mjs} +12 -12
- package/types/list/{test.f.cjs → test.f.mjs} +13 -11
- package/types/map/{module.f.cjs → module.f.mjs} +21 -18
- package/types/map/{test.f.cjs → test.f.mjs} +5 -4
- package/types/nibble_set/{module.f.cjs → module.f.mjs} +1 -1
- package/types/nibble_set/{test.f.cjs → test.f.mjs} +4 -3
- package/types/nullable/{module.f.cjs → module.f.mjs} +1 -1
- package/types/nullable/{test.f.cjs → test.f.mjs} +2 -2
- package/types/number/module.f.mjs +26 -0
- package/types/number/{test.f.cjs → test.f.mjs} +3 -2
- package/types/object/{module.f.cjs → module.f.mjs} +6 -6
- package/types/object/{test.f.cjs → test.f.mjs} +2 -2
- package/types/range/{module.f.cjs → module.f.mjs} +1 -1
- package/types/range/{test.f.cjs → test.f.mjs} +2 -2
- package/types/range_map/{module.f.cjs → module.f.mjs} +16 -15
- package/types/range_map/{test.f.cjs → test.f.mjs} +35 -33
- package/types/result/{module.f.cjs → module.f.mjs} +1 -1
- package/types/result/{module.cjs → module.mjs} +3 -3
- package/types/sorted_list/{module.f.cjs → module.f.mjs} +11 -10
- package/types/sorted_list/{test.f.cjs → test.f.mjs} +14 -10
- package/types/sorted_set/{module.f.cjs → module.f.mjs} +8 -7
- package/types/sorted_set/{test.f.cjs → test.f.mjs} +14 -10
- package/types/string/{module.f.cjs → module.f.mjs} +8 -7
- package/types/string/{test.f.cjs → test.f.mjs} +5 -3
- package/types/string_set/{module.f.cjs → module.f.mjs} +15 -10
- package/types/string_set/{test.f.cjs → test.f.mjs} +2 -2
- package/com/cpp/testlib.f.cjs +0 -6
- package/com/cs/testlib.f.cjs +0 -6
- package/com/module.f.cjs +0 -6
- package/com/rust/testlib.f.cjs +0 -6
- package/commonjs/module.f.cjs +0 -20
- package/nodejs/module.f.cjs +0 -4
- package/nodejs/version/main.cjs +0 -6
- package/text/ascii/test.f.cjs +0 -12
- package/types/number/module.f.cjs +0 -24
- package/types/object/test.html +0 -9
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import obj, * as O from '../../types/object/module.f.mjs'
|
|
2
|
+
import list, * as List from '../../types/list/module.f.mjs'
|
|
3
|
+
import f from '../../types/function/module.f.mjs'
|
|
4
|
+
const { compose } = f
|
|
4
5
|
const { filter } = list
|
|
5
6
|
const { entries } = Object
|
|
6
7
|
|
|
@@ -16,7 +17,7 @@ const { entries } = Object
|
|
|
16
17
|
|
|
17
18
|
/** @typedef {{readonly[k in string]: Type}} FieldArray */
|
|
18
19
|
|
|
19
|
-
/** @typedef {
|
|
20
|
+
/** @typedef {O.Entry<Type>} Field */
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* @typedef {{
|
|
@@ -27,7 +28,7 @@ const { entries } = Object
|
|
|
27
28
|
|
|
28
29
|
/** @typedef {{readonly[k in string]: FieldArray}} MethodArray */
|
|
29
30
|
|
|
30
|
-
/** @typedef {
|
|
31
|
+
/** @typedef {O.Entry<FieldArray>} Method */
|
|
31
32
|
|
|
32
33
|
/** @typedef {BaseType|Id|Pointer} Type */
|
|
33
34
|
|
|
@@ -53,18 +54,18 @@ const { entries } = Object
|
|
|
53
54
|
|
|
54
55
|
/** @typedef {readonly['*', Type]} Pointer */
|
|
55
56
|
|
|
56
|
-
/** @type {(kv:
|
|
57
|
+
/** @type {(kv: O.Entry<Type>) => boolean} */
|
|
57
58
|
const isParam = ([name]) => name !== '_'
|
|
58
59
|
|
|
59
60
|
const filterParam = filter(isParam)
|
|
60
61
|
|
|
61
|
-
/** @type {(fa: FieldArray) =>
|
|
62
|
+
/** @type {(fa: FieldArray) => List.List<Field> } */
|
|
62
63
|
const paramList = compose(entries)(filterParam)
|
|
63
64
|
|
|
64
65
|
/** @type {<T>(v: T) => (f: (type: Type) => T) => (fa: FieldArray) => T} */
|
|
65
66
|
const result = v => f => fa => '_' in fa ? f(fa._) : v
|
|
66
67
|
|
|
67
|
-
|
|
68
|
+
export default {
|
|
68
69
|
/** @readonly */
|
|
69
70
|
paramList,
|
|
70
71
|
/** @readonly */
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import package_, * as packageT from '../package/module.f.mjs'
|
|
2
|
+
import module_, * as moduleT from '../module/module.f.mjs'
|
|
3
3
|
const { idToString, dir } = module_
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import * as function_ from '../module/function/module.f.mjs'
|
|
5
|
+
import map, * as Map from '../../types/map/module.f.mjs'
|
|
6
6
|
const { empty: mapEmpty, setReplace } = map
|
|
7
|
-
|
|
7
|
+
import object from '../../types/object/module.f.mjs'
|
|
8
8
|
const { fromMap } = object
|
|
9
|
-
|
|
9
|
+
import path from '../path/module.f.mjs'
|
|
10
10
|
const { parseAndFind } = path
|
|
11
|
-
|
|
11
|
+
import stringSet, * as StringSet from '../../types/string_set/module.f.mjs'
|
|
12
12
|
const { set: setSet, contains: setContains, empty: stringSetEmpty } = stringSet
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @template M
|
|
16
16
|
* @typedef {{
|
|
17
|
-
* readonly packageGet:
|
|
18
|
-
* readonly moduleMapInterface:
|
|
19
|
-
* readonly moduleId:
|
|
17
|
+
* readonly packageGet: packageT.Get
|
|
18
|
+
* readonly moduleMapInterface: moduleT.MapInterface<M>
|
|
19
|
+
* readonly moduleId: moduleT.Id
|
|
20
20
|
* readonly moduleMap: M
|
|
21
21
|
* }} Config
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @template M
|
|
26
|
-
* @typedef {readonly[
|
|
26
|
+
* @typedef {readonly[moduleT.State, M]} Result
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
/** @type {<M>(moduleMap: M) => Result<M>} */
|
|
@@ -31,19 +31,19 @@ const notFound = moduleMap => [['error', ['file not found']], moduleMap]
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* @type {(compile: function_.Compile) =>
|
|
34
|
-
* (packageGet:
|
|
35
|
-
* <M>(moduleMapInterface:
|
|
36
|
-
* (moduleId:
|
|
34
|
+
* (packageGet: packageT.Get) =>
|
|
35
|
+
* <M>(moduleMapInterface: moduleT.MapInterface<M>) =>
|
|
36
|
+
* (moduleId: moduleT.Id) =>
|
|
37
37
|
* (moduleMap: M) =>
|
|
38
38
|
* Result<M>
|
|
39
39
|
* }
|
|
40
40
|
*/
|
|
41
41
|
const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
42
|
-
/** @typedef {typeof moduleMapInterface extends
|
|
42
|
+
/** @typedef {typeof moduleMapInterface extends moduleT.MapInterface<infer M> ? M : never} M */
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* @type {(buildSet:
|
|
46
|
-
* (moduleId:
|
|
45
|
+
* @type {(buildSet: StringSet.StringSet) =>
|
|
46
|
+
* (moduleId: moduleT.Id) =>
|
|
47
47
|
* (source: string) =>
|
|
48
48
|
* (moduleMap: M) =>
|
|
49
49
|
* Result<M>}
|
|
@@ -52,9 +52,9 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
|
52
52
|
const moduleIdStr = idToString(moduleId)
|
|
53
53
|
const buildSet1 = setSet(moduleIdStr)(buildSet)
|
|
54
54
|
const moduleDir = dir(moduleId)
|
|
55
|
-
/** @type {function_.Require<readonly[
|
|
55
|
+
/** @type {function_.Require<readonly[Map.Map<string>, M]>} */
|
|
56
56
|
const require_ = p => ([requireMap, m]) => {
|
|
57
|
-
/** @type {(e: unknown) => function_.Result<readonly[
|
|
57
|
+
/** @type {(e: unknown) => function_.Result<readonly[Map.Map<string>, M]>} */
|
|
58
58
|
const error = e => [['error', e], [requireMap, m]]
|
|
59
59
|
if (moduleDir === null) { return error('file not found') }
|
|
60
60
|
const r = parseAndFind(packageGet)(moduleDir)(p)
|
|
@@ -65,9 +65,9 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
|
65
65
|
return [state[0] === 'error' ? state : ['ok', state[1].exports], [setReplace(p)(rIdStr)(requireMap), m1]]
|
|
66
66
|
}
|
|
67
67
|
return source => moduleMap => {
|
|
68
|
-
/** @type {(s:
|
|
68
|
+
/** @type {(s: moduleT.State) => (m: M) => Result<M>} */
|
|
69
69
|
const set = s => m => [s, moduleMapInterface.setReplace(moduleIdStr)(s)(m)]
|
|
70
|
-
/** @type {(e:
|
|
70
|
+
/** @type {(e: moduleT.Error) => (m: M) => Result<M>} */
|
|
71
71
|
const error = e => set(['error', e])
|
|
72
72
|
// check compilation
|
|
73
73
|
const [kind, result] = compile(source)
|
|
@@ -80,7 +80,7 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
|
80
80
|
return x(moduleMap2)
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
/** @type {(moduleId:
|
|
83
|
+
/** @type {(moduleId: moduleT.Id) => (moduleMap: M) => Result<M>} */
|
|
84
84
|
const f = moduleId => moduleMap => {
|
|
85
85
|
const moduleIdStr = idToString(moduleId)
|
|
86
86
|
// check moduleMap
|
|
@@ -98,7 +98,7 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
|
98
98
|
return f
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
export default {
|
|
102
102
|
/** @readonly */
|
|
103
103
|
getOrBuild,
|
|
104
104
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import _ from './module.f.mjs'
|
|
2
|
+
import map, * as Map from '../../types/map/module.f.mjs'
|
|
3
|
+
import * as Module from '../module/module.f.mjs'
|
|
4
|
+
import * as ModuleFunction from '../module/function/module.f.mjs'
|
|
5
|
+
import * as Result from '../../types/result/module.f.mjs'
|
|
6
|
+
import * as Package from '../package/module.f.mjs'
|
|
7
|
+
import o from '../../types/object/module.f.mjs'
|
|
8
|
+
const { at } = o
|
|
8
9
|
|
|
9
|
-
/** @type {{ readonly [k in string]?:
|
|
10
|
+
/** @type {{ readonly [k in string]?: Result.Result<ModuleFunction.Function_, unknown> }} */
|
|
10
11
|
const compileMap = {
|
|
11
12
|
':index.js': [
|
|
12
13
|
'ok',
|
|
@@ -30,7 +31,7 @@ const compileMap = {
|
|
|
30
31
|
() => m0 => [['ok', 'x:r.js'], m0]],
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
/** @type {
|
|
34
|
+
/** @type {ModuleFunction.Compile} */
|
|
34
35
|
const compile = source => compileMap[source] ?? ['error', 'invalid source']
|
|
35
36
|
|
|
36
37
|
/** @typedef {{ readonly [k in string]: string }} StringMap */
|
|
@@ -55,7 +56,7 @@ const packageMap = {
|
|
|
55
56
|
},
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
/** @type {
|
|
59
|
+
/** @type {Package.Get} */
|
|
59
60
|
const packageGet = packageId => {
|
|
60
61
|
const p = at(packageId)(packageMap)
|
|
61
62
|
return p === null ? null :
|
|
@@ -68,9 +69,9 @@ const packageGet = packageId => {
|
|
|
68
69
|
const getOrBuild = _.getOrBuild
|
|
69
70
|
(compile)
|
|
70
71
|
(packageGet)
|
|
71
|
-
(/** @type {
|
|
72
|
+
(/** @type {Module.MapInterface<Map.Map<Module.State>>} */(map))
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
export default () => {
|
|
74
75
|
let [r, m] = getOrBuild({ package: '', path: ['index.js'] })(map.empty)
|
|
75
76
|
{
|
|
76
77
|
if (r === null) { throw 'r === null' }
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* An IO interface for creating and running module functions.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import * as Result from '../../../types/result/module.f.mjs'
|
|
6
6
|
|
|
7
7
|
/** @typedef {<M>(require: Require<M>) => (prior: M) => Result<M>} Function_ */
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @template M
|
|
11
|
-
* @typedef {readonly[
|
|
11
|
+
* @typedef {readonly[Result.Result<unknown, unknown>, M]} Result
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -16,6 +16,6 @@ const result = require('../../../types/result/module.f.cjs')
|
|
|
16
16
|
* @typedef {(path: string) => (prior: M) => Result<M>} Require
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
/** @typedef {(source: string) =>
|
|
19
|
+
/** @typedef {(source: string) => Result.Result<Function_, unknown>} Compile */
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
export default {}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import object, * as O from '../../types/object/module.f.mjs'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @template M
|
|
@@ -18,7 +18,7 @@ const object = require('../../types/object/module.f.cjs')
|
|
|
18
18
|
/**
|
|
19
19
|
* @typedef {{
|
|
20
20
|
* readonly exports: unknown
|
|
21
|
-
* readonly requireMap:
|
|
21
|
+
* readonly requireMap: O.Map<string>
|
|
22
22
|
* }} Module
|
|
23
23
|
*/
|
|
24
24
|
|
|
@@ -51,9 +51,7 @@ const dir = id => {
|
|
|
51
51
|
/** @type {(id: Id) => string} */
|
|
52
52
|
const idToString = id => `${id.package}/${id.path.join('/')}`
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
/** @readonly */
|
|
56
|
-
function: require('./function/module.f.cjs'),
|
|
54
|
+
export default {
|
|
57
55
|
/** @readonly */
|
|
58
56
|
dir,
|
|
59
57
|
/** @readonly */
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
const {
|
|
3
|
-
|
|
1
|
+
import unsafeResult from '../types/result/module.mjs'
|
|
2
|
+
const { tryCatch } = unsafeResult
|
|
3
|
+
import result from '../types/result/module.f.mjs'
|
|
4
|
+
const { unwrap } = result
|
|
5
|
+
import * as ModuleFunction from './module/function/module.f.mjs'
|
|
4
6
|
|
|
5
|
-
/** @type {(f: Function) =>
|
|
7
|
+
/** @type {(f: Function) => ModuleFunction.Function_} */
|
|
6
8
|
const build = f => immutableRequire => mutableData => {
|
|
7
9
|
/** @type {(path: string) => unknown} */
|
|
8
10
|
const mutableRequire = path => {
|
|
@@ -20,12 +22,12 @@ const build = f => immutableRequire => mutableData => {
|
|
|
20
22
|
return [result, mutableData]
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
/** @type {
|
|
25
|
+
/** @type {ModuleFunction.Compile} */
|
|
24
26
|
const compile = source =>
|
|
25
27
|
// Side effect: a `Function` constructor is not allowed in FunctionalScript.
|
|
26
28
|
tryCatch(() => build(Function('module', 'require', `"use strict";${source}`)))
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
export default {
|
|
29
31
|
/** @readonly */
|
|
30
32
|
compile,
|
|
31
33
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import json, * as jsonT from '../../../json/module.f.mjs'
|
|
2
2
|
const { isObject } = json
|
|
3
|
-
|
|
3
|
+
import list from '../../../types/list/module.f.mjs'
|
|
4
4
|
const { map, every } = list
|
|
5
5
|
const { entries } = Object
|
|
6
6
|
|
|
@@ -10,17 +10,17 @@ const { entries } = Object
|
|
|
10
10
|
|
|
11
11
|
/** @typedef {DependencyMapJson|null} DependenciesJson */
|
|
12
12
|
|
|
13
|
-
/** @type {(entry:
|
|
13
|
+
/** @type {(entry: jsonT.Entry) => boolean} */
|
|
14
14
|
const isDependencyJson = ([, v]) => typeof v === 'string'
|
|
15
15
|
|
|
16
|
-
/** @type {(j:
|
|
16
|
+
/** @type {(j: jsonT.Unknown) => j is DependenciesJson} */
|
|
17
17
|
const isDependenciesJson = j => {
|
|
18
18
|
if (j === null) { return true }
|
|
19
19
|
if (!isObject(j)) { return false }
|
|
20
20
|
return every(map(isDependencyJson)(entries(j)))
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
export default {
|
|
24
24
|
/** @readonly */
|
|
25
25
|
isDependenciesJson,
|
|
26
26
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import _ from './module.f.mjs'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default () => {
|
|
4
4
|
if (!_.isDependenciesJson(null)) { throw 'error' }
|
|
5
5
|
if (!_.isDependenciesJson({})) { throw 'error' }
|
|
6
6
|
if (!_.isDependenciesJson({'a':'b'})) { throw 'error' }
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import json, * as jsonT from '../../json/module.f.mjs'
|
|
2
2
|
const { isObject } = json
|
|
3
|
-
|
|
3
|
+
import dependencies, * as dependenciesT from './dependencies/module.f.mjs'
|
|
4
4
|
const { isDependenciesJson } = dependencies
|
|
5
|
-
|
|
5
|
+
import o from '../../types/object/module.f.mjs'
|
|
6
|
+
const { at } = o
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @typedef {{
|
|
9
10
|
* readonly name: string
|
|
10
11
|
* readonly version: string
|
|
11
|
-
* readonly dependencies?:
|
|
12
|
+
* readonly dependencies?: dependenciesT.DependenciesJson
|
|
12
13
|
* }} PackageJson
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
|
-
/** @type {(j:
|
|
16
|
+
/** @type {(j: jsonT.Unknown) => j is PackageJson} */
|
|
16
17
|
const isPackageJson = j => {
|
|
17
18
|
if (!isObject(j)) { return false }
|
|
18
19
|
if (typeof j.name !== 'string') { return false }
|
|
@@ -33,7 +34,7 @@ const isPackageJson = j => {
|
|
|
33
34
|
* @typedef {(packageId: string) => Package | null} Get
|
|
34
35
|
*/
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
export default {
|
|
37
38
|
/** @readonly */
|
|
38
39
|
dependencies,
|
|
39
40
|
/** @readonly */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import _ from './module.f.mjs'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default () => {
|
|
4
4
|
if (_.isPackageJson(null)) { throw 'error' }
|
|
5
5
|
if (_.isPackageJson({})) { throw 'error' }
|
|
6
6
|
if (_.isPackageJson({name:'x',version:12})) { throw 'error' }
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import list, * as List from '../../types/list/module.f.mjs'
|
|
2
2
|
const { next, fold, reverse, first, flat, toArray, filterMap, isEmpty, concat } = list
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
3
|
+
import string from '../../types/string/module.f.mjs'
|
|
4
|
+
const { join } = string
|
|
5
|
+
import package_, * as packageT from '../package/module.f.mjs'
|
|
6
|
+
import module_, * as moduleT from '../module/module.f.mjs'
|
|
6
7
|
|
|
7
8
|
/** @typedef {readonly string[]} Items */
|
|
8
9
|
|
|
@@ -17,7 +18,7 @@ const module_ = require("../module/module.f.cjs")
|
|
|
17
18
|
/** @type {(path: string) => readonly string[]} */
|
|
18
19
|
const split = path => path.split('/')
|
|
19
20
|
|
|
20
|
-
/** @typedef {readonly[
|
|
21
|
+
/** @typedef {readonly[List.List<string>] | null} OptionList */
|
|
21
22
|
|
|
22
23
|
/** @type {(items: string) => (prior: OptionList) => OptionList} */
|
|
23
24
|
const normItemsOp = first => prior => {
|
|
@@ -36,7 +37,7 @@ const normItemsOp = first => prior => {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
/** @type {(items:
|
|
40
|
+
/** @type {(items: List.List<string>) => OptionList} */
|
|
40
41
|
const normItems = items => {
|
|
41
42
|
const result = fold(normItemsOp)([list.empty])(items)
|
|
42
43
|
return result === null ? result : [reverse(result[0])]
|
|
@@ -46,7 +47,7 @@ const firstNull = first(null)
|
|
|
46
47
|
|
|
47
48
|
/** @type {(local: string) => (path: string) => LocalPath|null} */
|
|
48
49
|
const parseLocal = local => {
|
|
49
|
-
/** @type {(path: string) => readonly[boolean, boolean,
|
|
50
|
+
/** @type {(path: string) => readonly[boolean, boolean, List.List<string>]} */
|
|
50
51
|
const fSeq = path => {
|
|
51
52
|
const pathSeq = split(path)
|
|
52
53
|
const dir = [null, '', '.', '..'].includes(pathSeq[pathSeq.length - 1])
|
|
@@ -67,9 +68,9 @@ const parseLocal = local => {
|
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
/** @typedef {readonly[string,
|
|
71
|
+
/** @typedef {readonly[string, List.List<string>]} IdPath */
|
|
71
72
|
|
|
72
|
-
/** @type {(prior: readonly[string|null,
|
|
73
|
+
/** @type {(prior: readonly[string|null, List.List<string>]) => List.Thunk<IdPath>} */
|
|
73
74
|
const variants = prior => () => {
|
|
74
75
|
const [a, b] = prior
|
|
75
76
|
const r = next(b)
|
|
@@ -97,7 +98,7 @@ const mapDependency = d => ([external, internal]) => {
|
|
|
97
98
|
/**
|
|
98
99
|
* @type {(d: (local: string) => string|null) =>
|
|
99
100
|
* (dir: boolean) =>
|
|
100
|
-
* (items:
|
|
101
|
+
* (items: List.List<string>) =>
|
|
101
102
|
* Path|null}
|
|
102
103
|
*/
|
|
103
104
|
const parseGlobal = dependencies =>
|
|
@@ -131,7 +132,7 @@ const parse = packageId => dependencies => {
|
|
|
131
132
|
|
|
132
133
|
/**
|
|
133
134
|
* @typedef {{
|
|
134
|
-
* readonly id:
|
|
135
|
+
* readonly id: moduleT.Id
|
|
135
136
|
* readonly source: string
|
|
136
137
|
* }} FoundResult
|
|
137
138
|
*/
|
|
@@ -139,8 +140,8 @@ const parse = packageId => dependencies => {
|
|
|
139
140
|
/** @typedef {FoundResult| null} Result */
|
|
140
141
|
|
|
141
142
|
/**
|
|
142
|
-
* @type {(packageGet:
|
|
143
|
-
* (moduleId:
|
|
143
|
+
* @type {(packageGet: packageT.Get) =>
|
|
144
|
+
* (moduleId: moduleT.Id) =>
|
|
144
145
|
* (path: string) =>
|
|
145
146
|
* Result
|
|
146
147
|
* }
|
|
@@ -163,7 +164,7 @@ const parseAndFind = packageGet => moduleId => path => {
|
|
|
163
164
|
return firstNull(filterMap(tryFile)(fileList))
|
|
164
165
|
}
|
|
165
166
|
|
|
166
|
-
|
|
167
|
+
export default {
|
|
167
168
|
/** @readonly */
|
|
168
169
|
parseLocal,
|
|
169
170
|
/** @readonly */
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
|
|
1
|
+
import _ from './module.f.mjs'
|
|
2
|
+
import dev from '../../dev/module.f.mjs'
|
|
3
|
+
const { todo } = dev
|
|
4
|
+
import json, * as jsonT from '../../json/module.f.mjs'
|
|
5
|
+
import f from '../../types/function/module.f.mjs'
|
|
6
|
+
const { identity } = f
|
|
7
|
+
import object, * as O from '../../types/object/module.f.mjs'
|
|
8
|
+
const { at } = object
|
|
9
|
+
import * as packageT from '../package/module.f.mjs'
|
|
8
10
|
|
|
9
|
-
/** @type {<T>(o:
|
|
11
|
+
/** @type {<T>(o: O.Map<T>) => (s: string) => T|null} */
|
|
10
12
|
const i = o => s => at(s)(o)
|
|
11
13
|
|
|
12
|
-
/** @type {(g:
|
|
14
|
+
/** @type {(g: jsonT.Unknown) => string} */
|
|
13
15
|
const stringify = json.stringify(identity)
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
export default {
|
|
16
18
|
0: () => {
|
|
17
19
|
const result = _.parseLocal('')('./a')
|
|
18
20
|
if (stringify(result) !== '{"external":false,"dir":false,"items":["a"]}') { throw result }
|
|
@@ -68,7 +70,7 @@ module.exports = {
|
|
|
68
70
|
},
|
|
69
71
|
},
|
|
70
72
|
9: () => {
|
|
71
|
-
/** @type {
|
|
73
|
+
/** @type {O.Map<packageT.Package>} */
|
|
72
74
|
const packages = {
|
|
73
75
|
'': {
|
|
74
76
|
dependency: () => todo(),
|
|
@@ -79,7 +81,7 @@ module.exports = {
|
|
|
79
81
|
if (result !== '{"id":{"package":"","path":["a","c"]},"source":"return \\"a/c\\""}') { throw result }
|
|
80
82
|
},
|
|
81
83
|
10: () => {
|
|
82
|
-
/** @type {
|
|
84
|
+
/** @type {O.Map<packageT.Package>} */
|
|
83
85
|
const packages = {
|
|
84
86
|
'': {
|
|
85
87
|
dependency: x => {
|
|
@@ -129,7 +131,7 @@ module.exports = {
|
|
|
129
131
|
}
|
|
130
132
|
},
|
|
131
133
|
11: () => {
|
|
132
|
-
/** @type {
|
|
134
|
+
/** @type {O.Map<packageT.Package>} */
|
|
133
135
|
const packages = {
|
|
134
136
|
'': {
|
|
135
137
|
dependency: x => {
|
|
@@ -156,7 +158,7 @@ module.exports = {
|
|
|
156
158
|
}
|
|
157
159
|
},
|
|
158
160
|
12: () => {
|
|
159
|
-
/** @type {
|
|
161
|
+
/** @type {O.Map<packageT.Package>} */
|
|
160
162
|
const packages = {
|
|
161
163
|
'': {
|
|
162
164
|
dependency: x => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import _ from './module.mjs'
|
|
2
|
+
import run, * as runT from './module/function/module.f.mjs'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export default {
|
|
5
5
|
ok: () => {
|
|
6
6
|
const source = 'module.exports = "Hello world!"'
|
|
7
7
|
const m = _.compile(source)
|
|
@@ -32,7 +32,7 @@ module.exports = {
|
|
|
32
32
|
const d = _.compile(depSource)
|
|
33
33
|
if (d[0] !== 'ok') { throw d }
|
|
34
34
|
|
|
35
|
-
/** @type {
|
|
35
|
+
/** @type {runT.Require<number>} */
|
|
36
36
|
const req = path => prior => {
|
|
37
37
|
if (path !== 'm') { throw path }
|
|
38
38
|
return d[1](req)(prior + 1)
|
package/dev/module.mjs
CHANGED
|
@@ -86,7 +86,7 @@ export const loadModuleMap = async () => {
|
|
|
86
86
|
const file = `${p}/${name}`
|
|
87
87
|
if (i.isDirectory()) {
|
|
88
88
|
await f(file)
|
|
89
|
-
} else if (name.endsWith('.f.cjs')) {
|
|
89
|
+
} else if (name.endsWith('.f.cjs') || name.endsWith('.f.mjs')) {
|
|
90
90
|
const source = await import(`../${file}`)
|
|
91
91
|
map.push([file, source.default])
|
|
92
92
|
}
|
|
@@ -183,8 +183,10 @@ export const index = async() => {
|
|
|
183
183
|
let m = {}
|
|
184
184
|
for (const k in await loadModuleMap()) {
|
|
185
185
|
const [, ...s] = k.split('/')
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
switch (s[s.length - 1]) {
|
|
187
|
+
case 'module.f.cjs': case 'module.f.mjs':
|
|
188
|
+
m = folderMapAdd(m)(s)
|
|
189
|
+
break
|
|
188
190
|
}
|
|
189
191
|
}
|
|
190
192
|
const [e, i] = codeAdd(indent)('')(m)
|