Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

@ui5/fs

Package Overview
Dependencies
Maintainers
4
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ui5/fs - npm Package Compare versions

Comparing version
2.0.1
to
2.0.2
+88
lib/ResourceTagCollection.js
const tagNamespaceRegExp = new RegExp("^[a-z][a-z0-9]*$"); // part before the colon
const tagNameRegExp = new RegExp("^[A-Z][A-Za-z0-9]+$"); // part after the colon
const Resource = require("./Resource");
class ResourceTagCollection {
constructor({allowedTags}) {
if (!allowedTags || !allowedTags.length) {
throw new Error(`Missing parameter 'allowedTags'`);
}
// No validation of tag names here since we might remove/ignore
// this parameter in the future and generally allow all tags
this._allowedTags = Object.freeze(allowedTags);
this._pathTags = {};
}
setTag(resource, tag, value = true) {
this._validateResource(resource);
this._validateTag(tag);
this._validateValue(value);
const resourcePath = resource.getPath();
if (!this._pathTags[resourcePath]) {
this._pathTags[resourcePath] = {};
}
this._pathTags[resourcePath][tag] = value;
}
clearTag(resource, tag) {
this._validateResource(resource);
this._validateTag(tag);
const resourcePath = resource.getPath();
if (this._pathTags[resourcePath]) {
this._pathTags[resourcePath][tag] = undefined;
}
}
getTag(resource, tag) {
this._validateResource(resource);
this._validateTag(tag);
const resourcePath = resource.getPath();
if (this._pathTags[resourcePath]) {
return this._pathTags[resourcePath][tag];
}
}
_validateResource(resource) {
if (!(resource instanceof Resource)) {
throw new Error(`Invalid Resource: Must be instance of @ui5/fs.Resource`);
}
}
_validateTag(tag) {
if (!this._allowedTags.includes(tag)) {
throw new Error(`Invalid Tag: Not found in list of allowed tags. Allowed tags: ` +
this._allowedTags.join(", "));
}
if (!tag.includes(":")) {
throw new Error(`Invalid Tag: Colon required after namespace`);
}
const parts = tag.split(":");
if (parts.length > 2) {
throw new Error(`Invalid Tag: Expected exactly one colon but found ${parts.length - 1}`);
}
const [tagNamespace, tagName] = parts;
if (!tagNamespaceRegExp.test(tagNamespace)) {
throw new Error(
`Invalid Tag: Namespace part must be alphanumeric, lowercase and start with a letter`);
}
if (!tagNameRegExp.test(tagName)) {
throw new Error(`Invalid Tag: Name part must be alphanumeric and start with a capital letter`);
}
}
_validateValue(value) {
const type = typeof value;
if (!["string", "number", "boolean"].includes(type)) {
throw new Error(
`Invalid Tag Value: Must be of type string, number or boolean but is ${type}`);
}
}
}
module.exports = ResourceTagCollection;
+16
-2

@@ -5,6 +5,19 @@ # Changelog

A list of unreleased changes can be found [here](https://github.com/SAP/ui5-fs/compare/v2.0.1...HEAD).
A list of unreleased changes can be found [here](https://github.com/SAP/ui5-fs/compare/v2.0.2...HEAD).
<a name="v2.0.2"></a>
## [v2.0.2] - 2020-07-20
### Bug Fixes
- TypeScript type definition support ([#252](https://github.com/SAP/ui5-fs/issues/252)) [`f379094`](https://github.com/SAP/ui5-fs/commit/f37909483b2740219da36c7e0931f7824d51e1a3)
- **Resource:** Keep stats size up to date ([#253](https://github.com/SAP/ui5-fs/issues/253)) [`0ef976f`](https://github.com/SAP/ui5-fs/commit/0ef976fe658765ae46afd1b4aa5b9100aa9829f8)
- **Resource:** getStream for empty string ([#249](https://github.com/SAP/ui5-fs/issues/249)) [`bc5eafb`](https://github.com/SAP/ui5-fs/commit/bc5eafb19bf71141b88dff749240354898849a66)
- **Resource#getSize:** Retrieve Resource's size ([#256](https://github.com/SAP/ui5-fs/issues/256)) [`9d2cc6c`](https://github.com/SAP/ui5-fs/commit/9d2cc6cf92b4a3f29e5c42db2f14afeeac9a0c98)
- **adapters/Memory:** Return cloned resources ([#235](https://github.com/SAP/ui5-fs/issues/235)) [`7bf3c6a`](https://github.com/SAP/ui5-fs/commit/7bf3c6a2ce55cd1c48b8aaaed83591bd85c228fa)
### Reverts
- [FIX] adapters/Memory: Return cloned resources ([#235](https://github.com/SAP/ui5-fs/issues/235))
<a name="v2.0.1"></a>
## [v2.0.1] - 2020-04-29
## [v2.0.1] - 2020-04-30
### Bug Fixes

@@ -95,2 +108,3 @@ - Namespaces in API Reference (JSDoc) [`b9d7b3c`](https://github.com/SAP/ui5-fs/commit/b9d7b3c70679436e6cbea07a789ac5e83bab337a)

[v2.0.2]: https://github.com/SAP/ui5-fs/compare/v2.0.1...v2.0.2
[v2.0.1]: https://github.com/SAP/ui5-fs/compare/v2.0.0...v2.0.1

@@ -97,0 +111,0 @@ [v2.0.0]: https://github.com/SAP/ui5-fs/compare/v1.1.2...v2.0.0

+49
-15

@@ -5,3 +5,3 @@ /**

*/
const modules = {
module.exports = {
/**

@@ -13,30 +13,64 @@ * @public

adapters: {
/**
* @type {typeof import('./lib/adapters/AbstractAdapter')}
*/
AbstractAdapter: "./lib/adapters/AbstractAdapter",
/**
* @type {typeof import('./lib/adapters/FileSystem')}
*/
FileSystem: "./lib/adapters/FileSystem",
/**
* @type {typeof import('./lib/adapters/Memory')}
*/
Memory: "./lib/adapters/Memory"
},
/**
* @type {typeof import('./lib/AbstractReader')}
*/
AbstractReader: "./lib/AbstractReader",
/**
* @type {typeof import('./lib/AbstractReaderWriter')}
*/
AbstractReaderWriter: "./lib/AbstractReaderWriter",
/**
* @type {typeof import('./lib/DuplexCollection')}
*/
DuplexCollection: "./lib/DuplexCollection",
/**
* @type {import('./lib/fsInterface')}
*/
fsInterface: "./lib/fsInterface",
/**
* @type {typeof import('./lib/ReaderCollection')}
*/
ReaderCollection: "./lib/ReaderCollection",
/**
* @type {typeof import('./lib/ReaderCollectionPrioritized')}
*/
ReaderCollectionPrioritized: "./lib/ReaderCollectionPrioritized",
/**
* @type {typeof import('./lib/Resource')}
*/
Resource: "./lib/Resource",
/**
* @type {typeof import('./lib/ResourceTagCollection')}
*/
ResourceTagCollection: "./lib/ResourceTagCollection",
/**
* @type {import('./lib/resourceFactory')}
*/
resourceFactory: "./lib/resourceFactory"
};
const hasOwnProperty = Object.prototype.hasOwnProperty;
function exportModules(exportRoot, modulePaths) {
for (const moduleName in modulePaths) {
if (hasOwnProperty.call(modulePaths, moduleName)) {
if (typeof modulePaths[moduleName] === "object") {
exportRoot[moduleName] = {};
exportModules(exportRoot[moduleName], modulePaths[moduleName]);
} else {
Object.defineProperty(exportRoot, moduleName, {
get() {
return require(modulePaths[moduleName]);
}
});
}
for (const moduleName of Object.keys(modulePaths)) {
if (typeof modulePaths[moduleName] === "object") {
exportRoot[moduleName] = {};
exportModules(exportRoot[moduleName], modulePaths[moduleName]);
} else {
Object.defineProperty(exportRoot, moduleName, {
get() {
return require(modulePaths[moduleName]);
}
});
}

@@ -46,2 +80,2 @@ }

exportModules(module.exports, modules);
exportModules(module.exports, JSON.parse(JSON.stringify(module.exports)));
{
"tags": {
"allowUnknownTags": false
},
"source": {
"include": ["README.md", "index.js"],
"includePattern": ".+\\.js$",
"excludePattern": "(node_modules(\\\\|/))"
},
"plugins": [],
"opts": {
"template": "node_modules/docdash/",
"encoding": "utf8",
"destination": "jsdocs/",
"recurse": true,
"verbose": true,
"access": "public"
},
"templates": {
"cleverLinks": false,
"monospaceLinks": false,
"default": {
"useLongnameInNav": true
}
},
"openGraph": {
"title": "UI5 Tooling - API Reference",
"type": "website",
"image": "https://sap.github.io/ui5-tooling/docs/images/UI5_logo_wide.png",
"site_name": "UI5 Tooling - API Reference",
"url": "https://sap.github.io/ui5-tooling/"
},
"docdash": {
"sectionOrder": [
"Modules",
"Namespaces",
"Classes",
"Externals",
"Events",
"Mixins",
"Tutorials",
"Interfaces"
],
"meta": {
"title": "UI5 Tooling - API Reference - UI5 FS",
"description": "UI5 Tooling - API Reference - UI5 FS",
"keyword": "openui5 sapui5 ui5 build development tool api reference"
},
"search": true,
"wrap": true,
"menu": {
"GitHub": {
"href": "https://github.com/SAP/ui5-fs",
"target": "_blank",
"class": "menu-item",
"id": "github_link"
}
}
}
"tags": {
"allowUnknownTags": false
},
"source": {
"include": ["README.md", "index.js"],
"includePattern": ".+\\.js$",
"excludePattern": "(node_modules(\\\\|/))"
},
"plugins": [
"./jsdoc-plugin"
],
"opts": {
"template": "node_modules/docdash/",
"encoding": "utf8",
"destination": "jsdocs/",
"recurse": true,
"verbose": true,
"access": "public"
},
"templates": {
"cleverLinks": false,
"monospaceLinks": false,
"default": {
"useLongnameInNav": true
}
},
"openGraph": {
"title": "UI5 Tooling - API Reference",
"type": "website",
"image": "https://sap.github.io/ui5-tooling/docs/images/UI5_logo_wide.png",
"site_name": "UI5 Tooling - API Reference",
"url": "https://sap.github.io/ui5-tooling/"
},
"docdash": {
"sectionOrder": [
"Modules",
"Namespaces",
"Classes",
"Externals",
"Events",
"Mixins",
"Tutorials",
"Interfaces"
],
"meta": {
"title": "UI5 Tooling - API Reference - UI5 FS",
"description": "UI5 Tooling - API Reference - UI5 FS",
"keyword": "openui5 sapui5 ui5 build development tool api reference"
},
"search": true,
"wrap": true,
"menu": {
"GitHub": {
"href": "https://github.com/SAP/ui5-fs",
"target": "_blank",
"class": "menu-item",
"id": "github_link"
}
}
}
}

@@ -73,7 +73,10 @@ const stream = require("stream");

this._createStream = createStream || null;
this._stream = stream || null;
this._buffer = buffer || null;
if (string) {
this._buffer = Buffer.from(string, "utf8");
if (createStream) {
this._createStream = createStream;
} else if (stream) {
this._stream = stream;
} else if (buffer) {
this.setBuffer(buffer);
} else if (typeof string === "string" || string instanceof String) {
this.setString(string);
}

@@ -234,2 +237,5 @@

* Gets the resources stat info.
* Note that a resources stat information is not updated when the resource is being modified.
* Also, depending on the used adapter, some fields might be missing which would be present for a
* [fs.Stats]{@link https://nodejs.org/api/fs.html#fs_class_fs_stats} instance.
*

@@ -244,2 +250,17 @@ * @public

/**
* Size in bytes allocated by the underlying buffer.
*
* @see {TypedArray#byteLength}
* @returns {Promise<number>} size in bytes, <code>0</code> if there is no content yet
*/
async getSize() {
// if resource does not have any content it should have 0 bytes
if (!this._buffer && !this._createStream && !this._stream) {
return 0;
}
const buffer = await this.getBuffer();
return buffer.byteLength;
}
_getNameFromPath(virPath) {

@@ -246,0 +267,0 @@ return path.posix.basename(virPath);

{
"name": "@ui5/fs",
"version": "2.0.1",
"version": "2.0.2",
"description": "UI5 Tooling - File System Abstraction",

@@ -101,4 +101,4 @@ "author": "SAP SE (https://www.sap.com)",

"clone": "^2.1.0",
"globby": "^11.0.0",
"graceful-fs": "^4.2.3",
"globby": "^11.0.1",
"graceful-fs": "^4.2.4",
"make-dir": "^3.1.0",

@@ -113,3 +113,3 @@ "micromatch": "^4.0.2",

"devDependencies": {
"ava": "^3.8.1",
"ava": "^3.10.1",
"chai": "^4.1.2",

@@ -123,5 +123,5 @@ "chai-fs": "^2.0.0",

"eslint-config-google": "^0.14.0",
"eslint-plugin-jsdoc": "^24.0.0",
"jsdoc": "^3.6.4",
"nyc": "^15.0.1",
"eslint-plugin-jsdoc": "^24.0.6",
"jsdoc": "^3.6.5",
"nyc": "^15.1.0",
"open-cli": "^6.0.1",

@@ -128,0 +128,0 @@ "rimraf": "^3.0.2",