@sprucelabs/schema 27.1.71 → 28.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.
Files changed (35) hide show
  1. package/build/.spruce/schemas/fields/fieldClassMap.d.ts +2 -0
  2. package/build/.spruce/schemas/fields/fieldClassMap.js +17 -15
  3. package/build/.spruce/schemas/fields/fields.types.d.ts +51 -47
  4. package/build/addons/imageField.addon.d.ts +2 -0
  5. package/build/addons/imageField.addon.js +13 -0
  6. package/build/esm/.spruce/schemas/fields/fieldClassMap.d.ts +2 -0
  7. package/build/esm/.spruce/schemas/fields/fieldClassMap.js +17 -15
  8. package/build/esm/.spruce/schemas/fields/fields.types.d.ts +51 -47
  9. package/build/esm/addons/imageField.addon.d.ts +2 -0
  10. package/build/esm/addons/imageField.addon.js +8 -0
  11. package/build/esm/fields/AbstractField.d.ts +3 -3
  12. package/build/esm/fields/AbstractField.js +1 -1
  13. package/build/esm/fields/FileField.d.ts +2 -3
  14. package/build/esm/fields/FileField.js +11 -102
  15. package/build/esm/fields/FileField.types.d.ts +7 -17
  16. package/build/esm/fields/FileField.types.js +6 -0
  17. package/build/esm/fields/ImageField.d.ts +8 -0
  18. package/build/esm/fields/ImageField.js +41 -0
  19. package/build/esm/fields/ImageField.types.d.ts +21 -0
  20. package/build/esm/fields/ImageField.types.js +10 -0
  21. package/build/esm/fields/index.d.ts +2 -0
  22. package/build/esm/fields/index.js +2 -0
  23. package/build/fields/AbstractField.d.ts +3 -3
  24. package/build/fields/AbstractField.js +1 -1
  25. package/build/fields/FileField.d.ts +2 -3
  26. package/build/fields/FileField.js +11 -102
  27. package/build/fields/FileField.types.d.ts +7 -17
  28. package/build/fields/FileField.types.js +6 -0
  29. package/build/fields/ImageField.d.ts +8 -0
  30. package/build/fields/ImageField.js +47 -0
  31. package/build/fields/ImageField.types.d.ts +21 -0
  32. package/build/fields/ImageField.types.js +13 -0
  33. package/build/fields/index.d.ts +2 -0
  34. package/build/fields/index.js +4 -1
  35. package/package.json +6 -9
@@ -13,6 +13,7 @@ import SchemaField from '../../../fields/SchemaField';
13
13
  import SelectField from '../../../fields/SelectField';
14
14
  import TextField from '../../../fields/TextField';
15
15
  import EmailField from '../../../fields/EmailField';
16
+ import ImageField from '../../../fields/ImageField';
16
17
  declare const fieldClassMap: {
17
18
  readonly boolean: typeof BooleanField;
18
19
  readonly select: typeof SelectField;
@@ -29,5 +30,6 @@ declare const fieldClassMap: {
29
30
  readonly date: typeof DateField;
30
31
  readonly directory: typeof DirectoryField;
31
32
  readonly email: typeof EmailField;
33
+ readonly image: typeof ImageField;
32
34
  };
33
35
  export default fieldClassMap;
@@ -18,21 +18,23 @@ const SchemaField_1 = __importDefault(require("../../../fields/SchemaField"));
18
18
  const SelectField_1 = __importDefault(require("../../../fields/SelectField"));
19
19
  const TextField_1 = __importDefault(require("../../../fields/TextField"));
20
20
  const EmailField_1 = __importDefault(require("../../../fields/EmailField"));
21
+ const ImageField_1 = __importDefault(require("../../../fields/ImageField"));
21
22
  const fieldClassMap = {
22
- ['boolean']: BooleanField_1.default,
23
- ['select']: SelectField_1.default,
24
- ['duration']: DurationField_1.default,
25
- ['id']: IdField_1.default,
26
- ['address']: AddressField_1.default,
27
- ['phone']: PhoneField_1.default,
28
- ['schema']: SchemaField_1.default,
29
- ['raw']: RawField_1.default,
30
- ['number']: NumberField_1.default,
31
- ['dateTime']: DateTimeField_1.default,
32
- ['text']: TextField_1.default,
33
- ['file']: FileField_1.default,
34
- ['date']: DateField_1.default,
35
- ['directory']: DirectoryField_1.default,
36
- ['email']: EmailField_1.default
23
+ boolean: BooleanField_1.default,
24
+ select: SelectField_1.default,
25
+ duration: DurationField_1.default,
26
+ id: IdField_1.default,
27
+ address: AddressField_1.default,
28
+ phone: PhoneField_1.default,
29
+ schema: SchemaField_1.default,
30
+ raw: RawField_1.default,
31
+ number: NumberField_1.default,
32
+ dateTime: DateTimeField_1.default,
33
+ text: TextField_1.default,
34
+ file: FileField_1.default,
35
+ date: DateField_1.default,
36
+ directory: DirectoryField_1.default,
37
+ email: EmailField_1.default,
38
+ image: ImageField_1.default
37
39
  };
38
40
  exports.default = fieldClassMap;
@@ -8,62 +8,66 @@ import { EmailFieldDefinition } from '../../../fields/EmailField.types';
8
8
  import { Field } from '../../../fields/field.static.types';
9
9
  import { FileFieldDefinition } from '../../../fields/FileField.types';
10
10
  import { IdFieldDefinition } from '../../../fields/IdField.types';
11
+ import { ImageFieldDefinition } from '../../../fields/ImageField.types';
11
12
  import { NumberFieldDefinition } from '../../../fields/NumberField.types';
12
13
  import { PhoneFieldDefinition } from '../../../fields/PhoneField.types';
13
14
  import { RawFieldDefinition } from '../../../fields/RawField.types';
14
15
  import { SchemaFieldFieldDefinition, SchemaFieldValueTypeMapper } from '../../../fields/SchemaField.types';
15
16
  import { SelectFieldDefinition, SelectFieldValueTypeMapper } from '../../../fields/SelectField.types';
16
17
  import { TextFieldDefinition } from '../../../fields/TextField.types';
17
- export declare type FieldDefinitions = BooleanFieldDefinition | SelectFieldDefinition | DurationFieldDefinition | IdFieldDefinition | TextFieldDefinition | AddressFieldDefinition | PhoneFieldDefinition | SchemaFieldFieldDefinition | RawFieldDefinition | NumberFieldDefinition | DateTimeFieldDefinition | FileFieldDefinition | DateFieldDefinition | DirectoryFieldDefinition | EmailFieldDefinition;
18
- export declare type Fields = Field<BooleanFieldDefinition> | Field<SelectFieldDefinition> | Field<DurationFieldDefinition> | Field<IdFieldDefinition> | Field<TextFieldDefinition> | Field<AddressFieldDefinition> | Field<PhoneFieldDefinition> | Field<SchemaFieldFieldDefinition> | Field<RawFieldDefinition> | Field<NumberFieldDefinition> | Field<DateTimeFieldDefinition> | Field<FileFieldDefinition> | Field<DateFieldDefinition> | Field<DirectoryFieldDefinition> | Field<EmailFieldDefinition>;
18
+ export declare type FieldDefinitions = BooleanFieldDefinition | SelectFieldDefinition | DurationFieldDefinition | IdFieldDefinition | TextFieldDefinition | AddressFieldDefinition | PhoneFieldDefinition | SchemaFieldFieldDefinition | RawFieldDefinition | NumberFieldDefinition | DateTimeFieldDefinition | FileFieldDefinition | DateFieldDefinition | DirectoryFieldDefinition | EmailFieldDefinition | ImageFieldDefinition;
19
+ export declare type Fields = Field<BooleanFieldDefinition> | Field<SelectFieldDefinition> | Field<DurationFieldDefinition> | Field<IdFieldDefinition> | Field<TextFieldDefinition> | Field<AddressFieldDefinition> | Field<PhoneFieldDefinition> | Field<SchemaFieldFieldDefinition> | Field<RawFieldDefinition> | Field<NumberFieldDefinition> | Field<DateTimeFieldDefinition> | Field<FileFieldDefinition> | Field<DateFieldDefinition> | Field<DirectoryFieldDefinition> | Field<EmailFieldDefinition> | Field<ImageFieldDefinition>;
19
20
  export interface FieldDefinitionMap {
20
- ['boolean']: BooleanFieldDefinition;
21
- ['select']: SelectFieldDefinition;
22
- ['duration']: DurationFieldDefinition;
23
- ['id']: IdFieldDefinition;
24
- ['text']: TextFieldDefinition;
25
- ['address']: AddressFieldDefinition;
26
- ['phone']: PhoneFieldDefinition;
27
- ['schema']: SchemaFieldFieldDefinition;
28
- ['raw']: RawFieldDefinition;
29
- ['number']: NumberFieldDefinition;
30
- ['dateTime']: DateTimeFieldDefinition;
31
- ['file']: FileFieldDefinition;
32
- ['date']: DateFieldDefinition;
33
- ['directory']: DirectoryFieldDefinition;
34
- ['email']: EmailFieldDefinition;
21
+ boolean: BooleanFieldDefinition;
22
+ select: SelectFieldDefinition;
23
+ duration: DurationFieldDefinition;
24
+ id: IdFieldDefinition;
25
+ text: TextFieldDefinition;
26
+ address: AddressFieldDefinition;
27
+ phone: PhoneFieldDefinition;
28
+ schema: SchemaFieldFieldDefinition;
29
+ raw: RawFieldDefinition;
30
+ number: NumberFieldDefinition;
31
+ dateTime: DateTimeFieldDefinition;
32
+ file: FileFieldDefinition;
33
+ date: DateFieldDefinition;
34
+ directory: DirectoryFieldDefinition;
35
+ email: EmailFieldDefinition;
36
+ image: ImageFieldDefinition;
35
37
  }
36
38
  export interface FieldValueTypeGeneratorMap<F extends FieldDefinitions, CreateEntityInstances extends boolean> {
37
- ['boolean']: BooleanFieldDefinition['value'];
38
- ['select']: SelectFieldValueTypeMapper<F extends SelectFieldDefinition ? F : SelectFieldDefinition>;
39
- ['duration']: DurationFieldDefinition['value'];
40
- ['id']: IdFieldDefinition['value'];
41
- ['text']: TextFieldDefinition['value'];
42
- ['address']: AddressFieldDefinition['value'];
43
- ['phone']: PhoneFieldDefinition['value'];
44
- ['schema']: SchemaFieldValueTypeMapper<F extends SchemaFieldFieldDefinition ? F : SchemaFieldFieldDefinition, CreateEntityInstances>;
45
- ['raw']: RawFieldDefinition['value'];
46
- ['number']: NumberFieldDefinition['value'];
47
- ['dateTime']: DateTimeFieldDefinition['value'];
48
- ['file']: FileFieldDefinition['value'];
49
- ['date']: DateFieldDefinition['value'];
50
- ['directory']: DirectoryFieldDefinition['value'];
51
- ['email']: EmailFieldDefinition['value'];
39
+ boolean: BooleanFieldDefinition['value'];
40
+ select: SelectFieldValueTypeMapper<F extends SelectFieldDefinition ? F : SelectFieldDefinition>;
41
+ duration: DurationFieldDefinition['value'];
42
+ id: IdFieldDefinition['value'];
43
+ text: TextFieldDefinition['value'];
44
+ address: AddressFieldDefinition['value'];
45
+ phone: PhoneFieldDefinition['value'];
46
+ schema: SchemaFieldValueTypeMapper<F extends SchemaFieldFieldDefinition ? F : SchemaFieldFieldDefinition, CreateEntityInstances>;
47
+ raw: RawFieldDefinition['value'];
48
+ number: NumberFieldDefinition['value'];
49
+ dateTime: DateTimeFieldDefinition['value'];
50
+ file: FileFieldDefinition['value'];
51
+ date: DateFieldDefinition['value'];
52
+ directory: DirectoryFieldDefinition['value'];
53
+ email: EmailFieldDefinition['value'];
54
+ image: ImageFieldDefinition['value'];
52
55
  }
53
56
  export interface FieldMap {
54
- ['boolean']: Field<BooleanFieldDefinition>;
55
- ['select']: Field<SelectFieldDefinition>;
56
- ['duration']: Field<DurationFieldDefinition>;
57
- ['id']: Field<IdFieldDefinition>;
58
- ['text']: Field<TextFieldDefinition>;
59
- ['address']: Field<AddressFieldDefinition>;
60
- ['phone']: Field<PhoneFieldDefinition>;
61
- ['schema']: Field<SchemaFieldFieldDefinition>;
62
- ['raw']: Field<RawFieldDefinition>;
63
- ['number']: Field<NumberFieldDefinition>;
64
- ['dateTime']: Field<DateTimeFieldDefinition>;
65
- ['file']: Field<FileFieldDefinition>;
66
- ['date']: Field<DateFieldDefinition>;
67
- ['directory']: Field<DirectoryFieldDefinition>;
68
- ['email']: Field<EmailFieldDefinition>;
57
+ boolean: Field<BooleanFieldDefinition>;
58
+ select: Field<SelectFieldDefinition>;
59
+ duration: Field<DurationFieldDefinition>;
60
+ id: Field<IdFieldDefinition>;
61
+ text: Field<TextFieldDefinition>;
62
+ address: Field<AddressFieldDefinition>;
63
+ phone: Field<PhoneFieldDefinition>;
64
+ schema: Field<SchemaFieldFieldDefinition>;
65
+ raw: Field<RawFieldDefinition>;
66
+ number: Field<NumberFieldDefinition>;
67
+ dateTime: Field<DateTimeFieldDefinition>;
68
+ file: Field<FileFieldDefinition>;
69
+ date: Field<DateFieldDefinition>;
70
+ directory: Field<DirectoryFieldDefinition>;
71
+ email: Field<EmailFieldDefinition>;
72
+ image: Field<ImageFieldDefinition>;
69
73
  }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../utilities/registerFieldType").FieldRegistration;
2
+ export default _default;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const ImageField_1 = __importDefault(require("../fields/ImageField"));
7
+ const registerFieldType_1 = __importDefault(require("../utilities/registerFieldType"));
8
+ exports.default = (0, registerFieldType_1.default)({
9
+ type: 'Image',
10
+ class: ImageField_1.default,
11
+ package: '@sprucelabs/schema',
12
+ importAs: 'SpruceSchema',
13
+ });
@@ -13,6 +13,7 @@ import SchemaField from '../../../fields/SchemaField';
13
13
  import SelectField from '../../../fields/SelectField';
14
14
  import TextField from '../../../fields/TextField';
15
15
  import EmailField from '../../../fields/EmailField';
16
+ import ImageField from '../../../fields/ImageField';
16
17
  declare const fieldClassMap: {
17
18
  readonly boolean: typeof BooleanField;
18
19
  readonly select: typeof SelectField;
@@ -29,5 +30,6 @@ declare const fieldClassMap: {
29
30
  readonly date: typeof DateField;
30
31
  readonly directory: typeof DirectoryField;
31
32
  readonly email: typeof EmailField;
33
+ readonly image: typeof ImageField;
32
34
  };
33
35
  export default fieldClassMap;
@@ -13,21 +13,23 @@ import SchemaField from '../../../fields/SchemaField.js';
13
13
  import SelectField from '../../../fields/SelectField.js';
14
14
  import TextField from '../../../fields/TextField.js';
15
15
  import EmailField from '../../../fields/EmailField.js';
16
+ import ImageField from '../../../fields/ImageField.js';
16
17
  const fieldClassMap = {
17
- ['boolean']: BooleanField,
18
- ['select']: SelectField,
19
- ['duration']: DurationField,
20
- ['id']: IdField,
21
- ['address']: AddressField,
22
- ['phone']: PhoneField,
23
- ['schema']: SchemaField,
24
- ['raw']: RawField,
25
- ['number']: NumberField,
26
- ['dateTime']: DateTimeField,
27
- ['text']: TextField,
28
- ['file']: FileField,
29
- ['date']: DateField,
30
- ['directory']: DirectoryField,
31
- ['email']: EmailField
18
+ boolean: BooleanField,
19
+ select: SelectField,
20
+ duration: DurationField,
21
+ id: IdField,
22
+ address: AddressField,
23
+ phone: PhoneField,
24
+ schema: SchemaField,
25
+ raw: RawField,
26
+ number: NumberField,
27
+ dateTime: DateTimeField,
28
+ text: TextField,
29
+ file: FileField,
30
+ date: DateField,
31
+ directory: DirectoryField,
32
+ email: EmailField,
33
+ image: ImageField
32
34
  };
33
35
  export default fieldClassMap;
@@ -8,62 +8,66 @@ import { EmailFieldDefinition } from '../../../fields/EmailField.types';
8
8
  import { Field } from '../../../fields/field.static.types';
9
9
  import { FileFieldDefinition } from '../../../fields/FileField.types';
10
10
  import { IdFieldDefinition } from '../../../fields/IdField.types';
11
+ import { ImageFieldDefinition } from '../../../fields/ImageField.types';
11
12
  import { NumberFieldDefinition } from '../../../fields/NumberField.types';
12
13
  import { PhoneFieldDefinition } from '../../../fields/PhoneField.types';
13
14
  import { RawFieldDefinition } from '../../../fields/RawField.types';
14
15
  import { SchemaFieldFieldDefinition, SchemaFieldValueTypeMapper } from '../../../fields/SchemaField.types';
15
16
  import { SelectFieldDefinition, SelectFieldValueTypeMapper } from '../../../fields/SelectField.types';
16
17
  import { TextFieldDefinition } from '../../../fields/TextField.types';
17
- export declare type FieldDefinitions = BooleanFieldDefinition | SelectFieldDefinition | DurationFieldDefinition | IdFieldDefinition | TextFieldDefinition | AddressFieldDefinition | PhoneFieldDefinition | SchemaFieldFieldDefinition | RawFieldDefinition | NumberFieldDefinition | DateTimeFieldDefinition | FileFieldDefinition | DateFieldDefinition | DirectoryFieldDefinition | EmailFieldDefinition;
18
- export declare type Fields = Field<BooleanFieldDefinition> | Field<SelectFieldDefinition> | Field<DurationFieldDefinition> | Field<IdFieldDefinition> | Field<TextFieldDefinition> | Field<AddressFieldDefinition> | Field<PhoneFieldDefinition> | Field<SchemaFieldFieldDefinition> | Field<RawFieldDefinition> | Field<NumberFieldDefinition> | Field<DateTimeFieldDefinition> | Field<FileFieldDefinition> | Field<DateFieldDefinition> | Field<DirectoryFieldDefinition> | Field<EmailFieldDefinition>;
18
+ export declare type FieldDefinitions = BooleanFieldDefinition | SelectFieldDefinition | DurationFieldDefinition | IdFieldDefinition | TextFieldDefinition | AddressFieldDefinition | PhoneFieldDefinition | SchemaFieldFieldDefinition | RawFieldDefinition | NumberFieldDefinition | DateTimeFieldDefinition | FileFieldDefinition | DateFieldDefinition | DirectoryFieldDefinition | EmailFieldDefinition | ImageFieldDefinition;
19
+ export declare type Fields = Field<BooleanFieldDefinition> | Field<SelectFieldDefinition> | Field<DurationFieldDefinition> | Field<IdFieldDefinition> | Field<TextFieldDefinition> | Field<AddressFieldDefinition> | Field<PhoneFieldDefinition> | Field<SchemaFieldFieldDefinition> | Field<RawFieldDefinition> | Field<NumberFieldDefinition> | Field<DateTimeFieldDefinition> | Field<FileFieldDefinition> | Field<DateFieldDefinition> | Field<DirectoryFieldDefinition> | Field<EmailFieldDefinition> | Field<ImageFieldDefinition>;
19
20
  export interface FieldDefinitionMap {
20
- ['boolean']: BooleanFieldDefinition;
21
- ['select']: SelectFieldDefinition;
22
- ['duration']: DurationFieldDefinition;
23
- ['id']: IdFieldDefinition;
24
- ['text']: TextFieldDefinition;
25
- ['address']: AddressFieldDefinition;
26
- ['phone']: PhoneFieldDefinition;
27
- ['schema']: SchemaFieldFieldDefinition;
28
- ['raw']: RawFieldDefinition;
29
- ['number']: NumberFieldDefinition;
30
- ['dateTime']: DateTimeFieldDefinition;
31
- ['file']: FileFieldDefinition;
32
- ['date']: DateFieldDefinition;
33
- ['directory']: DirectoryFieldDefinition;
34
- ['email']: EmailFieldDefinition;
21
+ boolean: BooleanFieldDefinition;
22
+ select: SelectFieldDefinition;
23
+ duration: DurationFieldDefinition;
24
+ id: IdFieldDefinition;
25
+ text: TextFieldDefinition;
26
+ address: AddressFieldDefinition;
27
+ phone: PhoneFieldDefinition;
28
+ schema: SchemaFieldFieldDefinition;
29
+ raw: RawFieldDefinition;
30
+ number: NumberFieldDefinition;
31
+ dateTime: DateTimeFieldDefinition;
32
+ file: FileFieldDefinition;
33
+ date: DateFieldDefinition;
34
+ directory: DirectoryFieldDefinition;
35
+ email: EmailFieldDefinition;
36
+ image: ImageFieldDefinition;
35
37
  }
36
38
  export interface FieldValueTypeGeneratorMap<F extends FieldDefinitions, CreateEntityInstances extends boolean> {
37
- ['boolean']: BooleanFieldDefinition['value'];
38
- ['select']: SelectFieldValueTypeMapper<F extends SelectFieldDefinition ? F : SelectFieldDefinition>;
39
- ['duration']: DurationFieldDefinition['value'];
40
- ['id']: IdFieldDefinition['value'];
41
- ['text']: TextFieldDefinition['value'];
42
- ['address']: AddressFieldDefinition['value'];
43
- ['phone']: PhoneFieldDefinition['value'];
44
- ['schema']: SchemaFieldValueTypeMapper<F extends SchemaFieldFieldDefinition ? F : SchemaFieldFieldDefinition, CreateEntityInstances>;
45
- ['raw']: RawFieldDefinition['value'];
46
- ['number']: NumberFieldDefinition['value'];
47
- ['dateTime']: DateTimeFieldDefinition['value'];
48
- ['file']: FileFieldDefinition['value'];
49
- ['date']: DateFieldDefinition['value'];
50
- ['directory']: DirectoryFieldDefinition['value'];
51
- ['email']: EmailFieldDefinition['value'];
39
+ boolean: BooleanFieldDefinition['value'];
40
+ select: SelectFieldValueTypeMapper<F extends SelectFieldDefinition ? F : SelectFieldDefinition>;
41
+ duration: DurationFieldDefinition['value'];
42
+ id: IdFieldDefinition['value'];
43
+ text: TextFieldDefinition['value'];
44
+ address: AddressFieldDefinition['value'];
45
+ phone: PhoneFieldDefinition['value'];
46
+ schema: SchemaFieldValueTypeMapper<F extends SchemaFieldFieldDefinition ? F : SchemaFieldFieldDefinition, CreateEntityInstances>;
47
+ raw: RawFieldDefinition['value'];
48
+ number: NumberFieldDefinition['value'];
49
+ dateTime: DateTimeFieldDefinition['value'];
50
+ file: FileFieldDefinition['value'];
51
+ date: DateFieldDefinition['value'];
52
+ directory: DirectoryFieldDefinition['value'];
53
+ email: EmailFieldDefinition['value'];
54
+ image: ImageFieldDefinition['value'];
52
55
  }
53
56
  export interface FieldMap {
54
- ['boolean']: Field<BooleanFieldDefinition>;
55
- ['select']: Field<SelectFieldDefinition>;
56
- ['duration']: Field<DurationFieldDefinition>;
57
- ['id']: Field<IdFieldDefinition>;
58
- ['text']: Field<TextFieldDefinition>;
59
- ['address']: Field<AddressFieldDefinition>;
60
- ['phone']: Field<PhoneFieldDefinition>;
61
- ['schema']: Field<SchemaFieldFieldDefinition>;
62
- ['raw']: Field<RawFieldDefinition>;
63
- ['number']: Field<NumberFieldDefinition>;
64
- ['dateTime']: Field<DateTimeFieldDefinition>;
65
- ['file']: Field<FileFieldDefinition>;
66
- ['date']: Field<DateFieldDefinition>;
67
- ['directory']: Field<DirectoryFieldDefinition>;
68
- ['email']: Field<EmailFieldDefinition>;
57
+ boolean: Field<BooleanFieldDefinition>;
58
+ select: Field<SelectFieldDefinition>;
59
+ duration: Field<DurationFieldDefinition>;
60
+ id: Field<IdFieldDefinition>;
61
+ text: Field<TextFieldDefinition>;
62
+ address: Field<AddressFieldDefinition>;
63
+ phone: Field<PhoneFieldDefinition>;
64
+ schema: Field<SchemaFieldFieldDefinition>;
65
+ raw: Field<RawFieldDefinition>;
66
+ number: Field<NumberFieldDefinition>;
67
+ dateTime: Field<DateTimeFieldDefinition>;
68
+ file: Field<FileFieldDefinition>;
69
+ date: Field<DateFieldDefinition>;
70
+ directory: Field<DirectoryFieldDefinition>;
71
+ email: Field<EmailFieldDefinition>;
72
+ image: Field<ImageFieldDefinition>;
69
73
  }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../utilities/registerFieldType").FieldRegistration;
2
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import ImageField from '../fields/ImageField.js';
2
+ import registerFieldType from '../utilities/registerFieldType.js';
3
+ export default registerFieldType({
4
+ type: 'Image',
5
+ class: ImageField,
6
+ package: '@sprucelabs/schema',
7
+ importAs: 'SpruceSchema',
8
+ });
@@ -32,11 +32,11 @@ export default abstract class AbstractField<F extends FieldDefinitions> implemen
32
32
  } | {
33
33
  dateTimeFormat?: string | undefined;
34
34
  } | {
35
- acceptableTypes?: string[] | undefined;
36
- maxSize?: string | undefined;
37
- relativeTo?: string | undefined;
35
+ acceptableTypes: ("image/png" | "image/jpeg" | "application/pdf" | "*")[];
38
36
  } | {
39
37
  relativeTo?: string | undefined;
38
+ } | {
39
+ requiredSizes: ("s" | "*" | "xxs" | "xs" | "m" | "l" | "xl" | "xxl")[];
40
40
  } | undefined;
41
41
  get isRequired(): boolean;
42
42
  get isPrivate(): boolean;
@@ -32,7 +32,7 @@ public static get description() {
32
32
  instructions: `Copy and paste this into ${this.name}:
33
33
 
34
34
  public static generateTemplateDetails(
35
- options: IFieldTemplateDetailOptions<I{{YourFieldName}}Definition>
35
+ options: FieldTemplateDetailOptions<{{YourFieldName}}Definition>
36
36
  ): IFieldTemplateDetails {
37
37
  const { definition } = options
38
38
  return {
@@ -6,7 +6,6 @@ import { FileFieldDefinition, FileFieldValue } from './FileField.types';
6
6
  export default class FileField extends AbstractField<FileFieldDefinition> {
7
7
  static get description(): string;
8
8
  static generateTemplateDetails(options: FieldTemplateDetailOptions<FileFieldDefinition>): FieldTemplateDetails;
9
- validate(value: any, _?: ValidateOptions<FileFieldDefinition>): FieldError[];
10
- /** Take a range of possible values and transform it into a IFileFieldValue */
11
- toValueType<C extends boolean>(value: any, options?: ToValueTypeOptions<FileFieldDefinition, C>): FileFieldValue;
9
+ validate(value: FileFieldValue, _?: ValidateOptions<FileFieldDefinition>): FieldError[];
10
+ toValueType<C extends boolean>(value: any, _options?: ToValueTypeOptions<FileFieldDefinition, C>): FileFieldValue;
12
11
  }
@@ -1,121 +1,30 @@
1
- import SpruceError from '../errors/SpruceError.js';
2
1
  import AbstractField from './AbstractField.js';
3
- let mimeInstance;
4
- function mime() {
5
- if (!mimeInstance) {
6
- const mimeDb = require('mime-db');
7
- const Mime = require('mime-type').default;
8
- mimeInstance = new Mime(mimeDb, 2);
9
- mimeInstance.define('application/typescript', {
10
- source: 'spruce',
11
- extensions: ['ts', 'tsx'],
12
- });
13
- }
14
- return mimeInstance;
15
- }
16
2
  export default class FileField extends AbstractField {
17
3
  static get description() {
18
4
  return 'A way to handle files. Supports mime-type lookups.';
19
5
  }
20
6
  static generateTemplateDetails(options) {
21
7
  return {
22
- valueType: `${options.importAs}.IFileFieldValue${options.definition.isArray ? '[]' : ''}`,
8
+ valueType: `${options.importAs}.FileFieldValue${options.definition.isArray ? '[]' : ''}`,
23
9
  };
24
10
  }
25
11
  validate(value, _) {
26
- const errors = [];
27
- try {
28
- const file = this.toValueType(value);
29
- if (!file.ext && file.path) {
30
- // eslint-disable-next-line @typescript-eslint/no-var-requires
31
- const fsUtil = require('fs');
32
- // if this file has no extension, lets see if it's a directory
33
- const isDirExists = fsUtil.existsSync(file.path) &&
34
- fsUtil.lstatSync(file.path).isDirectory();
35
- if (isDirExists) {
36
- errors.push({
37
- code: 'INVALID_PARAMETER',
38
- friendlyMessage: `${file.path} is not a directory!`,
39
- name: this.name,
40
- });
41
- }
42
- }
43
- }
44
- catch (err) {
12
+ var _a, _b, _c;
13
+ const errors = super.validate(value);
14
+ const acceptableTypes = (_b = (_a = this.definition.options) === null || _a === void 0 ? void 0 : _a.acceptableTypes) !== null && _b !== void 0 ? _b : [];
15
+ if (value &&
16
+ !value.base64 &&
17
+ acceptableTypes[0] !== '*' &&
18
+ acceptableTypes.indexOf(value.type) === -1) {
45
19
  errors.push({
46
20
  code: 'INVALID_PARAMETER',
47
- originalError: err,
48
21
  name: this.name,
49
- friendlyMessage: err.message,
22
+ friendlyMessage: `You sent a '${value.type}' to '${(_c = this.label) !== null && _c !== void 0 ? _c : this.name}' and it only accepts '${acceptableTypes.join("', '")}'.`,
50
23
  });
51
24
  }
52
25
  return errors;
53
26
  }
54
- /** Take a range of possible values and transform it into a IFileFieldValue */
55
- toValueType(value, options) {
56
- let stringValue = typeof value === 'string' || value.toString ? value.toString() : undefined;
57
- const relativeTo = options === null || options === void 0 ? void 0 : options.relativeTo;
58
- let path;
59
- let name;
60
- let ext;
61
- let type;
62
- if (typeof value === 'object') {
63
- path = typeof value.path === 'string' ? value.path : undefined;
64
- name = typeof value.name === 'string' ? value.name : undefined;
65
- ext = typeof value.ext === 'string' ? value.ext : undefined;
66
- type = typeof value.type === 'string' ? value.type : undefined;
67
- // Use the name, fallback to path for looking up additional details
68
- stringValue = name || path;
69
- }
70
- // eslint-disable-next-line @typescript-eslint/no-var-requires
71
- const pathUtil = require('path');
72
- const dirname = pathUtil.sep === '/' ? pathUtil.dirname : pathUtil.win32.dirname;
73
- // Check if path is the full file path
74
- if (path) {
75
- const parts = pathUtil.parse(path);
76
- // If it is then we should just get the directory name and set it to path
77
- if (parts.ext.length > 0) {
78
- path = dirname(path);
79
- }
80
- }
81
- else if (!path) {
82
- // Try to pull the path off the value
83
- path =
84
- stringValue.indexOf(pathUtil.sep) > -1
85
- ? dirname(stringValue)
86
- : undefined;
87
- }
88
- name = name !== null && name !== void 0 ? name : stringValue.replace(path, '').replace(pathUtil.sep, '');
89
- if (!name) {
90
- throw new SpruceError({
91
- code: 'TRANSFORMATION_ERROR',
92
- fieldType: 'file',
93
- incomingTypeof: typeof value,
94
- incomingValue: value,
95
- name: this.name,
96
- });
97
- }
98
- ext = ext !== null && ext !== void 0 ? ext : pathUtil.extname(name);
99
- if (!type) {
100
- const m = mime();
101
- const lookupResults = m.lookup(name);
102
- if (Array.isArray(lookupResults)) {
103
- type = lookupResults.pop();
104
- }
105
- else {
106
- type = lookupResults;
107
- }
108
- }
109
- if (relativeTo && path) {
110
- // eslint-disable-next-line @typescript-eslint/no-var-requires
111
- const pathUtil = require('path');
112
- path = pathUtil.relative(relativeTo, path) || path;
113
- }
114
- return {
115
- name,
116
- path,
117
- type,
118
- ext,
119
- };
27
+ toValueType(value, _options) {
28
+ return value;
120
29
  }
121
30
  }
@@ -1,27 +1,17 @@
1
1
  import { FieldDefinition } from './field.static.types';
2
+ declare const supportedTypes: readonly ["image/png", "image/jpeg", "application/pdf", "*"];
3
+ export declare type SupportedFileType = typeof supportedTypes[number];
2
4
  export interface FileFieldValue {
3
- /** Date last modified */
4
- lastModified?: Date;
5
- /** The name of the file */
6
5
  name: string;
7
- /** The size of the file if we are able to load it locally */
8
- size?: number;
9
- /** The mime type of the file */
10
- type?: string;
11
- /** The path to the file if local */
12
- path?: string;
13
- /** The file extension */
14
- ext?: string;
6
+ type?: SupportedFileType;
7
+ uri?: string;
8
+ base64?: string;
15
9
  }
16
10
  export declare type FileFieldDefinition = FieldDefinition<FileFieldValue> & {
17
11
  /** * .File - a great way to deal with file management */
18
12
  type: 'file';
19
13
  options?: {
20
- /** Which mime types are acceptable? */
21
- acceptableTypes?: string[];
22
- /** What is the biggest this file can be? */
23
- maxSize?: string;
24
- /** All paths will be generated to this directory, if possible */
25
- relativeTo?: string;
14
+ acceptableTypes: SupportedFileType[];
26
15
  };
27
16
  };
17
+ export {};
@@ -1 +1,7 @@
1
+ const supportedTypes = [
2
+ 'image/png',
3
+ 'image/jpeg',
4
+ 'application/pdf',
5
+ '*',
6
+ ];
1
7
  export {};
@@ -0,0 +1,8 @@
1
+ import { FieldTemplateDetailOptions, FieldTemplateDetails } from '../types/template.types';
2
+ import AbstractField from './AbstractField';
3
+ import { ImageFieldDefinition, ImageFieldValue } from './ImageField.types';
4
+ export default class ImageField extends AbstractField<ImageFieldDefinition> {
5
+ static generateTemplateDetails(options: FieldTemplateDetailOptions<ImageFieldDefinition>): FieldTemplateDetails;
6
+ validate(value: ImageFieldValue): import("..").FieldError[];
7
+ private getRequiredSizes;
8
+ }
@@ -0,0 +1,41 @@
1
+ import AbstractField from './AbstractField.js';
2
+ import { requiredImageSizes, } from './ImageField.types.js';
3
+ export default class ImageField extends AbstractField {
4
+ static generateTemplateDetails(options) {
5
+ const { definition, importAs } = options;
6
+ return {
7
+ valueType: `${importAs}.ImageFieldValue${definition.isArray ? '[]' : ''}`,
8
+ };
9
+ }
10
+ validate(value) {
11
+ var _a;
12
+ const errors = super.validate(value);
13
+ if (errors.length === 0 && !value.base64) {
14
+ let sizes = this.getRequiredSizes();
15
+ const missing = [];
16
+ for (const size of sizes) {
17
+ const key = `${size}Uri`;
18
+ //@ts-ignore
19
+ if (value && !value[key]) {
20
+ missing.push(key);
21
+ }
22
+ }
23
+ if (missing.length > 0) {
24
+ errors.push({
25
+ code: 'INVALID_PARAMETER',
26
+ name: this.name,
27
+ friendlyMessage: `You need to supply the remaining sizes to upload an image to ${(_a = this.label) !== null && _a !== void 0 ? _a : this.name}: '${missing.join("', '")}'`,
28
+ });
29
+ }
30
+ }
31
+ return errors;
32
+ }
33
+ getRequiredSizes() {
34
+ var _a, _b;
35
+ let sizes = (_b = (_a = this.definition.options) === null || _a === void 0 ? void 0 : _a.requiredSizes) !== null && _b !== void 0 ? _b : [];
36
+ if (sizes[0] === '*') {
37
+ sizes = requiredImageSizes.filter((s) => s !== '*');
38
+ }
39
+ return sizes;
40
+ }
41
+ }
@@ -0,0 +1,21 @@
1
+ import { FieldDefinition } from './field.static.types';
2
+ export declare const requiredImageSizes: readonly ["xxs", "xs", "s", "m", "l", "xl", "xxl", "*"];
3
+ export declare type RequiredImageSize = typeof requiredImageSizes[number];
4
+ export interface ImageFieldValue {
5
+ name: string;
6
+ base64?: string;
7
+ xxsUri?: string;
8
+ xsUri?: string;
9
+ sUri?: string;
10
+ mUri?: string;
11
+ lUri?: string;
12
+ xlUri?: string;
13
+ xxlUri?: string;
14
+ }
15
+ export declare type ImageFieldDefinition = FieldDefinition<ImageFieldValue> & {
16
+ /** * .image - a great way to deal with file management */
17
+ type: 'image';
18
+ options?: {
19
+ requiredSizes: RequiredImageSize[];
20
+ };
21
+ };
@@ -0,0 +1,10 @@
1
+ export const requiredImageSizes = [
2
+ 'xxs',
3
+ 'xs',
4
+ 's',
5
+ 'm',
6
+ 'l',
7
+ 'xl',
8
+ 'xxl',
9
+ '*',
10
+ ];
@@ -37,6 +37,8 @@ export { default as DateTimeField } from './DateTimeField';
37
37
  export * from './FileField';
38
38
  export * from './FileField.types';
39
39
  export { default as FileField } from './FileField';
40
+ export * from './ImageField.types';
41
+ export { default as ImageField } from './ImageField';
40
42
  export * from './DateField';
41
43
  export * from './DateField.types';
42
44
  export { default as DateField } from './DateField';
@@ -37,6 +37,8 @@ export { default as DateTimeField } from './DateTimeField.js';
37
37
  export * from './FileField.js';
38
38
  export * from './FileField.types.js';
39
39
  export { default as FileField } from './FileField.js';
40
+ export * from './ImageField.types.js';
41
+ export { default as ImageField } from './ImageField.js';
40
42
  export * from './DateField.js';
41
43
  export * from './DateField.types.js';
42
44
  export { default as DateField } from './DateField.js';
@@ -32,11 +32,11 @@ export default abstract class AbstractField<F extends FieldDefinitions> implemen
32
32
  } | {
33
33
  dateTimeFormat?: string | undefined;
34
34
  } | {
35
- acceptableTypes?: string[] | undefined;
36
- maxSize?: string | undefined;
37
- relativeTo?: string | undefined;
35
+ acceptableTypes: ("image/png" | "image/jpeg" | "application/pdf" | "*")[];
38
36
  } | {
39
37
  relativeTo?: string | undefined;
38
+ } | {
39
+ requiredSizes: ("s" | "*" | "xxs" | "xs" | "m" | "l" | "xl" | "xxl")[];
40
40
  } | undefined;
41
41
  get isRequired(): boolean;
42
42
  get isPrivate(): boolean;
@@ -37,7 +37,7 @@ public static get description() {
37
37
  instructions: `Copy and paste this into ${this.name}:
38
38
 
39
39
  public static generateTemplateDetails(
40
- options: IFieldTemplateDetailOptions<I{{YourFieldName}}Definition>
40
+ options: FieldTemplateDetailOptions<{{YourFieldName}}Definition>
41
41
  ): IFieldTemplateDetails {
42
42
  const { definition } = options
43
43
  return {
@@ -6,7 +6,6 @@ import { FileFieldDefinition, FileFieldValue } from './FileField.types';
6
6
  export default class FileField extends AbstractField<FileFieldDefinition> {
7
7
  static get description(): string;
8
8
  static generateTemplateDetails(options: FieldTemplateDetailOptions<FileFieldDefinition>): FieldTemplateDetails;
9
- validate(value: any, _?: ValidateOptions<FileFieldDefinition>): FieldError[];
10
- /** Take a range of possible values and transform it into a IFileFieldValue */
11
- toValueType<C extends boolean>(value: any, options?: ToValueTypeOptions<FileFieldDefinition, C>): FileFieldValue;
9
+ validate(value: FileFieldValue, _?: ValidateOptions<FileFieldDefinition>): FieldError[];
10
+ toValueType<C extends boolean>(value: any, _options?: ToValueTypeOptions<FileFieldDefinition, C>): FileFieldValue;
12
11
  }
@@ -3,125 +3,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
7
6
  const AbstractField_1 = __importDefault(require("./AbstractField"));
8
- let mimeInstance;
9
- function mime() {
10
- if (!mimeInstance) {
11
- const mimeDb = require('mime-db');
12
- const Mime = require('mime-type').default;
13
- mimeInstance = new Mime(mimeDb, 2);
14
- mimeInstance.define('application/typescript', {
15
- source: 'spruce',
16
- extensions: ['ts', 'tsx'],
17
- });
18
- }
19
- return mimeInstance;
20
- }
21
7
  class FileField extends AbstractField_1.default {
22
8
  static get description() {
23
9
  return 'A way to handle files. Supports mime-type lookups.';
24
10
  }
25
11
  static generateTemplateDetails(options) {
26
12
  return {
27
- valueType: `${options.importAs}.IFileFieldValue${options.definition.isArray ? '[]' : ''}`,
13
+ valueType: `${options.importAs}.FileFieldValue${options.definition.isArray ? '[]' : ''}`,
28
14
  };
29
15
  }
30
16
  validate(value, _) {
31
- const errors = [];
32
- try {
33
- const file = this.toValueType(value);
34
- if (!file.ext && file.path) {
35
- // eslint-disable-next-line @typescript-eslint/no-var-requires
36
- const fsUtil = require('fs');
37
- // if this file has no extension, lets see if it's a directory
38
- const isDirExists = fsUtil.existsSync(file.path) &&
39
- fsUtil.lstatSync(file.path).isDirectory();
40
- if (isDirExists) {
41
- errors.push({
42
- code: 'INVALID_PARAMETER',
43
- friendlyMessage: `${file.path} is not a directory!`,
44
- name: this.name,
45
- });
46
- }
47
- }
48
- }
49
- catch (err) {
17
+ var _a, _b, _c;
18
+ const errors = super.validate(value);
19
+ const acceptableTypes = (_b = (_a = this.definition.options) === null || _a === void 0 ? void 0 : _a.acceptableTypes) !== null && _b !== void 0 ? _b : [];
20
+ if (value &&
21
+ !value.base64 &&
22
+ acceptableTypes[0] !== '*' &&
23
+ acceptableTypes.indexOf(value.type) === -1) {
50
24
  errors.push({
51
25
  code: 'INVALID_PARAMETER',
52
- originalError: err,
53
26
  name: this.name,
54
- friendlyMessage: err.message,
27
+ friendlyMessage: `You sent a '${value.type}' to '${(_c = this.label) !== null && _c !== void 0 ? _c : this.name}' and it only accepts '${acceptableTypes.join("', '")}'.`,
55
28
  });
56
29
  }
57
30
  return errors;
58
31
  }
59
- /** Take a range of possible values and transform it into a IFileFieldValue */
60
- toValueType(value, options) {
61
- let stringValue = typeof value === 'string' || value.toString ? value.toString() : undefined;
62
- const relativeTo = options === null || options === void 0 ? void 0 : options.relativeTo;
63
- let path;
64
- let name;
65
- let ext;
66
- let type;
67
- if (typeof value === 'object') {
68
- path = typeof value.path === 'string' ? value.path : undefined;
69
- name = typeof value.name === 'string' ? value.name : undefined;
70
- ext = typeof value.ext === 'string' ? value.ext : undefined;
71
- type = typeof value.type === 'string' ? value.type : undefined;
72
- // Use the name, fallback to path for looking up additional details
73
- stringValue = name || path;
74
- }
75
- // eslint-disable-next-line @typescript-eslint/no-var-requires
76
- const pathUtil = require('path');
77
- const dirname = pathUtil.sep === '/' ? pathUtil.dirname : pathUtil.win32.dirname;
78
- // Check if path is the full file path
79
- if (path) {
80
- const parts = pathUtil.parse(path);
81
- // If it is then we should just get the directory name and set it to path
82
- if (parts.ext.length > 0) {
83
- path = dirname(path);
84
- }
85
- }
86
- else if (!path) {
87
- // Try to pull the path off the value
88
- path =
89
- stringValue.indexOf(pathUtil.sep) > -1
90
- ? dirname(stringValue)
91
- : undefined;
92
- }
93
- name = name !== null && name !== void 0 ? name : stringValue.replace(path, '').replace(pathUtil.sep, '');
94
- if (!name) {
95
- throw new SpruceError_1.default({
96
- code: 'TRANSFORMATION_ERROR',
97
- fieldType: 'file',
98
- incomingTypeof: typeof value,
99
- incomingValue: value,
100
- name: this.name,
101
- });
102
- }
103
- ext = ext !== null && ext !== void 0 ? ext : pathUtil.extname(name);
104
- if (!type) {
105
- const m = mime();
106
- const lookupResults = m.lookup(name);
107
- if (Array.isArray(lookupResults)) {
108
- type = lookupResults.pop();
109
- }
110
- else {
111
- type = lookupResults;
112
- }
113
- }
114
- if (relativeTo && path) {
115
- // eslint-disable-next-line @typescript-eslint/no-var-requires
116
- const pathUtil = require('path');
117
- path = pathUtil.relative(relativeTo, path) || path;
118
- }
119
- return {
120
- name,
121
- path,
122
- type,
123
- ext,
124
- };
32
+ toValueType(value, _options) {
33
+ return value;
125
34
  }
126
35
  }
127
36
  exports.default = FileField;
@@ -1,27 +1,17 @@
1
1
  import { FieldDefinition } from './field.static.types';
2
+ declare const supportedTypes: readonly ["image/png", "image/jpeg", "application/pdf", "*"];
3
+ export declare type SupportedFileType = typeof supportedTypes[number];
2
4
  export interface FileFieldValue {
3
- /** Date last modified */
4
- lastModified?: Date;
5
- /** The name of the file */
6
5
  name: string;
7
- /** The size of the file if we are able to load it locally */
8
- size?: number;
9
- /** The mime type of the file */
10
- type?: string;
11
- /** The path to the file if local */
12
- path?: string;
13
- /** The file extension */
14
- ext?: string;
6
+ type?: SupportedFileType;
7
+ uri?: string;
8
+ base64?: string;
15
9
  }
16
10
  export declare type FileFieldDefinition = FieldDefinition<FileFieldValue> & {
17
11
  /** * .File - a great way to deal with file management */
18
12
  type: 'file';
19
13
  options?: {
20
- /** Which mime types are acceptable? */
21
- acceptableTypes?: string[];
22
- /** What is the biggest this file can be? */
23
- maxSize?: string;
24
- /** All paths will be generated to this directory, if possible */
25
- relativeTo?: string;
14
+ acceptableTypes: SupportedFileType[];
26
15
  };
27
16
  };
17
+ export {};
@@ -1,2 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const supportedTypes = [
4
+ 'image/png',
5
+ 'image/jpeg',
6
+ 'application/pdf',
7
+ '*',
8
+ ];
@@ -0,0 +1,8 @@
1
+ import { FieldTemplateDetailOptions, FieldTemplateDetails } from '../types/template.types';
2
+ import AbstractField from './AbstractField';
3
+ import { ImageFieldDefinition, ImageFieldValue } from './ImageField.types';
4
+ export default class ImageField extends AbstractField<ImageFieldDefinition> {
5
+ static generateTemplateDetails(options: FieldTemplateDetailOptions<ImageFieldDefinition>): FieldTemplateDetails;
6
+ validate(value: ImageFieldValue): import("..").FieldError[];
7
+ private getRequiredSizes;
8
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const AbstractField_1 = __importDefault(require("./AbstractField"));
7
+ const ImageField_types_1 = require("./ImageField.types");
8
+ class ImageField extends AbstractField_1.default {
9
+ static generateTemplateDetails(options) {
10
+ const { definition, importAs } = options;
11
+ return {
12
+ valueType: `${importAs}.ImageFieldValue${definition.isArray ? '[]' : ''}`,
13
+ };
14
+ }
15
+ validate(value) {
16
+ var _a;
17
+ const errors = super.validate(value);
18
+ if (errors.length === 0 && !value.base64) {
19
+ let sizes = this.getRequiredSizes();
20
+ const missing = [];
21
+ for (const size of sizes) {
22
+ const key = `${size}Uri`;
23
+ //@ts-ignore
24
+ if (value && !value[key]) {
25
+ missing.push(key);
26
+ }
27
+ }
28
+ if (missing.length > 0) {
29
+ errors.push({
30
+ code: 'INVALID_PARAMETER',
31
+ name: this.name,
32
+ friendlyMessage: `You need to supply the remaining sizes to upload an image to ${(_a = this.label) !== null && _a !== void 0 ? _a : this.name}: '${missing.join("', '")}'`,
33
+ });
34
+ }
35
+ }
36
+ return errors;
37
+ }
38
+ getRequiredSizes() {
39
+ var _a, _b;
40
+ let sizes = (_b = (_a = this.definition.options) === null || _a === void 0 ? void 0 : _a.requiredSizes) !== null && _b !== void 0 ? _b : [];
41
+ if (sizes[0] === '*') {
42
+ sizes = ImageField_types_1.requiredImageSizes.filter((s) => s !== '*');
43
+ }
44
+ return sizes;
45
+ }
46
+ }
47
+ exports.default = ImageField;
@@ -0,0 +1,21 @@
1
+ import { FieldDefinition } from './field.static.types';
2
+ export declare const requiredImageSizes: readonly ["xxs", "xs", "s", "m", "l", "xl", "xxl", "*"];
3
+ export declare type RequiredImageSize = typeof requiredImageSizes[number];
4
+ export interface ImageFieldValue {
5
+ name: string;
6
+ base64?: string;
7
+ xxsUri?: string;
8
+ xsUri?: string;
9
+ sUri?: string;
10
+ mUri?: string;
11
+ lUri?: string;
12
+ xlUri?: string;
13
+ xxlUri?: string;
14
+ }
15
+ export declare type ImageFieldDefinition = FieldDefinition<ImageFieldValue> & {
16
+ /** * .image - a great way to deal with file management */
17
+ type: 'image';
18
+ options?: {
19
+ requiredSizes: RequiredImageSize[];
20
+ };
21
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requiredImageSizes = void 0;
4
+ exports.requiredImageSizes = [
5
+ 'xxs',
6
+ 'xs',
7
+ 's',
8
+ 'm',
9
+ 'l',
10
+ 'xl',
11
+ 'xxl',
12
+ '*',
13
+ ];
@@ -37,6 +37,8 @@ export { default as DateTimeField } from './DateTimeField';
37
37
  export * from './FileField';
38
38
  export * from './FileField.types';
39
39
  export { default as FileField } from './FileField';
40
+ export * from './ImageField.types';
41
+ export { default as ImageField } from './ImageField';
40
42
  export * from './DateField';
41
43
  export * from './DateField.types';
42
44
  export { default as DateField } from './DateField';
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.fieldClassMap = exports.DateField = exports.FileField = exports.DateTimeField = exports.NumberField = exports.RawField = exports.SchemaField = exports.PhoneField = exports.AddressField = exports.SelectField = exports.IdField = exports.DurationField = exports.DirectoryField = exports.TextField = exports.BooleanField = void 0;
20
+ exports.fieldClassMap = exports.DateField = exports.ImageField = exports.FileField = exports.DateTimeField = exports.NumberField = exports.RawField = exports.SchemaField = exports.PhoneField = exports.AddressField = exports.SelectField = exports.IdField = exports.DurationField = exports.DirectoryField = exports.TextField = exports.BooleanField = void 0;
21
21
  __exportStar(require("./BooleanField"), exports);
22
22
  __exportStar(require("./BooleanField.types"), exports);
23
23
  var BooleanField_1 = require("./BooleanField");
@@ -70,6 +70,9 @@ __exportStar(require("./FileField"), exports);
70
70
  __exportStar(require("./FileField.types"), exports);
71
71
  var FileField_1 = require("./FileField");
72
72
  Object.defineProperty(exports, "FileField", { enumerable: true, get: function () { return __importDefault(FileField_1).default; } });
73
+ __exportStar(require("./ImageField.types"), exports);
74
+ var ImageField_1 = require("./ImageField");
75
+ Object.defineProperty(exports, "ImageField", { enumerable: true, get: function () { return __importDefault(ImageField_1).default; } });
73
76
  __exportStar(require("./DateField"), exports);
74
77
  __exportStar(require("./DateField.types"), exports);
75
78
  var DateField_1 = require("./DateField");
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "!build/__tests__",
9
9
  "esm"
10
10
  ],
11
- "version": "27.1.71",
11
+ "version": "28.0.2",
12
12
  "main": "./build/index.js",
13
13
  "types": "./build/index.d.ts",
14
14
  "module": "./build/esm/index.js",
@@ -66,12 +66,10 @@
66
66
  "build.copy-files": "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/"
67
67
  },
68
68
  "dependencies": {
69
- "@sprucelabs/error": "^5.0.451",
70
- "@sprucelabs/test": "^7.7.312",
69
+ "@sprucelabs/error": "^5.0.452",
70
+ "@sprucelabs/test": "^7.7.313",
71
71
  "email-validator": "^2.0.4",
72
- "lodash": "^4.17.21",
73
- "mime-db": "^1.52.0",
74
- "mime-type": "^4.0.0"
72
+ "lodash": "^4.17.21"
75
73
  },
76
74
  "devDependencies": {
77
75
  "@sprucelabs/esm-postbuild": "^1.0.424",
@@ -79,12 +77,11 @@
79
77
  "@sprucelabs/jest-sheets-reporter": "^1.3.29",
80
78
  "@sprucelabs/resolve-path-aliases": "^1.1.14",
81
79
  "@sprucelabs/semantic-release": "^4.0.8",
82
- "@sprucelabs/test-utils": "^3.0.540",
80
+ "@sprucelabs/test-utils": "^3.0.541",
83
81
  "@types/lodash": "^4.14.182",
84
- "@types/mime-db": "^1.43.1",
85
82
  "chokidar-cli": "^3.0.0",
86
83
  "concurrently": "^7.1.0",
87
- "eslint": "^8.14.0",
84
+ "eslint": "^8.15.0",
88
85
  "eslint-config-spruce": "^10.11.2",
89
86
  "jest": "^28.1.0",
90
87
  "jest-circus": "^28.1.0",