This repository has been archived by the owner on Jun 16, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
fix: refactor storage template #18
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f229e36
fix: add release script
juanpicado b851e79
Merge remote-tracking branch 'origin/master' into fix-storage-template
juanpicado 342ee4b
chore: add storage database handler
juanpicado 2d3b086
refactor: add documented storage template
juanpicado e3e654b
fix: test wrong file
juanpicado File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"@typescript-eslint/no-unused-vars": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"no-unused-vars": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
generators/app/templates/javascript/storage/src/PackageStorage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import { UploadTarball, ReadTarball } from "@verdaccio/streams"; | ||
import { getNotFound, getConflict, getInternalError } from '@verdaccio/commons-api'; | ||
|
||
|
||
export default class StoragePluginManage { | ||
constructor(packageName, helper, config, logger) { | ||
this.logger = logger; | ||
this.packageName = packageName; | ||
this.config = config; | ||
} | ||
|
||
/** | ||
* Handle a metadata update and | ||
* @param name | ||
* @param updateHandler | ||
* @param onWrite | ||
* @param transformPackage | ||
* @param onEnd | ||
*/ | ||
updatePackage(name, updateHandler, onWrite, transformPackage, onEnd) { | ||
/** | ||
* Example of implementation: | ||
this.customStore.get().then((pkg: Package) => { | ||
updateHandler(pkg, function onUpdateFinish(err) { | ||
if (err) { | ||
onEnd(err); | ||
} else { | ||
onWrite(name, pkg, onEnd); | ||
} | ||
}) | ||
}); | ||
*/ | ||
} | ||
|
||
/** | ||
* Delete a specific file (tarball or package.json) | ||
* @param fileName | ||
* @param callback | ||
*/ | ||
deletePackage(fileName, callback) { | ||
/** | ||
* Example of implementation: | ||
this.customStore.delete(fileName, (err) => { | ||
if (err) { | ||
callback(err); | ||
} else { | ||
callback(null); | ||
} | ||
}) | ||
*/ | ||
} | ||
|
||
/** | ||
* Delete a package (folder, path) | ||
* This happens after all versions ar tarballs have been removed. | ||
* @param callback | ||
*/ | ||
removePackage(callback) { | ||
/** | ||
* Example of implementation: | ||
this.customStore.removePackage((err) => { | ||
if (err) { | ||
callback(err); | ||
} else { | ||
callback(null); | ||
} | ||
}) | ||
*/ | ||
} | ||
|
||
/** | ||
* Publish a new package (version). | ||
* @param name | ||
* @param data | ||
* @param callback | ||
*/ | ||
createPackage(name, metadata, cb) { | ||
/** | ||
* Example of implementation: | ||
* this.customStore.create(name, data).then(err => { | ||
if (err.notFound) { | ||
callback(getNotFound()); | ||
} else if (err.alreadyExist) { | ||
callback(getConflict()); | ||
} else { | ||
callback(null); | ||
} | ||
}) | ||
*/ | ||
} | ||
|
||
/** | ||
* Perform write anobject to the storage. | ||
* Similar to updatePackage but without middleware handlers | ||
* @param pkgName package name | ||
* @param pkg package metadata | ||
* @param callback | ||
*/ | ||
savePackage(name, value, cb) { | ||
/* | ||
Example of implementation: | ||
this.cumstomStore.write(pkgName, pkgName).then(data => { | ||
callback(null); | ||
}).catch(err => { | ||
callback(getInternalError(err.message)); | ||
}) | ||
*/ | ||
} | ||
|
||
/** | ||
* Read a package from storage | ||
* @param pkgName package name | ||
* @param callback | ||
*/ | ||
readPackage(name, cb) { | ||
/** | ||
* Example of implementation: | ||
* this.customStorage.read(name, (err, pkg: Package) => { | ||
if (err.fooError) { | ||
callback(getInternalError(err)) | ||
} else if (err.barError) { | ||
callback(getNotFound()); | ||
} else { | ||
callback(null, pkg) | ||
} | ||
}); | ||
*/ | ||
} | ||
|
||
/** | ||
* Create writtable stream (write a tarball) | ||
* @param name | ||
*/ | ||
writeTarball(name) { | ||
/** | ||
* Example of implementation: | ||
* const stream = new UploadTarball({}); | ||
return stream; | ||
*/ | ||
} | ||
|
||
/** | ||
* Create a readable stream (read a from a tarball) | ||
* @param name | ||
*/ | ||
readTarball(name) { | ||
/** | ||
* Example of implementation: | ||
* const stream = new ReadTarball({}); | ||
return stream; | ||
*/ | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1 @@ | ||
class VerdaccioStoragePlugin { | ||
constructor(config, options) {} | ||
|
||
getSecret() {} | ||
|
||
setSecret(secret) {} | ||
|
||
/** | ||
* Add a new element. | ||
* @param {*} name | ||
* @return {Error|*} | ||
*/ | ||
add(name, cb) {} | ||
|
||
search(onPackage, onEnd, validateName) {} | ||
|
||
/** | ||
* Remove an element from the database. | ||
* @param {*} name | ||
* @return {Error|*} | ||
*/ | ||
remove(name, cb) {} | ||
|
||
/** | ||
* Return all database elements. | ||
* @return {Array} | ||
*/ | ||
get(cb) {} | ||
|
||
getPackageStorage(packageName) {} | ||
} | ||
|
||
module.exports = (config, options) => { | ||
return new VerdaccioStoragePlugin(config, options); | ||
}; | ||
export { default } from './plugin'; |
106 changes: 106 additions & 0 deletions
106
generators/app/templates/javascript/storage/src/plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import PackageStorage from './PackageStorage'; | ||
|
||
class VerdaccioStoragePlugin { | ||
constructor(config, options) { | ||
this.config = config; | ||
this.logger = options.logger; | ||
} | ||
|
||
async getSecret() { | ||
/** | ||
* return await resolveSecret(); | ||
*/ | ||
} | ||
|
||
async setSecret(secret) { | ||
/** | ||
* return await getYourSecret(); | ||
*/ | ||
} | ||
|
||
/** | ||
* Add a new element. | ||
* @param {*} name | ||
* @return {Error|*} | ||
*/ | ||
add(name, cb) {} | ||
|
||
search(onPackage, onEnd, validateName) { | ||
/** | ||
* Example of implementation: | ||
* try { | ||
* someApi.getPackages((items) => { | ||
* items.map(() => { | ||
* if (validateName(item.name)) { | ||
* onPackage(item); | ||
* } | ||
* }); | ||
* onEnd(); | ||
* } catch(err) { | ||
* onEnd(err); | ||
* } | ||
* }); | ||
*/ | ||
} | ||
|
||
/** | ||
* Remove an element from the database. | ||
* @param {*} name | ||
* @return {Error|*} | ||
*/ | ||
remove(name, callback) { | ||
/** | ||
* Example of implementation | ||
database.getPackage(name, (item, err) => { | ||
if (err) { | ||
callback(getInternalError('your own message here')); | ||
} | ||
|
||
// if all goes well we return nothing | ||
callback(null); | ||
} | ||
*/ | ||
} | ||
|
||
/** | ||
* Return all database elements. | ||
* @return {Array} | ||
*/ | ||
get(callback) { | ||
/* | ||
Example of implementation | ||
database.getAll((allItems, err) => { | ||
callback(err, allItems); | ||
}) | ||
*/ | ||
} | ||
|
||
/** | ||
* Create an instance of the `PackageStorage` | ||
* @param packageInfo | ||
*/ | ||
getPackageStorage(packageInfo) { | ||
return new PackageStorage(this.config, packageInfo, this.logger); | ||
} | ||
|
||
/** | ||
* All methods for npm token support | ||
* more info here https://github.com/verdaccio/verdaccio/pull/1427 | ||
*/ | ||
|
||
saveToken(token) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
deleteToken(user, tokenKey) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
readTokens(filter) { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} | ||
|
||
export default (config, options) => { | ||
return new VerdaccioStoragePlugin(config, options); | ||
}; |
19 changes: 0 additions & 19 deletions
19
generators/app/templates/javascript/storage/src/storageManager.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was quick 🚀