functionalscript 0.0.480 → 0.0.481

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.
@@ -90,10 +90,10 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
90
90
  }
91
91
  // check package
92
92
  const p = packageGet(moduleId.package)
93
- if (p === undefined) { return notFound(moduleMap) }
93
+ if (p === null) { return notFound(moduleMap) }
94
94
  // check file
95
95
  const source = p.file(moduleId.path.join('/'))
96
- return (source === undefined ? notFound : build(undefined)(moduleId)(source))(moduleMap)
96
+ return (source === null ? notFound : build(undefined)(moduleId)(source))(moduleMap)
97
97
  }
98
98
  return f
99
99
  }
@@ -4,6 +4,7 @@ const module_ = require('../module/module.f.cjs')
4
4
  const function_ = require('../module/function/module.f.cjs')
5
5
  const result = require('../../types/result/module.f.cjs')
6
6
  const package_ = require('../package/module.f.cjs')
7
+ const { at } = require('../../types/object/module.f.cjs')
7
8
 
8
9
  /** @type {{ readonly [k in string]?: result.Result<function_.Function_, unknown> }} */
9
10
  const compileMap = {
@@ -32,9 +33,9 @@ const compileMap = {
32
33
  /** @type {function_.Compile} */
33
34
  const compile = source => compileMap[source] ?? ['error', 'invalid source']
34
35
 
35
- /** @typedef {{ readonly [k in string]?: string }} StringMap */
36
+ /** @typedef {{ readonly [k in string]: string }} StringMap */
36
37
 
37
- /** @type {{ readonly [k in string]?: { readonly dependencies: StringMap, files: StringMap }}} */
38
+ /** @type {{ readonly [k in string]: { readonly dependencies: StringMap, readonly files: StringMap }}} */
38
39
  const packageMap = {
39
40
  '': {
40
41
  dependencies: {
@@ -56,11 +57,11 @@ const packageMap = {
56
57
 
57
58
  /** @type {package_.Get} */
58
59
  const packageGet = packageId => {
59
- const p = packageMap[packageId]
60
- return p === undefined ? undefined :
60
+ const p = at(packageId)(packageMap)
61
+ return p === null ? null :
61
62
  {
62
- dependency: dependency => p.dependencies[dependency],
63
- file: file => p.files[file]
63
+ dependency: dependency => at(dependency)(p.dependencies),
64
+ file: file => at(file)(p.files),
64
65
  }
65
66
  }
66
67
 
@@ -22,14 +22,14 @@ const isPackageJson = j => {
22
22
 
23
23
  /**
24
24
  * @typedef {{
25
- * readonly dependency: (localPackageId: string) => string | undefined
26
- * readonly file: (localFileId: string) => string | undefined
25
+ * readonly dependency: (localPackageId: string) => string | null
26
+ * readonly file: (localFileId: string) => string | null
27
27
  * }} Package
28
28
  */
29
29
 
30
30
  /**
31
31
  * @note Current package has an empty string '' as a packageId.
32
- * @typedef {(packageId: string) => Package | undefined} Get
32
+ * @typedef {(packageId: string) => Package | null} Get
33
33
  */
34
34
 
35
35
  module.exports = {
@@ -80,10 +80,10 @@ const variants = prior => () => {
80
80
  return { first: n, tail: variants(n) }
81
81
  }
82
82
 
83
- /** @type {(d: (local: string) => string|undefined) => (p: IdPath) => IdPath|undefined} */
83
+ /** @type {(d: (local: string) => string|null) => (p: IdPath) => IdPath|undefined} */
84
84
  const mapDependency = d => ([external, internal]) => {
85
85
  const id = d(external)
86
- return id === undefined ? undefined : [id, internal]
86
+ return id === null ? undefined : [id, internal]
87
87
  }
88
88
 
89
89
  /**
@@ -95,10 +95,10 @@ const mapDependency = d => ([external, internal]) => {
95
95
  */
96
96
 
97
97
  /**
98
- * @type {(d: (local: string) => string|undefined) =>
98
+ * @type {(d: (local: string) => string|null) =>
99
99
  * (dir: boolean) =>
100
100
  * (items: list.List<string>) =>
101
- * Path|undefined}
101
+ * Path|null}
102
102
  */
103
103
  const parseGlobal = dependencies =>
104
104
  {
@@ -106,23 +106,23 @@ const parseGlobal = dependencies =>
106
106
  return dir => items => {
107
107
  const v = variants([null, items])
108
108
  const r = firstNull(fMap(v))
109
- if (r === null) { return undefined }
109
+ if (r === null) { return null }
110
110
  return { package: r[0], items: toArray(r[1]), dir }
111
111
  }
112
112
  }
113
113
 
114
114
  /**
115
115
  * @type {(packageId: string) =>
116
- * (dependencies: (local: string) => string|undefined) =>
116
+ * (dependencies: (local: string) => string|null) =>
117
117
  * (local: string) =>
118
118
  * (path: string) =>
119
- * Path|undefined }
119
+ * Path|null }
120
120
  */
121
121
  const parse = packageId => dependencies => {
122
122
  const pg = parseGlobal(dependencies)
123
123
  return local => path => {
124
124
  const parsed = parseLocal(local)(path)
125
- if (parsed === null) { return undefined }
125
+ if (parsed === null) { return null }
126
126
  const {external, dir, items } = parsed
127
127
  if (!external) { return { package: packageId, items, dir } }
128
128
  return pg(dir)(items)
@@ -147,15 +147,15 @@ const parse = packageId => dependencies => {
147
147
  */
148
148
  const parseAndFind = packageGet => moduleId => path => {
149
149
  const currentPack = packageGet(moduleId.package)
150
- if (currentPack === undefined) { return null }
150
+ if (currentPack === null) { return null }
151
151
  const p = parse(moduleId.package)(currentPack.dependency)(moduleId.path.join('/'))(path)
152
- if (p === undefined) { return null }
152
+ if (p === null) { return null }
153
153
  const pack = packageGet(p.package)
154
- if (pack === undefined) { return null }
154
+ if (pack === null) { return null }
155
155
  /** @type {(file: string) => FoundResult | undefined } */
156
156
  const tryFile = file => {
157
157
  const source = pack.file(file)
158
- return source === undefined ? undefined : { id: { package: p.package, path: file.split('/') }, source }
158
+ return source === null ? undefined : { id: { package: p.package, path: file.split('/') }, source }
159
159
  }
160
160
  const file = p.items.join('/')
161
161
  const indexJs = join('/')(concat(p.items)(['index.js']))
@@ -6,11 +6,8 @@ const object = require('../../types/object/module.f.cjs')
6
6
  const { at } = require('../../types/object/module.f.cjs')
7
7
  const package_ = require('../package/module.f.cjs')
8
8
 
9
- /** @type {<T>(o: object.Map<T>) => (s: string) => T|undefined} */
10
- const i = o => s => {
11
- const r = at(s)(o)
12
- return r === null ? undefined : r
13
- }
9
+ /** @type {<T>(o: object.Map<T>) => (s: string) => T|null} */
10
+ const i = o => s => at(s)(o)
14
11
 
15
12
  /** @type {(g: json.Unknown|undefined) => string} */
16
13
  const stringify = g => {
@@ -51,27 +48,27 @@ module.exports = {
51
48
  const result = _.parseLocal('')('./x/..')
52
49
  if (stringify(result) !== '{"external":false,"dir":true,"items":[]}') { throw result }
53
50
  },
54
- 8: () => {
55
- if (_.parseGlobal(() => undefined)(false)(['a', 'b']) !== undefined) { throw 'error' }
56
- if (_.parseGlobal(() => undefined)(false)(['b']) !== undefined) { throw 'error' }
57
- if (_.parseGlobal(i({ b: 'x' }))(false)(['d']) !== undefined) { throw 'error' }
58
- {
51
+ 8: {
52
+ 0: () => { if (_.parseGlobal(() => null)(false)(['a', 'b']) !== null) { throw 'error' } },
53
+ 1: () => { if (_.parseGlobal(() => null)(false)(['b']) !== null) { throw 'error' } },
54
+ 2: () => { if (_.parseGlobal(i({ b: 'x' }))(false)(['d']) !== null) { throw 'error' } },
55
+ 3: () => {
59
56
  const result = stringify(_.parseGlobal(i({ b: 'x' }))(false)(['b']))
60
57
  if (result !== '{"package":"x","items":[],"dir":false}') { throw result }
61
- }
62
- if (_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b']) !== undefined) { throw 'error' }
63
- {
58
+ },
59
+ 4: () => { if (_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b']) !== null) { throw 'error' } },
60
+ 5: () => {
64
61
  const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b', 'r']))
65
62
  if (result !== '{"package":"x","items":[],"dir":false}') { throw result }
66
- }
67
- {
63
+ },
64
+ 6: () => {
68
65
  const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(false)(['b', 'r', 'd', 't']))
69
66
  if (result !== '{"package":"x","items":["d","t"],"dir":false}') { throw result }
70
- }
71
- {
67
+ },
68
+ 7: () => {
72
69
  const result = stringify(_.parseGlobal(i({ 'b/r': 'x' }))(true)(['b', 'r', 'd', 't']))
73
70
  if (result !== '{"package":"x","items":["d","t"],"dir":true}') { throw result }
74
- }
71
+ },
75
72
  },
76
73
  9: () => {
77
74
  /** @type {object.Map<package_.Package>} */
@@ -90,7 +87,7 @@ module.exports = {
90
87
  '': {
91
88
  dependency: x => {
92
89
  const path = `node_modules/${x}`
93
- return at(path)(packages) !== undefined ? path : undefined
90
+ return at(path)(packages) !== null ? path : null
94
91
  },
95
92
  file: i({
96
93
  'index.js': 'return "index.js"',
@@ -140,7 +137,7 @@ module.exports = {
140
137
  '': {
141
138
  dependency: x => {
142
139
  const path = `node_modules/${x}`
143
- return at(path)(packages) !== null ? path : undefined
140
+ return at(path)(packages) !== null ? path : null
144
141
  },
145
142
  file: todo
146
143
  },
@@ -167,7 +164,7 @@ module.exports = {
167
164
  '': {
168
165
  dependency: x => {
169
166
  const path = `node_modules/${x}`
170
- return at(path)(packages) !== null ? path : undefined
167
+ return at(path)(packages) !== null ? path : null
171
168
  },
172
169
  file: todo
173
170
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.480",
3
+ "version": "0.0.481",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {