lib0 0.2.66 → 0.2.68

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.
Files changed (61) hide show
  1. package/bin/0serve.d.ts +3 -0
  2. package/bin/0serve.d.ts.map +1 -0
  3. package/bin/0serve.js +88 -0
  4. package/bin/gendocs.d.ts +2 -0
  5. package/bin/gendocs.d.ts.map +1 -0
  6. package/bin/gendocs.js +17 -4
  7. package/bin/gentesthtml.d.ts +3 -0
  8. package/bin/gentesthtml.d.ts.map +1 -0
  9. package/bin/gentesthtml.js +29 -15
  10. package/cache.d.ts +1 -1
  11. package/cache.d.ts.map +1 -1
  12. package/coverage/tmp/coverage-53209-1678990177518-0.json +1 -0
  13. package/crypto/aes-gcm.d.ts +1 -1
  14. package/crypto/aes-gcm.d.ts.map +1 -1
  15. package/crypto/aes-gcm.js +1 -6
  16. package/crypto/common.d.ts +2 -0
  17. package/crypto/common.d.ts.map +1 -0
  18. package/crypto/common.js +10 -0
  19. package/crypto/ecdsa.d.ts +1 -1
  20. package/crypto/ecdsa.d.ts.map +1 -1
  21. package/crypto/ecdsa.js +1 -7
  22. package/crypto/rsa-oaep.d.ts +3 -3
  23. package/crypto/rsa-oaep.d.ts.map +1 -1
  24. package/crypto/rsa-oaep.js +5 -8
  25. package/dist/bin/0serve.d.ts +3 -0
  26. package/dist/bin/0serve.d.ts.map +1 -0
  27. package/dist/bin/gendocs.d.ts +2 -0
  28. package/dist/bin/gendocs.d.ts.map +1 -0
  29. package/dist/bin/gentesthtml.d.ts +3 -0
  30. package/dist/bin/gentesthtml.d.ts.map +1 -0
  31. package/dist/cache.d.ts +1 -1
  32. package/dist/cache.d.ts.map +1 -1
  33. package/dist/crypto/aes-gcm.d.ts +1 -1
  34. package/dist/crypto/aes-gcm.d.ts.map +1 -1
  35. package/dist/crypto/common.d.ts +2 -0
  36. package/dist/crypto/common.d.ts.map +1 -0
  37. package/dist/crypto/ecdsa.d.ts +1 -1
  38. package/dist/crypto/ecdsa.d.ts.map +1 -1
  39. package/dist/crypto/rsa-oaep.d.ts +3 -3
  40. package/dist/crypto/rsa-oaep.d.ts.map +1 -1
  41. package/dist/environment.test.d.ts +1 -0
  42. package/dist/index.cjs +1 -1
  43. package/dist/object.d.ts +3 -3
  44. package/dist/rollup.config.d.ts +1 -1
  45. package/dist/tree.test.d.ts +1 -0
  46. package/dist/{websocket-85f1d597.cjs → websocket-e861ab50.cjs} +2 -2
  47. package/dist/websocket-e861ab50.cjs.map +1 -0
  48. package/dist/websocket.cjs +1 -1
  49. package/dist/websocket.d.ts +2 -2
  50. package/dist/websocket.d.ts.map +1 -1
  51. package/environment.test.d.ts +1 -0
  52. package/object.d.ts +3 -3
  53. package/package.json +5 -5
  54. package/rollup.config.d.ts +1 -1
  55. package/test.html +3 -2
  56. package/tree.test.d.ts +1 -0
  57. package/websocket.d.ts +2 -2
  58. package/websocket.d.ts.map +1 -1
  59. package/websocket.js +1 -1
  60. package/coverage/tmp/coverage-29418-1678525324823-0.json +0 -1
  61. package/dist/websocket-85f1d597.cjs.map +0 -1
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=0serve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"0serve.d.ts","sourceRoot":"","sources":["0serve.js"],"names":[],"mappings":""}
package/bin/0serve.js ADDED
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ import http from 'http'
3
+ import path from 'path'
4
+ import fs from 'fs'
5
+ import * as env from '../environment.js'
6
+ import * as number from '../number.js'
7
+ import * as logging from '../logging.js'
8
+
9
+ const host = env.getParam('--host', 'localhost')
10
+ const port = number.parseInt(env.getParam('--port', '8000'))
11
+ const paramOpenFile = env.getParam('-o', '')
12
+
13
+ /**
14
+ * @type {Object<string,string>}
15
+ */
16
+ const types = {
17
+ html: 'text/html',
18
+ css: 'text/css',
19
+ js: 'application/javascript',
20
+ mjs: 'application/javascript',
21
+ png: 'image/png',
22
+ jpg: 'image/jpeg',
23
+ jpeg: 'image/jpeg',
24
+ gif: 'image/gif',
25
+ json: 'application/json',
26
+ xml: 'application/xml'
27
+ }
28
+
29
+ const root = path.normalize(path.resolve('./'))
30
+
31
+ const server = http.createServer((req, res) => {
32
+ const url = req.url || '/index.html'
33
+ logging.print(logging.ORANGE, logging.BOLD, req.method || '', ' ', logging.GREY, logging.UNBOLD, url)
34
+ const extension = path.extname(url).slice(1)
35
+ /**
36
+ * @type {string}
37
+ */
38
+ const type = (extension && types[extension]) || types.html
39
+ const supportedExtension = Boolean(type)
40
+ if (!supportedExtension) {
41
+ res.writeHead(404, { 'Content-Type': 'text/html' })
42
+ res.end('404: File not found')
43
+ return
44
+ }
45
+ let fileName = url
46
+ if (url === '/') fileName = 'index.html'
47
+ else if (!extension) {
48
+ try {
49
+ fs.accessSync(path.join(root, url + '.html'), fs.constants.F_OK)
50
+ fileName = url + '.html'
51
+ } catch (e) {
52
+ fileName = path.join(url, 'index.html')
53
+ }
54
+ }
55
+
56
+ const filePath = path.join(root, fileName)
57
+ const isPathUnderRoot = path
58
+ .normalize(path.resolve(filePath))
59
+ .startsWith(root)
60
+
61
+ if (!isPathUnderRoot) {
62
+ res.writeHead(404, { 'Content-Type': 'text/html' })
63
+ res.end('404: File not found')
64
+ logging.print(logging.RED, logging.BOLD, 'Not Found: ', logging.GREY, logging.UNBOLD, url)
65
+ return
66
+ }
67
+
68
+ fs.readFile(filePath, (err, data) => {
69
+ if (err) {
70
+ logging.print(logging.RED, logging.BOLD, 'Cannot read file: ', logging.GREY, logging.UNBOLD, url)
71
+ res.writeHead(404, { 'Content-Type': 'text/html' })
72
+ res.end('404: File not found')
73
+ } else {
74
+ res.writeHead(200, { 'Content-Type': type })
75
+ res.end(data)
76
+ }
77
+ })
78
+ })
79
+
80
+ server.listen(port, host, () => {
81
+ logging.print(logging.BOLD, logging.ORANGE, `Server is running on http://${host}:${port}`)
82
+ if (paramOpenFile) {
83
+ const start = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open'
84
+ import('child_process').then(cp => {
85
+ cp.exec(`${start} http://${host}:${port}/${paramOpenFile}`)
86
+ })
87
+ }
88
+ })
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=gendocs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gendocs.d.ts","sourceRoot":"","sources":["gendocs.js"],"names":[],"mappings":""}
package/bin/gendocs.js CHANGED
@@ -1,3 +1,4 @@
1
+ // @ts-ignore
1
2
  import jsdoc from 'jsdoc-api'
2
3
  import fs from 'fs'
3
4
 
@@ -9,6 +10,9 @@ const files = fs.readdirSync('./').filter(file => /(?<!(test|config))\.js$/.test
9
10
 
10
11
  const _ltregex = /</g
11
12
  const _rtregex = />/g
13
+ /**
14
+ * @param {string} s
15
+ */
12
16
  const toSafeHtml = s => s.replace(_ltregex, '&lt;').replace(_rtregex, '&gt;')
13
17
 
14
18
  const READMEcontent = fs.readFileSync('./README.md', 'utf8')
@@ -16,8 +20,11 @@ const READMEcontent = fs.readFileSync('./README.md', 'utf8')
16
20
  jsdoc.explain({
17
21
  files,
18
22
  configure: '.jsdoc.json'
19
- }).then(json => {
23
+ }).then(/** @param {Array<any>} json */ json => {
20
24
  const strBuilder = []
25
+ /**
26
+ * @type {Object<string, { items: Array<any>, name: string, description: string }>}
27
+ */
21
28
  const modules = {}
22
29
  json.forEach(item => {
23
30
  if (item.meta && item.meta.filename) {
@@ -30,6 +37,9 @@ jsdoc.explain({
30
37
  }
31
38
  }
32
39
  })
40
+ /**
41
+ * @type {Object<string,string>}
42
+ */
33
43
  const classDescriptions = {}
34
44
  for (const fileName in modules) {
35
45
  const mod = modules[fileName]
@@ -67,6 +77,9 @@ jsdoc.explain({
67
77
  }
68
78
  // eslint-disable-next-line
69
79
  case 'function': {
80
+ /**
81
+ * @param {string} name
82
+ */
70
83
  const getOriginalParamTypeDecl = name => {
71
84
  const regval = new RegExp('@param {(.*)} \\[?' + name + '\\]?[^\\w]*').exec(item.comment)
72
85
  return regval ? regval[1] : null
@@ -74,9 +87,9 @@ jsdoc.explain({
74
87
  if (item.params == null && item.returns == null) {
75
88
  break
76
89
  }
77
- const paramVal = (item.params || []).map(ret => `${ret.name}: ${getOriginalParamTypeDecl(ret.name) || ret.type.names.join('|')}`).join(', ')
90
+ const paramVal = (item.params || []).map(/** @param {any} ret */ ret => `${ret.name}: ${getOriginalParamTypeDecl(ret.name) || ret.type.names.join('|')}`).join(', ')
78
91
  const evalReturnRegex = jsdocReturnRegex.exec(item.comment)
79
- const returnVal = evalReturnRegex ? `: ${evalReturnRegex[1]}` : (item.returns ? item.returns.map(r => r.type.names.join('|')).join('|') : '')
92
+ const returnVal = evalReturnRegex ? `: ${evalReturnRegex[1]}` : (item.returns ? item.returns.map(/** @param {any} r */ r => r.type.names.join('|')).join('|') : '')
80
93
  strBuilder.push(`<b><code>${item.kind === 'class' ? 'new ' : ''}${item.longname.slice(7)}(${toSafeHtml(paramVal)})${toSafeHtml(returnVal)}</code></b><br>`)
81
94
  const desc = item.description || item.classdesc || classDescriptions[item.longname] || null
82
95
  if (desc) {
@@ -86,7 +99,7 @@ jsdoc.explain({
86
99
  }
87
100
  case 'member': {
88
101
  if (item.type) {
89
- strBuilder.push(`<b><code>${item.longname.slice(7)}: ${toSafeHtml(jsdocTypeRegex.exec(item.comment)[1])}</code></b><br>`)
102
+ strBuilder.push(`<b><code>${item.longname.slice(7)}: ${toSafeHtml(/** @type {RegExpExecArray} */ (jsdocTypeRegex.exec(item.comment))[1])}</code></b><br>`)
90
103
  if (item.description) {
91
104
  strBuilder.push(`<dd>${item.description}</dd>`)
92
105
  }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=gentesthtml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gentesthtml.d.ts","sourceRoot":"","sources":["gentesthtml.js"],"names":[],"mappings":""}
@@ -1,38 +1,51 @@
1
-
1
+ #!/usr/bin/env node
2
2
  import fs from 'fs'
3
3
  import * as object from '../object.js'
4
+ import * as env from '../environment.js'
5
+
6
+ const script = env.getParam('--script', './test.js')
4
7
 
5
8
  /**
6
9
  * @type {Object<string,string>}
7
10
  */
8
11
  const exports = {}
12
+ /**
13
+ * @type {Object<string,Object<string,string>>}
14
+ */
15
+ const scopes = {}
9
16
 
10
17
  /**
11
18
  * @param {any} v
12
19
  * @param {string} k
13
20
  * @param {string} pkgName
14
21
  * @param {string} pathPrefix
22
+ * @param {Object<string,string>} importMap
15
23
  */
16
- const extractModMap = (v, k, pkgName, pathPrefix) => {
24
+ const extractModMap = (v, k, pkgName, pathPrefix, importMap) => {
17
25
  if (k[0] !== '.') return
18
26
  if (typeof v === 'object') {
19
- extractModMap(v.browser || v.module || v.import, k, pkgName, pathPrefix)
27
+ extractModMap(v.browser || v.module || v.import, k, pkgName, pathPrefix, importMap)
20
28
  } else if (v && v[0] === '.') {
21
- exports[pkgName + k.slice(1)] = pathPrefix + v.slice(1)
29
+ importMap[pkgName + k.slice(1)] = pathPrefix + v.slice(1)
22
30
  }
23
31
  }
24
- const rootPkgJson = JSON.parse(fs.readFileSync('./package.json'))
32
+
25
33
  /**
26
- * @param {object} pkgJson
34
+ * @param {any} pkgJson
27
35
  * @param {string} pathPrefix
36
+ * @param {Object<string,string>} importMap
28
37
  */
29
- const extractPkgJsonInfo = (pkgJson, pathPrefix) => object.forEach(pkgJson.exports, (v, k) => extractModMap(v, k, pkgJson.name, pathPrefix))
30
- extractPkgJsonInfo(rootPkgJson, '.')
31
- object.forEach(rootPkgJson.dependencies, (_v, depName) => {
32
- const prefix = `./node_modules/${depName}`
33
- const depPkgJson = JSON.parse(fs.readFileSync(prefix + '/package.json'))
34
- extractPkgJsonInfo(depPkgJson, prefix)
35
- })
38
+ const readPkg = (pkgJson, pathPrefix, importMap) => {
39
+ object.forEach(pkgJson.exports, (v, k) => extractModMap(v, k, pkgJson.name, pathPrefix, importMap))
40
+ object.forEach(pkgJson.dependencies, (_v, depName) => {
41
+ const nextImportMap = pathPrefix === '.' ? exports : (scopes[pathPrefix + '/'] = {})
42
+ const prefix = `./node_modules/${depName}`
43
+ const depPkgJson = JSON.parse(fs.readFileSync(prefix + '/package.json', { encoding: 'utf8' }))
44
+ readPkg(depPkgJson, prefix, nextImportMap)
45
+ })
46
+ }
47
+
48
+ readPkg(JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf8' })), '.', exports)
36
49
 
37
50
  const testHtml = `
38
51
  <!DOCTYPE html>
@@ -41,12 +54,13 @@ const testHtml = `
41
54
  <title>Testing lib0</title>
42
55
  <script type="importmap">
43
56
  {
44
- "imports": ${JSON.stringify(exports, null, 2)}
57
+ "imports": ${JSON.stringify(exports, null, 2)},
58
+ "scopes": ${JSON.stringify(scopes, null, 2)}
45
59
  }
46
60
  </script>
47
61
  </head>
48
62
  <body>
49
- <script type="module" src="./test.js"></script>
63
+ <script type="module" src="${script}"></script>
50
64
  </body>
51
65
  </html>
52
66
  `
package/cache.d.ts CHANGED
@@ -21,7 +21,7 @@ export function set<K, V>(cache: Cache<K, V>, key: K, value: V): void;
21
21
  export function get<K, V>(cache: Cache<K, V>, key: K): V | undefined;
22
22
  export function refreshTimeout<K, V>(cache: Cache<K, V>, key: K): void;
23
23
  export function getAsync<K, V>(cache: Cache<K, V>, key: K): V | Promise<V> | undefined;
24
- export function remove<K, V>(cache: Cache<K, V>, key: K): V | undefined;
24
+ export function remove<K, V>(cache: Cache<K, V>, key: K): NonNullable<V> | undefined;
25
25
  export function setIfUndefined<K, V>(cache: Cache<K, V>, key: K, init: () => Promise<V>, removeNull?: boolean): V | Promise<V>;
26
26
  export function create(timeout: number): Cache<any, any>;
27
27
  import * as list from "./list.js";
package/cache.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["cache.js"],"names":[],"mappings":"AAsCA;;GAEG;AACH;IACE;;OAEG;IACH,qBAFW,MAAM,EAYhB;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