@open-audio-stack/core 0.0.22 → 0.0.24

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/Config.d.ts CHANGED
@@ -13,7 +13,8 @@ import { SystemType } from './types/SystemType.js';
13
13
  export declare class Config {
14
14
  config: ConfigInterface;
15
15
  constructor(config?: ConfigInterface);
16
- get(): ConfigInterface;
16
+ get(key?: keyof ConfigInterface): string | ConfigInterface | import("./types/Config.js").ConfigRegistry[] | undefined;
17
+ set(key: keyof ConfigInterface, val: any): string | ConfigInterface | import("./types/Config.js").ConfigRegistry[] | undefined;
17
18
  architecture(type: Architecture): import("./types/Architecture.js").ArchitectureOption;
18
19
  architectures(): import("./types/Architecture.js").ArchitectureOption[];
19
20
  fileFormat(format: FileFormat): import("./types/FileFormat.js").FileFormatOption;
package/build/Config.js CHANGED
@@ -12,11 +12,24 @@ import { systemTypes } from './types/SystemType.js';
12
12
  export class Config {
13
13
  config;
14
14
  constructor(config) {
15
- this.config = Object.assign({}, config);
16
- }
17
- get() {
15
+ this.config = Object.assign({
16
+ registries: [
17
+ {
18
+ name: 'Open Audio Registry',
19
+ url: 'https://open-audio-stack.github.io/open-audio-stack-registry',
20
+ },
21
+ ],
22
+ }, config);
23
+ }
24
+ get(key) {
25
+ if (key)
26
+ return this.config[key];
18
27
  return this.config;
19
28
  }
29
+ set(key, val) {
30
+ this.config[key] = val;
31
+ return this.get(key);
32
+ }
20
33
  // Architectures.
21
34
  architecture(type) {
22
35
  return architectures.filter(architecture => type === architecture.value)[0];
@@ -0,0 +1,26 @@
1
+ import { Config } from './Config.js';
2
+ import { Registry } from './Registry.js';
3
+ import { PackageVersion } from './index-browser.js';
4
+ import { RegistryInterface, RegistryType } from './types/Registry.js';
5
+ export declare class Manager {
6
+ registry: Registry;
7
+ config: Config;
8
+ constructor();
9
+ addPackages(json: RegistryInterface, type: RegistryType): void;
10
+ scan(type?: RegistryType): Promise<void>;
11
+ search(field: keyof PackageVersion, value: string | number | object, type?: RegistryType): import("./index-browser.js").RegistryPackages | {
12
+ plugins: import("./index-browser.js").RegistryPackages;
13
+ presets: import("./index-browser.js").RegistryPackages;
14
+ projects: import("./index-browser.js").RegistryPackages;
15
+ };
16
+ getByOrg(org: string, type?: RegistryType): import("./index-browser.js").RegistryPackages | {
17
+ plugins: import("./index-browser.js").RegistryPackages;
18
+ presets: import("./index-browser.js").RegistryPackages;
19
+ projects: import("./index-browser.js").RegistryPackages;
20
+ };
21
+ getBySlug(slug: string, type?: RegistryType, version?: string): import("./index-browser.js").PluginInterface | import("./index-browser.js").PresetInterface | import("./index-browser.js").ProjectInterface | {
22
+ plugins: import("./index-browser.js").PackageVersionType;
23
+ presets: import("./index-browser.js").PackageVersionType;
24
+ projects: import("./index-browser.js").PackageVersionType;
25
+ };
26
+ }
@@ -0,0 +1,64 @@
1
+ import { Config } from './Config.js';
2
+ import { Registry } from './Registry.js';
3
+ import { apiJson } from './helpers/api.js';
4
+ import { RegistryType } from './types/Registry.js';
5
+ export class Manager {
6
+ registry;
7
+ config;
8
+ constructor() {
9
+ this.config = new Config();
10
+ this.registry = new Registry();
11
+ this.scan();
12
+ }
13
+ addPackages(json, type) {
14
+ for (const slug in json[type]) {
15
+ this.registry.packageAdd(type, slug, json.plugins[slug]);
16
+ }
17
+ console.log(`${type}: ${this.registry.packages(type).length}`);
18
+ }
19
+ async scan(type) {
20
+ this.registry.reset();
21
+ const registries = this.config.get('registries');
22
+ for (const index in registries) {
23
+ const json = await apiJson(registries[index].url);
24
+ if (type) {
25
+ this.addPackages(json, type);
26
+ }
27
+ else {
28
+ this.addPackages(json, RegistryType.Plugins);
29
+ this.addPackages(json, RegistryType.Presets);
30
+ this.addPackages(json, RegistryType.Projects);
31
+ }
32
+ }
33
+ }
34
+ search(field, value, type) {
35
+ if (type) {
36
+ return this.registry.packagesSearch(type, field, value);
37
+ }
38
+ return {
39
+ plugins: this.registry.packagesSearch(RegistryType.Plugins, field, value),
40
+ presets: this.registry.packagesSearch(RegistryType.Presets, field, value),
41
+ projects: this.registry.packagesSearch(RegistryType.Projects, field, value),
42
+ };
43
+ }
44
+ getByOrg(org, type) {
45
+ if (type) {
46
+ return this.registry.packagesOrg(type, org);
47
+ }
48
+ return {
49
+ plugins: this.registry.packagesOrg(RegistryType.Plugins, org),
50
+ presets: this.registry.packagesOrg(RegistryType.Presets, org),
51
+ projects: this.registry.packagesOrg(RegistryType.Projects, org),
52
+ };
53
+ }
54
+ getBySlug(slug, type, version) {
55
+ if (type) {
56
+ return this.registry.packageLatest(type, slug, version);
57
+ }
58
+ return {
59
+ plugins: this.registry.packageLatest(RegistryType.Plugins, slug, version),
60
+ presets: this.registry.packageLatest(RegistryType.Presets, slug, version),
61
+ projects: this.registry.packageLatest(RegistryType.Projects, slug, version),
62
+ };
63
+ }
64
+ }
@@ -2,22 +2,20 @@ import { PackageInterface, PackageVersion, PackageVersions, PackageVersionType }
2
2
  import { RegistryInterface, RegistryPackages, RegistryType } from './types/Registry.js';
3
3
  export declare class Registry {
4
4
  registry: RegistryInterface;
5
- constructor(registry?: RegistryInterface);
6
- packageAdd(slug: string, type: RegistryType): {
7
- slug: string;
8
- version: string;
9
- versions: {};
10
- };
11
- packageVersionAdd(slug: string, type: RegistryType, version: string, pkgVersion: PackageVersionType): void;
12
- package(slug: string, type: RegistryType): PackageInterface;
5
+ constructor();
6
+ packageAdd(type: RegistryType, slug: string, pkg?: PackageInterface): PackageInterface;
7
+ packageVersionAdd(type: RegistryType, slug: string, version: string, pkgVersion: PackageVersionType): void;
8
+ package(type: RegistryType, slug: string): PackageInterface;
13
9
  packages(type: RegistryType): RegistryPackages;
14
- packagesFilter(type: RegistryType, field: keyof PackageVersion, value: string | number | object): RegistryPackages;
15
- packageLatest(slug: string, type: RegistryType, version?: string): PackageVersionType;
10
+ packagesSearch(type: RegistryType, field: keyof PackageVersion, value: string | number | object): RegistryPackages;
11
+ packagesOrg(type: RegistryType, match: string): RegistryPackages;
12
+ packageLatest(type: RegistryType, slug: string, version?: string): PackageVersionType;
16
13
  packageVersionLatest(versions: PackageVersions): string;
17
14
  get(): RegistryInterface;
18
15
  name(): string;
16
+ reset(): void;
19
17
  url(): string;
20
18
  version(): string;
21
- packageRemove(slug: string, type: RegistryType): void;
22
- packageVersionRemove(slug: string, type: RegistryType, version: string): void;
19
+ packageRemove(type: RegistryType, slug: string): void;
20
+ packageVersionRemove(type: RegistryType, slug: string, version: string): void;
23
21
  }
package/build/Registry.js CHANGED
@@ -1,45 +1,60 @@
1
1
  import * as semver from 'semver';
2
2
  export class Registry {
3
3
  registry;
4
- constructor(registry) {
5
- this.registry = Object.assign({}, registry);
4
+ constructor() {
5
+ this.registry = {
6
+ name: 'Open Audio Registry',
7
+ plugins: {},
8
+ presets: {},
9
+ projects: {},
10
+ url: 'https://open-audio-stack.github.io/open-audio-stack-registry',
11
+ version: '1.0.0',
12
+ };
6
13
  }
7
- packageAdd(slug, type) {
8
- return (this.registry[type][slug] = {
14
+ packageAdd(type, slug, pkg) {
15
+ return (this.registry[type][slug] = pkg || {
9
16
  slug,
10
17
  version: '',
11
18
  versions: {},
12
19
  });
13
20
  }
14
- packageVersionAdd(slug, type, version, pkgVersion) {
21
+ packageVersionAdd(type, slug, version, pkgVersion) {
15
22
  if (!semver.valid(version))
16
23
  throw Error(`${version} is not a valid Semantic version`);
17
- let pkg = this.package(slug, type);
24
+ let pkg = this.package(type, slug);
18
25
  if (!pkg) {
19
- pkg = this.packageAdd(slug, type);
26
+ pkg = this.packageAdd(type, slug);
20
27
  }
21
28
  pkg.versions[version] = pkgVersion;
22
29
  pkg.version = this.packageVersionLatest(pkg.versions);
23
30
  }
24
- package(slug, type) {
31
+ package(type, slug) {
25
32
  return this.registry[type][slug];
26
33
  }
27
34
  packages(type) {
28
35
  return this.registry[type];
29
36
  }
30
- packagesFilter(type, field, value) {
31
- const registryFiltered = {};
37
+ packagesSearch(type, field, value) {
38
+ const results = {};
32
39
  Object.keys(this.registry[type]).forEach((slug) => {
33
- if (this.packageLatest(slug, type)[field] === value) {
34
- registryFiltered[slug] = this.registry[type][slug];
40
+ if (this.packageLatest(type, slug)[field] === value) {
41
+ results[slug] = this.registry[type][slug];
35
42
  }
36
43
  });
37
- return registryFiltered;
44
+ return results;
38
45
  }
39
- packageLatest(slug, type, version) {
46
+ packagesOrg(type, match) {
47
+ const results = {};
48
+ for (const slug in this.registry[type]) {
49
+ if (slug.startsWith(match))
50
+ results[slug] = this.registry[type][slug];
51
+ }
52
+ return results;
53
+ }
54
+ packageLatest(type, slug, version) {
40
55
  if (version && !semver.valid(version))
41
56
  throw Error(`${version} is not a valid Semantic version`);
42
- const pkg = this.package(slug, type);
57
+ const pkg = this.package(type, slug);
43
58
  const pkgVersion = this.packageVersionLatest(pkg.versions);
44
59
  return pkg.versions[version || pkgVersion];
45
60
  }
@@ -58,25 +73,30 @@ export class Registry {
58
73
  name() {
59
74
  return this.registry.name;
60
75
  }
76
+ reset() {
77
+ this.registry.plugins = {};
78
+ this.registry.presets = {};
79
+ this.registry.projects = {};
80
+ }
61
81
  url() {
62
82
  return this.registry.url;
63
83
  }
64
84
  version() {
65
85
  return this.registry.version;
66
86
  }
67
- packageRemove(slug, type) {
87
+ packageRemove(type, slug) {
68
88
  delete this.registry[type][slug];
69
89
  }
70
- packageVersionRemove(slug, type, version) {
90
+ packageVersionRemove(type, slug, version) {
71
91
  if (!semver.valid(version))
72
92
  throw Error(`${version} is not a valid Semantic version`);
73
- const pkg = this.package(slug, type);
93
+ const pkg = this.package(type, slug);
74
94
  if (pkg && pkg.versions[version]) {
75
95
  delete pkg.versions[version];
76
96
  pkg.version = this.packageVersionLatest(pkg.versions);
77
97
  }
78
98
  if (!Object.keys(pkg.versions).length) {
79
- this.packageRemove(slug, type);
99
+ this.packageRemove(type, slug);
80
100
  }
81
101
  }
82
102
  }
@@ -184,19 +184,19 @@ export async function fileValidateMetadata(filePath, fileMetadata) {
184
184
  if (fileMetadata.sha256 !== hash) {
185
185
  errors.push({
186
186
  code: ZodIssueCode.invalid_type,
187
- expected: hash,
187
+ expected: fileMetadata.sha256,
188
188
  message: 'Required',
189
189
  path: ['sha256'],
190
- received: fileMetadata.sha256,
190
+ received: hash,
191
191
  });
192
192
  }
193
193
  if (fileMetadata.size !== fileSize(filePath)) {
194
194
  errors.push({
195
195
  code: ZodIssueCode.invalid_type,
196
- expected: String(fileSize(filePath)),
196
+ expected: String(fileMetadata.size),
197
197
  message: 'Required',
198
198
  path: ['size'],
199
- received: String(fileMetadata.size),
199
+ received: String(fileSize(filePath)),
200
200
  });
201
201
  }
202
202
  return errors;
@@ -58,9 +58,9 @@ export function packageRecommendations(pkgVersion) {
58
58
  rec: 'should use the flac format',
59
59
  });
60
60
  }
61
- // Architectures/systems
62
61
  const supportedArchitectures = {};
63
62
  const supportedSystems = {};
63
+ const supportedFileFormats = {};
64
64
  pkgVersion.files.forEach(file => {
65
65
  file.architectures.forEach(architecture => {
66
66
  supportedArchitectures[architecture] = true;
@@ -68,18 +68,32 @@ export function packageRecommendations(pkgVersion) {
68
68
  file.systems.forEach(system => {
69
69
  supportedSystems[system.type] = true;
70
70
  });
71
+ supportedFileFormats[file.format] = true;
71
72
  packageRecommendationsUrl(file, recs, 'url');
72
73
  });
74
+ // Architectures
73
75
  if (!supportedArchitectures.arm64)
74
76
  recs.push({ field: 'architectures', rec: 'should support arm64' });
75
77
  if (!supportedArchitectures.x64)
76
78
  recs.push({ field: 'architectures', rec: 'should support x64' });
79
+ // Systems
77
80
  if (!supportedSystems.linux)
78
81
  recs.push({ field: 'systems', rec: 'should support Linux' });
79
82
  if (!supportedSystems.mac)
80
83
  recs.push({ field: 'systems', rec: 'should support Mac' });
81
84
  if (!supportedSystems.win)
82
85
  recs.push({ field: 'systems', rec: 'should support Windows' });
86
+ // Formats
87
+ if (supportedFileFormats.deb)
88
+ recs.push({
89
+ field: 'format',
90
+ rec: 'should support all Linux distributions, consider using AppImage or Tarball instead',
91
+ });
92
+ if (supportedFileFormats.rpm)
93
+ recs.push({
94
+ field: 'format',
95
+ rec: 'should support all Linux distributions, consider using AppImage or Tarball instead',
96
+ });
83
97
  // Tags
84
98
  const pluginTags = pkgVersion.tags.map(tag => tag.toLowerCase());
85
99
  if (pluginTags.length < 2)
@@ -1,4 +1,5 @@
1
1
  export * from './Config.js';
2
+ export * from './Manager.js';
2
3
  export * from './Registry.js';
3
4
  export * from './helpers/api.js';
4
5
  export * from './helpers/package.js';
@@ -4,6 +4,7 @@
4
4
  // Comment out any files which are not browser compatible.
5
5
  // Classes
6
6
  export * from './Config.js';
7
+ export * from './Manager.js';
7
8
  export * from './Registry.js';
8
9
  // Helpers
9
10
  export * from './helpers/api.js';
package/build/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './Config.js';
2
+ export * from './Manager.js';
2
3
  export * from './Registry.js';
3
4
  export * from './helpers/api.js';
4
5
  export * from './helpers/file.js';
package/build/index.js CHANGED
@@ -4,6 +4,7 @@
4
4
  // Comment out any files which are not NodeJS compatible.
5
5
  // Classes
6
6
  export * from './Config.js';
7
+ export * from './Manager.js';
7
8
  export * from './Registry.js';
8
9
  // Helpers
9
10
  export * from './helpers/api.js';
@@ -1,2 +1,10 @@
1
1
  export interface ConfigInterface {
2
+ pluginDir?: string;
3
+ presetDir?: string;
4
+ projectDir?: string;
5
+ registries?: ConfigRegistry[];
6
+ }
7
+ export interface ConfigRegistry {
8
+ name: string;
9
+ url: string;
2
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-audio-stack/core",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "Open-source audio plugin management software",
5
5
  "type": "module",
6
6
  "main": "./build/index.js",