functionalscript 0.0.233 → 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.
@@ -30,7 +30,7 @@ jobs:
30
30
  node-version: 14
31
31
  registry-url: https://registry.npmjs.org/
32
32
  - run: npm ci
33
- - run: node ./version
33
+ - run: node ./io/nodejs/version
34
34
  - run: npm publish
35
35
  env:
36
36
  NODE_AUTH_TOKEN: ${{secrets.npm_token}}
@@ -0,0 +1,61 @@
1
+ const { todo } = require('../../../dev')
2
+ const json = require('../../../json')
3
+ const { isObject } = json
4
+ const seq = require('../../../types/sequence')
5
+ const path = require('../../path')
6
+ const { at } = require('../../../types/object')
7
+
8
+ /** @typedef {readonly[string, string]} DependencyJson */
9
+
10
+ /** @typedef {{readonly[k in string]: string}} DependencyMapJson */
11
+
12
+ /** @typedef {DependencyMapJson|undefined} DependenciesJson */
13
+
14
+ /** @type {(entry: json.Entry) => boolean} */
15
+ const isDependencyJson = ([, v]) => typeof v === 'string'
16
+
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)))
22
+ }
23
+
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
+ module.exports = {
57
+ /** @readonly */
58
+ isDependenciesJson,
59
+ /** @readonly */
60
+ idPath,
61
+ }
@@ -0,0 +1,37 @@
1
+ const _ = require('.')
2
+ const json = require('../../../json')
3
+ const { sort } = require('../../../types/object')
4
+ const seq = require('../../../types/sequence')
5
+
6
+ {
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' }
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,72 +1,28 @@
1
- const { todo } = require('../../dev')
2
1
  const json = require('../../json')
3
- const { isObject } = json
4
- const seq = require('../../types/sequence')
5
- const { split } = require('../path')
6
- const map = require('../../types/map')
7
-
8
- /** @typedef {(directoryName: string) => undefined|string|Directory} Directory */
9
-
10
- const empty = () => undefined
2
+ const dep = require('./dependencies')
11
3
 
12
4
  /**
13
5
  * @typedef {{
14
- * readonly get: (dir: string) => Item|undefined
15
- * readonly set: (dir: string) => (item: Item) => Map
16
- * }} Map
6
+ * readonly version: string
7
+ * readonly dependencies?: dep.DependenciesJson
8
+ * }} PackageJson
17
9
  */
18
10
 
19
- /** @typedef {Map|string} Item */
20
-
21
- /** @typedef {readonly[string, Map]} Pair */
22
-
23
- /** @type {(prior: seq.Sequence<Pair>) => (dir: string) => seq.Sequence<Pair>} */
24
- const get = prior => dir => {
25
- const result = seq.next(prior)
26
- if (result === undefined) { throw 'panic' }
27
- const { first: [,m] } = result
28
- const child = m.get(dir)
29
- const childMap = child === undefined || typeof child === 'string' ? map.empty : child
30
- /** @type {Pair} */
31
- const pair = [dir, childMap]
32
- return seq.sequence(pair)(prior)
33
- }
34
-
35
- /** @typedef {readonly[string, Item]} Result */
36
-
37
- /** @type {(a: Result) => (b: Pair) => Result} */
38
- const set = ([aDir, item]) => ([bDir, bMap]) => [bDir, bMap.set(aDir)(item)]
39
-
40
- /** @type {(prior: Map) => (entry: json.Entry) => Map} */
41
- const addDirectory = prior => ([directory, id]) => {
42
- if (typeof id !== 'string') { return prior }
43
- const path = split(directory)
44
- const rev = seq.reduce(get)([['', prior]])(path)
45
- const result = seq.next(rev)
46
- if (result === undefined) { throw 'panic' }
47
- const { first: [dir], tail } = result
48
- const [, m] = seq.reduce(set)([dir, id])(tail)
49
- if (typeof m === 'string') { return prior }
50
- return m
51
- }
52
-
53
- /** @type {(m: Map) => Directory} */
54
- const func = m => dir => {
55
- const r = m.get(dir)
56
- if (typeof r !== 'object') { return r }
57
- return func(r)
11
+ /** @type {(j: json.Unknown) => j is PackageJson} */
12
+ const isPackageJson = j => {
13
+ if (!json.isObject(j)) { return false }
14
+ if (typeof j.version !== 'string') { return false }
15
+ if (!dep.isDependenciesJson(j.dependencies)) { return false }
16
+ return true
58
17
  }
59
18
 
60
- /** @type {(packageJson: json.Unknown) => Directory} */
61
- const dependencies = packageJson => {
62
- if (!isObject(packageJson)) { return empty }
63
- const dependencies = packageJson['dependencies']
64
- if (dependencies === undefined || !isObject(dependencies)) { return empty }
65
- const result = seq.reduce(addDirectory)(map.empty)(Object.entries(dependencies))
66
- return func(result)
67
- }
19
+ /**
20
+ * @typedef {{
21
+ * readonly dependencies: dep.DependenciesJson
22
+ * }} Package
23
+ */
68
24
 
69
25
  module.exports = {
70
26
  /** @readonly */
71
- dependencies,
72
- }
27
+ isPackageJson,
28
+ }
@@ -1,33 +1,16 @@
1
1
  const _ = require('.')
2
2
 
3
- {
4
- const packageJson = { dependencies: {} }
5
- const dir = _.dependencies(packageJson)
6
- const r = dir('x')
7
- if (r !== undefined) { throw r }
8
- }
3
+ require('./dependencies/test')
9
4
 
10
5
  {
11
- const packageJson = { dependencies: { 'x': 'e' } }
12
- const dir = _.dependencies(packageJson)
13
- const r = dir('x')
14
- if (r !== 'e') { throw r }
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' }
15
14
  }
16
15
 
17
- {
18
- const packageJson = {
19
- dependencies: {
20
- 'x/a': 'xa',
21
- 'x/b': 'xb'
22
- }
23
- }
24
- const dir = _.dependencies(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
- }
16
+ module.exports = {}
@@ -0,0 +1,20 @@
1
+ const cp = require('child_process')
2
+ const fs = require('fs')
3
+ const json = require('../../../json')
4
+ const { isPackageJson } = 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 (!isPackageJson(package_json)) { throw 'error' }
17
+
18
+ const x = { ...package_json, version: v }
19
+
20
+ fs.writeFileSync('package.json', JSON.stringify(x, null, 2))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.233",
3
+ "version": "0.0.237",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test.js CHANGED
@@ -5,6 +5,7 @@ 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')
8
9
  require('./commonjs/package/test')
9
10
 
10
11
  /** @type {() => never} */
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))