functionalscript 0.0.431 → 0.0.433
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/dev/module.mjs +155 -0
- package/dev/test/module.f.cjs +32 -11
- package/{test.f.cjs → dev/test.f.cjs} +0 -2
- package/dev/test.mjs +2 -156
- package/module.f.cjs +8 -0
- package/nodejs/module.f.cjs +4 -0
- package/package.json +1 -1
- package/types/function/operator/module.f.cjs +3 -3
- package/types/list/module.f.cjs +2 -2
package/dev/module.mjs
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {{
|
|
3
|
+
* readonly withFileTypes: true
|
|
4
|
+
* }} Options
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {{
|
|
9
|
+
* readonly name: string
|
|
10
|
+
* readonly isDirectory: () => boolean
|
|
11
|
+
* }} Dirent
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {{
|
|
16
|
+
* readonly readdir: (path: string, options: Options) => Promise<readonly Dirent[]>
|
|
17
|
+
* readonly readFile: (path: string, options: 'utf8') => Promise<string>
|
|
18
|
+
* }} FsPromises
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {{
|
|
23
|
+
* [k in string]?: MutableModule
|
|
24
|
+
* }} MutableDependencyMap
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {{
|
|
29
|
+
* dependencyMap: MutableDependencyMap
|
|
30
|
+
* exports?: unknown
|
|
31
|
+
* }} MutableModule
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {{
|
|
36
|
+
* readonly dependencyMap: DependencyMap
|
|
37
|
+
* readonly exports?: unknown
|
|
38
|
+
* }} Module
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @typedef {{
|
|
43
|
+
* readonly[k in string]?: Module
|
|
44
|
+
* }} DependencyMap
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/** @typedef {(name: string) => unknown} Require */
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {{
|
|
51
|
+
* readonly[k in string]: Function
|
|
52
|
+
* }} FunctionMap
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @template T
|
|
57
|
+
* @typedef {readonly[string, T]} Entry
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/** @type {(a: Entry<Function>, b: Entry<Function>) => number} */
|
|
61
|
+
const cmp = ([a], [b]) => a < b ? -1 : a > b ? 1 : 0
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @typedef {{
|
|
65
|
+
* [k in string]: MutableModule
|
|
66
|
+
* }} MutableModuleMap
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @typedef {{
|
|
71
|
+
* readonly[k in string]: Module
|
|
72
|
+
* }} ModuleMap
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
/** @type {(v: readonly string[]) => (dif: number) => readonly string[]} */
|
|
76
|
+
const remove_tail = v => dif => v.slice(0, v.length - dif)
|
|
77
|
+
|
|
78
|
+
/** @type {any} */
|
|
79
|
+
const self = globalThis
|
|
80
|
+
|
|
81
|
+
export const loadModuleMap = async () => {
|
|
82
|
+
/** @type {FsPromises} */
|
|
83
|
+
const { readdir, readFile } = await import(self.Deno ? 'https://deno.land/std/node/fs/promises.ts' : 'node:fs/promises')
|
|
84
|
+
|
|
85
|
+
/** @type {() => Promise<FunctionMap>} */
|
|
86
|
+
const load = async () => {
|
|
87
|
+
/** @type {(readonly[string, Function])[]} */
|
|
88
|
+
const map = []
|
|
89
|
+
/** @type {(path: string) => Promise<void>} */
|
|
90
|
+
const f = async p => {
|
|
91
|
+
for (const i of await readdir(p, { withFileTypes: true })) {
|
|
92
|
+
const { name } = i
|
|
93
|
+
if (!name.startsWith('.')) {
|
|
94
|
+
const file = `${p}/${name}`
|
|
95
|
+
if (i.isDirectory()) {
|
|
96
|
+
await f(file)
|
|
97
|
+
} else if (name.endsWith('.f.cjs')) {
|
|
98
|
+
const source = await readFile(file, 'utf8')
|
|
99
|
+
map.push([file, Function('module', 'require', `"use strict";${source}`)])
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
await f('.')
|
|
105
|
+
map.sort(cmp)
|
|
106
|
+
return Object.fromEntries(map)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const map = await load()
|
|
110
|
+
|
|
111
|
+
/** @type {() => ModuleMap} */
|
|
112
|
+
const build = () => {
|
|
113
|
+
/** @type {MutableModuleMap} */
|
|
114
|
+
const d = {}
|
|
115
|
+
/** @type {(base: readonly string[]) => (k: string) => readonly[string, MutableModule]} */
|
|
116
|
+
const getModule = base => k => {
|
|
117
|
+
const relativePath = k.split('/')
|
|
118
|
+
const dif = relativePath.filter(v => v === '..').length
|
|
119
|
+
const path = [remove_tail(base)(dif), relativePath.filter(v => !['..', '.'].includes(v))]
|
|
120
|
+
.flat()
|
|
121
|
+
const pathStr = path.join('/')
|
|
122
|
+
{
|
|
123
|
+
const module = d[pathStr]
|
|
124
|
+
if (module !== undefined) {
|
|
125
|
+
return [pathStr, module]
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
{
|
|
129
|
+
/** @type {MutableDependencyMap} */
|
|
130
|
+
const dependencyMap = {}
|
|
131
|
+
/** @type {MutableModule} */
|
|
132
|
+
const module = { dependencyMap }
|
|
133
|
+
const get = getModule(remove_tail(path)(1))
|
|
134
|
+
/** @type {(s: string) => unknown} */
|
|
135
|
+
const newReq = s => {
|
|
136
|
+
const [p, result] = get(s)
|
|
137
|
+
dependencyMap[p] = result
|
|
138
|
+
return result.exports
|
|
139
|
+
}
|
|
140
|
+
map[pathStr](module, newReq)
|
|
141
|
+
d[pathStr] = module
|
|
142
|
+
return [pathStr, module]
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
{
|
|
146
|
+
const get = getModule(['.'])
|
|
147
|
+
for (const k of Object.keys(map)) {
|
|
148
|
+
get(k)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return d
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return build()
|
|
155
|
+
}
|
package/dev/test/module.f.cjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
const list = require('../../types/list/module.f.cjs')
|
|
2
|
+
const { fold } = list
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* @typedef {{
|
|
3
6
|
* readonly[k in string]?: Module
|
|
@@ -31,6 +34,20 @@
|
|
|
31
34
|
* }} Input
|
|
32
35
|
*/
|
|
33
36
|
|
|
37
|
+
/**
|
|
38
|
+
* https://en.wikipedia.org/wiki/ANSI_escape_code#SGR
|
|
39
|
+
*
|
|
40
|
+
* @type {(c: number) => string}
|
|
41
|
+
*/
|
|
42
|
+
const sgr = c => `\x1b[${c.toString()}m`
|
|
43
|
+
|
|
44
|
+
const reset = sgr(0)
|
|
45
|
+
|
|
46
|
+
const fgGreen = sgr(32)
|
|
47
|
+
|
|
48
|
+
/** @type {(s: string) => boolean} */
|
|
49
|
+
const isTest = s => s.endsWith('test.f.cjs')
|
|
50
|
+
|
|
34
51
|
/** @type {<T>(input: Input<T>) => T} */
|
|
35
52
|
const main = ({moduleMap, log, state}) => {
|
|
36
53
|
/** @typedef {log extends Log<infer T> ? T : never} T */
|
|
@@ -41,21 +58,23 @@ const main = ({moduleMap, log, state}) => {
|
|
|
41
58
|
case 'function': {
|
|
42
59
|
if (v.length === 0) {
|
|
43
60
|
const r = v()
|
|
44
|
-
state = log(`${i}()
|
|
61
|
+
state = log(`${i}() ${fgGreen}ok${reset}`)(state)
|
|
45
62
|
state = next(r)(state)
|
|
46
63
|
}
|
|
47
64
|
break
|
|
48
65
|
}
|
|
49
66
|
case 'object': {
|
|
67
|
+
/** @type {(k: readonly[string|number, unknown]) => (state: T) => T} */
|
|
68
|
+
const f = ([k, v]) => state => {
|
|
69
|
+
state = log(`${i}${k}:`)(state)
|
|
70
|
+
state = next(v)(state)
|
|
71
|
+
return state
|
|
72
|
+
}
|
|
73
|
+
const foldF = fold(f)(state)
|
|
50
74
|
if (v instanceof Array) {
|
|
51
|
-
|
|
52
|
-
state = next(v2)(state)
|
|
53
|
-
}
|
|
75
|
+
state = foldF(list.entries(v))
|
|
54
76
|
} else if (v !== null) {
|
|
55
|
-
|
|
56
|
-
state = log(`${i}${k}:`)(state)
|
|
57
|
-
state = next(v2)(state)
|
|
58
|
-
}
|
|
77
|
+
state = foldF(Object.entries(v))
|
|
59
78
|
}
|
|
60
79
|
break
|
|
61
80
|
}
|
|
@@ -63,13 +82,15 @@ const main = ({moduleMap, log, state}) => {
|
|
|
63
82
|
return state
|
|
64
83
|
}
|
|
65
84
|
const next = test('| ')
|
|
66
|
-
|
|
67
|
-
|
|
85
|
+
/** @type {(k: readonly[string, Module]) => (state: T) => T} */
|
|
86
|
+
const f = ([k, v]) => state => {
|
|
87
|
+
if (isTest(k)) {
|
|
68
88
|
state = log(`testing ${k}`)(state)
|
|
69
89
|
state = next(v.exports)(state)
|
|
70
90
|
}
|
|
91
|
+
return state
|
|
71
92
|
}
|
|
72
|
-
return state
|
|
93
|
+
return fold(f)(state)(Object.entries(moduleMap))
|
|
73
94
|
}
|
|
74
95
|
|
|
75
96
|
module.exports = main
|
package/dev/test.mjs
CHANGED
|
@@ -1,162 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
* @typedef {{
|
|
3
|
-
* readonly withFileTypes: true
|
|
4
|
-
* }} Options
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {{
|
|
9
|
-
* readonly name: string
|
|
10
|
-
* readonly isDirectory: () => boolean
|
|
11
|
-
* }} Dirent
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @typedef {{
|
|
16
|
-
* readonly readdir: (path: string, options: Options) => Promise<readonly Dirent[]>
|
|
17
|
-
* readonly readFile: (path: string, options: 'utf8') => Promise<string>
|
|
18
|
-
* }} FsPromises
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @typedef {{
|
|
23
|
-
* [k in string]?: MutableModule
|
|
24
|
-
* }} MutableDependencyMap
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @typedef {{
|
|
29
|
-
* dependencyMap: MutableDependencyMap
|
|
30
|
-
* exports?: unknown
|
|
31
|
-
* }} MutableModule
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @typedef {{
|
|
36
|
-
* readonly dependencyMap: DependencyMap
|
|
37
|
-
* readonly exports?: unknown
|
|
38
|
-
* }} Module
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @typedef {{
|
|
43
|
-
* readonly[k in string]?: Module
|
|
44
|
-
* }} DependencyMap
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
/** @typedef {(name: string) => unknown} Require */
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @typedef {{
|
|
51
|
-
* readonly[k in string]: Function
|
|
52
|
-
* }} FunctionMap
|
|
53
|
-
*/
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @template T
|
|
57
|
-
* @typedef {readonly[string, T]} Entry
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
/** @type {(a: Entry<Function>, b: Entry<Function>) => number} */
|
|
61
|
-
const cmp = ([a], [b]) => a < b ? -1 : a > b ? 1 : 0
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @typedef {{
|
|
65
|
-
* [k in string]: MutableModule
|
|
66
|
-
* }} MutableModuleMap
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @typedef {{
|
|
71
|
-
* readonly[k in string]: Module
|
|
72
|
-
* }} ModuleMap
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
/** @type {(v: readonly string[]) => (dif: number) => readonly string[]} */
|
|
76
|
-
const remove_tail = v => dif => v.slice(0, v.length - dif)
|
|
77
|
-
|
|
78
|
-
/** @type {any} */
|
|
79
|
-
const self = globalThis
|
|
80
|
-
|
|
81
|
-
const boot = async() => {
|
|
82
|
-
/** @type {FsPromises} */
|
|
83
|
-
const { readdir, readFile } = await import(self.Deno ? 'https://deno.land/std/node/fs/promises.ts' : 'node:fs/promises')
|
|
84
|
-
|
|
85
|
-
/** @type {() => Promise<FunctionMap>} */
|
|
86
|
-
const load = async () => {
|
|
87
|
-
/** @type {(readonly[string, Function])[]} */
|
|
88
|
-
const map = []
|
|
89
|
-
/** @type {(path: string) => Promise<void>} */
|
|
90
|
-
const f = async p => {
|
|
91
|
-
for (const i of await readdir(p, { withFileTypes: true })) {
|
|
92
|
-
const { name } = i
|
|
93
|
-
if (!name.startsWith('.')) {
|
|
94
|
-
const file = `${p}/${name}`
|
|
95
|
-
if (i.isDirectory()) {
|
|
96
|
-
await f(file)
|
|
97
|
-
} else if (name.endsWith('.f.cjs')) {
|
|
98
|
-
const source = await readFile(file, 'utf8')
|
|
99
|
-
map.push([file, Function('module', 'require', `"use strict";${source}`)])
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
await f('.')
|
|
105
|
-
map.sort(cmp)
|
|
106
|
-
return Object.fromEntries(map)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const map = await load()
|
|
110
|
-
|
|
111
|
-
/** @type {() => ModuleMap} */
|
|
112
|
-
const build = () => {
|
|
113
|
-
/** @type {MutableModuleMap} */
|
|
114
|
-
const d = {}
|
|
115
|
-
/** @type {(base: readonly string[]) => (k: string) => readonly[string, MutableModule]} */
|
|
116
|
-
const getModule = base => k => {
|
|
117
|
-
const relativePath = k.split('/')
|
|
118
|
-
const dif = relativePath.filter(v => v === '..').length
|
|
119
|
-
const path = [remove_tail(base)(dif), relativePath.filter(v => !['..', '.'].includes(v))]
|
|
120
|
-
.flat()
|
|
121
|
-
const pathStr = path.join('/')
|
|
122
|
-
{
|
|
123
|
-
const module = d[pathStr]
|
|
124
|
-
if (module !== undefined) {
|
|
125
|
-
return [pathStr, module]
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
{
|
|
129
|
-
/** @type {MutableDependencyMap} */
|
|
130
|
-
const dependencyMap = {}
|
|
131
|
-
/** @type {MutableModule} */
|
|
132
|
-
const module = { dependencyMap }
|
|
133
|
-
const get = getModule(remove_tail(path)(1))
|
|
134
|
-
/** @type {(s: string) => unknown} */
|
|
135
|
-
const newReq = s => {
|
|
136
|
-
const [p, result] = get(s)
|
|
137
|
-
dependencyMap[p] = result
|
|
138
|
-
return result.exports
|
|
139
|
-
}
|
|
140
|
-
map[pathStr](module, newReq)
|
|
141
|
-
d[pathStr] = module
|
|
142
|
-
return [pathStr, module]
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
{
|
|
146
|
-
const get = getModule(['.'])
|
|
147
|
-
for (const k of Object.keys(map)) {
|
|
148
|
-
get(k)
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return d
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return build()
|
|
155
|
-
}
|
|
1
|
+
import { loadModuleMap } from './module.mjs'
|
|
156
2
|
|
|
157
3
|
// test runner.
|
|
158
4
|
const main = async() => {
|
|
159
|
-
const moduleMap = await
|
|
5
|
+
const moduleMap = await loadModuleMap()
|
|
160
6
|
|
|
161
7
|
/** @type {(s: string) => (_: undefined) => undefined} */
|
|
162
8
|
const log = s => state => {
|
package/module.f.cjs
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
+
/** @readonly */
|
|
3
|
+
com: require('./com/module.f.cjs'),
|
|
2
4
|
/** @readonly */
|
|
3
5
|
commonjs: require('./commonjs/module.f.cjs'),
|
|
4
6
|
/** @readonly */
|
|
5
7
|
dev: require('./dev/module.f.cjs'),
|
|
6
8
|
/** @readonly */
|
|
9
|
+
fsm: require('./fsm/module.f.cjs'),
|
|
10
|
+
/** @readonly */
|
|
7
11
|
html: require('./html/module.f.cjs'),
|
|
8
12
|
/** @readonly */
|
|
9
13
|
json: require('./json/module.f.cjs'),
|
|
10
14
|
/** @readonly */
|
|
15
|
+
nodejs: require('./nodejs/module.f.cjs'),
|
|
16
|
+
/** @readonly */
|
|
11
17
|
sha2: require('./sha2/module.f.cjs'),
|
|
12
18
|
/** @readonly */
|
|
19
|
+
text: require('./text/module.f.cjs'),
|
|
20
|
+
/** @readonly */
|
|
13
21
|
types: require('./types/module.f.cjs'),
|
|
14
22
|
}
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @template I,O
|
|
10
|
-
* @typedef {Binary<I, O, O>}
|
|
10
|
+
* @typedef {Binary<I, O, O>} Fold
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
/** @type {(separator: string) => Reduce<string>} */
|
|
@@ -49,7 +49,7 @@ const stateScanToScan = op => prior => i => {
|
|
|
49
49
|
return [o, stateScanToScan(op)(s)]
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
/** @type {<I, O>(fold:
|
|
52
|
+
/** @type {<I, O>(fold: Fold<I, O>) => (prior: O) => Scan<I, O>} */
|
|
53
53
|
const foldToScan = fold => prior => i => {
|
|
54
54
|
const result = fold(i)(prior)
|
|
55
55
|
return [result, foldToScan(fold)(result)]
|
|
@@ -57,7 +57,7 @@ const foldToScan = fold => prior => i => {
|
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* @template T
|
|
60
|
-
* @typedef {
|
|
60
|
+
* @typedef {Fold<T, T>} Reduce
|
|
61
61
|
*/
|
|
62
62
|
|
|
63
63
|
/** @type {<T>(fold: Reduce<T>) => Scan<T, T>} */
|
package/types/list/module.f.cjs
CHANGED
|
@@ -250,10 +250,10 @@ const scan = op => apply(scanStep(op))
|
|
|
250
250
|
/** @type {<I, S, O>(op: operator.StateScan<I, S, O>) => (init: S) => (input: List<I>) => Thunk<O>} */
|
|
251
251
|
const stateScan = op => init => scan(stateScanToScan(op)(init))
|
|
252
252
|
|
|
253
|
-
/** @type {<I,O>(op: operator.
|
|
253
|
+
/** @type {<I,O>(op: operator.Fold<I, O>) => (init: O) => (input: List<I>) => Thunk<O>} */
|
|
254
254
|
const foldScan = op => init => scan(foldToScan(op)(init))
|
|
255
255
|
|
|
256
|
-
/** @type {<I,O>(op: operator.
|
|
256
|
+
/** @type {<I,O>(op: operator.Fold<I, O>) => (init: O) => (input: List<I>) => O} */
|
|
257
257
|
const fold = op => init => input => last(init)(foldScan(op)(init)(input))
|
|
258
258
|
|
|
259
259
|
/** @type {<T>(op: operator.Reduce<T>) => <D>(def: D) => (input: List<T>) => D|T} */
|