@kumori/aurora-backend-handler 1.0.38 → 1.0.40
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/helpers/revision-helper.ts +107 -34
- package/package.json +1 -1
|
@@ -482,7 +482,7 @@ const collectNamedTypes = (schema: any): string[] => {
|
|
|
482
482
|
|
|
483
483
|
const namedTypeToResourceKind = (
|
|
484
484
|
namedTypes: string[],
|
|
485
|
-
): { type: string; kind?: string } => {
|
|
485
|
+
): { type: string; kind?: string } | null => {
|
|
486
486
|
for (const name of namedTypes) {
|
|
487
487
|
switch (name) {
|
|
488
488
|
case "Secret":
|
|
@@ -507,21 +507,30 @@ const namedTypeToResourceKind = (
|
|
|
507
507
|
return { type: "volume" };
|
|
508
508
|
}
|
|
509
509
|
}
|
|
510
|
-
return
|
|
510
|
+
return null;
|
|
511
511
|
};
|
|
512
512
|
|
|
513
513
|
export const extractStructuredSchema = (
|
|
514
514
|
revisionData: any,
|
|
515
|
-
):
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
515
|
+
):
|
|
516
|
+
| {
|
|
517
|
+
parameters: {
|
|
518
|
+
name: string;
|
|
519
|
+
type: string;
|
|
520
|
+
required: boolean;
|
|
521
|
+
defaultValue?: any;
|
|
522
|
+
}[];
|
|
523
|
+
resources: {
|
|
524
|
+
name: string;
|
|
525
|
+
type: string;
|
|
526
|
+
kind?: string;
|
|
527
|
+
required: boolean;
|
|
528
|
+
}[];
|
|
529
|
+
}
|
|
530
|
+
| {} => {
|
|
524
531
|
const configSchema = revisionData?.configSchema;
|
|
532
|
+
if (!configSchema) return {};
|
|
533
|
+
|
|
525
534
|
const deploymentName = revisionData?.solution?.top;
|
|
526
535
|
const deployment = deploymentName
|
|
527
536
|
? revisionData?.solution?.deployments?.[deploymentName]
|
|
@@ -529,14 +538,15 @@ export const extractStructuredSchema = (
|
|
|
529
538
|
|
|
530
539
|
const parameterValues: Record<string, any> =
|
|
531
540
|
(deployment as any)?.config?.parameter ?? {};
|
|
541
|
+
const configResourceValues: Record<string, any> =
|
|
542
|
+
(deployment as any)?.config?.resource ?? {};
|
|
543
|
+
|
|
532
544
|
const requiredParams: string[] =
|
|
533
545
|
configSchema?.properties?.config?.required ?? [];
|
|
534
546
|
const requiredResources: string[] =
|
|
535
547
|
configSchema?.properties?.resource?.required ?? [];
|
|
536
548
|
const schemaConfigProps: Record<string, any> =
|
|
537
549
|
configSchema?.properties?.config?.properties ?? {};
|
|
538
|
-
const schemaResourceProps: Record<string, any> =
|
|
539
|
-
configSchema?.properties?.resource?.properties ?? {};
|
|
540
550
|
|
|
541
551
|
const parameters = Object.entries(schemaConfigProps).map(
|
|
542
552
|
([name, propSchema]) => {
|
|
@@ -558,10 +568,49 @@ export const extractStructuredSchema = (
|
|
|
558
568
|
},
|
|
559
569
|
);
|
|
560
570
|
|
|
561
|
-
const
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
571
|
+
const resolveResourceType = (
|
|
572
|
+
configValue: any,
|
|
573
|
+
): { type: string; kind?: string } | null => {
|
|
574
|
+
if (!configValue || typeof configValue !== "object") return null;
|
|
575
|
+
if ("secret" in configValue) return { type: "secret" };
|
|
576
|
+
if ("domain" in configValue) return { type: "domain" };
|
|
577
|
+
if ("port" in configValue) return { type: "port" };
|
|
578
|
+
if ("certificate" in configValue) return { type: "certificate" };
|
|
579
|
+
if ("ca" in configValue) return { type: "ca" };
|
|
580
|
+
if ("volume" in configValue) {
|
|
581
|
+
const volType = configValue.volume?.type;
|
|
582
|
+
if (volType === "persistent" || volType === "Persisted")
|
|
583
|
+
return { type: "volume", kind: "persistent" };
|
|
584
|
+
if (volType === "nonReplicated" || volType === "NonReplicated")
|
|
585
|
+
return { type: "volume", kind: "nonReplicated" };
|
|
586
|
+
if (
|
|
587
|
+
volType === "volatile" ||
|
|
588
|
+
volType === "Volatile" ||
|
|
589
|
+
volType === "ephemeral" ||
|
|
590
|
+
volType === "Ephemeral"
|
|
591
|
+
)
|
|
592
|
+
return { type: "volume", kind: "volatile" };
|
|
593
|
+
return { type: "volume" };
|
|
594
|
+
}
|
|
595
|
+
return null;
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
const allResourceNames = new Set<string>([
|
|
599
|
+
...Object.keys(configResourceValues),
|
|
600
|
+
...Object.keys(configSchema?.properties?.resource?.properties ?? {}),
|
|
601
|
+
]);
|
|
602
|
+
|
|
603
|
+
const resources = Array.from(allResourceNames)
|
|
604
|
+
.map((name) => {
|
|
605
|
+
const configValue = configResourceValues[name];
|
|
606
|
+
const fromConfig = resolveResourceType(configValue);
|
|
607
|
+
const schemaProps =
|
|
608
|
+
configSchema?.properties?.resource?.properties?.[name];
|
|
609
|
+
const fromSchema = schemaProps
|
|
610
|
+
? namedTypeToResourceKind(collectNamedTypes(schemaProps))
|
|
611
|
+
: null;
|
|
612
|
+
const resolved = fromConfig ?? fromSchema;
|
|
613
|
+
if (!resolved) return null;
|
|
565
614
|
const entry: {
|
|
566
615
|
name: string;
|
|
567
616
|
type: string;
|
|
@@ -574,8 +623,13 @@ export const extractStructuredSchema = (
|
|
|
574
623
|
};
|
|
575
624
|
if (resolved.kind) entry.kind = resolved.kind;
|
|
576
625
|
return entry;
|
|
577
|
-
}
|
|
578
|
-
|
|
626
|
+
})
|
|
627
|
+
.filter(Boolean) as {
|
|
628
|
+
name: string;
|
|
629
|
+
type: string;
|
|
630
|
+
kind?: string;
|
|
631
|
+
required: boolean;
|
|
632
|
+
}[];
|
|
579
633
|
|
|
580
634
|
return { parameters, resources };
|
|
581
635
|
};
|
|
@@ -592,10 +646,20 @@ export const processRevisionData = (
|
|
|
592
646
|
const parameters = extractParametersFromConfig(config.parameter || {});
|
|
593
647
|
const resources = extractResources(config.resource || {});
|
|
594
648
|
|
|
595
|
-
|
|
649
|
+
const schemaResult = revisionData.revision
|
|
650
|
+
? extractStructuredSchema(revisionData)
|
|
651
|
+
: {};
|
|
652
|
+
const schema =
|
|
653
|
+
schemaResult && "parameters" in schemaResult ? schemaResult : {};
|
|
654
|
+
|
|
655
|
+
if (
|
|
656
|
+
revisionsMap &&
|
|
657
|
+
serviceId &&
|
|
658
|
+
revisionData.revision &&
|
|
659
|
+
"parameters" in schema
|
|
660
|
+
) {
|
|
596
661
|
const revisionId: string = revisionData.revision;
|
|
597
662
|
const revisionKey = `${serviceId}-${revisionId}`;
|
|
598
|
-
const schema = extractStructuredSchema(revisionData);
|
|
599
663
|
const existing = revisionsMap.get(revisionKey);
|
|
600
664
|
if (existing) {
|
|
601
665
|
revisionsMap.set(revisionKey, { ...existing, schema });
|
|
@@ -645,26 +709,35 @@ export const processRevisionData = (
|
|
|
645
709
|
const deploymentName = solution.top || service.name;
|
|
646
710
|
const deployment = solution.deployments[deploymentName];
|
|
647
711
|
|
|
712
|
+
const applySchemaToService = (svc: Service): Service => {
|
|
713
|
+
if (!revisionData.revision || !("parameters" in schema)) return svc;
|
|
714
|
+
const revisionId: string = revisionData.revision;
|
|
715
|
+
return {
|
|
716
|
+
...svc,
|
|
717
|
+
revisions: svc.revisions.map((rev) =>
|
|
718
|
+
rev.id === revisionId ? { ...rev, schema } : rev,
|
|
719
|
+
),
|
|
720
|
+
};
|
|
721
|
+
};
|
|
722
|
+
|
|
648
723
|
if (!deployment) {
|
|
649
724
|
const firstDeploymentKey = Object.keys(solution.deployments)[0];
|
|
650
725
|
if (firstDeploymentKey) {
|
|
651
|
-
return
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
726
|
+
return applySchemaToService(
|
|
727
|
+
processDeployment(
|
|
728
|
+
service,
|
|
729
|
+
solution.deployments[firstDeploymentKey],
|
|
730
|
+
revisionData,
|
|
731
|
+
parameters,
|
|
732
|
+
resources,
|
|
733
|
+
),
|
|
657
734
|
);
|
|
658
735
|
}
|
|
659
|
-
return { ...service, parameters, resources };
|
|
736
|
+
return applySchemaToService({ ...service, parameters, resources });
|
|
660
737
|
}
|
|
661
738
|
|
|
662
|
-
return
|
|
663
|
-
service,
|
|
664
|
-
deployment,
|
|
665
|
-
revisionData,
|
|
666
|
-
parameters,
|
|
667
|
-
resources,
|
|
739
|
+
return applySchemaToService(
|
|
740
|
+
processDeployment(service, deployment, revisionData, parameters, resources),
|
|
668
741
|
);
|
|
669
742
|
};
|
|
670
743
|
|