@open-audio-stack/core 0.0.13 → 0.0.15
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.d.ts +10 -15
- package/build/Registry.js +21 -122
- package/build/helpers/file.js +3 -3
- package/build/helpers/package.d.ts +3 -0
- package/build/helpers/package.js +102 -0
- package/build/index-browser.d.ts +1 -0
- package/build/index-browser.js +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/types/File.d.ts +1 -1
- package/build/types/Registry.d.ts +8 -1
- package/build/types/Registry.js +6 -1
- package/package.json +1 -1
package/build/Registry.d.ts
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
import { PackageInterface,
|
|
2
|
-
import { RegistryInterface, RegistryPackages } from './types/Registry.js';
|
|
3
|
-
import { PluginType } from './types/PluginType.js';
|
|
4
|
-
import { PresetType } from './types/PresetType.js';
|
|
5
|
-
import { ProjectType } from './types/ProjectType.js';
|
|
1
|
+
import { PackageInterface, PackageVersion, PackageVersions, PackageVersionType } from './types/Package.js';
|
|
2
|
+
import { RegistryInterface, RegistryPackages, RegistryType } from './types/Registry.js';
|
|
6
3
|
export declare class Registry {
|
|
7
4
|
registry: RegistryInterface;
|
|
8
5
|
constructor(registry?: RegistryInterface);
|
|
9
|
-
packageAdd(slug: string): {
|
|
6
|
+
packageAdd(slug: string, type: RegistryType): {
|
|
10
7
|
slug: string;
|
|
11
8
|
version: string;
|
|
12
9
|
versions: {};
|
|
13
10
|
};
|
|
14
|
-
packageVersionAdd(slug: string, version: string, pkgVersion: PackageVersionType): void;
|
|
15
|
-
package(slug: string): PackageInterface;
|
|
16
|
-
packages(): RegistryPackages;
|
|
17
|
-
packagesFilter(type:
|
|
18
|
-
packageLatest(slug: string, version?: string): PackageVersionType;
|
|
11
|
+
packageVersionAdd(slug: string, type: RegistryType, version: string, pkgVersion: PackageVersionType): void;
|
|
12
|
+
package(slug: string, type: RegistryType): PackageInterface;
|
|
13
|
+
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;
|
|
19
16
|
packageVersionLatest(versions: PackageVersions): string;
|
|
20
17
|
get(): RegistryInterface;
|
|
21
18
|
name(): string;
|
|
22
19
|
url(): string;
|
|
23
20
|
version(): string;
|
|
24
|
-
packageRemove(slug: string): void;
|
|
25
|
-
packageVersionRemove(slug: string, version: string): void;
|
|
26
|
-
packageVersionValidate(pkgVersion: PackageVersionType): PackageValidationError[];
|
|
27
|
-
packageVersionRecommendations(pkgVersion: PackageVersionType): PackageValidationRec[];
|
|
21
|
+
packageRemove(slug: string, type: RegistryType): void;
|
|
22
|
+
packageVersionRemove(slug: string, type: RegistryType, version: string): void;
|
|
28
23
|
}
|
package/build/Registry.js
CHANGED
|
@@ -1,42 +1,41 @@
|
|
|
1
1
|
import * as semver from 'semver';
|
|
2
|
-
import { PackageValidation, } from './types/Package.js';
|
|
3
|
-
import { License } from './types/License.js';
|
|
4
2
|
export class Registry {
|
|
5
3
|
registry;
|
|
6
4
|
constructor(registry) {
|
|
7
5
|
this.registry = Object.assign({}, registry);
|
|
8
6
|
}
|
|
9
|
-
packageAdd(slug) {
|
|
10
|
-
return (this.registry
|
|
7
|
+
packageAdd(slug, type) {
|
|
8
|
+
return (this.registry[type][slug] = {
|
|
11
9
|
slug,
|
|
12
10
|
version: '',
|
|
13
11
|
versions: {},
|
|
14
12
|
});
|
|
15
13
|
}
|
|
16
|
-
packageVersionAdd(slug, version, pkgVersion) {
|
|
17
|
-
let pkg = this.package(slug);
|
|
14
|
+
packageVersionAdd(slug, type, version, pkgVersion) {
|
|
15
|
+
let pkg = this.package(slug, type);
|
|
18
16
|
if (!pkg) {
|
|
19
|
-
pkg = this.packageAdd(slug);
|
|
17
|
+
pkg = this.packageAdd(slug, type);
|
|
20
18
|
}
|
|
21
19
|
pkg.versions[version] = pkgVersion;
|
|
22
20
|
pkg.version = this.packageVersionLatest(pkg.versions);
|
|
23
21
|
}
|
|
24
|
-
package(slug) {
|
|
25
|
-
return this.registry
|
|
22
|
+
package(slug, type) {
|
|
23
|
+
return this.registry[type][slug];
|
|
26
24
|
}
|
|
27
|
-
packages() {
|
|
28
|
-
return this.registry
|
|
25
|
+
packages(type) {
|
|
26
|
+
return this.registry[type];
|
|
29
27
|
}
|
|
30
|
-
packagesFilter(type) {
|
|
28
|
+
packagesFilter(type, field, value) {
|
|
31
29
|
const registryFiltered = {};
|
|
32
|
-
Object.keys(this.registry
|
|
33
|
-
if (
|
|
34
|
-
registryFiltered[slug] = this.registry
|
|
30
|
+
Object.keys(this.registry[type]).forEach((slug) => {
|
|
31
|
+
if (this.packageLatest(slug, type)[field] === value) {
|
|
32
|
+
registryFiltered[slug] = this.registry[type][slug];
|
|
33
|
+
}
|
|
35
34
|
});
|
|
36
35
|
return registryFiltered;
|
|
37
36
|
}
|
|
38
|
-
packageLatest(slug, version) {
|
|
39
|
-
const pkg = this.package(slug);
|
|
37
|
+
packageLatest(slug, type, version) {
|
|
38
|
+
const pkg = this.package(slug, type);
|
|
40
39
|
const pkgVersion = this.packageVersionLatest(pkg.versions);
|
|
41
40
|
return pkg.versions[version || pkgVersion];
|
|
42
41
|
}
|
|
@@ -61,117 +60,17 @@ export class Registry {
|
|
|
61
60
|
version() {
|
|
62
61
|
return this.registry.version;
|
|
63
62
|
}
|
|
64
|
-
packageRemove(slug) {
|
|
65
|
-
delete this.registry
|
|
63
|
+
packageRemove(slug, type) {
|
|
64
|
+
delete this.registry[type][slug];
|
|
66
65
|
}
|
|
67
|
-
packageVersionRemove(slug, version) {
|
|
68
|
-
const pkg = this.package(slug);
|
|
66
|
+
packageVersionRemove(slug, type, version) {
|
|
67
|
+
const pkg = this.package(slug, type);
|
|
69
68
|
if (pkg && pkg.versions[version]) {
|
|
70
69
|
delete pkg.versions[version];
|
|
71
70
|
pkg.version = this.packageVersionLatest(pkg.versions);
|
|
72
71
|
}
|
|
73
72
|
if (!Object.keys(pkg.versions).length) {
|
|
74
|
-
this.packageRemove(slug);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
packageVersionValidate(pkgVersion) {
|
|
78
|
-
const fields = [
|
|
79
|
-
{ name: 'audio', type: 'string' },
|
|
80
|
-
{ name: 'author', type: 'string' },
|
|
81
|
-
{ name: 'changes', type: 'string' },
|
|
82
|
-
{ name: 'date', type: 'string' },
|
|
83
|
-
{ name: 'description', type: 'string' },
|
|
84
|
-
{ name: 'files', type: 'object' },
|
|
85
|
-
{ name: 'image', type: 'string' },
|
|
86
|
-
{ name: 'license', type: 'string' },
|
|
87
|
-
{ name: 'name', type: 'string' },
|
|
88
|
-
{ name: 'tags', type: 'object' },
|
|
89
|
-
{ name: 'type', type: 'string' },
|
|
90
|
-
{ name: 'url', type: 'string' },
|
|
91
|
-
];
|
|
92
|
-
const errors = [];
|
|
93
|
-
fields.forEach((field) => {
|
|
94
|
-
const versionField = pkgVersion[field.name];
|
|
95
|
-
if (versionField === undefined) {
|
|
96
|
-
errors.push({
|
|
97
|
-
field: field.name,
|
|
98
|
-
error: PackageValidation.MISSING_FIELD,
|
|
99
|
-
valueExpected: field.type,
|
|
100
|
-
valueReceived: 'undefined',
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
else if (typeof versionField !== field.type) {
|
|
104
|
-
errors.push({
|
|
105
|
-
field: field.name,
|
|
106
|
-
error: PackageValidation.INVALID_TYPE,
|
|
107
|
-
valueExpected: field.type,
|
|
108
|
-
valueReceived: typeof versionField,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
return errors;
|
|
113
|
-
}
|
|
114
|
-
// TODO refactor all this using a proper validation library.
|
|
115
|
-
packageVersionRecommendations(pkgVersion) {
|
|
116
|
-
const recs = [];
|
|
117
|
-
// Urls
|
|
118
|
-
if (!pkgVersion.url.startsWith('https://')) {
|
|
119
|
-
recs.push({
|
|
120
|
-
field: 'url',
|
|
121
|
-
rec: 'should use https url',
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
if (!pkgVersion.url.includes('github.com') && !pkgVersion.url.includes('github.io')) {
|
|
125
|
-
recs.push({
|
|
126
|
-
field: 'url',
|
|
127
|
-
rec: 'should point to GitHub',
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
// Image/audio previews
|
|
131
|
-
if (pkgVersion.image && pkgVersion.image.includes('png')) {
|
|
132
|
-
recs.push({
|
|
133
|
-
field: 'image',
|
|
134
|
-
rec: 'should use the jpg format',
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
if (pkgVersion.audio && pkgVersion.audio.includes('wav')) {
|
|
138
|
-
recs.push({
|
|
139
|
-
field: 'audio',
|
|
140
|
-
rec: 'should use the flac format',
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
// Architectures/systems
|
|
144
|
-
const supportedArchitectures = {};
|
|
145
|
-
const supportedSystems = {};
|
|
146
|
-
pkgVersion.files.forEach(file => {
|
|
147
|
-
file.architectures.forEach(architecture => {
|
|
148
|
-
supportedArchitectures[architecture] = true;
|
|
149
|
-
});
|
|
150
|
-
file.systems.forEach(system => {
|
|
151
|
-
supportedSystems[system.type] = true;
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
if (!supportedArchitectures.arm64)
|
|
155
|
-
recs.push({ field: 'architectures', rec: 'should support Arm64' });
|
|
156
|
-
if (!supportedArchitectures.bit64)
|
|
157
|
-
recs.push({ field: 'architectures', rec: 'should support Bit64' });
|
|
158
|
-
if (!supportedSystems.linux)
|
|
159
|
-
recs.push({ field: 'systems', rec: 'should support Linux' });
|
|
160
|
-
if (!supportedSystems.mac)
|
|
161
|
-
recs.push({ field: 'systems', rec: 'should support Mac' });
|
|
162
|
-
if (!supportedSystems.win)
|
|
163
|
-
recs.push({ field: 'systems', rec: 'should support Windows' });
|
|
164
|
-
// Tags
|
|
165
|
-
const pluginTags = pkgVersion.tags.map(tag => tag.toLowerCase());
|
|
166
|
-
if (pluginTags.length < 2)
|
|
167
|
-
recs.push({ field: 'tags', rec: 'should have more items' });
|
|
168
|
-
// Licence
|
|
169
|
-
if (!Object.values(License).includes(pkgVersion.license)) {
|
|
170
|
-
recs.push({ field: 'license', rec: 'should be from the supported list' });
|
|
171
|
-
}
|
|
172
|
-
else if (pkgVersion.license === License.Other) {
|
|
173
|
-
recs.push({ field: 'license', rec: 'should be more specific' });
|
|
73
|
+
this.packageRemove(slug, type);
|
|
174
74
|
}
|
|
175
|
-
return recs;
|
|
176
75
|
}
|
|
177
76
|
}
|
package/build/helpers/file.js
CHANGED
|
@@ -177,12 +177,12 @@ export function fileSize(filePath) {
|
|
|
177
177
|
}
|
|
178
178
|
export function fileValidateMetadata(filePath, fileMetadata) {
|
|
179
179
|
const errors = [];
|
|
180
|
-
if (fileMetadata.
|
|
180
|
+
if (fileMetadata.sha256 !== fileHash(filePath)) {
|
|
181
181
|
errors.push({
|
|
182
|
-
field: '
|
|
182
|
+
field: 'sha256',
|
|
183
183
|
error: PackageValidation.INVALID_VALUE,
|
|
184
184
|
valueExpected: fileHash(filePath),
|
|
185
|
-
valueReceived: fileMetadata.
|
|
185
|
+
valueReceived: fileMetadata.sha256,
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
188
|
if (fileMetadata.size !== fileSize(filePath)) {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { PackageValidationError, PackageValidationRec, PackageVersionType } from '../types/Package.js';
|
|
2
|
+
export declare function packageRecommendations(pkgVersion: PackageVersionType): PackageValidationRec[];
|
|
3
|
+
export declare function packageValidate(pkgVersion: PackageVersionType): PackageValidationError[];
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { License } from '../types/License.js';
|
|
2
|
+
import { PackageValidation, } from '../types/Package.js';
|
|
3
|
+
// TODO refactor all this using a proper validation library.
|
|
4
|
+
export function packageRecommendations(pkgVersion) {
|
|
5
|
+
const recs = [];
|
|
6
|
+
// Urls
|
|
7
|
+
if (!pkgVersion.url.startsWith('https://')) {
|
|
8
|
+
recs.push({
|
|
9
|
+
field: 'url',
|
|
10
|
+
rec: 'should use https url',
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
if (!pkgVersion.url.includes('github.com') && !pkgVersion.url.includes('github.io')) {
|
|
14
|
+
recs.push({
|
|
15
|
+
field: 'url',
|
|
16
|
+
rec: 'should point to GitHub',
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
// Image/audio previews
|
|
20
|
+
if (pkgVersion.image && pkgVersion.image.includes('png')) {
|
|
21
|
+
recs.push({
|
|
22
|
+
field: 'image',
|
|
23
|
+
rec: 'should use the jpg format',
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (pkgVersion.audio && pkgVersion.audio.includes('wav')) {
|
|
27
|
+
recs.push({
|
|
28
|
+
field: 'audio',
|
|
29
|
+
rec: 'should use the flac format',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// Architectures/systems
|
|
33
|
+
const supportedArchitectures = {};
|
|
34
|
+
const supportedSystems = {};
|
|
35
|
+
pkgVersion.files.forEach(file => {
|
|
36
|
+
file.architectures.forEach(architecture => {
|
|
37
|
+
supportedArchitectures[architecture] = true;
|
|
38
|
+
});
|
|
39
|
+
file.systems.forEach(system => {
|
|
40
|
+
supportedSystems[system.type] = true;
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
if (!supportedArchitectures.arm64)
|
|
44
|
+
recs.push({ field: 'architectures', rec: 'should support Arm64' });
|
|
45
|
+
if (!supportedArchitectures.bit64)
|
|
46
|
+
recs.push({ field: 'architectures', rec: 'should support Bit64' });
|
|
47
|
+
if (!supportedSystems.linux)
|
|
48
|
+
recs.push({ field: 'systems', rec: 'should support Linux' });
|
|
49
|
+
if (!supportedSystems.mac)
|
|
50
|
+
recs.push({ field: 'systems', rec: 'should support Mac' });
|
|
51
|
+
if (!supportedSystems.win)
|
|
52
|
+
recs.push({ field: 'systems', rec: 'should support Windows' });
|
|
53
|
+
// Tags
|
|
54
|
+
const pluginTags = pkgVersion.tags.map(tag => tag.toLowerCase());
|
|
55
|
+
if (pluginTags.length < 2)
|
|
56
|
+
recs.push({ field: 'tags', rec: 'should have more items' });
|
|
57
|
+
// Licence
|
|
58
|
+
if (!Object.values(License).includes(pkgVersion.license)) {
|
|
59
|
+
recs.push({ field: 'license', rec: 'should be from the supported list' });
|
|
60
|
+
}
|
|
61
|
+
else if (pkgVersion.license === License.Other) {
|
|
62
|
+
recs.push({ field: 'license', rec: 'should be more specific' });
|
|
63
|
+
}
|
|
64
|
+
return recs;
|
|
65
|
+
}
|
|
66
|
+
export function packageValidate(pkgVersion) {
|
|
67
|
+
const fields = [
|
|
68
|
+
{ name: 'audio', type: 'string' },
|
|
69
|
+
{ name: 'author', type: 'string' },
|
|
70
|
+
{ name: 'changes', type: 'string' },
|
|
71
|
+
{ name: 'date', type: 'string' },
|
|
72
|
+
{ name: 'description', type: 'string' },
|
|
73
|
+
{ name: 'files', type: 'object' },
|
|
74
|
+
{ name: 'image', type: 'string' },
|
|
75
|
+
{ name: 'license', type: 'string' },
|
|
76
|
+
{ name: 'name', type: 'string' },
|
|
77
|
+
{ name: 'tags', type: 'object' },
|
|
78
|
+
{ name: 'type', type: 'string' },
|
|
79
|
+
{ name: 'url', type: 'string' },
|
|
80
|
+
];
|
|
81
|
+
const errors = [];
|
|
82
|
+
fields.forEach((field) => {
|
|
83
|
+
const versionField = pkgVersion[field.name];
|
|
84
|
+
if (versionField === undefined) {
|
|
85
|
+
errors.push({
|
|
86
|
+
field: field.name,
|
|
87
|
+
error: PackageValidation.MISSING_FIELD,
|
|
88
|
+
valueExpected: field.type,
|
|
89
|
+
valueReceived: 'undefined',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
else if (typeof versionField !== field.type) {
|
|
93
|
+
errors.push({
|
|
94
|
+
field: field.name,
|
|
95
|
+
error: PackageValidation.INVALID_TYPE,
|
|
96
|
+
valueExpected: field.type,
|
|
97
|
+
valueReceived: typeof versionField,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return errors;
|
|
102
|
+
}
|
package/build/index-browser.d.ts
CHANGED
package/build/index-browser.js
CHANGED
package/build/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './Config.js';
|
|
|
2
2
|
export * from './Registry.js';
|
|
3
3
|
export * from './helpers/api.js';
|
|
4
4
|
export * from './helpers/file.js';
|
|
5
|
+
export * from './helpers/package.js';
|
|
5
6
|
export * from './helpers/utils.js';
|
|
6
7
|
export * from './types/Architecture.js';
|
|
7
8
|
export * from './types/Config.js';
|
package/build/index.js
CHANGED
package/build/types/File.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { PackageInterface } from './Package.js';
|
|
2
2
|
export interface RegistryInterface {
|
|
3
3
|
name: string;
|
|
4
|
-
|
|
4
|
+
[RegistryType.Plugins]: RegistryPackages;
|
|
5
|
+
[RegistryType.Presets]: RegistryPackages;
|
|
6
|
+
[RegistryType.Projects]: RegistryPackages;
|
|
5
7
|
url: string;
|
|
6
8
|
version: string;
|
|
7
9
|
}
|
|
10
|
+
export declare enum RegistryType {
|
|
11
|
+
Plugins = "plugins",
|
|
12
|
+
Presets = "presets",
|
|
13
|
+
Projects = "projects"
|
|
14
|
+
}
|
|
8
15
|
export interface RegistryPackages {
|
|
9
16
|
[slug: string]: PackageInterface;
|
|
10
17
|
}
|
package/build/types/Registry.js
CHANGED