functionalscript 0.0.343 → 0.0.344

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,8 +1,10 @@
1
1
  # Common.js
2
2
 
3
- ```ts
4
- // package/index.js
3
+ ## Package
4
+
5
+ [package/index.js](package/index.js)
5
6
 
7
+ ```ts
6
8
  // A dictionary of packages.
7
9
  //
8
10
  // A package contains a dictionary of dependencies and a dictionary of files.
@@ -25,9 +27,13 @@ type Package = {
25
27
  // returns source of the file.
26
28
  readonly file: (localFileId: string) => string | undefined
27
29
  }
30
+ ```
28
31
 
29
- // module/index.js
32
+ ## Module
30
33
 
34
+ [module/index.js](module/index.js)
35
+
36
+ ```ts
31
37
  // A module map is a dictionary of modules.
32
38
  //
33
39
  // A module is a compiled and initialized source file.
@@ -62,9 +68,13 @@ type ModuleId = {
62
68
  }
63
69
 
64
70
  const moduleIdToString: (moduleId: ModuleId) => string;
71
+ ```
65
72
 
66
- // build/index.js
73
+ ## Build
67
74
 
75
+ [build/index.js](build/index.js)
76
+
77
+ ```ts
68
78
  type BuildConfig<M> = {
69
79
  readonly packageGet: PackageGet
70
80
  readonly moduleMapInterface: ModuleMapInterface<M>
@@ -81,8 +91,4 @@ type BuildState<M> = {
81
91
  }
82
92
 
83
93
  const getOrBuild: <M>(buildConfig: BuildConfig<M>) => readonly[ModuleState, M];
84
-
85
- //
86
-
87
-
88
94
  ```
@@ -36,7 +36,13 @@ const notFound = moduleMap => [['error', ['file not found']], moduleMap]
36
36
  const getOrBuild = compile => packageGet => moduleMapInterface => {
37
37
  /** @typedef {typeof moduleMapInterface extends module_.MapInterface<infer M> ? M : never} M */
38
38
 
39
- /** @type {(buildSet: stringSet.StringSet) => (moduleId: module_.Id) => (source: string) => (moduleMap: M) => Result<M>} */
39
+ /**
40
+ * @type {(buildSet: stringSet.StringSet) =>
41
+ * (moduleId: module_.Id) =>
42
+ * (source: string) =>
43
+ * (moduleMap: M) =>
44
+ * Result<M>}
45
+ */
40
46
  const build = buildSet => moduleId => {
41
47
  const moduleIdStr = module_.idToString(moduleId)
42
48
  const buildSet1 = stringSet.set(moduleIdStr)(buildSet)
@@ -25,7 +25,10 @@ const isPackageJson = j => {
25
25
  * }} Package
26
26
  */
27
27
 
28
- /** @typedef {(packageId: string) => Package | undefined} Get */
28
+ /**
29
+ * @note Current package has an empty string '' as a packageId.
30
+ * @typedef {(packageId: string) => Package | undefined} Get
31
+ */
29
32
 
30
33
  module.exports = {
31
34
  /** @readonly */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.343",
3
+ "version": "0.0.344",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/functionalscript/functionalscript#readme",
30
30
  "devDependencies": {
31
- "@types/node": "^17.0.35",
32
- "typescript": "^4.7.2"
31
+ "@types/node": "^17.0.42",
32
+ "typescript": "^4.7.3"
33
33
  }
34
34
  }
package/test.js CHANGED
@@ -1,4 +1,4 @@
1
- const i = require('./index.js')
1
+ // const i = require('./index.js')
2
2
 
3
3
  require('./types/list/test.js')
4
4
  require('./types/array/test.js')
@@ -23,53 +23,6 @@ const assert = () => { throw 'assert' }
23
23
  /** @type {(_: boolean) => void} */
24
24
  const assert_if = c => { if (c) { throw 'assert_if' } }
25
25
 
26
- {
27
- i.parseModuleUrl('')(
28
- assert,
29
- e => assert_if(e.id !== 'expected' || e.params[0] !== ':'))
30
- }
31
-
32
- {
33
- i.parseModuleUrl(':')(
34
- assert,
35
- e => assert_if(e.id !== 'unknownProtocol'))
36
- }
37
-
38
- {
39
- i.parseModuleUrl('github:r')(
40
- assert,
41
- e => assert_if(e.id !== 'expected'))
42
- }
43
-
44
- {
45
- i.parseModuleUrl('github:functionalscript/node-example')(
46
- v => assert_if(
47
- v.repo.org !== 'functionalscript' ||
48
- v.repo.name !== 'node-example' ||
49
- 'branch' in v),
50
- assert)
51
- }
52
-
53
- {
54
- i.parseModuleUrl('github:functionalscript/node-example#main')(
55
- v => assert_if(
56
- v.repo.org !== 'functionalscript' ||
57
- v.repo.name !== 'node-example' ||
58
- !('branch' in v) ||
59
- v.branch !== 'main'),
60
- assert)
61
- }
62
-
63
- {
64
- i.parseModuleUrl('github:functionalscript/node-example#4b14a7a2b11cf53f037931eb7bef240f96dcea64')(
65
- v => assert_if(
66
- v.repo.org !== 'functionalscript' ||
67
- v.repo.name !== 'node-example' ||
68
- !('commit' in v) ||
69
- v.commit !== '4b14a7a2b11cf53f037931eb7bef240f96dcea64'),
70
- assert)
71
- }
72
-
73
26
  {
74
27
  const c = (()=>{})['constructor']
75
28
  const f = c('return 5')
package/index.js DELETED
@@ -1,76 +0,0 @@
1
- /** @type {<F>(c: string, found: (before: string, after: string) => F, notFound: (c: string, source: string) => F) => (source: string) => F} */
2
- const splitOne = (c, found, notFound) => source => {
3
- const i = source.indexOf(c)
4
- return i !== -1 ? found(source.substring(0, i), source.substring(i + 1)) : notFound(c, source)
5
- }
6
-
7
- /** @type {<T>(f: (_: T) => boolean) => (_: Iterable<T>) => boolean} */
8
- const every = f => i => {
9
- for (let e of i) {
10
- if (!f(e)) {
11
- return false
12
- }
13
- }
14
- return true
15
- }
16
-
17
- /** @typedef {{org: string, name: string}} RepoId */
18
- /** @typedef {{repo: RepoId}} ModuleRepoId */
19
- /** @typedef {{repo: RepoId, branch: string}} ModuleRepoBranchId */
20
- /** @typedef {{repo: RepoId, commit: string}} ModuleRepoCommitId */
21
- /** @typedef {ModuleRepoId|ModuleRepoBranchId|ModuleRepoCommitId} ModuleId */
22
-
23
- /** @typedef {(..._: string[]) => string} GetMsg */
24
- /** @typedef {'expected'|'unknownProtocol'} ErrorId */
25
- /** @typedef {{[_ in ErrorId]: GetMsg}} ErrorMap */
26
- /** @typedef {{ id: ErrorId, params: string[]}} ErrorValue */
27
-
28
- /**
29
- * @template T
30
- * @typedef {<R>(v: (_: T) => R, e: (_: ErrorValue) => R) => R} Result
31
- */
32
-
33
- /** @type {<T>(_: T) => Result<T>} */
34
- const value = v => vf => vf(v)
35
-
36
- /**
37
- * @typedef {<R, T>(_: (_: T) => R, e: (_: ErrorValue) => R) => R} ErrorResult
38
- */
39
-
40
- /** @type {(e: ErrorValue) => ErrorResult} */
41
- const error = e => (_, ef) => ef(e)
42
-
43
- /** @type {(id: ErrorId) => (...params: string[]) => ErrorResult} */
44
- const createError = id => (...params) => error({ id, params })
45
-
46
- /** @type {(_: string) => Result<ModuleId>} */
47
- const parseRepo = repo => {
48
- const s = repo.split('/')
49
- return s.length === 2 ? value({ repo: { org: s[0], name: s[1] } }) : createError('expected')('/', repo)
50
- }
51
-
52
- /** @type {(_: string) => boolean} */
53
- const isCommit = name => name.length === 40 && every(c => "0123456789ABCDEFabcdef".includes(c))(name)
54
-
55
- /** @type {(repo: string, branch: string) => Result<ModuleId>} */
56
- const parseRepoAndBranchCommit = (repo, branchCommit) =>
57
- parseRepo(repo)(
58
- ({repo}) => value(isCommit(branchCommit) ? { repo, commit: branchCommit } : { repo, branch: branchCommit }),
59
- error)
60
-
61
- const parseGitHubId = splitOne('#', parseRepoAndBranchCommit, (_, repo) => parseRepo(repo))
62
-
63
- /** @type {(protocol: string, id: string) => Result<ModuleId>} */
64
- const parseProtocolAndId = (protocol, id) => protocol === 'github'
65
- ? parseGitHubId(id) : createError('unknownProtocol')(protocol)
66
-
67
- module.exports = {
68
- every,
69
- isCommit,
70
- parseModuleUrl: splitOne(':', parseProtocolAndId, createError('expected')),
71
- /** @type {ErrorMap} */
72
- errorMap: {
73
- expected: (c, s) => `expected '${c}' in '${s}'`,
74
- unknownProtocol: protocol => `unknown protocol '${protocol}'`,
75
- },
76
- }