@appstrate/validation 1.0.1 → 1.0.2
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/package.json +1 -1
- package/src/dependencies.ts +5 -7
- package/src/index.ts +0 -1
- package/src/naming.ts +22 -0
package/package.json
CHANGED
package/src/dependencies.ts
CHANGED
|
@@ -6,20 +6,18 @@ export interface DepEntry {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export function extractDependencies(manifest: Record<string, unknown>): DepEntry[] {
|
|
9
|
-
const
|
|
9
|
+
const registryDependencies = manifest.registryDependencies as
|
|
10
10
|
| {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
extensions?: Record<string, string>;
|
|
14
|
-
};
|
|
11
|
+
skills?: Record<string, string>;
|
|
12
|
+
extensions?: Record<string, string>;
|
|
15
13
|
}
|
|
16
14
|
| undefined;
|
|
17
15
|
|
|
18
|
-
if (!
|
|
16
|
+
if (!registryDependencies) return [];
|
|
19
17
|
|
|
20
18
|
const deps: DepEntry[] = [];
|
|
21
19
|
|
|
22
|
-
const { skills = {}, extensions = {} } =
|
|
20
|
+
const { skills = {}, extensions = {} } = registryDependencies;
|
|
23
21
|
|
|
24
22
|
for (const [fullName, versionRange] of Object.entries(skills)) {
|
|
25
23
|
const { scope, name } = parseScopedName(fullName);
|
package/src/index.ts
CHANGED
|
@@ -82,7 +82,6 @@ const flowSharedFields = {
|
|
|
82
82
|
services: z.array(serviceRequirementSchema),
|
|
83
83
|
skills: z.array(slugString).optional().default([]),
|
|
84
84
|
extensions: z.array(slugString).optional().default([]),
|
|
85
|
-
registryDependencies: registryDependenciesSchema,
|
|
86
85
|
}),
|
|
87
86
|
input: z
|
|
88
87
|
.object({
|
package/src/naming.ts
CHANGED
|
@@ -8,3 +8,25 @@ export function normalizeScope(scope: string): string {
|
|
|
8
8
|
export function stripScope(scope: string): string {
|
|
9
9
|
return scope.startsWith("@") ? scope.slice(1) : scope;
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
/** Convert "@scope/name" to strate packageId "scope--name" */
|
|
13
|
+
export function scopedNameToPackageId(scopedName: string): string {
|
|
14
|
+
const match = scopedName.match(/^@([a-z0-9][a-z0-9-]*[a-z0-9]?)\/([a-z0-9][a-z0-9-]*[a-z0-9]?)$/);
|
|
15
|
+
if (!match) throw new Error(`Invalid scoped package name: ${scopedName}`);
|
|
16
|
+
return `${match[1]}--${match[2]}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Convert strate packageId "scope--name" to "@scope/name", or null for local slugs */
|
|
20
|
+
export function packageIdToScopedName(packageId: string): string | null {
|
|
21
|
+
const idx = packageId.indexOf("--");
|
|
22
|
+
if (idx === -1) return null;
|
|
23
|
+
const scope = packageId.slice(0, idx);
|
|
24
|
+
const name = packageId.slice(idx + 2);
|
|
25
|
+
if (!scope || !name) return null;
|
|
26
|
+
return `@${scope}/${name}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Convert separated scope + name to strate packageId */
|
|
30
|
+
export function depEntryToPackageId(depScope: string, depName: string): string {
|
|
31
|
+
return `${stripScope(depScope)}--${depName}`;
|
|
32
|
+
}
|