@ostro/filesystem 0.0.0-alpha.2 → 0.0.0-alpha.6

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.
@@ -0,0 +1,22 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3
+
4
+ name: Node.js Package
5
+
6
+ on:
7
+ release:
8
+ types: [created]
9
+
10
+ jobs:
11
+
12
+ publish-npm:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - uses: actions/setup-node@v2
17
+ with:
18
+ node-version: 14
19
+ registry-url: https://registry.npmjs.org/
20
+ - run: npm publish
21
+ env:
22
+ NODE_AUTH_TOKEN: ${{secrets.npm_token}}
package/LICENSE.md CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 Ostro NodeJs Framework
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Ostro NodeJs Framework
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,37 +1,37 @@
1
- <div align="center">
2
- <h1>OstroJS Framework</h1>
3
-
4
- </div>
5
- <br />
6
-
7
- <div align="center">
8
- <h3>OstroJS Filesystem</h3>
9
- <p>Filesystem Module for OstroJS</p>
10
- </div>
11
-
12
- <br />
13
-
14
- <div align="center">
15
-
16
- ![][javascript-image] [![license-image]][license-url] [![nodejs-image]][npm-url]
17
-
18
- </div>
19
-
20
- <div align="center">
21
- <h3>
22
- <a href="https://ostrojs.com">
23
- Website
24
- </a>
25
-
26
- </h3>
27
- </div>
28
-
29
-
30
- [javascript-image]: https://img.shields.io/badge/JS-javascript-green
31
- [javascript-url]: "javascript"
32
-
33
- [nodejs-image]: https://img.shields.io/badge/node-%3E%3D%2012.0.0-green
34
- [npm-url]: https://npmjs.org/package/@ostro/filesystem "npm"
35
-
36
- [license-image]: https://img.shields.io/github/license/ostrojs/filesystem
1
+ <div align="center">
2
+ <h1>OstroJS Framework</h1>
3
+
4
+ </div>
5
+ <br />
6
+
7
+ <div align="center">
8
+ <h3>OstroJS Filesystem</h3>
9
+ <p>Filesystem Module for OstroJS</p>
10
+ </div>
11
+
12
+ <br />
13
+
14
+ <div align="center">
15
+
16
+ ![][javascript-image] [![license-image]][license-url] [![nodejs-image]][npm-url]
17
+
18
+ </div>
19
+
20
+ <div align="center">
21
+ <h3>
22
+ <a href="https://ostrojs.com">
23
+ Website
24
+ </a>
25
+
26
+ </h3>
27
+ </div>
28
+
29
+
30
+ [javascript-image]: https://img.shields.io/badge/JS-javascript-green
31
+ [javascript-url]: "javascript"
32
+
33
+ [nodejs-image]: https://img.shields.io/badge/node-%3E%3D%2012.0.0-green
34
+ [npm-url]: https://npmjs.org/package/@ostro/filesystem "npm"
35
+
36
+ [license-image]: https://img.shields.io/github/license/ostrojs/filesystem
37
37
  [license-url]: LICENSE.md "license"
@@ -1,85 +1,85 @@
1
- const path = require('path')
2
- const url = require('url')
3
- const { ensureDir } = require('fs-extra')
4
- const kConfig = Symbol('config')
5
- const kRootPath = Symbol('rootPath')
6
- const kRootUrlPath = Symbol('rootUrlPath')
7
- class CoreAdapter {
8
- setConfig(config) {
9
- this[kConfig] = config
10
- }
11
-
12
- getConfig() {
13
- return this[kConfig] || null
14
- }
15
-
16
- setPathPrefix(root) {
17
- this[kRootPath] = root
18
- }
19
-
20
- setUrlPrefix(root) {
21
- this[kRootUrlPath] = root
22
- }
23
-
24
- applyPathPrefix(dest) {
25
- return path.resolve(path.join(this[kRootPath], path.join('/', path.normalize(dest))))
26
- }
27
-
28
- applyUrlPrefix(dest) {
29
- return url.resolve(([this[kRootUrlPath], (dest || '')].join('/')), '')
30
- }
31
-
32
- ensureDirectory(dir, callback) {
33
- ensureDir(dir, callback)
34
- }
35
-
36
- parsePath(dest) {
37
- return path.parse(dest)
38
- }
39
-
40
- dirname(dest) {
41
- return this.parsePath(dest).dir
42
- }
43
-
44
- getContent(content) {
45
- if (Array.isArray(content))
46
- return content[0]
47
- else
48
- return content
49
- }
50
-
51
- getBufferData(content) {
52
- return this.getContent(content).buffer
53
- }
54
- move(path, newpath, callback) {
55
- callback(this.formatError({ message: 'there was no such functionality available.' }), {})
56
- }
57
-
58
- delete($path, options = {}, callback) {
59
- callback(this.formatError({ message: 'there was no such functionality available.' }), {})
60
-
61
- }
62
-
63
- has($path, options = {}, callback) {
64
- callback(this.formatError({ message: 'there was no such functionality available.' }), {})
65
-
66
- }
67
-
68
- write($path, $contents, options = {}, ...rest) {
69
- callback(this.formatError({ message: 'there was no such functionality available.' }), {})
70
-
71
- }
72
-
73
- read($path, options = {}, callback) {
74
- callback(this.formatError({ message: 'there was no such functionality available.' }), {})
75
-
76
- }
77
- formatError(err) {
78
- return {
79
- 'message': 'Storage Error',
80
- 'errors': err,
81
- 'status': 500
82
- }
83
- }
84
- }
1
+ const path = require('path')
2
+ const url = require('url')
3
+ const { ensureDir } = require('fs-extra')
4
+ const kConfig = Symbol('config')
5
+ const kRootPath = Symbol('rootPath')
6
+ const kRootUrlPath = Symbol('rootUrlPath')
7
+ class CoreAdapter {
8
+ setConfig(config) {
9
+ this[kConfig] = config
10
+ }
11
+
12
+ getConfig() {
13
+ return this[kConfig] || null
14
+ }
15
+
16
+ setPathPrefix(root) {
17
+ this[kRootPath] = root
18
+ }
19
+
20
+ setUrlPrefix(root) {
21
+ this[kRootUrlPath] = root
22
+ }
23
+
24
+ applyPathPrefix(dest) {
25
+ return path.resolve(path.join(this[kRootPath], path.join('/', path.normalize(dest))))
26
+ }
27
+
28
+ applyUrlPrefix(dest) {
29
+ return url.resolve(([this[kRootUrlPath], (dest || '')].join('/')), '')
30
+ }
31
+
32
+ ensureDirectory(dir, callback) {
33
+ ensureDir(dir, callback)
34
+ }
35
+
36
+ parsePath(dest) {
37
+ return path.parse(dest)
38
+ }
39
+
40
+ dirname(dest) {
41
+ return this.parsePath(dest).dir
42
+ }
43
+
44
+ getContent(content) {
45
+ if (Array.isArray(content))
46
+ return content[0]
47
+ else
48
+ return content
49
+ }
50
+
51
+ getBufferData(content) {
52
+ return this.getContent(content).buffer
53
+ }
54
+ move(path, newpath, callback) {
55
+ callback(this.formatError({ message: 'there was no such functionality available.' }), {})
56
+ }
57
+
58
+ delete($path, options = {}, callback) {
59
+ callback(this.formatError({ message: 'there was no such functionality available.' }), {})
60
+
61
+ }
62
+
63
+ has($path, options = {}, callback) {
64
+ callback(this.formatError({ message: 'there was no such functionality available.' }), {})
65
+
66
+ }
67
+
68
+ write($path, $contents, options = {}, ...rest) {
69
+ callback(this.formatError({ message: 'there was no such functionality available.' }), {})
70
+
71
+ }
72
+
73
+ read($path, options = {}, callback) {
74
+ callback(this.formatError({ message: 'there was no such functionality available.' }), {})
75
+
76
+ }
77
+ formatError(err) {
78
+ return {
79
+ 'message': 'Storage Error',
80
+ 'errors': err,
81
+ 'status': 500
82
+ }
83
+ }
84
+ }
85
85
  module.exports = CoreAdapter
package/adapter/azure.js CHANGED
@@ -1,68 +1,68 @@
1
- const CoreAdapter = require('./CoreAdapter')
2
- const kClient = Symbol('client')
3
- const kHandler = Symbol('handler')
4
- class Azure extends CoreAdapter {
5
-
6
- constructor($client, $config) {
7
- super()
8
- this[kClient] = $client;
9
- this[kHandler] = typeof $config.handler == 'function' ? new $config.handler : typeof $config.handler == 'object' ? $config.handler : {};
10
- this.setUrlPrefix(this[kClient].url)
11
- }
12
-
13
- read($path, options = {}, callback) {
14
- let basePath = this.applyUrlPrefix();
15
- this[kClient].getContainer(options.container).getBlockBlobClient($path).downloadToBuffer()
16
- .then(data => ({ error: null, data: data }))
17
- .catch(error => Promise.resolve({ error, data: null }))
18
- .then(({ error, data }) => {
19
- if (typeof this[kHandler].read == 'function') {
20
- this[kHandler].read({
21
- path: $path,
22
- options,
23
- callback,
24
- error,
25
- basePath,
26
- contents: data
27
- })
28
- } else {
29
- callback(error, function() {
30
- return {
31
- 'type': 'file',
32
- 'path': $path,
33
- 'contents': (options.dataType == 'base64') ? data.toString('base64') : data.toString(),
34
- }
35
- }, basePath)
36
- }
37
- });
38
- }
39
- write($path, data, options = {}, callback) {
40
- let basePath = this.applyUrlPrefix();
41
- this[kClient].getContainer(options.container).getBlockBlobClient($path).upload(data, data.length)
42
- .then(response => ({ error: null, response }))
43
- .catch(error => Promise.resolve({ error, response: null }))
44
- .then(({ error, response }) => {
45
- if (typeof this[kHandler].read == 'function') {
46
- this[kHandler].write({
47
- path: $path,
48
- options,
49
- callback,
50
- error,
51
- basePath,
52
- response,
53
- contents: data
54
- })
55
- } else {
56
- callback(error, function() {
57
- return {
58
- 'type': 'file',
59
- 'path': $path,
60
- 'message': 'File uploaded successfully'
61
- }
62
- }, basePath)
63
- }
64
- });
65
- }
66
-
67
- }
1
+ const CoreAdapter = require('./CoreAdapter')
2
+ const kClient = Symbol('client')
3
+ const kHandler = Symbol('handler')
4
+ class Azure extends CoreAdapter {
5
+
6
+ constructor($client, $config) {
7
+ super()
8
+ this[kClient] = $client;
9
+ this[kHandler] = typeof $config.handler == 'function' ? new $config.handler : typeof $config.handler == 'object' ? $config.handler : {};
10
+ this.setUrlPrefix(this[kClient].url)
11
+ }
12
+
13
+ read($path, options = {}, callback) {
14
+ let basePath = this.applyUrlPrefix();
15
+ this[kClient].getContainer(options.container).getBlockBlobClient($path).downloadToBuffer()
16
+ .then(data => ({ error: null, data: data }))
17
+ .catch(error => Promise.resolve({ error, data: null }))
18
+ .then(({ error, data }) => {
19
+ if (typeof this[kHandler].read == 'function') {
20
+ this[kHandler].read({
21
+ path: $path,
22
+ options,
23
+ callback,
24
+ error,
25
+ basePath,
26
+ contents: data
27
+ })
28
+ } else {
29
+ callback(error, function() {
30
+ return {
31
+ 'type': 'file',
32
+ 'path': $path,
33
+ 'contents': (options.dataType == 'base64') ? data.toString('base64') : data.toString(),
34
+ }
35
+ }, basePath)
36
+ }
37
+ });
38
+ }
39
+ write($path, data, options = {}, callback) {
40
+ let basePath = this.applyUrlPrefix();
41
+ this[kClient].getContainer(options.container).getBlockBlobClient($path).upload(data, data.length)
42
+ .then(response => ({ error: null, response }))
43
+ .catch(error => Promise.resolve({ error, response: null }))
44
+ .then(({ error, response }) => {
45
+ if (typeof this[kHandler].read == 'function') {
46
+ this[kHandler].write({
47
+ path: $path,
48
+ options,
49
+ callback,
50
+ error,
51
+ basePath,
52
+ response,
53
+ contents: data
54
+ })
55
+ } else {
56
+ callback(error, function() {
57
+ return {
58
+ 'type': 'file',
59
+ 'path': $path,
60
+ 'message': 'File uploaded successfully'
61
+ }
62
+ }, basePath)
63
+ }
64
+ });
65
+ }
66
+
67
+ }
68
68
  module.exports = Azure