functionalscript 0.0.236 → 0.0.237
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.
|
@@ -1,71 +1,61 @@
|
|
|
1
|
+
const { todo } = require('../../../dev')
|
|
1
2
|
const json = require('../../../json')
|
|
2
3
|
const { isObject } = json
|
|
3
4
|
const seq = require('../../../types/sequence')
|
|
4
|
-
const
|
|
5
|
-
const
|
|
5
|
+
const path = require('../../path')
|
|
6
|
+
const { at } = require('../../../types/object')
|
|
6
7
|
|
|
7
|
-
/** @typedef {
|
|
8
|
+
/** @typedef {readonly[string, string]} DependencyJson */
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
/** @typedef {{readonly[k in string]: string}} DependencyMapJson */
|
|
10
11
|
|
|
11
|
-
/**
|
|
12
|
-
* @typedef {{
|
|
13
|
-
* readonly get: (dir: string) => Item|undefined
|
|
14
|
-
* readonly set: (dir: string) => (item: Item) => Map
|
|
15
|
-
* }} Map
|
|
16
|
-
*/
|
|
12
|
+
/** @typedef {DependencyMapJson|undefined} DependenciesJson */
|
|
17
13
|
|
|
18
|
-
/** @
|
|
14
|
+
/** @type {(entry: json.Entry) => boolean} */
|
|
15
|
+
const isDependencyJson = ([, v]) => typeof v === 'string'
|
|
19
16
|
|
|
20
|
-
/** @
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (result === undefined) { throw 'panic' }
|
|
26
|
-
const { first: [,m] } = result
|
|
27
|
-
const child = m.get(dir)
|
|
28
|
-
const childMap = child === undefined || typeof child === 'string' ? map.empty : child
|
|
29
|
-
/** @type {Pair} */
|
|
30
|
-
const pair = [dir, childMap]
|
|
31
|
-
return seq.sequence(pair)(prior)
|
|
17
|
+
/** @type {(j: json.Unknown|undefined) => j is DependenciesJson} */
|
|
18
|
+
const isDependenciesJson = j => {
|
|
19
|
+
if (j === undefined) { return true }
|
|
20
|
+
if (!json.isObject(j)) { return false }
|
|
21
|
+
return seq.every(seq.map(isDependencyJson)(Object.entries(j)))
|
|
32
22
|
}
|
|
33
23
|
|
|
34
|
-
/** @typedef {readonly[string,
|
|
35
|
-
|
|
36
|
-
/** @type {(
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
if (result === undefined) { throw 'panic' }
|
|
46
|
-
const { first: [dir], tail } = result
|
|
47
|
-
const [, m] = seq.reduce(set)([dir, id])(tail)
|
|
48
|
-
if (typeof m === 'string') { return prior }
|
|
49
|
-
return m
|
|
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) }
|
|
50
35
|
}
|
|
51
36
|
|
|
52
|
-
/** @type {(
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
return
|
|
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]
|
|
57
42
|
}
|
|
58
43
|
|
|
59
|
-
/** @
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
const
|
|
65
|
-
|
|
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)]
|
|
66
54
|
}
|
|
67
55
|
|
|
68
56
|
module.exports = {
|
|
69
57
|
/** @readonly */
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
isDependenciesJson,
|
|
59
|
+
/** @readonly */
|
|
60
|
+
idPath,
|
|
61
|
+
}
|
|
@@ -1,33 +1,37 @@
|
|
|
1
1
|
const _ = require('.')
|
|
2
|
+
const json = require('../../../json')
|
|
3
|
+
const { sort } = require('../../../types/object')
|
|
4
|
+
const seq = require('../../../types/sequence')
|
|
2
5
|
|
|
3
6
|
{
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (
|
|
7
|
+
if (!_.isDependenciesJson(undefined)) { throw 'error' }
|
|
8
|
+
if (_.isDependenciesJson(null)) { throw 'error' }
|
|
9
|
+
if (!_.isDependenciesJson({})) { throw 'error' }
|
|
10
|
+
if (!_.isDependenciesJson({'a':'b'})) { throw 'error' }
|
|
11
|
+
if (_.isDependenciesJson({ 'a': 12 })) { throw 'error' }
|
|
8
12
|
}
|
|
9
13
|
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (r !== 'e') { throw r }
|
|
14
|
+
/** @type {(g: _.GlobalPath|undefined) => string} */
|
|
15
|
+
const stringify = g => {
|
|
16
|
+
if (g === undefined) { throw g }
|
|
17
|
+
return json.stringify(sort)(g)
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
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 }
|
|
23
32
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const xb = x('b')
|
|
30
|
-
if (xb !== 'xb') { throw xb }
|
|
31
|
-
const xc = x('c')
|
|
32
|
-
if (xc !== undefined) { throw xc }
|
|
33
|
-
}
|
|
33
|
+
{
|
|
34
|
+
const result = stringify(_.idPath({ 'b/r': 'x' })(['b', 'r', 'd', 't']))
|
|
35
|
+
if (result !== '["x","d/t"]') { throw result }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,37 +1,28 @@
|
|
|
1
1
|
const json = require('../../json')
|
|
2
|
-
const
|
|
2
|
+
const dep = require('./dependencies')
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {{
|
|
6
6
|
* readonly version: string
|
|
7
|
-
* readonly dependencies?:
|
|
8
|
-
* }}
|
|
7
|
+
* readonly dependencies?: dep.DependenciesJson
|
|
8
|
+
* }} PackageJson
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
/** @type {(j: json.Unknown) => j is
|
|
12
|
-
const
|
|
11
|
+
/** @type {(j: json.Unknown) => j is PackageJson} */
|
|
12
|
+
const isPackageJson = j => {
|
|
13
13
|
if (!json.isObject(j)) { return false }
|
|
14
14
|
if (typeof j.version !== 'string') { return false }
|
|
15
|
-
if (
|
|
15
|
+
if (!dep.isDependenciesJson(j.dependencies)) { return false }
|
|
16
16
|
return true
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* @typedef {{
|
|
21
|
-
* readonly
|
|
22
|
-
* }}
|
|
21
|
+
* readonly dependencies: dep.DependenciesJson
|
|
22
|
+
* }} Package
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
/** @type {(entry: json.Entry) => boolean} */
|
|
26
|
-
const isDependency = ([,v]) => typeof v === 'string'
|
|
27
|
-
|
|
28
|
-
/** @type {(j: json.Unknown) => j is Dependencies} */
|
|
29
|
-
const isDependencies = j => {
|
|
30
|
-
if (!json.isObject(j)) { return false }
|
|
31
|
-
return seq.every(seq.map(isDependency)(Object.entries(j)))
|
|
32
|
-
}
|
|
33
|
-
|
|
34
25
|
module.exports = {
|
|
35
26
|
/** @readonly */
|
|
36
|
-
|
|
37
|
-
}
|
|
27
|
+
isPackageJson,
|
|
28
|
+
}
|
package/commonjs/package/test.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
const _ = require('.')
|
|
2
2
|
|
|
3
|
+
require('./dependencies/test')
|
|
4
|
+
|
|
3
5
|
{
|
|
4
|
-
if (_.
|
|
5
|
-
if (_.
|
|
6
|
-
if (_.
|
|
7
|
-
if (!_.
|
|
8
|
-
if (_.
|
|
9
|
-
if (!_.
|
|
10
|
-
if (_.
|
|
11
|
-
if (!_.
|
|
6
|
+
if (_.isPackageJson(null)) { throw 'error' }
|
|
7
|
+
if (_.isPackageJson({})) { throw 'error' }
|
|
8
|
+
if (_.isPackageJson({version:12})) { throw 'error' }
|
|
9
|
+
if (!_.isPackageJson({version:"12"})) { throw 'error' }
|
|
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' }
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
module.exports = {}
|
|
16
|
+
module.exports = {}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const cp = require('child_process')
|
|
2
2
|
const fs = require('fs')
|
|
3
3
|
const json = require('../../../json')
|
|
4
|
-
const {
|
|
4
|
+
const { isPackageJson } = require('../../../commonjs/package')
|
|
5
5
|
|
|
6
6
|
const b =cp.execSync('git log --oneline')
|
|
7
7
|
|
|
@@ -13,7 +13,7 @@ console.log(`version: ${v}`)
|
|
|
13
13
|
|
|
14
14
|
const package_json = json.parse(fs.readFileSync('package.json').toString())
|
|
15
15
|
|
|
16
|
-
if (!
|
|
16
|
+
if (!isPackageJson(package_json)) { throw 'error' }
|
|
17
17
|
|
|
18
18
|
const x = { ...package_json, version: v }
|
|
19
19
|
|