@sprucelabs/schema 25.5.63 → 25.5.67

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 (94) hide show
  1. package/build/esm/DynamicSchemaEntityImplementation.d.ts +1 -1
  2. package/build/esm/fields/AbstractField.d.ts +1 -1
  3. package/build/esm/fields/field.static.types.d.ts +1 -1
  4. package/build/esm/schemas.static.types.d.ts +1 -1
  5. package/build/esm/utilities/normalizeFieldValue.d.ts +1 -1
  6. package/package.json +15 -14
  7. package/build/esm/__tests__/behavioral/AssertingSelectOptions.test.d.ts +0 -7
  8. package/build/esm/__tests__/behavioral/AssertingSelectOptions.test.js +0 -93
  9. package/build/esm/__tests__/behavioral/AssertingValidationErrors.test.d.ts +0 -18
  10. package/build/esm/__tests__/behavioral/AssertingValidationErrors.test.js +0 -217
  11. package/build/esm/__tests__/behavioral/BuildSchema.test.d.ts +0 -5
  12. package/build/esm/__tests__/behavioral/BuildSchema.test.js +0 -66
  13. package/build/esm/__tests__/behavioral/CreatingEntityInstances.test.d.ts +0 -7
  14. package/build/esm/__tests__/behavioral/CreatingEntityInstances.test.js +0 -93
  15. package/build/esm/__tests__/behavioral/DroppingFields.test.d.ts +0 -5
  16. package/build/esm/__tests__/behavioral/DroppingFields.test.js +0 -86
  17. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplates.test.d.ts +0 -9
  18. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplates.test.js +0 -137
  19. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplatesWithSuffix.test.d.ts +0 -5
  20. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplatesWithSuffix.test.js +0 -146
  21. package/build/esm/__tests__/behavioral/GeneratesTemplates.test.d.ts +0 -5
  22. package/build/esm/__tests__/behavioral/GeneratesTemplates.test.js +0 -67
  23. package/build/esm/__tests__/behavioral/GeneratesTypeMappers.test.d.ts +0 -5
  24. package/build/esm/__tests__/behavioral/GeneratesTypeMappers.test.js +0 -29
  25. package/build/esm/__tests__/behavioral/GeneratesVersionedRelationshipTemplates.test.d.ts +0 -11
  26. package/build/esm/__tests__/behavioral/GeneratesVersionedRelationshipTemplates.test.js +0 -191
  27. package/build/esm/__tests__/behavioral/GettingFieldsOffASchema.test.d.ts +0 -7
  28. package/build/esm/__tests__/behavioral/GettingFieldsOffASchema.test.js +0 -88
  29. package/build/esm/__tests__/behavioral/HandlesDynamicFields.test.d.ts +0 -17
  30. package/build/esm/__tests__/behavioral/HandlesDynamicFields.test.js +0 -284
  31. package/build/esm/__tests__/behavioral/HandlesHidingPrivateFields.test.d.ts +0 -11
  32. package/build/esm/__tests__/behavioral/HandlesHidingPrivateFields.test.js +0 -111
  33. package/build/esm/__tests__/behavioral/HandlesRelationships.test.d.ts +0 -9
  34. package/build/esm/__tests__/behavioral/HandlesRelationships.test.js +0 -175
  35. package/build/esm/__tests__/behavioral/HandlesRequiredFields.test.d.ts +0 -4
  36. package/build/esm/__tests__/behavioral/HandlesRequiredFields.test.js +0 -37
  37. package/build/esm/__tests__/behavioral/HandlesVersionedRelationships.test.d.ts +0 -6
  38. package/build/esm/__tests__/behavioral/HandlesVersionedRelationships.test.js +0 -102
  39. package/build/esm/__tests__/behavioral/HandlesVersioning.test.d.ts +0 -8
  40. package/build/esm/__tests__/behavioral/HandlesVersioning.test.js +0 -93
  41. package/build/esm/__tests__/behavioral/IsIdWithVersion.test.d.ts +0 -4
  42. package/build/esm/__tests__/behavioral/IsIdWithVersion.test.js +0 -30
  43. package/build/esm/__tests__/behavioral/MakingFieldsOptional.test.d.ts +0 -4
  44. package/build/esm/__tests__/behavioral/MakingFieldsOptional.test.js +0 -57
  45. package/build/esm/__tests__/behavioral/NormalizeToSchemaIdWithVersion.test.d.ts +0 -6
  46. package/build/esm/__tests__/behavioral/NormalizeToSchemaIdWithVersion.test.js +0 -77
  47. package/build/esm/__tests__/behavioral/NormalizingSchemaValues.test.d.ts +0 -8
  48. package/build/esm/__tests__/behavioral/NormalizingSchemaValues.test.js +0 -148
  49. package/build/esm/__tests__/behavioral/ResetsSchemasEveryTest.test.d.ts +0 -6
  50. package/build/esm/__tests__/behavioral/ResetsSchemasEveryTest.test.js +0 -45
  51. package/build/esm/__tests__/behavioral/SchemaDefaultValues.test.d.ts +0 -9
  52. package/build/esm/__tests__/behavioral/SchemaDefaultValues.test.js +0 -138
  53. package/build/esm/__tests__/behavioral/SelectChoicesToHash.test.d.ts +0 -4
  54. package/build/esm/__tests__/behavioral/SelectChoicesToHash.test.js +0 -43
  55. package/build/esm/__tests__/behavioral/SettingMinAndMaxValuesOnArrayFields.test.d.ts +0 -9
  56. package/build/esm/__tests__/behavioral/SettingMinAndMaxValuesOnArrayFields.test.js +0 -104
  57. package/build/esm/__tests__/behavioral/UsingSchemas.test.d.ts +0 -13
  58. package/build/esm/__tests__/behavioral/UsingSchemas.test.js +0 -281
  59. package/build/esm/__tests__/behavioral/UsingTheSchemaRegisteryForNamespacedSchemas.test.d.ts +0 -14
  60. package/build/esm/__tests__/behavioral/UsingTheSchemaRegisteryForNamespacedSchemas.test.js +0 -140
  61. package/build/esm/__tests__/behavioral/UsingTheSchemaRegistry.test.d.ts +0 -15
  62. package/build/esm/__tests__/behavioral/UsingTheSchemaRegistry.test.js +0 -117
  63. package/build/esm/__tests__/behavioral/ValidatingSchemaValues.test.d.ts +0 -28
  64. package/build/esm/__tests__/behavioral/ValidatingSchemaValues.test.js +0 -674
  65. package/build/esm/__tests__/data/personWithCars.d.ts +0 -188
  66. package/build/esm/__tests__/data/personWithCars.js +0 -163
  67. package/build/esm/__tests__/data/versionedPersonWithCars.d.ts +0 -323
  68. package/build/esm/__tests__/data/versionedPersonWithCars.js +0 -281
  69. package/build/esm/__tests__/implementation/BooleanField.test.d.ts +0 -6
  70. package/build/esm/__tests__/implementation/BooleanField.test.js +0 -59
  71. package/build/esm/__tests__/implementation/DurationField.test.d.ts +0 -7
  72. package/build/esm/__tests__/implementation/DurationField.test.js +0 -45
  73. package/build/esm/__tests__/implementation/EmailField.test.d.ts +0 -4
  74. package/build/esm/__tests__/implementation/EmailField.test.js +0 -39
  75. package/build/esm/__tests__/implementation/ErrorMapUtil.test.d.ts +0 -11
  76. package/build/esm/__tests__/implementation/ErrorMapUtil.test.js +0 -176
  77. package/build/esm/__tests__/implementation/FieldFactory.test.d.ts +0 -4
  78. package/build/esm/__tests__/implementation/FieldFactory.test.js +0 -35
  79. package/build/esm/__tests__/implementation/FileField.test.d.ts +0 -19
  80. package/build/esm/__tests__/implementation/FileField.test.js +0 -125
  81. package/build/esm/__tests__/implementation/NumberField.test.d.ts +0 -5
  82. package/build/esm/__tests__/implementation/NumberField.test.js +0 -54
  83. package/build/esm/__tests__/implementation/PhoneField.test.d.ts +0 -7
  84. package/build/esm/__tests__/implementation/PhoneField.test.js +0 -82
  85. package/build/esm/__tests__/implementation/SchemaFieldTransformingOptions.test.d.ts +0 -5
  86. package/build/esm/__tests__/implementation/SchemaFieldTransformingOptions.test.js +0 -209
  87. package/build/esm/__tests__/implementation/SchemaFieldValidation.test.d.ts +0 -8
  88. package/build/esm/__tests__/implementation/SchemaFieldValidation.test.js +0 -87
  89. package/build/esm/__tests__/implementation/SelectField.test.d.ts +0 -8
  90. package/build/esm/__tests__/implementation/SelectField.test.js +0 -127
  91. package/build/esm/__tests__/implementation/TextField.test.d.ts +0 -4
  92. package/build/esm/__tests__/implementation/TextField.test.js +0 -34
  93. package/build/esm/__tests__/implementation/ValidateErrorMessageFormatter.test.d.ts +0 -16
  94. package/build/esm/__tests__/implementation/ValidateErrorMessageFormatter.test.js +0 -216
@@ -1,19 +0,0 @@
1
- import AbstractSpruceTest from '@sprucelabs/test';
2
- import { FileFieldValue } from '../../fields/FileField.types';
3
- interface FileDetailExpectations {
4
- expectedName: string;
5
- expectedType: string;
6
- expectedExtension: string;
7
- }
8
- declare enum EnvKind {
9
- Linux = "linux",
10
- Windows = "windows"
11
- }
12
- export default class FileFieldTest extends AbstractSpruceTest {
13
- private static fileDefinition;
14
- static testGettingFileDetails(filePath: string, expectations: FileDetailExpectations): void;
15
- static testCompletingFileObject(partial: Partial<FileFieldValue>, complete: FileFieldValue): void;
16
- static testInSchema(env: EnvKind, expectedPath: string, setTarget: FileFieldValue): void;
17
- protected static testGettingRelativePath(path: string, relativeTo: string, expectedPath: string): void;
18
- }
19
- export {};
@@ -1,125 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import path from 'path';
8
- import AbstractSpruceTest, { test, assert } from '@sprucelabs/test';
9
- import FieldFactory from '../../factories/FieldFactory.js';
10
- import StaticSchemaEntityImplementation from '../../StaticSchemaEntityImplementation.js';
11
- import buildSchema from '../../utilities/buildSchema.js';
12
- var EnvKind;
13
- (function (EnvKind) {
14
- EnvKind["Linux"] = "linux";
15
- EnvKind["Windows"] = "windows";
16
- })(EnvKind || (EnvKind = {}));
17
- const linuxTestPath = '/some/directory/path';
18
- const windowsTestPath = 'C:\\some\\directory\\path';
19
- export default class FileFieldTest extends AbstractSpruceTest {
20
- static testGettingFileDetails(filePath, expectations) {
21
- const field = FieldFactory.Field('test', {
22
- type: 'file',
23
- });
24
- const file = field.toValueType(filePath);
25
- assert.isEqual(file.name, expectations.expectedName, 'File name did not parse as expected');
26
- assert.isEqual(file.type, expectations.expectedType, 'File type did not lookup as expected');
27
- assert.isEqual(file.ext, expectations.expectedExtension, 'File type did not lookup as expected');
28
- }
29
- static testCompletingFileObject(partial, complete) {
30
- const file = FieldFactory.Field('test', { type: 'file' });
31
- const augmented = file.toValueType(partial);
32
- assert.isEqualDeep(augmented, complete);
33
- }
34
- static testInSchema(env, expectedPath, setTarget) {
35
- if (env === EnvKind.Linux) {
36
- // @ts-ignore
37
- path.sep = '/';
38
- }
39
- else if (env === EnvKind.Windows) {
40
- // @ts-ignore
41
- path.sep = '\\';
42
- }
43
- const schema = new StaticSchemaEntityImplementation(this.fileDefinition);
44
- schema.set('target', setTarget);
45
- const values = schema.getValues({
46
- fields: ['target'],
47
- });
48
- assert.isTruthy(values.target);
49
- assert.isEqual(values.target.path, expectedPath);
50
- }
51
- static testGettingRelativePath(path, relativeTo, expectedPath) {
52
- const schema = new StaticSchemaEntityImplementation(this.fileDefinition);
53
- schema.set('target', { path, name: 'app.ts' });
54
- const target = schema.get('target', { byField: { target: { relativeTo } } });
55
- assert.isEqual(target.path, expectedPath);
56
- }
57
- }
58
- FileFieldTest.fileDefinition = buildSchema({
59
- id: 'testFeature',
60
- name: 'Test Feature',
61
- fields: {
62
- target: {
63
- type: 'file',
64
- isRequired: true,
65
- label: 'What file would you like to test?',
66
- },
67
- },
68
- });
69
- __decorate([
70
- test('Can get .ts details', '/does/not/need/to/exist/TestFile.ts', {
71
- expectedName: 'TestFile.ts',
72
- expectedType: 'application/typescript',
73
- expectedExtension: '.ts',
74
- }),
75
- test('Can get .js details', '/does/not/need/to/exist/TestFile.js', {
76
- expectedName: 'TestFile.js',
77
- expectedType: 'application/javascript',
78
- expectedExtension: '.js',
79
- }),
80
- test('Can get .png details', '/does/not/need/to/exist/avatar.png', {
81
- expectedName: 'avatar.png',
82
- expectedType: 'image/png',
83
- expectedExtension: '.png',
84
- })
85
- ], FileFieldTest, "testGettingFileDetails", null);
86
- __decorate([
87
- test('Can get file value based on only name', { name: 'NewFile.ts' }, {
88
- name: 'NewFile.ts',
89
- ext: '.ts',
90
- type: 'application/typescript',
91
- path: undefined,
92
- }),
93
- test('Can get file value based on only path', { path: '/path/to/a/non/existent/file/isTruthy/NewFile.ts' }, {
94
- name: 'NewFile.ts',
95
- ext: '.ts',
96
- type: 'application/typescript',
97
- path: '/path/to/a/non/existent/file/isTruthy',
98
- })
99
- ], FileFieldTest, "testCompletingFileObject", null);
100
- __decorate([
101
- test('Can create schema and properly parse path set path', EnvKind.Linux, linuxTestPath, {
102
- path: linuxTestPath,
103
- ext: '.ts',
104
- type: 'application/typescript',
105
- name: 'test.ts',
106
- }),
107
- test('Can create schema and properly parse path set path by name', EnvKind.Linux, linuxTestPath, {
108
- name: `${linuxTestPath}/test.ts`,
109
- }),
110
- test('Can create schema and properly parse path set as string', EnvKind.Linux, linuxTestPath, `${linuxTestPath}/test.ts`),
111
- test('Can create schema and properly parse path set path in windows', EnvKind.Windows, windowsTestPath, {
112
- path: windowsTestPath,
113
- ext: '.ts',
114
- type: 'application/typescript',
115
- name: 'test.ts',
116
- }),
117
- test('Can create schema and properly parse path set path by name in windows', EnvKind.Windows, windowsTestPath, {
118
- name: `${windowsTestPath}\\test.ts`,
119
- }),
120
- test('Can create schema and properly parse path set as string in windows', EnvKind.Windows, windowsTestPath, `${windowsTestPath}/test.ts`)
121
- ], FileFieldTest, "testInSchema", null);
122
- __decorate([
123
- test('can get paths relative to provided relativeTo', '/home/user/test/me', '/home/user', 'test/me'),
124
- test('can get paths relative to provided relativeTo going back', '/home/user/test/me', '/home/user/tacos', '../test/me')
125
- ], FileFieldTest, "testGettingRelativePath", null);
@@ -1,5 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- export default class NumberFieldTest extends AbstractSchemaTest {
3
- protected static numberFieldErrorsWhenValueNaN(input: string, shouldPass: boolean): Promise<void>;
4
- protected static convertsThingsToNumbers(input: any, expected: number): Promise<void>;
5
- }
@@ -1,54 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- import { test, assert } from '@sprucelabs/test';
17
- import AbstractSchemaTest from '../../AbstractSchemaTest.js';
18
- import FieldFactory from '../../factories/FieldFactory.js';
19
- export default class NumberFieldTest extends AbstractSchemaTest {
20
- static numberFieldErrorsWhenValueNaN(input, shouldPass) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const field = FieldFactory.Field('test', {
23
- type: 'number',
24
- });
25
- const errs = field.validate(input);
26
- if (shouldPass) {
27
- assert.isEqual(errs.length, 0);
28
- }
29
- else {
30
- assert.isAbove(errs.length, 0);
31
- assert.doesInclude(errs[0], { code: 'INVALID_PARAMETER' });
32
- }
33
- });
34
- }
35
- static convertsThingsToNumbers(input, expected) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const field = FieldFactory.Field('test', {
38
- type: 'number',
39
- });
40
- const actual = field.toValueType(input);
41
- assert.isEqual(actual, expected);
42
- });
43
- }
44
- }
45
- __decorate([
46
- test('non-string characters fails', 'aoeuaoeu', false),
47
- test('number passes', 4, true),
48
- test('string as number passes', '4', true),
49
- test('null passes when not required', null, true),
50
- test('undefined passes when not required', undefined, true)
51
- ], NumberFieldTest, "numberFieldErrorsWhenValueNaN", null);
52
- __decorate([
53
- test('string number transformed to number', '4', 4)
54
- ], NumberFieldTest, "convertsThingsToNumbers", null);
@@ -1,7 +0,0 @@
1
- import AbstractSpruceTest from '@sprucelabs/test';
2
- export declare class PhoneFieldTest extends AbstractSpruceTest {
3
- protected static validate(phone: string, expected: any, isRequired?: boolean): void;
4
- protected static format(phone: string, expected: string): void;
5
- protected static failingFormattingWithFailSilentReturnsOriginalNumber(): void;
6
- protected static failSilentlyFalseThrows(): void;
7
- }
@@ -1,82 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import AbstractSpruceTest, { assert, test } from '@sprucelabs/test';
8
- import FieldFactory from '../../factories/FieldFactory.js';
9
- import formatPhoneNumber from '../../utilities/formatPhoneNumber.js';
10
- export class PhoneFieldTest extends AbstractSpruceTest {
11
- static validate(phone, expected, isRequired = false) {
12
- const field = FieldFactory.Field('phone', {
13
- type: 'phone',
14
- isRequired,
15
- });
16
- const errors = field.validate(phone);
17
- assert.doesInclude(errors, expected);
18
- }
19
- static format(phone, expected) {
20
- const field = FieldFactory.Field('phone', {
21
- type: 'phone',
22
- });
23
- const actual = field.toValueType(phone);
24
- assert.isEqual(actual, expected);
25
- }
26
- static failingFormattingWithFailSilentReturnsOriginalNumber() {
27
- const formatted = formatPhoneNumber('aoeuaoue', true);
28
- assert.isEqual(formatted, 'aoeuaoue');
29
- }
30
- static failSilentlyFalseThrows() {
31
- const err = assert.doesThrow(() => formatPhoneNumber('aoeuaoue', false));
32
- assert.isTruthy(err);
33
- assert.isTruthy(err.message, 'INVALID_PHONE_NUMBER');
34
- }
35
- }
36
- __decorate([
37
- test('can handle dummy number', '1-555-555-5555', []),
38
- test('optional handles null phone', null, []),
39
- test('optional handles undefined phone', undefined, []),
40
- test('can handle dummy number without country code', '555-555-5555', []),
41
- test('can handle dummy number with country code +', '+1 555-555-5555', []),
42
- test('can handle dummy number with country code and hyphen', '+1-555-555-5555', []),
43
- test('fails with bad number', '234th2s34th', [
44
- {
45
- code: 'INVALID_PARAMETER',
46
- name: 'phone',
47
- },
48
- ]),
49
- test('fails with partial number', '720253', [
50
- {
51
- code: 'INVALID_PARAMETER',
52
- name: 'phone',
53
- },
54
- ]),
55
- test('fails with bad number with country', '+1 234th2s34th', [
56
- {
57
- code: 'INVALID_PARAMETER',
58
- name: 'phone',
59
- },
60
- ]),
61
- test('required fails with empty string for a number', '', [{ code: 'MISSING_PARAMETER', name: 'phone' }], true),
62
- test('passes with good number', '720-253-5555', []),
63
- test('passes with good number with country', '+1720-253-5555', []),
64
- test('passes with good number with country formatted', '+1 720-253-5555', []),
65
- test('passes with good number with country formatted hyphen', '+1-720-253-5555', [])
66
- ], PhoneFieldTest, "validate", null);
67
- __decorate([
68
- test('formats 720', '720', '+1 720'),
69
- test('formats 720233', '720233', '+1 720-233'),
70
- test('formats 72023323', '72023323', '+1 720-233-23'),
71
- test('formats 720-233-2355', '720-233-2355', '+1 720-233-2355'),
72
- test('formats 7202332355', '7202332355', '+1 720-233-2355'),
73
- test('formats 720 233 2355', '720 233 2355', '+1 720-233-2355'),
74
- test('formats 1720 233 2355', '1720 233 2355', '+1 720-233-2355'),
75
- test('formats +1-720-233-2355', '+1-720-233-2355', '+1 720-233-2355')
76
- ], PhoneFieldTest, "format", null);
77
- __decorate([
78
- test()
79
- ], PhoneFieldTest, "failingFormattingWithFailSilentReturnsOriginalNumber", null);
80
- __decorate([
81
- test()
82
- ], PhoneFieldTest, "failSilentlyFalseThrows", null);
@@ -1,5 +0,0 @@
1
- import AbstractSpruceTest from '@sprucelabs/test';
2
- import { SchemaFieldFieldDefinition } from '../../fields/SchemaField.types';
3
- export default class SchemaFieldTemplateTest extends AbstractSpruceTest {
4
- protected static testNormalizingOptionsToId(options: SchemaFieldFieldDefinition['options'], toSchemaIdExpected: any, toSchemaOrIdExpected?: any): Promise<void>;
5
- }
@@ -1,209 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- import AbstractSpruceTest, { test, assert } from '@sprucelabs/test';
17
- import SchemaField from '../../fields/SchemaField.js';
18
- import buildSchema from '../../utilities/buildSchema.js';
19
- const wrenchSchema = buildSchema({
20
- id: 'wrench',
21
- name: 'Wrench',
22
- fields: {
23
- wrenchSize: {
24
- type: 'number',
25
- label: 'Size',
26
- },
27
- },
28
- });
29
- const versionedWrench = buildSchema({
30
- id: 'wrench',
31
- name: 'Wrench',
32
- version: '1.0',
33
- fields: {
34
- wrenchSize: {
35
- type: 'number',
36
- label: 'Size',
37
- },
38
- },
39
- });
40
- const namespacedWrench = buildSchema({
41
- id: 'wrench',
42
- name: 'Wrench',
43
- namespace: 'one',
44
- fields: {
45
- wrenchSize: {
46
- type: 'number',
47
- label: 'Size',
48
- },
49
- },
50
- });
51
- const namespacedVersionedWrench = buildSchema({
52
- id: 'wrench',
53
- name: 'Wrench',
54
- version: '1.0',
55
- namespace: 'one',
56
- fields: {
57
- wrenchSize: {
58
- type: 'number',
59
- label: 'Size',
60
- },
61
- },
62
- });
63
- const namespaced2VersionedWrench = buildSchema({
64
- id: 'wrench',
65
- name: 'Wrench',
66
- version: '1.0',
67
- namespace: 'two',
68
- fields: {
69
- wrenchSize: {
70
- type: 'number',
71
- label: 'Size',
72
- },
73
- },
74
- });
75
- const screwdriverSchema = buildSchema({
76
- id: 'screwdriver',
77
- name: 'Screwdriver',
78
- fields: {
79
- isFlathead: {
80
- type: 'boolean',
81
- },
82
- screwdriverLength: {
83
- type: 'number',
84
- label: 'Length',
85
- },
86
- },
87
- });
88
- const personSchema = buildSchema({
89
- id: 'union-person',
90
- name: 'Union Person',
91
- fields: {
92
- favoriteTool: {
93
- type: 'schema',
94
- options: {
95
- schemas: [wrenchSchema, screwdriverSchema],
96
- },
97
- },
98
- tools: {
99
- type: 'schema',
100
- isArray: true,
101
- options: {
102
- schemas: [wrenchSchema, screwdriverSchema],
103
- },
104
- },
105
- },
106
- });
107
- export default class SchemaFieldTemplateTest extends AbstractSpruceTest {
108
- static testNormalizingOptionsToId(options, toSchemaIdExpected, toSchemaOrIdExpected) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- const idsWithVersion = SchemaField.mapFieldDefinitionToSchemaIdsWithVersion({
111
- type: 'schema',
112
- options,
113
- });
114
- assert.isEqualDeep(idsWithVersion, toSchemaIdExpected);
115
- const schemasOrIdsWithVersion = SchemaField.mapFieldDefinitionToSchemasOrIdsWithVersion({
116
- type: 'schema',
117
- options,
118
- });
119
- assert.isEqualDeep(schemasOrIdsWithVersion, toSchemaOrIdExpected !== null && toSchemaOrIdExpected !== void 0 ? toSchemaOrIdExpected : toSchemaIdExpected);
120
- });
121
- }
122
- }
123
- __decorate([
124
- test('can normalize schemaId to array [schemaId]', { schemaId: 'user' }, [
125
- { id: 'user' },
126
- ]),
127
- test('can normalize schemaIds to array [schemaId]', { schemaIds: ['user', 'wrench'] }, [{ id: 'user' }, { id: 'wrench' }]),
128
- test('can normalize schemaIds to array [schemaId]', { schemaIds: ['user', 'wrench'] }, [{ id: 'user' }, { id: 'wrench' }]),
129
- test('can normalize schema to array [schemaId]', { schema: wrenchSchema }, [{ id: 'wrench' }], [wrenchSchema]),
130
- test('can normalize schemas to array [schemaId]', {
131
- schemas: [wrenchSchema, screwdriverSchema],
132
- }, [{ id: 'wrench' }, { id: 'screwdriver' }], [wrenchSchema, screwdriverSchema]),
133
- test('can normalize schema, schemas to array [schemaId]', {
134
- schema: personSchema,
135
- schemas: [wrenchSchema, screwdriverSchema],
136
- }, [{ id: 'union-person' }, { id: 'wrench' }, { id: 'screwdriver' }], [personSchema, wrenchSchema, screwdriverSchema]),
137
- test('can normalize schemas, schema to array [schemaId]', {
138
- schemas: [wrenchSchema, screwdriverSchema],
139
- schema: personSchema,
140
- }, [{ id: 'union-person' }, { id: 'wrench' }, { id: 'screwdriver' }], [personSchema, wrenchSchema, screwdriverSchema]),
141
- test('can normalize schemas, schemaId to array [schemaId]', {
142
- schemas: [wrenchSchema, screwdriverSchema],
143
- schemaId: 'union-person',
144
- }, [{ id: 'union-person' }, { id: 'wrench' }, { id: 'screwdriver' }], [{ id: 'union-person' }, wrenchSchema, screwdriverSchema]),
145
- test('can handle versioned and un-versioned', {
146
- schemas: [
147
- {
148
- id: versionedWrench.id,
149
- version: versionedWrench.version,
150
- },
151
- wrenchSchema,
152
- ],
153
- }, [
154
- { id: versionedWrench.id, version: versionedWrench.version },
155
- { id: wrenchSchema.id },
156
- ], [{ id: versionedWrench.id, version: versionedWrench.version }, wrenchSchema]),
157
- test('can handle same namespace with different versions', {
158
- schemas: [
159
- {
160
- id: namespacedVersionedWrench.id,
161
- version: namespacedVersionedWrench.version,
162
- namespace: namespacedVersionedWrench.namespace,
163
- },
164
- namespacedWrench,
165
- ],
166
- }, [
167
- {
168
- id: namespacedVersionedWrench.id,
169
- version: namespacedVersionedWrench.version,
170
- namespace: namespacedVersionedWrench.namespace,
171
- },
172
- { id: namespacedWrench.id, namespace: namespacedWrench.namespace },
173
- ], [
174
- {
175
- id: namespacedVersionedWrench.id,
176
- version: namespacedVersionedWrench.version,
177
- namespace: namespacedVersionedWrench.namespace,
178
- },
179
- namespacedWrench,
180
- ]),
181
- test('can handle different namespace with same versions and and id', {
182
- schemas: [
183
- {
184
- id: namespacedVersionedWrench.id,
185
- version: namespacedVersionedWrench.version,
186
- namespace: namespacedVersionedWrench.namespace,
187
- },
188
- namespaced2VersionedWrench,
189
- ],
190
- }, [
191
- {
192
- id: namespacedVersionedWrench.id,
193
- version: namespacedVersionedWrench.version,
194
- namespace: namespacedVersionedWrench.namespace,
195
- },
196
- {
197
- id: namespaced2VersionedWrench.id,
198
- version: namespaced2VersionedWrench.version,
199
- namespace: namespaced2VersionedWrench.namespace,
200
- },
201
- ], [
202
- {
203
- id: namespacedVersionedWrench.id,
204
- version: namespacedVersionedWrench.version,
205
- namespace: namespacedVersionedWrench.namespace,
206
- },
207
- namespaced2VersionedWrench,
208
- ])
209
- ], SchemaFieldTemplateTest, "testNormalizingOptionsToId", null);
@@ -1,8 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- export default class SchemaFieldTest extends AbstractSchemaTest {
3
- private static personSchema;
4
- protected static beforeEach(): Promise<void>;
5
- protected static testNonUnionValidation(value: any, expectedErrorCodes: string[]): Promise<void>;
6
- protected static testSingleUnionFailsValidation(): Promise<void>;
7
- protected static testSingleUnionValidation(): Promise<void>;
8
- }
@@ -1,87 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- import { test, assert } from '@sprucelabs/test';
17
- import AbstractSchemaTest from '../../AbstractSchemaTest.js';
18
- import FieldFactory from '../../factories/FieldFactory.js';
19
- import buildPersonWithCar from '../data/personWithCars.js';
20
- export default class SchemaFieldTest extends AbstractSchemaTest {
21
- static beforeEach() {
22
- const _super = Object.create(null, {
23
- beforeEach: { get: () => super.beforeEach }
24
- });
25
- return __awaiter(this, void 0, void 0, function* () {
26
- yield _super.beforeEach.call(this);
27
- const { personSchema } = buildPersonWithCar();
28
- this.personSchema = personSchema;
29
- });
30
- }
31
- static testNonUnionValidation(value, expectedErrorCodes) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const requiredField = FieldFactory.Field('requiredCar', this.personSchema.fields.requiredCar);
34
- const optionalField = FieldFactory.Field('optionalCar', this.personSchema.fields.optionalCar);
35
- const requiredIsArrayField = FieldFactory.Field('requiredIsArrayCar', this.personSchema.fields.requiredIsArrayCars);
36
- const optionalIsArrayField = FieldFactory.Field('optionalRequiredCar', this.personSchema.fields.optionalIsArrayCars);
37
- let codes = requiredField.validate(value).map((err) => err.code);
38
- assert.isEqualDeep(codes, expectedErrorCodes);
39
- codes = optionalField.validate(value).map((err) => err.code);
40
- assert.isEqualDeep(codes, expectedErrorCodes);
41
- codes = requiredIsArrayField.validate(value).map((err) => err.code);
42
- assert.isEqualDeep(codes, expectedErrorCodes);
43
- codes = optionalIsArrayField.validate(value).map((err) => err.code);
44
- assert.isEqualDeep(codes, expectedErrorCodes);
45
- });
46
- }
47
- static testSingleUnionFailsValidation() {
48
- var _a, _b, _c, _d;
49
- return __awaiter(this, void 0, void 0, function* () {
50
- const optionalCarOrTruckField = FieldFactory.Field('optionalCarOrTruck', this.personSchema.fields.optionalCarOrTruck);
51
- const value = {
52
- schemaId: 'car',
53
- values: {},
54
- };
55
- const errors = optionalCarOrTruckField.validate(value);
56
- assert.isEqual(errors[0].code, 'INVALID_PARAMETER');
57
- assert.isEqual((_b = (_a = errors[0].errors) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.code, 'MISSING_PARAMETER');
58
- assert.isEqual((_d = (_c = errors[0].errors) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.name, 'name');
59
- });
60
- }
61
- static testSingleUnionValidation() {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- const optionalCarOrTruckField = FieldFactory.Field('optionalCarOrTruck', this.personSchema.fields.optionalCarOrTruck);
64
- const value = {
65
- schemaId: 'car',
66
- values: {
67
- name: 'great car',
68
- },
69
- };
70
- const codes = optionalCarOrTruckField.validate(value);
71
- assert.isLength(codes, 0);
72
- });
73
- }
74
- }
75
- __decorate([
76
- test('fails on non-object', true, ['INVALID_PARAMETER']),
77
- test('passes because everything has name and a string is good', { name: 'cheese!' }, []),
78
- test("knows it's missing the name and name is required", { taco: true }, [
79
- 'INVALID_PARAMETER',
80
- ])
81
- ], SchemaFieldTest, "testNonUnionValidation", null);
82
- __decorate([
83
- test()
84
- ], SchemaFieldTest, "testSingleUnionFailsValidation", null);
85
- __decorate([
86
- test()
87
- ], SchemaFieldTest, "testSingleUnionValidation", null);
@@ -1,8 +0,0 @@
1
- import AbstractSpruceTest from '@sprucelabs/test';
2
- export default class SelectFieldTest extends AbstractSpruceTest {
3
- private static userSchema;
4
- protected static canMakeSelectOptionsUnion(): Promise<void>;
5
- protected static catchesBadChoice(): void;
6
- protected static validationHandlesUndefinedForOptional(): void;
7
- protected static validationHandlesRequired(): void;
8
- }