@open-audio-stack/core 0.0.17 → 0.0.19

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.
@@ -1,3 +1,222 @@
1
- import { PackageValidationError, PackageValidationRec, PackageVersionType } from '../types/Package.js';
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
+ }>;
2
221
  export declare function packageRecommendations(pkgVersion: PackageVersionType): PackageValidationRec[];
3
- export declare function packageValidate(pkgVersion: PackageVersionType): PackageValidationError[];
222
+ export declare function packageRecommendationsUrl(obj: PackageVersionType | PluginFile | PresetFile | ProjectFile, recs: PackageValidationRec[], field: string): void;
@@ -1,29 +1,58 @@
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 { PackageValidation, } from '../types/Package.js';
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 = [];
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
- }
45
+ packageRecommendationsUrl(pkgVersion, recs, 'audio');
46
+ packageRecommendationsUrl(pkgVersion, recs, 'image');
47
+ packageRecommendationsUrl(pkgVersion, recs, 'url');
19
48
  // Image/audio previews
20
- if (pkgVersion.image && pkgVersion.image.includes('png')) {
49
+ if (pkgVersion.image && pkgVersion.image.endsWith('png')) {
21
50
  recs.push({
22
51
  field: 'image',
23
52
  rec: 'should use the jpg format',
24
53
  });
25
54
  }
26
- if (pkgVersion.audio && pkgVersion.audio.includes('wav')) {
55
+ if (pkgVersion.audio && pkgVersion.audio.endsWith('wav')) {
27
56
  recs.push({
28
57
  field: 'audio',
29
58
  rec: 'should use the flac format',
@@ -39,6 +68,7 @@ export function packageRecommendations(pkgVersion) {
39
68
  file.systems.forEach(system => {
40
69
  supportedSystems[system.type] = true;
41
70
  });
71
+ packageRecommendationsUrl(file, recs, 'url');
42
72
  });
43
73
  if (!supportedArchitectures.arm64)
44
74
  recs.push({ field: 'architectures', rec: 'should support arm64' });
@@ -63,40 +93,21 @@ export function packageRecommendations(pkgVersion) {
63
93
  }
64
94
  return recs;
65
95
  }
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;
96
+ export function packageRecommendationsUrl(obj, recs, field) {
97
+ // @ts-expect-error indexing a field with multiple package types.
98
+ const val = obj[field];
99
+ if (typeof val !== 'string')
100
+ return;
101
+ if (!val.startsWith('https://')) {
102
+ recs.push({
103
+ field,
104
+ rec: 'should use https url',
105
+ });
106
+ }
107
+ if (!val.includes('github.com') && !val.includes('github.io')) {
108
+ recs.push({
109
+ field,
110
+ rec: 'should point to GitHub',
111
+ });
112
+ }
102
113
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-audio-stack/core",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
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",