@open-audio-stack/core 0.0.18 → 0.0.21
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/helpers/file.d.ts +3 -2
- package/build/helpers/file.js +11 -9
- package/build/helpers/package.d.ts +220 -3
- package/build/helpers/package.js +40 -38
- package/build/helpers/utils.d.ts +4 -3
- package/build/helpers/utils.js +9 -1
- package/build/types/Package.d.ts +0 -6
- package/package.json +3 -2
package/build/helpers/file.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { PackageInterface
|
|
1
|
+
import { PackageInterface } from '../types/Package.js';
|
|
2
2
|
import { PluginFile } from '../types/Plugin.js';
|
|
3
3
|
import { PresetFile } from '../types/Preset.js';
|
|
4
4
|
import { ProjectFile } from '../types/Project.js';
|
|
5
|
+
import { ZodIssue } from 'zod';
|
|
5
6
|
export declare function dirApp(): string;
|
|
6
7
|
export declare function dirCreate(dir: string): string | false;
|
|
7
8
|
export declare function dirDelete(dir: string): false | void;
|
|
@@ -30,6 +31,6 @@ export declare function fileReadJson(filePath: string): any;
|
|
|
30
31
|
export declare function fileReadString(filePath: string): string;
|
|
31
32
|
export declare function fileReadYaml(filePath: string): unknown;
|
|
32
33
|
export declare function fileSize(filePath: string): number;
|
|
33
|
-
export declare function fileValidateMetadata(filePath: string, fileMetadata: PluginFile | PresetFile | ProjectFile): Promise<
|
|
34
|
+
export declare function fileValidateMetadata(filePath: string, fileMetadata: PluginFile | PresetFile | ProjectFile): Promise<ZodIssue[]>;
|
|
34
35
|
export declare function zipCreate(filesPath: string, zipPath: string): void;
|
|
35
36
|
export declare function zipExtract(content: any, dirPath: string): void;
|
package/build/helpers/file.js
CHANGED
|
@@ -8,7 +8,7 @@ import { moveSync } from 'fs-extra/esm';
|
|
|
8
8
|
import os from 'os';
|
|
9
9
|
import path from 'path';
|
|
10
10
|
import yaml from 'js-yaml';
|
|
11
|
-
import {
|
|
11
|
+
import { ZodIssueCode } from 'zod';
|
|
12
12
|
export function dirApp() {
|
|
13
13
|
if (process.platform === 'win32')
|
|
14
14
|
return process.env.APPDATA || os.homedir();
|
|
@@ -183,18 +183,20 @@ export async function fileValidateMetadata(filePath, fileMetadata) {
|
|
|
183
183
|
const hash = await fileHash(filePath);
|
|
184
184
|
if (fileMetadata.sha256 !== hash) {
|
|
185
185
|
errors.push({
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
186
|
+
code: ZodIssueCode.invalid_type,
|
|
187
|
+
expected: hash,
|
|
188
|
+
message: 'Required',
|
|
189
|
+
path: ['sha256'],
|
|
190
|
+
received: fileMetadata.sha256,
|
|
190
191
|
});
|
|
191
192
|
}
|
|
192
193
|
if (fileMetadata.size !== fileSize(filePath)) {
|
|
193
194
|
errors.push({
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
code: ZodIssueCode.invalid_type,
|
|
196
|
+
expected: String(fileSize(filePath)),
|
|
197
|
+
message: 'Required',
|
|
198
|
+
path: ['size'],
|
|
199
|
+
received: String(fileMetadata.size),
|
|
198
200
|
});
|
|
199
201
|
}
|
|
200
202
|
return errors;
|
|
@@ -1,5 +1,222 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Architecture } from '../types/Architecture.js';
|
|
3
|
+
import { FileFormat } from '../types/FileFormat.js';
|
|
4
|
+
import { FileType } from '../types/FileType.js';
|
|
5
|
+
import { License } from '../types/License.js';
|
|
6
|
+
import { PluginFile } from '../types/Plugin.js';
|
|
7
|
+
import { PluginType } from '../types/PluginType.js';
|
|
8
|
+
import { PresetFile } from '../types/Preset.js';
|
|
9
|
+
import { PresetType } from '../types/PresetType.js';
|
|
10
|
+
import { ProjectFile } from '../types/Project.js';
|
|
11
|
+
import { ProjectType } from '../types/ProjectType.js';
|
|
12
|
+
import { SystemType } from '../types/SystemType.js';
|
|
13
|
+
import { PackageValidationRec, PackageVersionType } from '../types/Package.js';
|
|
14
|
+
export declare const PackageSystemValidator: z.ZodObject<{
|
|
15
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
16
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
type: z.ZodNativeEnum<typeof SystemType>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
type: SystemType;
|
|
20
|
+
max?: number | undefined;
|
|
21
|
+
min?: number | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
type: SystemType;
|
|
24
|
+
max?: number | undefined;
|
|
25
|
+
min?: number | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
export declare const PackageFileValidator: z.ZodObject<{
|
|
28
|
+
architectures: z.ZodArray<z.ZodNativeEnum<typeof Architecture>, "many">;
|
|
29
|
+
format: z.ZodNativeEnum<typeof FileFormat>;
|
|
30
|
+
sha256: z.ZodString;
|
|
31
|
+
size: z.ZodNumber;
|
|
32
|
+
systems: z.ZodArray<z.ZodObject<{
|
|
33
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
type: z.ZodNativeEnum<typeof SystemType>;
|
|
36
|
+
}, "strip", z.ZodTypeAny, {
|
|
37
|
+
type: SystemType;
|
|
38
|
+
max?: number | undefined;
|
|
39
|
+
min?: number | undefined;
|
|
40
|
+
}, {
|
|
41
|
+
type: SystemType;
|
|
42
|
+
max?: number | undefined;
|
|
43
|
+
min?: number | undefined;
|
|
44
|
+
}>, "many">;
|
|
45
|
+
type: z.ZodNativeEnum<typeof FileType>;
|
|
46
|
+
url: z.ZodString;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
|
+
url: string;
|
|
49
|
+
type: FileType;
|
|
50
|
+
architectures: Architecture[];
|
|
51
|
+
format: FileFormat;
|
|
52
|
+
sha256: string;
|
|
53
|
+
size: number;
|
|
54
|
+
systems: {
|
|
55
|
+
type: SystemType;
|
|
56
|
+
max?: number | undefined;
|
|
57
|
+
min?: number | undefined;
|
|
58
|
+
}[];
|
|
59
|
+
}, {
|
|
60
|
+
url: string;
|
|
61
|
+
type: FileType;
|
|
62
|
+
architectures: Architecture[];
|
|
63
|
+
format: FileFormat;
|
|
64
|
+
sha256: string;
|
|
65
|
+
size: number;
|
|
66
|
+
systems: {
|
|
67
|
+
type: SystemType;
|
|
68
|
+
max?: number | undefined;
|
|
69
|
+
min?: number | undefined;
|
|
70
|
+
}[];
|
|
71
|
+
}>;
|
|
72
|
+
export declare const PackageTypeObj: {
|
|
73
|
+
Audiobook: ProjectType.Audiobook;
|
|
74
|
+
DJSet: ProjectType.DJSet;
|
|
75
|
+
Performance: ProjectType.Performance;
|
|
76
|
+
Podcast: ProjectType.Podcast;
|
|
77
|
+
Remix: ProjectType.Remix;
|
|
78
|
+
Song: ProjectType.Song;
|
|
79
|
+
Score: ProjectType.Score;
|
|
80
|
+
Chain: PresetType.Chain;
|
|
81
|
+
Layout: PresetType.Layout;
|
|
82
|
+
Mapping: PresetType.Mapping;
|
|
83
|
+
Patch: PresetType.Patch;
|
|
84
|
+
Pattern: PresetType.Pattern;
|
|
85
|
+
Theme: PresetType.Theme;
|
|
86
|
+
Effect: PluginType.Effect;
|
|
87
|
+
Generator: PluginType.Generator;
|
|
88
|
+
Instrument: PluginType.Instrument;
|
|
89
|
+
Preset: PluginType.Preset;
|
|
90
|
+
Sampler: PluginType.Sampler;
|
|
91
|
+
Tool: PluginType.Tool;
|
|
92
|
+
};
|
|
93
|
+
export declare const PackageVersionValidator: z.ZodObject<{
|
|
94
|
+
audio: z.ZodString;
|
|
95
|
+
author: z.ZodString;
|
|
96
|
+
changes: z.ZodString;
|
|
97
|
+
date: z.ZodString;
|
|
98
|
+
description: z.ZodString;
|
|
99
|
+
files: z.ZodArray<z.ZodObject<{
|
|
100
|
+
architectures: z.ZodArray<z.ZodNativeEnum<typeof Architecture>, "many">;
|
|
101
|
+
format: z.ZodNativeEnum<typeof FileFormat>;
|
|
102
|
+
sha256: z.ZodString;
|
|
103
|
+
size: z.ZodNumber;
|
|
104
|
+
systems: z.ZodArray<z.ZodObject<{
|
|
105
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
106
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
107
|
+
type: z.ZodNativeEnum<typeof SystemType>;
|
|
108
|
+
}, "strip", z.ZodTypeAny, {
|
|
109
|
+
type: SystemType;
|
|
110
|
+
max?: number | undefined;
|
|
111
|
+
min?: number | undefined;
|
|
112
|
+
}, {
|
|
113
|
+
type: SystemType;
|
|
114
|
+
max?: number | undefined;
|
|
115
|
+
min?: number | undefined;
|
|
116
|
+
}>, "many">;
|
|
117
|
+
type: z.ZodNativeEnum<typeof FileType>;
|
|
118
|
+
url: z.ZodString;
|
|
119
|
+
}, "strip", z.ZodTypeAny, {
|
|
120
|
+
url: string;
|
|
121
|
+
type: FileType;
|
|
122
|
+
architectures: Architecture[];
|
|
123
|
+
format: FileFormat;
|
|
124
|
+
sha256: string;
|
|
125
|
+
size: number;
|
|
126
|
+
systems: {
|
|
127
|
+
type: SystemType;
|
|
128
|
+
max?: number | undefined;
|
|
129
|
+
min?: number | undefined;
|
|
130
|
+
}[];
|
|
131
|
+
}, {
|
|
132
|
+
url: string;
|
|
133
|
+
type: FileType;
|
|
134
|
+
architectures: Architecture[];
|
|
135
|
+
format: FileFormat;
|
|
136
|
+
sha256: string;
|
|
137
|
+
size: number;
|
|
138
|
+
systems: {
|
|
139
|
+
type: SystemType;
|
|
140
|
+
max?: number | undefined;
|
|
141
|
+
min?: number | undefined;
|
|
142
|
+
}[];
|
|
143
|
+
}>, "many">;
|
|
144
|
+
image: z.ZodString;
|
|
145
|
+
license: z.ZodNativeEnum<typeof License>;
|
|
146
|
+
name: z.ZodString;
|
|
147
|
+
tags: z.ZodArray<z.ZodString, "many">;
|
|
148
|
+
type: z.ZodNativeEnum<{
|
|
149
|
+
Audiobook: ProjectType.Audiobook;
|
|
150
|
+
DJSet: ProjectType.DJSet;
|
|
151
|
+
Performance: ProjectType.Performance;
|
|
152
|
+
Podcast: ProjectType.Podcast;
|
|
153
|
+
Remix: ProjectType.Remix;
|
|
154
|
+
Song: ProjectType.Song;
|
|
155
|
+
Score: ProjectType.Score;
|
|
156
|
+
Chain: PresetType.Chain;
|
|
157
|
+
Layout: PresetType.Layout;
|
|
158
|
+
Mapping: PresetType.Mapping;
|
|
159
|
+
Patch: PresetType.Patch;
|
|
160
|
+
Pattern: PresetType.Pattern;
|
|
161
|
+
Theme: PresetType.Theme;
|
|
162
|
+
Effect: PluginType.Effect;
|
|
163
|
+
Generator: PluginType.Generator;
|
|
164
|
+
Instrument: PluginType.Instrument;
|
|
165
|
+
Preset: PluginType.Preset;
|
|
166
|
+
Sampler: PluginType.Sampler;
|
|
167
|
+
Tool: PluginType.Tool;
|
|
168
|
+
}>;
|
|
169
|
+
url: z.ZodString;
|
|
170
|
+
}, "strip", z.ZodTypeAny, {
|
|
171
|
+
audio: string;
|
|
172
|
+
author: string;
|
|
173
|
+
changes: string;
|
|
174
|
+
date: string;
|
|
175
|
+
description: string;
|
|
176
|
+
image: string;
|
|
177
|
+
license: License;
|
|
178
|
+
name: string;
|
|
179
|
+
tags: string[];
|
|
180
|
+
url: string;
|
|
181
|
+
type: PluginType | PresetType | ProjectType;
|
|
182
|
+
files: {
|
|
183
|
+
url: string;
|
|
184
|
+
type: FileType;
|
|
185
|
+
architectures: Architecture[];
|
|
186
|
+
format: FileFormat;
|
|
187
|
+
sha256: string;
|
|
188
|
+
size: number;
|
|
189
|
+
systems: {
|
|
190
|
+
type: SystemType;
|
|
191
|
+
max?: number | undefined;
|
|
192
|
+
min?: number | undefined;
|
|
193
|
+
}[];
|
|
194
|
+
}[];
|
|
195
|
+
}, {
|
|
196
|
+
audio: string;
|
|
197
|
+
author: string;
|
|
198
|
+
changes: string;
|
|
199
|
+
date: string;
|
|
200
|
+
description: string;
|
|
201
|
+
image: string;
|
|
202
|
+
license: License;
|
|
203
|
+
name: string;
|
|
204
|
+
tags: string[];
|
|
205
|
+
url: string;
|
|
206
|
+
type: PluginType | PresetType | ProjectType;
|
|
207
|
+
files: {
|
|
208
|
+
url: string;
|
|
209
|
+
type: FileType;
|
|
210
|
+
architectures: Architecture[];
|
|
211
|
+
format: FileFormat;
|
|
212
|
+
sha256: string;
|
|
213
|
+
size: number;
|
|
214
|
+
systems: {
|
|
215
|
+
type: SystemType;
|
|
216
|
+
max?: number | undefined;
|
|
217
|
+
min?: number | undefined;
|
|
218
|
+
}[];
|
|
219
|
+
}[];
|
|
220
|
+
}>;
|
|
3
221
|
export declare function packageRecommendations(pkgVersion: PackageVersionType): PackageValidationRec[];
|
|
4
222
|
export declare function packageRecommendationsUrl(obj: PackageVersionType | PluginFile | PresetFile | ProjectFile, recs: PackageValidationRec[], field: string): void;
|
|
5
|
-
export declare function packageValidate(pkgVersion: PackageVersionType): PackageValidationError[];
|
package/build/helpers/package.js
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Architecture } from '../types/Architecture.js';
|
|
3
|
+
import { FileFormat } from '../types/FileFormat.js';
|
|
4
|
+
import { FileType } from '../types/FileType.js';
|
|
1
5
|
import { License } from '../types/License.js';
|
|
2
|
-
import {
|
|
6
|
+
import { PluginType } from '../types/PluginType.js';
|
|
7
|
+
import { PresetType } from '../types/PresetType.js';
|
|
8
|
+
import { ProjectType } from '../types/ProjectType.js';
|
|
9
|
+
import { SystemType } from '../types/SystemType.js';
|
|
10
|
+
// This is a first version using zod library for validation.
|
|
11
|
+
// If it works well, consider updating all types to infer from Zod objects.
|
|
12
|
+
// This will remove duplicatation of code between types and validators.
|
|
13
|
+
export const PackageSystemValidator = z.object({
|
|
14
|
+
max: z.number().min(0).max(99).optional(),
|
|
15
|
+
min: z.number().min(0).max(99).optional(),
|
|
16
|
+
type: z.nativeEnum(SystemType),
|
|
17
|
+
});
|
|
18
|
+
export const PackageFileValidator = z.object({
|
|
19
|
+
architectures: z.nativeEnum(Architecture).array(),
|
|
20
|
+
format: z.nativeEnum(FileFormat),
|
|
21
|
+
sha256: z.string().length(64),
|
|
22
|
+
size: z.number().min(0).max(9999999999),
|
|
23
|
+
systems: PackageSystemValidator.array(),
|
|
24
|
+
type: z.nativeEnum(FileType),
|
|
25
|
+
url: z.string().min(0).max(256).startsWith('https://'),
|
|
26
|
+
});
|
|
27
|
+
export const PackageTypeObj = { ...PluginType, ...PresetType, ...ProjectType };
|
|
28
|
+
export const PackageVersionValidator = z.object({
|
|
29
|
+
audio: z.string().min(0).max(256).startsWith('https://'),
|
|
30
|
+
author: z.string().min(0).max(256),
|
|
31
|
+
changes: z.string().min(0).max(256),
|
|
32
|
+
date: z.string().datetime(),
|
|
33
|
+
description: z.string().min(0).max(256),
|
|
34
|
+
files: z.array(PackageFileValidator),
|
|
35
|
+
image: z.string().min(0).max(256).startsWith('https://'),
|
|
36
|
+
license: z.nativeEnum(License),
|
|
37
|
+
name: z.string().min(0).max(256),
|
|
38
|
+
tags: z.string().min(0).max(256).array(),
|
|
39
|
+
type: z.nativeEnum(PackageTypeObj),
|
|
40
|
+
url: z.string().min(0).max(256).startsWith('https://'),
|
|
41
|
+
});
|
|
3
42
|
// TODO refactor all this using a proper validation library.
|
|
4
43
|
export function packageRecommendations(pkgVersion) {
|
|
5
44
|
const recs = [];
|
|
@@ -72,40 +111,3 @@ export function packageRecommendationsUrl(obj, recs, field) {
|
|
|
72
111
|
});
|
|
73
112
|
}
|
|
74
113
|
}
|
|
75
|
-
export function packageValidate(pkgVersion) {
|
|
76
|
-
const fields = [
|
|
77
|
-
{ name: 'audio', type: 'string' },
|
|
78
|
-
{ name: 'author', type: 'string' },
|
|
79
|
-
{ name: 'changes', type: 'string' },
|
|
80
|
-
{ name: 'date', type: 'string' },
|
|
81
|
-
{ name: 'description', type: 'string' },
|
|
82
|
-
{ name: 'files', type: 'object' },
|
|
83
|
-
{ name: 'image', type: 'string' },
|
|
84
|
-
{ name: 'license', type: 'string' },
|
|
85
|
-
{ name: 'name', type: 'string' },
|
|
86
|
-
{ name: 'tags', type: 'object' },
|
|
87
|
-
{ name: 'type', type: 'string' },
|
|
88
|
-
{ name: 'url', type: 'string' },
|
|
89
|
-
];
|
|
90
|
-
const errors = [];
|
|
91
|
-
fields.forEach((field) => {
|
|
92
|
-
const versionField = pkgVersion[field.name];
|
|
93
|
-
if (versionField === undefined) {
|
|
94
|
-
errors.push({
|
|
95
|
-
field: field.name,
|
|
96
|
-
error: PackageValidation.MISSING_FIELD,
|
|
97
|
-
valueExpected: field.type,
|
|
98
|
-
valueReceived: 'undefined',
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
else if (typeof versionField !== field.type) {
|
|
102
|
-
errors.push({
|
|
103
|
-
field: field.name,
|
|
104
|
-
error: PackageValidation.INVALID_TYPE,
|
|
105
|
-
valueExpected: field.type,
|
|
106
|
-
valueReceived: typeof versionField,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
return errors;
|
|
111
|
-
}
|
package/build/helpers/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
1
|
+
import { PackageValidationRec } from '../types/Package.js';
|
|
2
|
+
import { ZodIssue } from 'zod';
|
|
3
|
+
export declare function logReport(info: string, errors?: ZodIssue[], recs?: PackageValidationRec[]): void;
|
|
4
|
+
export declare function logErrors(errors: ZodIssue[]): void;
|
|
4
5
|
export declare function logRecommendations(recs: PackageValidationRec[]): void;
|
|
5
6
|
export declare function pathGetExt(path: string, sep?: string): string;
|
|
6
7
|
export declare function pathGetDirectory(path: string, sep?: string): string;
|
package/build/helpers/utils.js
CHANGED
|
@@ -12,7 +12,15 @@ export function logReport(info, errors, recs) {
|
|
|
12
12
|
}
|
|
13
13
|
export function logErrors(errors) {
|
|
14
14
|
errors.forEach(error => {
|
|
15
|
-
|
|
15
|
+
// @ts-expect-error need to filter by code.
|
|
16
|
+
if (error.received) {
|
|
17
|
+
console.log(chalk.red(
|
|
18
|
+
// @ts-expect-error need to filter by code.
|
|
19
|
+
`- ${error.path} (${error.message}) received '${error.received}' expected '${error.expected}'`));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
console.log(chalk.red(`- ${error.path} (${error.message})`));
|
|
23
|
+
}
|
|
16
24
|
});
|
|
17
25
|
}
|
|
18
26
|
export function logRecommendations(recs) {
|
package/build/types/Package.d.ts
CHANGED
|
@@ -32,12 +32,6 @@ export interface PackageValidationField {
|
|
|
32
32
|
name: string;
|
|
33
33
|
type: string;
|
|
34
34
|
}
|
|
35
|
-
export interface PackageValidationError {
|
|
36
|
-
field: string;
|
|
37
|
-
error: PackageValidation;
|
|
38
|
-
valueExpected: boolean | number | string;
|
|
39
|
-
valueReceived: boolean | number | string;
|
|
40
|
-
}
|
|
41
35
|
export interface PackageValidationRec {
|
|
42
36
|
field: string;
|
|
43
37
|
rec: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-audio-stack/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "Open-source audio plugin management software",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
"fs-extra": "^11.2.0",
|
|
57
57
|
"glob": "^11.0.0",
|
|
58
58
|
"js-yaml": "^4.1.0",
|
|
59
|
-
"semver": "^7.6.3"
|
|
59
|
+
"semver": "^7.6.3",
|
|
60
|
+
"zod": "^3.23.8"
|
|
60
61
|
},
|
|
61
62
|
"repository": {
|
|
62
63
|
"type": "git",
|