functionalscript 0.0.237 → 0.0.238
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/module/index.js +22 -0
- package/commonjs/package/dependencies/index.js +0 -38
- package/commonjs/package/dependencies/test.js +0 -25
- package/commonjs/package/index.js +7 -5
- package/commonjs/package/test.js +5 -5
- package/commonjs/path/index.js +55 -5
- package/commonjs/path/test.js +33 -16
- package/io/commonjs/index.js +5 -5
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const map = require('../../types/map')
|
|
2
|
+
const object = require('../../types/object')
|
|
3
|
+
const run = require('../run')
|
|
4
|
+
const seq = require('../../types/sequence')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {{
|
|
8
|
+
* readonly map: object.Map<string>
|
|
9
|
+
* readonly run: run.Module
|
|
10
|
+
* }} Module
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {{
|
|
15
|
+
* readonly map: map.Map<Module>
|
|
16
|
+
* readonly order: seq.Sequence<string>
|
|
17
|
+
* }} Cache
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** @typedef {(path: string) => string|undefined} ReadFile */
|
|
21
|
+
|
|
22
|
+
module.exports = {}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
const { todo } = require('../../../dev')
|
|
2
1
|
const json = require('../../../json')
|
|
3
|
-
const { isObject } = json
|
|
4
2
|
const seq = require('../../../types/sequence')
|
|
5
|
-
const path = require('../../path')
|
|
6
|
-
const { at } = require('../../../types/object')
|
|
7
3
|
|
|
8
4
|
/** @typedef {readonly[string, string]} DependencyJson */
|
|
9
5
|
|
|
@@ -21,41 +17,7 @@ const isDependenciesJson = j => {
|
|
|
21
17
|
return seq.every(seq.map(isDependencyJson)(Object.entries(j)))
|
|
22
18
|
}
|
|
23
19
|
|
|
24
|
-
/** @typedef {readonly[string, seq.Sequence<string>]} IdPath */
|
|
25
|
-
|
|
26
|
-
/** @type {(prior: readonly[string|undefined, seq.Sequence<string>]) => seq.Thunk<IdPath>} */
|
|
27
|
-
const variants = prior => () => {
|
|
28
|
-
const [a, b] = prior
|
|
29
|
-
const r = seq.next(b)
|
|
30
|
-
if (r === undefined) { return undefined }
|
|
31
|
-
const { first, tail } = r
|
|
32
|
-
/** @type {IdPath} */
|
|
33
|
-
const n = [a === undefined ? first : `${a}/${first}`, tail]
|
|
34
|
-
return { first: n, tail: variants(n) }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** @type {(d: DependencyMapJson) => (p: IdPath) => IdPath|undefined} */
|
|
38
|
-
const mapDependency = d => ([external, internal]) => {
|
|
39
|
-
const id = at(external)(d)
|
|
40
|
-
if (id === undefined) { return undefined }
|
|
41
|
-
return [id, internal]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** @typedef {readonly[string, string]} GlobalPath */
|
|
45
|
-
|
|
46
|
-
/** @type {(d: DependenciesJson) => (p: path.Items) => GlobalPath|undefined} */
|
|
47
|
-
const idPath = d => p => {
|
|
48
|
-
if (d === undefined) { return undefined }
|
|
49
|
-
const v = variants([undefined, p])
|
|
50
|
-
const valid = seq.first(undefined)(seq.filterMap(mapDependency(d))(v))
|
|
51
|
-
if (valid === undefined) { return undefined }
|
|
52
|
-
const [packId, localId] = valid
|
|
53
|
-
return [packId, seq.join('/')(localId)]
|
|
54
|
-
}
|
|
55
|
-
|
|
56
20
|
module.exports = {
|
|
57
21
|
/** @readonly */
|
|
58
22
|
isDependenciesJson,
|
|
59
|
-
/** @readonly */
|
|
60
|
-
idPath,
|
|
61
23
|
}
|
|
@@ -10,28 +10,3 @@ const seq = require('../../../types/sequence')
|
|
|
10
10
|
if (!_.isDependenciesJson({'a':'b'})) { throw 'error' }
|
|
11
11
|
if (_.isDependenciesJson({ 'a': 12 })) { throw 'error' }
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
/** @type {(g: _.GlobalPath|undefined) => string} */
|
|
15
|
-
const stringify = g => {
|
|
16
|
-
if (g === undefined) { throw g }
|
|
17
|
-
return json.stringify(sort)(g)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
{
|
|
21
|
-
if (_.idPath(undefined)(['a', 'b']) !== undefined) { throw 'error' }
|
|
22
|
-
if (_.idPath({})(['b']) !== undefined) { throw 'error' }
|
|
23
|
-
if (_.idPath({b:'x'})(['d']) !== undefined) { throw 'error'}
|
|
24
|
-
{
|
|
25
|
-
const result = stringify(_.idPath({ b: 'x' })(['b']))
|
|
26
|
-
if (result !== '["x",""]') { throw result }
|
|
27
|
-
}
|
|
28
|
-
if (_.idPath({ 'b/r': 'x' })(['b']) !== undefined) { throw 'error'}
|
|
29
|
-
{
|
|
30
|
-
const result = stringify(_.idPath({ 'b/r': 'x' })(['b', 'r']))
|
|
31
|
-
if (result !== '["x",""]') { throw result }
|
|
32
|
-
}
|
|
33
|
-
{
|
|
34
|
-
const result = stringify(_.idPath({ 'b/r': 'x' })(['b', 'r', 'd', 't']))
|
|
35
|
-
if (result !== '["x","d/t"]') { throw result }
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
const json = require('../../json')
|
|
2
2
|
const dep = require('./dependencies')
|
|
3
|
+
const object = require('../../types/object')
|
|
4
|
+
const run = require('../run')
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* @typedef {{
|
|
8
|
+
* readonly name: string
|
|
6
9
|
* readonly version: string
|
|
7
10
|
* readonly dependencies?: dep.DependenciesJson
|
|
8
11
|
* }} PackageJson
|
|
@@ -11,16 +14,15 @@ const dep = require('./dependencies')
|
|
|
11
14
|
/** @type {(j: json.Unknown) => j is PackageJson} */
|
|
12
15
|
const isPackageJson = j => {
|
|
13
16
|
if (!json.isObject(j)) { return false }
|
|
17
|
+
if (typeof j.name !== 'string') { return false }
|
|
14
18
|
if (typeof j.version !== 'string') { return false }
|
|
15
19
|
if (!dep.isDependenciesJson(j.dependencies)) { return false }
|
|
16
20
|
return true
|
|
17
21
|
}
|
|
18
22
|
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* }} Package
|
|
23
|
-
*/
|
|
23
|
+
/** @typedef {object.Map<string>} Files */
|
|
24
|
+
|
|
25
|
+
/** @typedef {object.Map<dep.DependencyJson>} PackageMap */
|
|
24
26
|
|
|
25
27
|
module.exports = {
|
|
26
28
|
/** @readonly */
|
package/commonjs/package/test.js
CHANGED
|
@@ -5,12 +5,12 @@ require('./dependencies/test')
|
|
|
5
5
|
{
|
|
6
6
|
if (_.isPackageJson(null)) { throw 'error' }
|
|
7
7
|
if (_.isPackageJson({})) { throw 'error' }
|
|
8
|
-
if (_.isPackageJson({version:12})) { throw 'error' }
|
|
9
|
-
if (!_.isPackageJson({version:"12"})) { throw 'error' }
|
|
8
|
+
if (_.isPackageJson({name:'x',version:12})) { throw 'error' }
|
|
9
|
+
if (!_.isPackageJson({name:'x',version:"12"})) { throw 'error' }
|
|
10
10
|
if (_.isPackageJson({version:"",dependencies:[]})) { throw 'error' }
|
|
11
|
-
if (!_.isPackageJson({ version: "", dependencies: {} })) { throw 'error' }
|
|
12
|
-
if (_.isPackageJson({ version: "", dependencies: { x: 12} })) { throw 'error' }
|
|
13
|
-
if (!_.isPackageJson({ version: "", dependencies: { x: "12" } })) { throw 'error' }
|
|
11
|
+
if (!_.isPackageJson({name:'a', version: "", dependencies: {} })) { throw 'error' }
|
|
12
|
+
if (_.isPackageJson({name:'b', version: "", dependencies: { x: 12} })) { throw 'error' }
|
|
13
|
+
if (!_.isPackageJson({name:'c', version: "", dependencies: { x: "12" } })) { throw 'error' }
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
module.exports = {}
|
package/commonjs/path/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const seq = require("../../types/sequence")
|
|
2
2
|
const option = require("../../types/option")
|
|
3
3
|
const { compose } = require("../../types/function")
|
|
4
|
+
const dep = require("../package/dependencies")
|
|
5
|
+
const { at } = require("../../types/object")
|
|
6
|
+
const pack = require("../package")
|
|
4
7
|
|
|
5
8
|
/** @typedef {readonly string[]} Items */
|
|
6
9
|
|
|
@@ -9,7 +12,7 @@ const { compose } = require("../../types/function")
|
|
|
9
12
|
* readonly external: boolean
|
|
10
13
|
* readonly dir: boolean
|
|
11
14
|
* readonly items: Items
|
|
12
|
-
* }}
|
|
15
|
+
* }} LocalPath
|
|
13
16
|
*/
|
|
14
17
|
|
|
15
18
|
/** @type {(path: string) => readonly string[]} */
|
|
@@ -34,8 +37,8 @@ const normItemsOp = prior => item => {
|
|
|
34
37
|
/** @type {(items: seq.Sequence<string>) => seq.Sequence<string>|undefined} */
|
|
35
38
|
const normItems = compose(seq.reduce(normItemsOp)([]))(option.map(seq.reverse))
|
|
36
39
|
|
|
37
|
-
/** @type {(local: string) => (path: string) =>
|
|
38
|
-
const
|
|
40
|
+
/** @type {(local: string) => (path: string) => LocalPath|undefined} */
|
|
41
|
+
const parseLocal = local => {
|
|
39
42
|
/** @type {(path: string) => readonly[boolean, seq.Sequence<string>]} */
|
|
40
43
|
const fSeq = path => {
|
|
41
44
|
const pathSeq = split(path)
|
|
@@ -44,7 +47,7 @@ const parse = local => {
|
|
|
44
47
|
default: { return [true, pathSeq] }
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
|
-
/** @type {(path: string) =>
|
|
50
|
+
/** @type {(path: string) => LocalPath|undefined} */
|
|
48
51
|
const f = path => {
|
|
49
52
|
const [external, items] = fSeq(path)
|
|
50
53
|
const n = normItems(items)
|
|
@@ -58,9 +61,56 @@ const parse = local => {
|
|
|
58
61
|
return f
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
/** @typedef {readonly[string, seq.Sequence<string>]} IdPath */
|
|
65
|
+
|
|
66
|
+
/** @type {(prior: readonly[string|undefined, seq.Sequence<string>]) => seq.Thunk<IdPath>} */
|
|
67
|
+
const variants = prior => () => {
|
|
68
|
+
const [a, b] = prior
|
|
69
|
+
const r = seq.next(b)
|
|
70
|
+
if (r === undefined) { return undefined }
|
|
71
|
+
const { first, tail } = r
|
|
72
|
+
/** @type {IdPath} */
|
|
73
|
+
const n = [a === undefined ? first : `${a}/${first}`, tail]
|
|
74
|
+
return { first: n, tail: variants(n) }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @type {(d: dep.DependencyMapJson) => (p: IdPath) => IdPath|undefined} */
|
|
78
|
+
const mapDependency = d => ([external, internal]) => {
|
|
79
|
+
const id = at(external)(d)
|
|
80
|
+
return id === undefined ? undefined : [id, internal]
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @typedef {{
|
|
85
|
+
* readonly name: string,
|
|
86
|
+
* readonly items: Items,
|
|
87
|
+
* readonly dir: boolean,
|
|
88
|
+
* }} Path
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
/** @type {(d: dep.DependenciesJson) => (dir: boolean) => (items: seq.Sequence<string>) => Path|undefined} */
|
|
92
|
+
const parseGlobal = d => dir => items => {
|
|
93
|
+
if (d === undefined) { return undefined }
|
|
94
|
+
const v = variants([undefined, items])
|
|
95
|
+
const r = seq.first(undefined)(seq.filterMap(mapDependency(d))(v))
|
|
96
|
+
if (r === undefined) { return undefined }
|
|
97
|
+
return { name: r[0], items: seq.toArray(r[1]), dir }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** @type {(name: string) => (dependencies: dep.DependenciesJson) => (local: string) => (path: string) => Path|undefined } */
|
|
101
|
+
const parse = name => dependencies => local => path => {
|
|
102
|
+
const parsed = parseLocal(local)(path)
|
|
103
|
+
if (parsed === undefined) { return undefined }
|
|
104
|
+
const {external, dir, items} = parsed
|
|
105
|
+
if (!external) { return { name, items, dir } }
|
|
106
|
+
return parseGlobal(dependencies)(dir)(items)
|
|
107
|
+
}
|
|
108
|
+
|
|
61
109
|
module.exports = {
|
|
62
110
|
/** @readonly */
|
|
63
|
-
|
|
111
|
+
parseLocal,
|
|
112
|
+
/** @readonly */
|
|
113
|
+
parseGlobal,
|
|
64
114
|
/** @readonly */
|
|
65
115
|
parse,
|
|
66
116
|
}
|
package/commonjs/path/test.js
CHANGED
|
@@ -1,47 +1,64 @@
|
|
|
1
1
|
const _ = require('.')
|
|
2
2
|
const json = require('../../json')
|
|
3
|
-
const { identity
|
|
4
|
-
const seq = require('../../types/sequence')
|
|
3
|
+
const { identity } = require('../../types/function')
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
/** @type {(g: json.Unknown|undefined) => string} */
|
|
6
|
+
const stringify = g => {
|
|
7
|
+
if (g === undefined) { throw g }
|
|
8
|
+
return json.stringify(identity)(g)
|
|
9
|
+
}
|
|
7
10
|
|
|
8
11
|
{
|
|
9
|
-
const
|
|
10
|
-
|
|
12
|
+
const p = { name: '', version: '' }
|
|
13
|
+
const result = _.parseLocal('')('./a')
|
|
11
14
|
if (stringify(result) !== '{"external":false,"dir":false,"items":["a"]}') { throw result }
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
{
|
|
15
|
-
const result = _.
|
|
16
|
-
if (result === undefined) { throw result }
|
|
18
|
+
const result = _.parseLocal('')('./a/')
|
|
17
19
|
if (stringify(result) !== '{"external":false,"dir":true,"items":["a"]}') { throw result }
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
{
|
|
21
|
-
const result = _.
|
|
23
|
+
const result = _.parseLocal('')('..')
|
|
22
24
|
if (result !== undefined) { throw result }
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
{
|
|
26
|
-
const result = _.
|
|
27
|
-
if (result === undefined) { throw result }
|
|
28
|
+
const result = _.parseLocal('a')('')
|
|
28
29
|
if (stringify(result) !== '{"external":true,"dir":false,"items":[]}') { throw result }
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
{
|
|
32
|
-
const result = _.
|
|
33
|
-
if (result === undefined) { throw result }
|
|
33
|
+
const result = _.parseLocal('')('./a/b/.././c')
|
|
34
34
|
if (stringify(result) !== '{"external":false,"dir":false,"items":["a","c"]}') { throw result }
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
{
|
|
38
|
-
const result = _.
|
|
39
|
-
if (result === undefined) { throw result }
|
|
38
|
+
const result = _.parseLocal('x/r')('./a/b/.././c')
|
|
40
39
|
if (stringify(result) !== '{"external":false,"dir":false,"items":["x","r","a","c"]}') { throw result }
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
{
|
|
44
|
-
const result = _.
|
|
45
|
-
if (result === undefined) { throw result }
|
|
43
|
+
const result = _.parseLocal('a')('a/b/.././c')
|
|
46
44
|
if (stringify(result) !== '{"external":true,"dir":false,"items":["a","c"]}') { throw result }
|
|
47
45
|
}
|
|
46
|
+
|
|
47
|
+
{
|
|
48
|
+
if (_.parseGlobal(undefined)(false)(['a', 'b']) !== undefined) { throw 'error' }
|
|
49
|
+
if (_.parseGlobal({})(false)(['b']) !== undefined) { throw 'error' }
|
|
50
|
+
if (_.parseGlobal({ b: 'x' })(false)(['d']) !== undefined) { throw 'error' }
|
|
51
|
+
{
|
|
52
|
+
const result = stringify(_.parseGlobal({ b: 'x' })(false)(['b']))
|
|
53
|
+
if (result !== '["x",""]') { throw result }
|
|
54
|
+
}
|
|
55
|
+
if (_.parseGlobal({ 'b/r': 'x' })(false)(['b']) !== undefined) { throw 'error' }
|
|
56
|
+
{
|
|
57
|
+
const result = stringify(_.parseGlobal({ 'b/r': 'x' })(false)(['b', 'r']))
|
|
58
|
+
if (result !== '["x",""]') { throw result }
|
|
59
|
+
}
|
|
60
|
+
{
|
|
61
|
+
const result = stringify(_.parseGlobal({ 'b/r': 'x' })(false)(['b', 'r', 'd', 't']))
|
|
62
|
+
if (result !== '["x","d/t"]') { throw result }
|
|
63
|
+
}
|
|
64
|
+
}
|
package/io/commonjs/index.js
CHANGED
|
@@ -3,11 +3,11 @@ const { unwrap } = require('../../types/result')
|
|
|
3
3
|
const run = require('../../commonjs/run')
|
|
4
4
|
|
|
5
5
|
/** @type {(f: Function) => run.Module} */
|
|
6
|
-
const
|
|
6
|
+
const build = f => immutableRequire => mutableData => {
|
|
7
7
|
/** @type {(path: string) => unknown} */
|
|
8
8
|
const mutableRequire = path => {
|
|
9
|
-
const [result,
|
|
10
|
-
|
|
9
|
+
const [result, data] = immutableRequire(mutableData)(path)
|
|
10
|
+
mutableData = data
|
|
11
11
|
return unwrap(result)
|
|
12
12
|
}
|
|
13
13
|
const result = tryCatch(() => {
|
|
@@ -15,12 +15,12 @@ const createModule = f => req => mutableInfo => {
|
|
|
15
15
|
f(mutableModule, mutableRequire)
|
|
16
16
|
return mutableModule.exports
|
|
17
17
|
})
|
|
18
|
-
return [result,
|
|
18
|
+
return [result, mutableData]
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/** @type {run.Compile} */
|
|
22
22
|
const compile = source =>
|
|
23
|
-
tryCatch(() =>
|
|
23
|
+
tryCatch(() => build(Function('module', 'require', `"use strict";${source}`)))
|
|
24
24
|
|
|
25
25
|
module.exports = {
|
|
26
26
|
/** @readonly */
|