@punks/backend-entity-manager 0.0.378 → 0.0.380

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,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  export type EntryValidationError = {
3
3
  errorCode: string;
4
+ value?: any;
4
5
  };
5
6
  export type EntryValidationResult = {
6
7
  isValid: boolean;
@@ -11,6 +12,7 @@ export type ImportEntryValidationError = {
11
12
  column: {
12
13
  name: string;
13
14
  key: string;
15
+ value?: any;
14
16
  };
15
17
  };
16
18
  export type ImportEntryValidationResult = {
@@ -1,4 +1,4 @@
1
1
  export { getLocalizedText } from "./localization";
2
2
  export { renderHandlebarsTemplate } from "./rendering";
3
3
  export { newUuid } from "./uid";
4
- export { fieldRequiredValidator } from "./validators";
4
+ export { fieldRequiredValidator, fieldOptionValidator, fieldOptionsValidator, } from "./validators";
@@ -1,2 +1,11 @@
1
1
  import { EntryValidationResult } from "../abstractions/serializer";
2
2
  export declare const fieldRequiredValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => any) => EntryValidationResult;
3
+ export declare const fieldOptionValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => string, { availableOptions, required, }: {
4
+ availableOptions: string[];
5
+ required?: boolean | undefined;
6
+ }) => EntryValidationResult;
7
+ export declare const fieldOptionsValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => string[], { availableOptions, minSelected, maxSelected, }: {
8
+ availableOptions: string[];
9
+ minSelected?: number | undefined;
10
+ maxSelected?: number | undefined;
11
+ }) => EntryValidationResult;
package/dist/esm/index.js CHANGED
@@ -257,13 +257,16 @@ class EntitySerializer {
257
257
  for (const validator of column.validators ?? []) {
258
258
  const result = validator.fn(entity);
259
259
  if (!result.isValid) {
260
- validationErrors.push({
261
- errorCode: validator.key,
262
- column: {
263
- name: column.name,
264
- key: column.key,
265
- },
266
- });
260
+ for (const error of result.validationErrors) {
261
+ validationErrors.push({
262
+ errorCode: error.errorCode,
263
+ column: {
264
+ name: column.name,
265
+ key: column.key,
266
+ value: error.value,
267
+ },
268
+ });
269
+ }
267
270
  }
268
271
  }
269
272
  }
@@ -40706,6 +40709,43 @@ const fieldRequiredValidator = (item, selector) => {
40706
40709
  validationErrors: value ? [] : [{ errorCode: "required" }],
40707
40710
  };
40708
40711
  };
40712
+ const fieldOptionValidator = (item, selector, { availableOptions, required, }) => {
40713
+ const value = selector(item);
40714
+ if (!value) {
40715
+ return {
40716
+ isValid: true,
40717
+ validationErrors: [],
40718
+ };
40719
+ }
40720
+ const errors = [];
40721
+ const isValidOption = availableOptions.includes(value);
40722
+ if (!isValidOption) {
40723
+ errors.push({ errorCode: "invalidOption" });
40724
+ }
40725
+ if (required && !value) {
40726
+ errors.push({ errorCode: "required" });
40727
+ }
40728
+ return {
40729
+ isValid: errors.length === 0,
40730
+ validationErrors: errors,
40731
+ };
40732
+ };
40733
+ const fieldOptionsValidator = (item, selector, { availableOptions, minSelected, maxSelected, }) => {
40734
+ const values = selector(item);
40735
+ const errors = [];
40736
+ const invalidOptions = values.filter((x) => !availableOptions.includes(x));
40737
+ invalidOptions.forEach((x) => errors.push({ errorCode: "invalidOption", value: x }));
40738
+ if (minSelected && values.length < minSelected) {
40739
+ errors.push({ errorCode: "minSelected" });
40740
+ }
40741
+ if (maxSelected && values.length > maxSelected) {
40742
+ errors.push({ errorCode: "maxSelected" });
40743
+ }
40744
+ return {
40745
+ isValid: errors.length === 0,
40746
+ validationErrors: errors,
40747
+ };
40748
+ };
40709
40749
 
40710
40750
  const createClient$2 = (settings) => new SESClient({
40711
40751
  region: settings.region,
@@ -44716,5 +44756,5 @@ class TestingAppSessionService {
44716
44756
  }
44717
44757
  }
44718
44758
 
44719
- export { AUTHENTICATION_EVENTS_NAMESPACE, ApiKeyAccess, AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSession, AppSessionMiddleware, AppSessionService, AuthGuard, Authenticated, AuthenticationEmailTemplates, AuthenticationError, AuthenticationEvents, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsBucketModule, AwsDynamoDbModule, AwsEmailModule, AwsJobsModule, AwsS3BucketError, AwsS3BucketProvider, AwsS3MediaError, AwsS3MediaModule, AwsS3MediaProvider, AwsSecretsModule, AwsSecretsProvider, AwsSesEmailTemplate, BucketItemType, CacheService, ConnectorMode, CurrentUser, CustomDiscoveryModule, CustomDiscoveryService, DynamoDbCacheInstance, DynamoDbCollection, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EntityParseResult, EntityParseValidationError, EntitySeeder, EntitySerializationFormat, EntitySerializer, EntitySnapshotService, EntityVersionOperation, EventsService, ExclusiveOperationResult, FilesManager, IEntityVersionsCursor, InMemoryBucketProvider, InMemoryEmailProvider, InMemoryFileProvider, InMemoryMediaProvider, InMemorySecretsProvider, InvalidCredentialsError, JobConcurrency, JobInstance, JobProviderState, JobRunType, JobSchedule, JobStatus, JobsModule, JobsService, LockNotFoundError, MediaLibraryService, MemberOf, MissingEntityIdError, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestEntitySerializer, NestEntitySnapshotService, NestPipelineTemplate, NestTypeOrmEntitySeeder, NestTypeOrmQueryBuilder, NestTypeOrmRepository, OperationLockService, OperationTokenMismatchError, PLATFORM_EVENT_NAMESPACE, Permissions, PipelineController, PipelineErrorType, PipelineInvocationError, PipelineStatus, PipelineStepErrorType, PipelinesBuilder, PipelinesRunner, PlatformEvents, Public, QueryBuilderBase, QueryBuilderOperation, ReplicationMode, Roles, SanityMediaError, SanityMediaModule, SanityMediaProvider, SecretsService, SendgridEmailModule, SendgridEmailTemplate, SortDirection, TaskConcurrency, TaskRunType, TasksModule, TasksService, TestingAppSessionService, TrackingService, TypeOrmQueryBuilder, TypeOrmRepository, TypeormCacheInstance, TypeormOperationLockRepository, UserCreationError, UserRegistrationError, WpApiKeysService, WpAppInitializer, WpAwsSesEmailTemplate, WpBucketProvider, WpCacheInstance, WpEmailLogger, WpEmailProvider, WpEmailTemplate, WpEmailTemplateMiddleware, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConnectorMapper, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpEntitySeeder, WpEntitySerializer, WpEntitySnapshotService, WpEntityVersioningProvider, WpEventsTracker, WpFileProvider, WpFileReferenceRepository, WpGlobalAuthenticationMiddleware, WpMediaFolderRepository, WpMediaProvider, WpMediaReferenceRepository, WpPermissionsService, WpPipeline, WpRolesService, WpSendgridEmailTemplate, WpTask, WpUserRolesService, WpUserService, awsBatchSettings, buildPermissionsGuard, buildProviderToken, buildRolesGuard, createContainer, createExpressFileResponse, fieldRequiredValidator, getEntityManagerProviderToken, getLocalizedText, newUuid, renderHandlebarsTemplate, sessionStorage, toEntitiesImportInput };
44759
+ export { AUTHENTICATION_EVENTS_NAMESPACE, ApiKeyAccess, AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSession, AppSessionMiddleware, AppSessionService, AuthGuard, Authenticated, AuthenticationEmailTemplates, AuthenticationError, AuthenticationEvents, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsBucketModule, AwsDynamoDbModule, AwsEmailModule, AwsJobsModule, AwsS3BucketError, AwsS3BucketProvider, AwsS3MediaError, AwsS3MediaModule, AwsS3MediaProvider, AwsSecretsModule, AwsSecretsProvider, AwsSesEmailTemplate, BucketItemType, CacheService, ConnectorMode, CurrentUser, CustomDiscoveryModule, CustomDiscoveryService, DynamoDbCacheInstance, DynamoDbCollection, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EntityParseResult, EntityParseValidationError, EntitySeeder, EntitySerializationFormat, EntitySerializer, EntitySnapshotService, EntityVersionOperation, EventsService, ExclusiveOperationResult, FilesManager, IEntityVersionsCursor, InMemoryBucketProvider, InMemoryEmailProvider, InMemoryFileProvider, InMemoryMediaProvider, InMemorySecretsProvider, InvalidCredentialsError, JobConcurrency, JobInstance, JobProviderState, JobRunType, JobSchedule, JobStatus, JobsModule, JobsService, LockNotFoundError, MediaLibraryService, MemberOf, MissingEntityIdError, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestEntitySerializer, NestEntitySnapshotService, NestPipelineTemplate, NestTypeOrmEntitySeeder, NestTypeOrmQueryBuilder, NestTypeOrmRepository, OperationLockService, OperationTokenMismatchError, PLATFORM_EVENT_NAMESPACE, Permissions, PipelineController, PipelineErrorType, PipelineInvocationError, PipelineStatus, PipelineStepErrorType, PipelinesBuilder, PipelinesRunner, PlatformEvents, Public, QueryBuilderBase, QueryBuilderOperation, ReplicationMode, Roles, SanityMediaError, SanityMediaModule, SanityMediaProvider, SecretsService, SendgridEmailModule, SendgridEmailTemplate, SortDirection, TaskConcurrency, TaskRunType, TasksModule, TasksService, TestingAppSessionService, TrackingService, TypeOrmQueryBuilder, TypeOrmRepository, TypeormCacheInstance, TypeormOperationLockRepository, UserCreationError, UserRegistrationError, WpApiKeysService, WpAppInitializer, WpAwsSesEmailTemplate, WpBucketProvider, WpCacheInstance, WpEmailLogger, WpEmailProvider, WpEmailTemplate, WpEmailTemplateMiddleware, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConnectorMapper, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpEntitySeeder, WpEntitySerializer, WpEntitySnapshotService, WpEntityVersioningProvider, WpEventsTracker, WpFileProvider, WpFileReferenceRepository, WpGlobalAuthenticationMiddleware, WpMediaFolderRepository, WpMediaProvider, WpMediaReferenceRepository, WpPermissionsService, WpPipeline, WpRolesService, WpSendgridEmailTemplate, WpTask, WpUserRolesService, WpUserService, awsBatchSettings, buildPermissionsGuard, buildProviderToken, buildRolesGuard, createContainer, createExpressFileResponse, fieldOptionValidator, fieldOptionsValidator, fieldRequiredValidator, getEntityManagerProviderToken, getLocalizedText, newUuid, renderHandlebarsTemplate, sessionStorage, toEntitiesImportInput };
44720
44760
  //# sourceMappingURL=index.js.map