functionalscript 0.0.480 → 0.0.482
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/commonjs/build/module.f.cjs +5 -5
- package/commonjs/build/test.f.cjs +8 -7
- package/commonjs/package/dependencies/module.f.cjs +3 -3
- package/commonjs/package/dependencies/test.f.cjs +1 -2
- package/commonjs/package/module.f.cjs +5 -4
- package/commonjs/path/module.f.cjs +12 -12
- package/commonjs/path/test.f.cjs +20 -26
- package/dev/module.mjs +1 -1
- package/doc/LANGUAGE.md +1 -1
- package/fsm/module.f.cjs +2 -2
- package/package.json +1 -1
- package/types/btree/module.f.cjs +2 -0
- package/types/string_set/module.f.cjs +3 -0
|
@@ -3,13 +3,13 @@ const module_ = require('../module/module.f.cjs')
|
|
|
3
3
|
const { idToString, dir } = module_
|
|
4
4
|
const function_ = require('../module/function/module.f.cjs')
|
|
5
5
|
const map = require('../../types/map/module.f.cjs')
|
|
6
|
-
const { setReplace } = map
|
|
6
|
+
const { empty: mapEmpty, setReplace } = map
|
|
7
7
|
const object = require('../../types/object/module.f.cjs')
|
|
8
8
|
const { fromMap } = object
|
|
9
9
|
const path = require('../path/module.f.cjs')
|
|
10
10
|
const { parseAndFind } = path
|
|
11
11
|
const stringSet = require('../../types/string_set/module.f.cjs')
|
|
12
|
-
const { set: setSet, contains: setContains } = stringSet
|
|
12
|
+
const { set: setSet, contains: setContains, empty: stringSetEmpty } = stringSet
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @template M
|
|
@@ -73,7 +73,7 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
|
73
73
|
const [kind, result] = compile(source)
|
|
74
74
|
if (kind === 'error') { return error(['compilation error', result])(moduleMap) }
|
|
75
75
|
// build
|
|
76
|
-
const [[state, value], [requireMap, moduleMap2]] = result(require_)([
|
|
76
|
+
const [[state, value], [requireMap, moduleMap2]] = result(require_)([mapEmpty, moduleMap])
|
|
77
77
|
const x = state === 'error' ?
|
|
78
78
|
error(['runtime error', value]) :
|
|
79
79
|
set(['ok', { exports: value, requireMap: fromMap(requireMap) }])
|
|
@@ -90,10 +90,10 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
|
90
90
|
}
|
|
91
91
|
// check package
|
|
92
92
|
const p = packageGet(moduleId.package)
|
|
93
|
-
if (p ===
|
|
93
|
+
if (p === null) { return notFound(moduleMap) }
|
|
94
94
|
// check file
|
|
95
95
|
const source = p.file(moduleId.path.join('/'))
|
|
96
|
-
return (source ===
|
|
96
|
+
return (source === null ? notFound : build(stringSetEmpty)(moduleId)(source))(moduleMap)
|
|
97
97
|
}
|
|
98
98
|
return f
|
|
99
99
|
}
|
|
@@ -4,6 +4,7 @@ const module_ = require('../module/module.f.cjs')
|
|
|
4
4
|
const function_ = require('../module/function/module.f.cjs')
|
|
5
5
|
const result = require('../../types/result/module.f.cjs')
|
|
6
6
|
const package_ = require('../package/module.f.cjs')
|
|
7
|
+
const { at } = require('../../types/object/module.f.cjs')
|
|
7
8
|
|
|
8
9
|
/** @type {{ readonly [k in string]?: result.Result<function_.Function_, unknown> }} */
|
|
9
10
|
const compileMap = {
|
|
@@ -32,9 +33,9 @@ const compileMap = {
|
|
|
32
33
|
/** @type {function_.Compile} */
|
|
33
34
|
const compile = source => compileMap[source] ?? ['error', 'invalid source']
|
|
34
35
|
|
|
35
|
-
/** @typedef {{ readonly [k in string]
|
|
36
|
+
/** @typedef {{ readonly [k in string]: string }} StringMap */
|
|
36
37
|
|
|
37
|
-
/** @type {{ readonly [k in string]
|
|
38
|
+
/** @type {{ readonly [k in string]: { readonly dependencies: StringMap, readonly files: StringMap }}} */
|
|
38
39
|
const packageMap = {
|
|
39
40
|
'': {
|
|
40
41
|
dependencies: {
|
|
@@ -56,11 +57,11 @@ const packageMap = {
|
|
|
56
57
|
|
|
57
58
|
/** @type {package_.Get} */
|
|
58
59
|
const packageGet = packageId => {
|
|
59
|
-
const p = packageMap
|
|
60
|
-
return p ===
|
|
60
|
+
const p = at(packageId)(packageMap)
|
|
61
|
+
return p === null ? null :
|
|
61
62
|
{
|
|
62
|
-
dependency: dependency => p.dependencies
|
|
63
|
-
file: file => p.files
|
|
63
|
+
dependency: dependency => at(dependency)(p.dependencies),
|
|
64
|
+
file: file => at(file)(p.files),
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
|
|
@@ -70,7 +71,7 @@ const getOrBuild = _.getOrBuild
|
|
|
70
71
|
(/** @type {module_.MapInterface<map.Map<module_.State>>} */(map))
|
|
71
72
|
|
|
72
73
|
module.exports = () => {
|
|
73
|
-
let [r, m] = getOrBuild({ package: '', path: ['index.js'] })(
|
|
74
|
+
let [r, m] = getOrBuild({ package: '', path: ['index.js'] })(map.empty)
|
|
74
75
|
{
|
|
75
76
|
const x = JSON.stringify(r)
|
|
76
77
|
if (x !==
|
|
@@ -8,14 +8,14 @@ const { entries } = Object
|
|
|
8
8
|
|
|
9
9
|
/** @typedef {{readonly[k in string]: string}} DependencyMapJson */
|
|
10
10
|
|
|
11
|
-
/** @typedef {DependencyMapJson|
|
|
11
|
+
/** @typedef {DependencyMapJson|null} DependenciesJson */
|
|
12
12
|
|
|
13
13
|
/** @type {(entry: json.Entry) => boolean} */
|
|
14
14
|
const isDependencyJson = ([, v]) => typeof v === 'string'
|
|
15
15
|
|
|
16
|
-
/** @type {(j: json.Unknown
|
|
16
|
+
/** @type {(j: json.Unknown) => j is DependenciesJson} */
|
|
17
17
|
const isDependenciesJson = j => {
|
|
18
|
-
if (j ===
|
|
18
|
+
if (j === null) { return true }
|
|
19
19
|
if (!isObject(j)) { return false }
|
|
20
20
|
return every(map(isDependencyJson)(entries(j)))
|
|
21
21
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
const _ = require('./module.f.cjs')
|
|
2
2
|
|
|
3
3
|
module.exports = () => {
|
|
4
|
-
if (!_.isDependenciesJson(
|
|
5
|
-
if (_.isDependenciesJson(null)) { throw 'error' }
|
|
4
|
+
if (!_.isDependenciesJson(null)) { throw 'error' }
|
|
6
5
|
if (!_.isDependenciesJson({})) { throw 'error' }
|
|
7
6
|
if (!_.isDependenciesJson({'a':'b'})) { throw 'error' }
|
|
8
7
|
if (_.isDependenciesJson({ 'a': 12 })) { throw 'error' }
|
|
@@ -2,6 +2,7 @@ const json = require('../../json/module.f.cjs')
|
|
|
2
2
|
const { isObject } = json
|
|
3
3
|
const dependencies = require('./dependencies/module.f.cjs')
|
|
4
4
|
const { isDependenciesJson } = dependencies
|
|
5
|
+
const { at } = require('../../types/object/module.f.cjs')
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @typedef {{
|
|
@@ -16,20 +17,20 @@ const isPackageJson = j => {
|
|
|
16
17
|
if (!isObject(j)) { return false }
|
|
17
18
|
if (typeof j.name !== 'string') { return false }
|
|
18
19
|
if (typeof j.version !== 'string') { return false }
|
|
19
|
-
if (!isDependenciesJson(
|
|
20
|
+
if (!isDependenciesJson(at('dependencies')(j))) { return false }
|
|
20
21
|
return true
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* @typedef {{
|
|
25
|
-
* readonly dependency: (localPackageId: string) => string |
|
|
26
|
-
* readonly file: (localFileId: string) => string |
|
|
26
|
+
* readonly dependency: (localPackageId: string) => string | null
|
|
27
|
+
* readonly file: (localFileId: string) => string | null
|
|
27
28
|
* }} Package
|
|
28
29
|
*/
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* @note Current package has an empty string '' as a packageId.
|
|
32
|
-
* @typedef {(packageId: string) => Package |
|
|
33
|
+
* @typedef {(packageId: string) => Package | null} Get
|
|
33
34
|
*/
|
|
34
35
|
|
|
35
36
|
module.exports = {
|
|
@@ -80,10 +80,10 @@ const variants = prior => () => {
|
|
|
80
80
|
return { first: n, tail: variants(n) }
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/** @type {(d: (local: string) => string|
|
|
83
|
+
/** @type {(d: (local: string) => string|null) => (p: IdPath) => IdPath|undefined} */
|
|
84
84
|
const mapDependency = d => ([external, internal]) => {
|
|
85
85
|
const id = d(external)
|
|
86
|
-
return id ===
|
|
86
|
+
return id === null ? undefined : [id, internal]
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
@@ -95,10 +95,10 @@ const mapDependency = d => ([external, internal]) => {
|
|
|
95
95
|
*/
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
|
-
* @type {(d: (local: string) => string|
|
|
98
|
+
* @type {(d: (local: string) => string|null) =>
|
|
99
99
|
* (dir: boolean) =>
|
|
100
100
|
* (items: list.List<string>) =>
|
|
101
|
-
* Path|
|
|
101
|
+
* Path|null}
|
|
102
102
|
*/
|
|
103
103
|
const parseGlobal = dependencies =>
|
|
104
104
|
{
|
|
@@ -106,23 +106,23 @@ const parseGlobal = dependencies =>
|
|
|
106
106
|
return dir => items => {
|
|
107
107
|
const v = variants([null, items])
|
|
108
108
|
const r = firstNull(fMap(v))
|
|
109
|
-
if (r === null) { return
|
|
109
|
+
if (r === null) { return null }
|
|
110
110
|
return { package: r[0], items: toArray(r[1]), dir }
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* @type {(packageId: string) =>
|
|
116
|
-
* (dependencies: (local: string) => string|
|
|
116
|
+
* (dependencies: (local: string) => string|null) =>
|
|
117
117
|
* (local: string) =>
|
|
118
118
|
* (path: string) =>
|
|
119
|
-
* Path|
|
|
119
|
+
* Path|null }
|
|
120
120
|
*/
|
|
121
121
|
const parse = packageId => dependencies => {
|
|
122
122
|
const pg = parseGlobal(dependencies)
|
|
123
123
|
return local => path => {
|
|
124
124
|
const parsed = parseLocal(local)(path)
|
|
125
|
-
if (parsed === null) { return
|
|
125
|
+
if (parsed === null) { return null }
|
|
126
126
|
const {external, dir, items } = parsed
|
|
127
127
|
if (!external) { return { package: packageId, items, dir } }
|
|
128
128
|
return pg(dir)(items)
|
|
@@ -147,15 +147,15 @@ const parse = packageId => dependencies => {
|
|
|
147
147
|
*/
|
|
148
148
|
const parseAndFind = packageGet => moduleId => path => {
|
|
149
149
|
const currentPack = packageGet(moduleId.package)
|
|
150
|
-
if (currentPack ===
|
|
150
|
+
if (currentPack === null) { return null }
|
|
151
151
|
const p = parse(moduleId.package)(currentPack.dependency)(moduleId.path.join('/'))(path)
|
|
152
|
-
if (p ===
|
|
152
|
+
if (p === null) { return null }
|
|
153
153
|
const pack = packageGet(p.package)
|
|
154
|
-
if (pack ===
|
|
154
|
+
if (pack === null) { return null }
|
|
155
155
|
/** @type {(file: string) => FoundResult | undefined } */
|
|
156
156
|
const tryFile = file => {
|
|
157
157
|
const source = pack.file(file)
|
|
158
|
-
return source ===
|
|
158
|
+
return source === null ? undefined : { id: { package: p.package, path: file.split('/') }, source }
|
|
159
159
|
}
|
|
160
160
|
const file = p.items.join('/')
|
|
161
161
|
const indexJs = join('/')(concat(p.items)(['index.js']))
|
package/commonjs/path/test.f.cjs
CHANGED
|
@@ -6,17 +6,11 @@ const object = require('../../types/object/module.f.cjs')
|
|
|
6
6
|
const { at } = require('../../types/object/module.f.cjs')
|
|
7
7
|
const package_ = require('../package/module.f.cjs')
|
|
8
8
|
|
|
9
|
-
/** @type {<T>(o: object.Map<T>) => (s: string) => T|
|
|
10
|
-
const i = o => s =>
|
|
11
|
-
const r = at(s)(o)
|
|
12
|
-
return r === null ? undefined : r
|
|
13
|
-
}
|
|
9
|
+
/** @type {<T>(o: object.Map<T>) => (s: string) => T|null} */
|
|
10
|
+
const i = o => s => at(s)(o)
|
|
14
11
|
|
|
15
|
-
/** @type {(g: json.Unknown
|
|
16
|
-
const stringify =
|
|
17
|
-
if (g === undefined) { throw g }
|
|
18
|
-
return json.stringify(identity)(g)
|
|
19
|
-
}
|
|
12
|
+
/** @type {(g: json.Unknown) => string} */
|
|
13
|
+
const stringify = json.stringify(identity)
|
|
20
14
|
|
|
21
15
|
module.exports = {
|
|
22
16
|
0: () => {
|
|
@@ -51,27 +45,27 @@ module.exports = {
|
|
|
51
45
|
const result = _.parseLocal('')('./x/..')
|
|
52
46
|
if (stringify(result) !== '{"external":false,"dir":true,"items":[]}') { throw result }
|
|
53
47
|
},
|
|
54
|
-
8:
|
|
55
|
-
if (_.parseGlobal(() =>
|
|
56
|
-
if (_.parseGlobal(() =>
|
|
57
|
-
if (_.parseGlobal(i({ b: 'x' }))(false)(['d']) !==
|
|
58
|
-
{
|
|
48
|
+
8: {
|
|
49
|
+
0: () => { if (_.parseGlobal(() => null)(false)(['a', 'b']) !== null) { throw 'error' } },
|
|
50
|
+
1: () => { if (_.parseGlobal(() => null)(false)(['b']) !== null) { throw 'error' } },
|
|
51
|
+
2: () => { if (_.parseGlobal(i({ b: 'x' }))(false)(['d']) !== null) { throw 'error' } },
|
|
52
|
+
3: () => {
|
|
59
53
|
const result = stringify(_.parseGlobal(i({ b: 'x' }))(false)(['b']))
|
|
60
54
|
if (result !== '{"package":"x","items":[],"dir":false}') { throw result }
|
|
61
|
-
}
|
|
62
|
-
if (_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b']) !==
|
|
63
|
-
{
|
|
55
|
+
},
|
|
56
|
+
4: () => { if (_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b']) !== null) { throw 'error' } },
|
|
57
|
+
5: () => {
|
|
64
58
|
const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b', 'r']))
|
|
65
59
|
if (result !== '{"package":"x","items":[],"dir":false}') { throw result }
|
|
66
|
-
}
|
|
67
|
-
{
|
|
60
|
+
},
|
|
61
|
+
6: () => {
|
|
68
62
|
const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b', 'r', 'd', 't']))
|
|
69
63
|
if (result !== '{"package":"x","items":["d","t"],"dir":false}') { throw result }
|
|
70
|
-
}
|
|
71
|
-
{
|
|
64
|
+
},
|
|
65
|
+
7: () => {
|
|
72
66
|
const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(true)(['b', 'r', 'd', 't']))
|
|
73
67
|
if (result !== '{"package":"x","items":["d","t"],"dir":true}') { throw result }
|
|
74
|
-
}
|
|
68
|
+
},
|
|
75
69
|
},
|
|
76
70
|
9: () => {
|
|
77
71
|
/** @type {object.Map<package_.Package>} */
|
|
@@ -90,7 +84,7 @@ module.exports = {
|
|
|
90
84
|
'': {
|
|
91
85
|
dependency: x => {
|
|
92
86
|
const path = `node_modules/${x}`
|
|
93
|
-
return at(path)(packages) !==
|
|
87
|
+
return at(path)(packages) !== null ? path : null
|
|
94
88
|
},
|
|
95
89
|
file: i({
|
|
96
90
|
'index.js': 'return "index.js"',
|
|
@@ -140,7 +134,7 @@ module.exports = {
|
|
|
140
134
|
'': {
|
|
141
135
|
dependency: x => {
|
|
142
136
|
const path = `node_modules/${x}`
|
|
143
|
-
return at(path)(packages) !== null ? path :
|
|
137
|
+
return at(path)(packages) !== null ? path : null
|
|
144
138
|
},
|
|
145
139
|
file: todo
|
|
146
140
|
},
|
|
@@ -167,7 +161,7 @@ module.exports = {
|
|
|
167
161
|
'': {
|
|
168
162
|
dependency: x => {
|
|
169
163
|
const path = `node_modules/${x}`
|
|
170
|
-
return at(path)(packages) !== null ? path :
|
|
164
|
+
return at(path)(packages) !== null ? path : null
|
|
171
165
|
},
|
|
172
166
|
file: todo
|
|
173
167
|
},
|
package/dev/module.mjs
CHANGED
package/doc/LANGUAGE.md
CHANGED
package/fsm/module.f.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const list = require('../types/list/module.f.cjs')
|
|
2
|
-
const { equal, isEmpty, fold, toArray, scan, foldScan } = list
|
|
2
|
+
const { equal, isEmpty, fold, toArray, scan, foldScan, empty: emptyList } = list
|
|
3
3
|
const byteSet = require('../types/byte_set/module.f.cjs')
|
|
4
4
|
const { toRangeMap, union: byteSetUnion, one, empty } = byteSet
|
|
5
5
|
const sortedSet = require('../types/sorted_set/module.f.cjs')
|
|
@@ -66,7 +66,7 @@ const scanFetch = scan(fetchOp)
|
|
|
66
66
|
const addEntry = grammar => set => dfa => {
|
|
67
67
|
const s = stringifyIdentity(set)
|
|
68
68
|
if (s in dfa) { return dfa }
|
|
69
|
-
const setMap = fold(foldOp(set))(
|
|
69
|
+
const setMap = fold(foldOp(set))(emptyList)(grammar)
|
|
70
70
|
const stringMap = toArray(scanStringify(setMap))
|
|
71
71
|
const newDfa = { ...dfa, [s]: stringMap }
|
|
72
72
|
const newStates = scanFetch(setMap)
|
package/package.json
CHANGED
package/types/btree/module.f.cjs
CHANGED
|
@@ -6,6 +6,7 @@ const {
|
|
|
6
6
|
set: { set: btreeSet },
|
|
7
7
|
/** @type {(s: StringSet) => list.List<string>} */
|
|
8
8
|
values,
|
|
9
|
+
empty,
|
|
9
10
|
} = btree
|
|
10
11
|
const { cmp } = require("../string/module.f.cjs")
|
|
11
12
|
const list = require('../list/module.f.cjs')
|
|
@@ -29,6 +30,8 @@ const fromValues = fold(set)(undefined)
|
|
|
29
30
|
const remove = compose(cmp)(btreeRemove)
|
|
30
31
|
|
|
31
32
|
module.exports = {
|
|
33
|
+
/** @readonly */
|
|
34
|
+
empty,
|
|
32
35
|
/** @readonly */
|
|
33
36
|
contains,
|
|
34
37
|
/** @readonly */
|