@open-audio-stack/core 0.0.15 → 0.0.16

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.
package/build/Registry.js CHANGED
@@ -12,6 +12,8 @@ export class Registry {
12
12
  });
13
13
  }
14
14
  packageVersionAdd(slug, type, version, pkgVersion) {
15
+ if (!semver.valid(version))
16
+ throw Error(`${version} is not a valid Semantic version`);
15
17
  let pkg = this.package(slug, type);
16
18
  if (!pkg) {
17
19
  pkg = this.packageAdd(slug, type);
@@ -35,6 +37,8 @@ export class Registry {
35
37
  return registryFiltered;
36
38
  }
37
39
  packageLatest(slug, type, version) {
40
+ if (version && !semver.valid(version))
41
+ throw Error(`${version} is not a valid Semantic version`);
38
42
  const pkg = this.package(slug, type);
39
43
  const pkgVersion = this.packageVersionLatest(pkg.versions);
40
44
  return pkg.versions[version || pkgVersion];
@@ -64,6 +68,8 @@ export class Registry {
64
68
  delete this.registry[type][slug];
65
69
  }
66
70
  packageVersionRemove(slug, type, version) {
71
+ if (!semver.valid(version))
72
+ throw Error(`${version} is not a valid Semantic version`);
67
73
  const pkg = this.package(slug, type);
68
74
  if (pkg && pkg.versions[version]) {
69
75
  delete pkg.versions[version];
@@ -22,7 +22,7 @@ export declare function fileDelete(filePath: string): boolean | void;
22
22
  export declare function fileExec(filePath: string): void;
23
23
  export declare function fileExists(filePath: string): boolean;
24
24
  export declare function fileJsonCreate(filePath: string, data: object): void;
25
- export declare function fileHash(filePath: string, algorithm?: string): string;
25
+ export declare function fileHash(filePath: string, algorithm?: string): Promise<string>;
26
26
  export declare function fileMove(filePath: string, newPath: string): void | boolean;
27
27
  export declare function fileOpen(filePath: string): Buffer;
28
28
  export declare function fileRead(filePath: string): string;
@@ -30,6 +30,6 @@ export declare function fileReadJson(filePath: string): any;
30
30
  export declare function fileReadString(filePath: string): string;
31
31
  export declare function fileReadYaml(filePath: string): unknown;
32
32
  export declare function fileSize(filePath: string): number;
33
- export declare function fileValidateMetadata(filePath: string, fileMetadata: PluginFile | PresetFile | ProjectFile): PackageValidationError[];
33
+ export declare function fileValidateMetadata(filePath: string, fileMetadata: PluginFile | PresetFile | ProjectFile): Promise<PackageValidationError[]>;
34
34
  export declare function zipCreate(filesPath: string, zipPath: string): void;
35
35
  export declare function zipExtract(content: any, dirPath: string): void;
@@ -1,7 +1,9 @@
1
1
  import AdmZip from 'adm-zip';
2
2
  import { execSync } from 'child_process';
3
- import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, unlinkSync, writeFileSync, } from 'fs';
3
+ import { createReadStream, chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, unlinkSync, writeFileSync, } from 'fs';
4
4
  import { createHash } from 'crypto';
5
+ import stream from 'stream/promises';
6
+ import { Transform } from 'stream';
5
7
  import { globSync } from 'glob';
6
8
  import { moveSync } from 'fs-extra/esm';
7
9
  import os from 'os';
@@ -127,10 +129,17 @@ export function fileExists(filePath) {
127
129
  export function fileJsonCreate(filePath, data) {
128
130
  return fileCreate(filePath, JSON.stringify(data, null, 2));
129
131
  }
130
- export function fileHash(filePath, algorithm = 'sha256') {
131
- const fileData = fileReadString(filePath);
132
- const fileNormalized = fileData.replace(/\r\n/g, '\n');
133
- return createHash(algorithm).update(fileNormalized, 'utf8').digest('hex');
132
+ export async function fileHash(filePath, algorithm = 'sha256') {
133
+ const normalizeLineEndings = new Transform({
134
+ transform(chunk, encoding, callback) {
135
+ const normalized = chunk.toString('utf8').replace(/\r\n/g, '\n').replace(/\r/g, '\n');
136
+ callback(null, Buffer.from(normalized));
137
+ },
138
+ });
139
+ const input = createReadStream(filePath);
140
+ const hash = createHash(algorithm);
141
+ await stream.pipeline(input, normalizeLineEndings, hash);
142
+ return hash.digest('hex');
134
143
  }
135
144
  export function fileMove(filePath, newPath) {
136
145
  if (fileExists(filePath)) {
@@ -175,13 +184,14 @@ export function fileReadYaml(filePath) {
175
184
  export function fileSize(filePath) {
176
185
  return statSync(filePath).size;
177
186
  }
178
- export function fileValidateMetadata(filePath, fileMetadata) {
187
+ export async function fileValidateMetadata(filePath, fileMetadata) {
179
188
  const errors = [];
180
- if (fileMetadata.sha256 !== fileHash(filePath)) {
189
+ const hash = await fileHash(filePath);
190
+ if (fileMetadata.sha256 !== hash) {
181
191
  errors.push({
182
192
  field: 'sha256',
183
193
  error: PackageValidation.INVALID_VALUE,
184
- valueExpected: fileHash(filePath),
194
+ valueExpected: hash,
185
195
  valueReceived: fileMetadata.sha256,
186
196
  });
187
197
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-audio-stack/core",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "Open-source audio plugin management software",
5
5
  "type": "module",
6
6
  "main": "./build/index.js",