functionalscript 0.0.232 → 0.0.236
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/npm-publish.yml +1 -1
- package/commonjs/package/dependencies/index.js +71 -0
- package/commonjs/package/dependencies/test.js +33 -0
- package/commonjs/package/index.js +37 -0
- package/commonjs/package/test.js +14 -0
- package/commonjs/path/index.js +3 -1
- package/io/commonjs/index.js +14 -20
- package/io/nodejs/version/index.js +20 -0
- package/io/result/index.js +15 -0
- package/json/index.js +7 -3
- package/package.json +1 -1
- package/test.js +2 -0
- package/types/result/index.js +8 -0
- package/version.js +0 -17
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const json = require('../../../json')
|
|
2
|
+
const { isObject } = json
|
|
3
|
+
const seq = require('../../../types/sequence')
|
|
4
|
+
const { split } = require('../../path')
|
|
5
|
+
const map = require('../../../types/map')
|
|
6
|
+
|
|
7
|
+
/** @typedef {(directoryName: string) => undefined|string|Directory} Directory */
|
|
8
|
+
|
|
9
|
+
const empty = () => undefined
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {{
|
|
13
|
+
* readonly get: (dir: string) => Item|undefined
|
|
14
|
+
* readonly set: (dir: string) => (item: Item) => Map
|
|
15
|
+
* }} Map
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** @typedef {Map|string} Item */
|
|
19
|
+
|
|
20
|
+
/** @typedef {readonly[string, Map]} Pair */
|
|
21
|
+
|
|
22
|
+
/** @type {(prior: seq.Sequence<Pair>) => (dir: string) => seq.Sequence<Pair>} */
|
|
23
|
+
const get = prior => dir => {
|
|
24
|
+
const result = seq.next(prior)
|
|
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)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @typedef {readonly[string, Item]} Result */
|
|
35
|
+
|
|
36
|
+
/** @type {(a: Result) => (b: Pair) => Result} */
|
|
37
|
+
const set = ([aDir, item]) => ([bDir, bMap]) => [bDir, bMap.set(aDir)(item)]
|
|
38
|
+
|
|
39
|
+
/** @type {(prior: Map) => (entry: json.Entry) => Map} */
|
|
40
|
+
const addDirectory = prior => ([directory, id]) => {
|
|
41
|
+
if (typeof id !== 'string') { return prior }
|
|
42
|
+
const path = split(directory)
|
|
43
|
+
const rev = seq.reduce(get)([['', prior]])(path)
|
|
44
|
+
const result = seq.next(rev)
|
|
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
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @type {(m: Map) => Directory} */
|
|
53
|
+
const func = m => dir => {
|
|
54
|
+
const r = m.get(dir)
|
|
55
|
+
if (typeof r !== 'object') { return r }
|
|
56
|
+
return func(r)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @type {(packageJson: json.Unknown) => Directory} */
|
|
60
|
+
const getDirectory = packageJson => {
|
|
61
|
+
if (!isObject(packageJson)) { return empty }
|
|
62
|
+
const dep = packageJson['dependencies']
|
|
63
|
+
if (dep === undefined || !isObject(dep)) { return empty }
|
|
64
|
+
const result = seq.reduce(addDirectory)(map.empty)(Object.entries(dep))
|
|
65
|
+
return func(result)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = {
|
|
69
|
+
/** @readonly */
|
|
70
|
+
getDirectory,
|
|
71
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const _ = require('.')
|
|
2
|
+
|
|
3
|
+
{
|
|
4
|
+
const packageJson = { dependencies: {} }
|
|
5
|
+
const dir = _.getDirectory(packageJson)
|
|
6
|
+
const r = dir('x')
|
|
7
|
+
if (r !== undefined) { throw r }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
{
|
|
11
|
+
const packageJson = { dependencies: { 'x': 'e' } }
|
|
12
|
+
const dir = _.getDirectory(packageJson)
|
|
13
|
+
const r = dir('x')
|
|
14
|
+
if (r !== 'e') { throw r }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
{
|
|
18
|
+
const packageJson = {
|
|
19
|
+
dependencies: {
|
|
20
|
+
'x/a': 'xa',
|
|
21
|
+
'x/b': 'xb'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const dir = _.getDirectory(packageJson)
|
|
25
|
+
const x = dir('x')
|
|
26
|
+
if (typeof x !== 'function') { throw x }
|
|
27
|
+
const xa = x('a')
|
|
28
|
+
if (xa !== 'xa') { throw xa }
|
|
29
|
+
const xb = x('b')
|
|
30
|
+
if (xb !== 'xb') { throw xb }
|
|
31
|
+
const xc = x('c')
|
|
32
|
+
if (xc !== undefined) { throw xc }
|
|
33
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const json = require('../../json')
|
|
2
|
+
const seq = require('../../types/sequence')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {{
|
|
6
|
+
* readonly version: string
|
|
7
|
+
* readonly dependencies?: Dependencies
|
|
8
|
+
* }} Package
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** @type {(j: json.Unknown) => j is Package} */
|
|
12
|
+
const isPackage = j => {
|
|
13
|
+
if (!json.isObject(j)) { return false }
|
|
14
|
+
if (typeof j.version !== 'string') { return false }
|
|
15
|
+
if (j.dependencies !== undefined && !isDependencies(j.dependencies)) { return false }
|
|
16
|
+
return true
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {{
|
|
21
|
+
* readonly [k in string]: string
|
|
22
|
+
* }} Dependencies
|
|
23
|
+
*/
|
|
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
|
+
module.exports = {
|
|
35
|
+
/** @readonly */
|
|
36
|
+
isPackage,
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const _ = require('.')
|
|
2
|
+
|
|
3
|
+
{
|
|
4
|
+
if (_.isPackage(null)) { throw 'error' }
|
|
5
|
+
if (_.isPackage({})) { throw 'error' }
|
|
6
|
+
if (_.isPackage({version:12})) { throw 'error' }
|
|
7
|
+
if (!_.isPackage({version:"12"})) { throw 'error' }
|
|
8
|
+
if (_.isPackage({version:"",dependencies:[]})) { throw 'error' }
|
|
9
|
+
if (!_.isPackage({ version: "", dependencies: {} })) { throw 'error' }
|
|
10
|
+
if (_.isPackage({ version: "", dependencies: { x: 12} })) { throw 'error' }
|
|
11
|
+
if (!_.isPackage({ version: "", dependencies: { x: "12" } })) { throw 'error' }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = {}
|
package/commonjs/path/index.js
CHANGED
|
@@ -12,7 +12,7 @@ const { compose } = require("../../types/function")
|
|
|
12
12
|
* }} Path
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
/** @type {(path: string) =>
|
|
15
|
+
/** @type {(path: string) => readonly string[]} */
|
|
16
16
|
const split = path => path.split('/')
|
|
17
17
|
|
|
18
18
|
/** @type {(s: undefined|seq.Sequence<string>) => (items: string) => undefined|seq.Sequence<string>} */
|
|
@@ -59,6 +59,8 @@ const parse = local => {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
module.exports = {
|
|
62
|
+
/** @readonly */
|
|
63
|
+
split,
|
|
62
64
|
/** @readonly */
|
|
63
65
|
parse,
|
|
64
66
|
}
|
package/io/commonjs/index.js
CHANGED
|
@@ -1,34 +1,28 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { tryCatch } = require('../result')
|
|
2
|
+
const { unwrap } = require('../../types/result')
|
|
2
3
|
const run = require('../../commonjs/run')
|
|
3
4
|
|
|
4
5
|
/** @type {(f: Function) => run.Module} */
|
|
5
|
-
const
|
|
6
|
+
const createModule = f => req => mutableInfo => {
|
|
6
7
|
/** @type {(path: string) => unknown} */
|
|
7
8
|
const mutableRequire = path => {
|
|
8
|
-
const [result,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return result[1]
|
|
9
|
+
const [result, info] = req(mutableInfo)(path)
|
|
10
|
+
mutableInfo = info
|
|
11
|
+
return unwrap(result)
|
|
12
12
|
}
|
|
13
|
-
const
|
|
14
|
-
|
|
13
|
+
const result = tryCatch(() => {
|
|
14
|
+
const mutableModule = { exports: {} }
|
|
15
15
|
f(mutableModule, mutableRequire)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return [ok(mutableModule.exports), info]
|
|
16
|
+
return mutableModule.exports
|
|
17
|
+
})
|
|
18
|
+
return [result, mutableInfo]
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
/** @type {run.Compile} */
|
|
23
|
-
const compile = source =>
|
|
24
|
-
|
|
25
|
-
return ok(runModule(Function('module', 'require', `"use strict";${source}`)))
|
|
26
|
-
} catch (e) {
|
|
27
|
-
return error(e)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
22
|
+
const compile = source =>
|
|
23
|
+
tryCatch(() => createModule(Function('module', 'require', `"use strict";${source}`)))
|
|
30
24
|
|
|
31
25
|
module.exports = {
|
|
32
26
|
/** @readonly */
|
|
33
27
|
compile,
|
|
34
|
-
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const cp = require('child_process')
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
const json = require('../../../json')
|
|
4
|
+
const { isPackage } = require('../../../commonjs/package')
|
|
5
|
+
|
|
6
|
+
const b =cp.execSync('git log --oneline')
|
|
7
|
+
|
|
8
|
+
const r = b.toString().split('\n').length
|
|
9
|
+
|
|
10
|
+
const v = `0.0.${r}`
|
|
11
|
+
|
|
12
|
+
console.log(`version: ${v}`)
|
|
13
|
+
|
|
14
|
+
const package_json = json.parse(fs.readFileSync('package.json').toString())
|
|
15
|
+
|
|
16
|
+
if (!isPackage(package_json)) { throw 'error' }
|
|
17
|
+
|
|
18
|
+
const x = { ...package_json, version: v }
|
|
19
|
+
|
|
20
|
+
fs.writeFileSync('package.json', JSON.stringify(x, null, 2))
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const result = require('../../types/result')
|
|
2
|
+
|
|
3
|
+
/** @type {<T>(f: () => T) => result.Result<T, unknown>} */
|
|
4
|
+
const tryCatch = f => {
|
|
5
|
+
try {
|
|
6
|
+
return result.ok(f())
|
|
7
|
+
} catch (e) {
|
|
8
|
+
return result.error(e)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
/** @readonly */
|
|
14
|
+
tryCatch,
|
|
15
|
+
}
|
package/json/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const seq = require('../types/sequence')
|
|
2
2
|
const object = require('../types/object')
|
|
3
3
|
const array = require('../types/array')
|
|
4
|
+
const { todo } = require('../dev')
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @typedef {{
|
|
@@ -104,8 +105,6 @@ const serialize = sort => {
|
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
/**
|
|
107
|
-
* A version of `JSON.stringify` with an alphabeticly ordered `keys`.
|
|
108
|
-
*
|
|
109
108
|
* The standard `JSON.stringify` rules determined by
|
|
110
109
|
* https://262.ecma-international.org/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
|
|
111
110
|
*
|
|
@@ -119,6 +118,9 @@ const stringify = sort => value => {
|
|
|
119
118
|
/** @type {(value: string) => Unknown} */
|
|
120
119
|
const parse = value => JSON.parse(value)
|
|
121
120
|
|
|
121
|
+
/** @type {(value: Unknown) => value is Object} */
|
|
122
|
+
const isObject = value => typeof value === 'object' && value !== null && !(value instanceof Array)
|
|
123
|
+
|
|
122
124
|
module.exports = {
|
|
123
125
|
/** @readonly */
|
|
124
126
|
setProperty,
|
|
@@ -128,4 +130,6 @@ module.exports = {
|
|
|
128
130
|
serialize,
|
|
129
131
|
/** @readonly */
|
|
130
132
|
parse,
|
|
131
|
-
|
|
133
|
+
/** @readonly */
|
|
134
|
+
isObject,
|
|
135
|
+
}
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -5,6 +5,8 @@ require('./types/btree/test')
|
|
|
5
5
|
require('./json/test')
|
|
6
6
|
require('./types/object/test')
|
|
7
7
|
require('./io/commonjs/test')
|
|
8
|
+
require('./commonjs/package/dependencies/test')
|
|
9
|
+
require('./commonjs/package/test')
|
|
8
10
|
|
|
9
11
|
/** @type {() => never} */
|
|
10
12
|
const assert = () => { throw 'assert' }
|
package/types/result/index.js
CHANGED
|
@@ -20,9 +20,17 @@ const ok = value => ['ok', value]
|
|
|
20
20
|
/** @type {<E>(e: E) => Error<E>} */
|
|
21
21
|
const error = e => ['error', e]
|
|
22
22
|
|
|
23
|
+
/** @type {<T, E>(r: Result<T, E>) => T} */
|
|
24
|
+
const unwrap = result => {
|
|
25
|
+
if (result[0] === 'error') { throw result[1] }
|
|
26
|
+
return result[1]
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
module.exports = {
|
|
24
30
|
/** @readonly */
|
|
25
31
|
ok,
|
|
26
32
|
/** @readonly */
|
|
27
33
|
error,
|
|
34
|
+
/** @readonly */
|
|
35
|
+
unwrap,
|
|
28
36
|
}
|
package/version.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const cp = require('child_process')
|
|
2
|
-
const fs = require('fs')
|
|
3
|
-
const json = require('./json')
|
|
4
|
-
|
|
5
|
-
const b =cp.execSync('git log --oneline')
|
|
6
|
-
|
|
7
|
-
const r = b.toString().split('\n').length
|
|
8
|
-
|
|
9
|
-
const v = `0.0.${r}`
|
|
10
|
-
|
|
11
|
-
console.log(`version: ${v}`)
|
|
12
|
-
|
|
13
|
-
let package_json = json.parse(fs.readFileSync('package.json').toString())
|
|
14
|
-
|
|
15
|
-
package_json = json.setProperty(v)(['version'])(package_json)
|
|
16
|
-
|
|
17
|
-
fs.writeFileSync('package.json', JSON.stringify(package_json, null, 2))
|