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 { split } = require('../../path')
5
- const map = require('../../../types/map')
5
+ const path = require('../../path')
6
+ const { at } = require('../../../types/object')
6
7
 
7
- /** @typedef {(directoryName: string) => undefined|string|Directory} Directory */
8
+ /** @typedef {readonly[string, string]} DependencyJson */
8
9
 
9
- const empty = () => undefined
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
- /** @typedef {Map|string} Item */
14
+ /** @type {(entry: json.Entry) => boolean} */
15
+ const isDependencyJson = ([, v]) => typeof v === 'string'
19
16
 
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)
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, 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
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 {(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)
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
- /** @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)
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
- getDirectory,
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
- const packageJson = { dependencies: {} }
5
- const dir = _.getDirectory(packageJson)
6
- const r = dir('x')
7
- if (r !== undefined) { throw r }
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
- const packageJson = { dependencies: { 'x': 'e' } }
12
- const dir = _.getDirectory(packageJson)
13
- const r = dir('x')
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
- const packageJson = {
19
- dependencies: {
20
- 'x/a': 'xa',
21
- 'x/b': 'xb'
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
- 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
- }
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 seq = require('../../types/sequence')
2
+ const dep = require('./dependencies')
3
3
 
4
4
  /**
5
5
  * @typedef {{
6
6
  * readonly version: string
7
- * readonly dependencies?: Dependencies
8
- * }} Package
7
+ * readonly dependencies?: dep.DependenciesJson
8
+ * }} PackageJson
9
9
  */
10
10
 
11
- /** @type {(j: json.Unknown) => j is Package} */
12
- const isPackage = j => {
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 (j.dependencies !== undefined && !isDependencies(j.dependencies)) { return false }
15
+ if (!dep.isDependenciesJson(j.dependencies)) { return false }
16
16
  return true
17
17
  }
18
18
 
19
19
  /**
20
20
  * @typedef {{
21
- * readonly [k in string]: string
22
- * }} Dependencies
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
- isPackage,
37
- }
27
+ isPackageJson,
28
+ }
@@ -1,14 +1,16 @@
1
1
  const _ = require('.')
2
2
 
3
+ require('./dependencies/test')
4
+
3
5
  {
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' }
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 { isPackage } = require('../../../commonjs/package')
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 (!isPackage(package_json)) { throw 'error' }
16
+ if (!isPackageJson(package_json)) { throw 'error' }
17
17
 
18
18
  const x = { ...package_json, version: v }
19
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.236",
3
+ "version": "0.0.237",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {