@elek-io/core 0.14.4 → 0.15.0

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.
@@ -429,7 +429,7 @@ var FieldWidthSchema = z7.enum(["12", "6", "4", "3"]);
429
429
  var FieldDefinitionBaseSchema = z7.object({
430
430
  id: uuidSchema.readonly(),
431
431
  label: translatableStringSchema,
432
- description: translatableStringSchema,
432
+ description: translatableStringSchema.nullable(),
433
433
  isRequired: z7.boolean(),
434
434
  isDisabled: z7.boolean(),
435
435
  isUnique: z7.boolean(),
@@ -551,104 +551,6 @@ var fieldDefinitionSchema = z7.union([
551
551
  entryFieldDefinitionSchema
552
552
  // sharedValueDefinitionSchema,
553
553
  ]);
554
- function getValueContentSchemaFromFieldDefinition(fieldDefinition) {
555
- switch (fieldDefinition.valueType) {
556
- case ValueTypeSchema.enum.boolean:
557
- return getBooleanValueContentSchema();
558
- case ValueTypeSchema.enum.number:
559
- return getNumberValueContentSchema(fieldDefinition);
560
- case ValueTypeSchema.enum.string:
561
- return getStringValueContentSchema(fieldDefinition);
562
- case ValueTypeSchema.enum.reference:
563
- return getReferenceValueContentSchema(fieldDefinition);
564
- default:
565
- throw new Error(
566
- // @ts-expect-error
567
- `Error generating schema for unsupported ValueType "${fieldDefinition.valueType}"`
568
- );
569
- }
570
- }
571
- function getBooleanValueContentSchema() {
572
- return z7.boolean();
573
- }
574
- function getNumberValueContentSchema(definition) {
575
- let schema = z7.number();
576
- if (definition.min) {
577
- schema = schema.min(definition.min);
578
- }
579
- if (definition.max) {
580
- schema = schema.max(definition.max);
581
- }
582
- if (definition.isRequired === false) {
583
- return schema.nullable();
584
- }
585
- return schema;
586
- }
587
- function getStringValueContentSchema(definition) {
588
- let schema = null;
589
- switch (definition.fieldType) {
590
- case FieldTypeSchema.enum.email:
591
- schema = z7.email();
592
- break;
593
- case FieldTypeSchema.enum.url:
594
- schema = z7.url();
595
- break;
596
- case FieldTypeSchema.enum.ipv4:
597
- schema = z7.ipv4();
598
- break;
599
- case FieldTypeSchema.enum.date:
600
- schema = z7.iso.date();
601
- break;
602
- case FieldTypeSchema.enum.time:
603
- schema = z7.iso.time();
604
- break;
605
- case FieldTypeSchema.enum.datetime:
606
- schema = z7.iso.datetime();
607
- break;
608
- case FieldTypeSchema.enum.telephone:
609
- schema = z7.e164();
610
- break;
611
- case FieldTypeSchema.enum.text:
612
- case FieldTypeSchema.enum.textarea:
613
- schema = z7.string().trim();
614
- break;
615
- }
616
- if ("min" in definition && definition.min) {
617
- schema = schema.min(definition.min);
618
- }
619
- if ("max" in definition && definition.max) {
620
- schema = schema.max(definition.max);
621
- }
622
- if (definition.isRequired === false) {
623
- return schema.nullable();
624
- }
625
- return schema.min(1, "shared.stringValueRequired");
626
- }
627
- function getReferenceValueContentSchema(definition) {
628
- let schema;
629
- switch (definition.fieldType) {
630
- case FieldTypeSchema.enum.asset:
631
- {
632
- schema = z7.array(valueContentReferenceToAssetSchema);
633
- }
634
- break;
635
- case FieldTypeSchema.enum.entry:
636
- {
637
- schema = z7.array(valueContentReferenceToEntrySchema);
638
- }
639
- break;
640
- }
641
- if (definition.isRequired) {
642
- schema = schema.min(1, "shared.referenceRequired");
643
- }
644
- if (definition.min) {
645
- schema = schema.min(definition.min);
646
- }
647
- if (definition.max) {
648
- schema = schema.max(definition.max);
649
- }
650
- return schema;
651
- }
652
554
 
653
555
  // src/schema/collectionSchema.ts
654
556
  var collectionFileSchema = baseFileSchema.extend({
@@ -854,9 +756,182 @@ var searchProjectSchema = z10.object({
854
756
  type: z10.array(objectTypeSchema).optional()
855
757
  });
856
758
 
759
+ // src/schema/schemaFromFieldDefinition.ts
760
+ import z11 from "zod";
761
+ function getBooleanValueContentSchemaFromFieldDefinition() {
762
+ return z11.boolean();
763
+ }
764
+ function getNumberValueContentSchemaFromFieldDefinition(fieldDefinition) {
765
+ let schema = z11.number();
766
+ if (fieldDefinition.min) {
767
+ schema = schema.min(fieldDefinition.min);
768
+ }
769
+ if (fieldDefinition.max) {
770
+ schema = schema.max(fieldDefinition.max);
771
+ }
772
+ if (fieldDefinition.isRequired === false) {
773
+ return schema.nullable();
774
+ }
775
+ return schema;
776
+ }
777
+ function getStringValueContentSchemaFromFieldDefinition(fieldDefinition) {
778
+ let schema = null;
779
+ switch (fieldDefinition.fieldType) {
780
+ case FieldTypeSchema.enum.email:
781
+ schema = z11.email();
782
+ break;
783
+ case FieldTypeSchema.enum.url:
784
+ schema = z11.url();
785
+ break;
786
+ case FieldTypeSchema.enum.ipv4:
787
+ schema = z11.ipv4();
788
+ break;
789
+ case FieldTypeSchema.enum.date:
790
+ schema = z11.iso.date();
791
+ break;
792
+ case FieldTypeSchema.enum.time:
793
+ schema = z11.iso.time();
794
+ break;
795
+ case FieldTypeSchema.enum.datetime:
796
+ schema = z11.iso.datetime();
797
+ break;
798
+ case FieldTypeSchema.enum.telephone:
799
+ schema = z11.e164();
800
+ break;
801
+ case FieldTypeSchema.enum.text:
802
+ case FieldTypeSchema.enum.textarea:
803
+ schema = z11.string().trim();
804
+ break;
805
+ }
806
+ if ("min" in fieldDefinition && fieldDefinition.min) {
807
+ schema = schema.min(fieldDefinition.min);
808
+ }
809
+ if ("max" in fieldDefinition && fieldDefinition.max) {
810
+ schema = schema.max(fieldDefinition.max);
811
+ }
812
+ if (fieldDefinition.isRequired === false) {
813
+ return schema.nullable();
814
+ }
815
+ return schema.min(1, "shared.stringValueRequired");
816
+ }
817
+ function getReferenceValueContentSchemaFromFieldDefinition(fieldDefinition) {
818
+ let schema;
819
+ switch (fieldDefinition.fieldType) {
820
+ case FieldTypeSchema.enum.asset:
821
+ {
822
+ schema = z11.array(valueContentReferenceToAssetSchema);
823
+ }
824
+ break;
825
+ case FieldTypeSchema.enum.entry:
826
+ {
827
+ schema = z11.array(valueContentReferenceToEntrySchema);
828
+ }
829
+ break;
830
+ }
831
+ if (fieldDefinition.isRequired) {
832
+ schema = schema.min(1, "shared.referenceRequired");
833
+ }
834
+ if (fieldDefinition.min) {
835
+ schema = schema.min(fieldDefinition.min);
836
+ }
837
+ if (fieldDefinition.max) {
838
+ schema = schema.max(fieldDefinition.max);
839
+ }
840
+ return schema;
841
+ }
842
+ function getTranslatableStringValueContentSchemaFromFieldDefinition(fieldDefinition) {
843
+ return z11.partialRecord(
844
+ supportedLanguageSchema,
845
+ getStringValueContentSchemaFromFieldDefinition(fieldDefinition)
846
+ );
847
+ }
848
+ function getTranslatableNumberValueContentSchemaFromFieldDefinition(fieldDefinition) {
849
+ return z11.partialRecord(
850
+ supportedLanguageSchema,
851
+ getNumberValueContentSchemaFromFieldDefinition(fieldDefinition)
852
+ );
853
+ }
854
+ function getTranslatableBooleanValueContentSchemaFromFieldDefinition() {
855
+ return z11.partialRecord(
856
+ supportedLanguageSchema,
857
+ getBooleanValueContentSchemaFromFieldDefinition()
858
+ );
859
+ }
860
+ function getTranslatableReferenceValueContentSchemaFromFieldDefinition(fieldDefinition) {
861
+ return z11.partialRecord(
862
+ supportedLanguageSchema,
863
+ getReferenceValueContentSchemaFromFieldDefinition(fieldDefinition)
864
+ );
865
+ }
866
+ function getValueSchemaFromFieldDefinition(fieldDefinition) {
867
+ switch (fieldDefinition.valueType) {
868
+ case ValueTypeSchema.enum.boolean:
869
+ return directBooleanValueSchema.extend({
870
+ content: getTranslatableBooleanValueContentSchemaFromFieldDefinition()
871
+ });
872
+ case ValueTypeSchema.enum.number:
873
+ return directNumberValueSchema.extend({
874
+ content: getTranslatableNumberValueContentSchemaFromFieldDefinition(
875
+ fieldDefinition
876
+ )
877
+ });
878
+ case ValueTypeSchema.enum.string:
879
+ return directStringValueSchema.extend({
880
+ content: getTranslatableStringValueContentSchemaFromFieldDefinition(
881
+ fieldDefinition
882
+ )
883
+ });
884
+ case ValueTypeSchema.enum.reference:
885
+ return referencedValueSchema.extend({
886
+ content: getTranslatableReferenceValueContentSchemaFromFieldDefinition(
887
+ fieldDefinition
888
+ )
889
+ });
890
+ default:
891
+ throw new Error(
892
+ // @ts-expect-error Code cannot be reached, but if we add a new ValueType and forget to update this function, we want to be notified about it
893
+ `Error generating schema for unsupported ValueType "${fieldDefinition.valueType}"`
894
+ );
895
+ }
896
+ }
897
+ function getCreateEntrySchemaFromFieldDefinitions(fieldDefinitions, values) {
898
+ const schema = {
899
+ ...createEntrySchema,
900
+ values: values.map((value) => {
901
+ const fieldDefinition = fieldDefinitions.find(
902
+ (fieldDefinition2) => fieldDefinition2.id === value.fieldDefinitionId
903
+ );
904
+ if (!fieldDefinition) {
905
+ throw new Error(
906
+ `Field definition with ID "${value.fieldDefinitionId}" not found`
907
+ );
908
+ }
909
+ return getValueSchemaFromFieldDefinition(fieldDefinition);
910
+ })
911
+ };
912
+ return schema;
913
+ }
914
+ function getUpdateEntrySchemaFromFieldDefinitions(fieldDefinitions, values) {
915
+ const schema = {
916
+ ...updateEntrySchema,
917
+ values: values.map((value) => {
918
+ const fieldDefinition = fieldDefinitions.find(
919
+ (fieldDefinition2) => fieldDefinition2.id === value.fieldDefinitionId
920
+ );
921
+ if (!fieldDefinition) {
922
+ throw new Error(
923
+ `Field definition with ID "${value.fieldDefinitionId}" not found`
924
+ );
925
+ }
926
+ return getValueSchemaFromFieldDefinition(fieldDefinition);
927
+ })
928
+ };
929
+ return schema;
930
+ }
931
+
857
932
  // src/schema/serviceSchema.ts
858
- import { z as z11 } from "zod";
859
- var serviceTypeSchema = z11.enum([
933
+ import { z as z12 } from "zod";
934
+ var serviceTypeSchema = z12.enum([
860
935
  "Git",
861
936
  "GitTag",
862
937
  "User",
@@ -869,17 +944,17 @@ var serviceTypeSchema = z11.enum([
869
944
  "Value"
870
945
  ]);
871
946
  function paginatedListOf(schema) {
872
- return z11.object({
873
- total: z11.number(),
874
- limit: z11.number(),
875
- offset: z11.number(),
876
- list: z11.array(schema)
947
+ return z12.object({
948
+ total: z12.number(),
949
+ limit: z12.number(),
950
+ offset: z12.number(),
951
+ list: z12.array(schema)
877
952
  });
878
953
  }
879
- var listSchema = z11.object({
954
+ var listSchema = z12.object({
880
955
  projectId: uuidSchema,
881
- limit: z11.number().optional(),
882
- offset: z11.number().optional()
956
+ limit: z12.number().optional(),
957
+ offset: z12.number().optional()
883
958
  });
884
959
  var listCollectionsSchema = listSchema;
885
960
  var listEntriesSchema = listSchema.extend({
@@ -889,35 +964,35 @@ var listAssetsSchema = listSchema;
889
964
  var listProjectsSchema = listSchema.omit({
890
965
  projectId: true
891
966
  });
892
- var listGitTagsSchema = z11.object({
893
- path: z11.string()
967
+ var listGitTagsSchema = z12.object({
968
+ path: z12.string()
894
969
  });
895
970
 
896
971
  // src/schema/userSchema.ts
897
- import z12 from "zod";
898
- var UserTypeSchema = z12.enum(["local", "cloud"]);
972
+ import z13 from "zod";
973
+ var UserTypeSchema = z13.enum(["local", "cloud"]);
899
974
  var baseUserSchema = gitSignatureSchema.extend({
900
975
  userType: UserTypeSchema,
901
976
  language: supportedLanguageSchema,
902
- localApi: z12.object({
977
+ localApi: z13.object({
903
978
  /**
904
979
  * If set to true the local API is started whenever Core is initialized
905
980
  */
906
- isEnabled: z12.boolean(),
981
+ isEnabled: z13.boolean(),
907
982
  /**
908
983
  * The port the local API uses
909
984
  */
910
- port: z12.number()
985
+ port: z13.number()
911
986
  })
912
987
  });
913
988
  var localUserSchema = baseUserSchema.extend({
914
- userType: z12.literal(UserTypeSchema.enum.local)
989
+ userType: z13.literal(UserTypeSchema.enum.local)
915
990
  });
916
991
  var cloudUserSchema = baseUserSchema.extend({
917
- userType: z12.literal(UserTypeSchema.enum.cloud),
992
+ userType: z13.literal(UserTypeSchema.enum.cloud),
918
993
  id: uuidSchema
919
994
  });
920
- var userFileSchema = z12.union([localUserSchema, cloudUserSchema]);
995
+ var userFileSchema = z13.union([localUserSchema, cloudUserSchema]);
921
996
  var userSchema = userFileSchema;
922
997
  var setUserSchema = userSchema;
923
998
 
@@ -994,8 +1069,10 @@ export {
994
1069
  fieldDefinitionSchema,
995
1070
  fileReferenceSchema,
996
1071
  getChangesProjectSchema,
1072
+ getCreateEntrySchemaFromFieldDefinitions,
997
1073
  getRemoteOriginUrlProjectSchema,
998
- getValueContentSchemaFromFieldDefinition,
1074
+ getUpdateEntrySchemaFromFieldDefinitions,
1075
+ getValueSchemaFromFieldDefinition,
999
1076
  gitCloneOptionsSchema,
1000
1077
  gitCommitSchema,
1001
1078
  gitInitOptionsSchema,