@sprucelabs/schema 25.5.65 → 25.5.69

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 (96) 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/assertOptions.js +1 -1
  6. package/build/esm/utilities/normalizeFieldValue.d.ts +1 -1
  7. package/build/utilities/assertOptions.js +1 -1
  8. package/package.json +13 -12
  9. package/build/esm/__tests__/behavioral/AssertingSelectOptions.test.d.ts +0 -7
  10. package/build/esm/__tests__/behavioral/AssertingSelectOptions.test.js +0 -93
  11. package/build/esm/__tests__/behavioral/AssertingValidationErrors.test.d.ts +0 -18
  12. package/build/esm/__tests__/behavioral/AssertingValidationErrors.test.js +0 -217
  13. package/build/esm/__tests__/behavioral/BuildSchema.test.d.ts +0 -5
  14. package/build/esm/__tests__/behavioral/BuildSchema.test.js +0 -66
  15. package/build/esm/__tests__/behavioral/CreatingEntityInstances.test.d.ts +0 -7
  16. package/build/esm/__tests__/behavioral/CreatingEntityInstances.test.js +0 -93
  17. package/build/esm/__tests__/behavioral/DroppingFields.test.d.ts +0 -5
  18. package/build/esm/__tests__/behavioral/DroppingFields.test.js +0 -86
  19. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplates.test.d.ts +0 -9
  20. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplates.test.js +0 -137
  21. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplatesWithSuffix.test.d.ts +0 -5
  22. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplatesWithSuffix.test.js +0 -146
  23. package/build/esm/__tests__/behavioral/GeneratesTemplates.test.d.ts +0 -5
  24. package/build/esm/__tests__/behavioral/GeneratesTemplates.test.js +0 -67
  25. package/build/esm/__tests__/behavioral/GeneratesTypeMappers.test.d.ts +0 -5
  26. package/build/esm/__tests__/behavioral/GeneratesTypeMappers.test.js +0 -29
  27. package/build/esm/__tests__/behavioral/GeneratesVersionedRelationshipTemplates.test.d.ts +0 -11
  28. package/build/esm/__tests__/behavioral/GeneratesVersionedRelationshipTemplates.test.js +0 -191
  29. package/build/esm/__tests__/behavioral/GettingFieldsOffASchema.test.d.ts +0 -7
  30. package/build/esm/__tests__/behavioral/GettingFieldsOffASchema.test.js +0 -88
  31. package/build/esm/__tests__/behavioral/HandlesDynamicFields.test.d.ts +0 -17
  32. package/build/esm/__tests__/behavioral/HandlesDynamicFields.test.js +0 -284
  33. package/build/esm/__tests__/behavioral/HandlesHidingPrivateFields.test.d.ts +0 -11
  34. package/build/esm/__tests__/behavioral/HandlesHidingPrivateFields.test.js +0 -111
  35. package/build/esm/__tests__/behavioral/HandlesRelationships.test.d.ts +0 -9
  36. package/build/esm/__tests__/behavioral/HandlesRelationships.test.js +0 -175
  37. package/build/esm/__tests__/behavioral/HandlesRequiredFields.test.d.ts +0 -4
  38. package/build/esm/__tests__/behavioral/HandlesRequiredFields.test.js +0 -37
  39. package/build/esm/__tests__/behavioral/HandlesVersionedRelationships.test.d.ts +0 -6
  40. package/build/esm/__tests__/behavioral/HandlesVersionedRelationships.test.js +0 -102
  41. package/build/esm/__tests__/behavioral/HandlesVersioning.test.d.ts +0 -8
  42. package/build/esm/__tests__/behavioral/HandlesVersioning.test.js +0 -93
  43. package/build/esm/__tests__/behavioral/IsIdWithVersion.test.d.ts +0 -4
  44. package/build/esm/__tests__/behavioral/IsIdWithVersion.test.js +0 -30
  45. package/build/esm/__tests__/behavioral/MakingFieldsOptional.test.d.ts +0 -4
  46. package/build/esm/__tests__/behavioral/MakingFieldsOptional.test.js +0 -57
  47. package/build/esm/__tests__/behavioral/NormalizeToSchemaIdWithVersion.test.d.ts +0 -6
  48. package/build/esm/__tests__/behavioral/NormalizeToSchemaIdWithVersion.test.js +0 -77
  49. package/build/esm/__tests__/behavioral/NormalizingSchemaValues.test.d.ts +0 -8
  50. package/build/esm/__tests__/behavioral/NormalizingSchemaValues.test.js +0 -148
  51. package/build/esm/__tests__/behavioral/ResetsSchemasEveryTest.test.d.ts +0 -6
  52. package/build/esm/__tests__/behavioral/ResetsSchemasEveryTest.test.js +0 -45
  53. package/build/esm/__tests__/behavioral/SchemaDefaultValues.test.d.ts +0 -9
  54. package/build/esm/__tests__/behavioral/SchemaDefaultValues.test.js +0 -138
  55. package/build/esm/__tests__/behavioral/SelectChoicesToHash.test.d.ts +0 -4
  56. package/build/esm/__tests__/behavioral/SelectChoicesToHash.test.js +0 -43
  57. package/build/esm/__tests__/behavioral/SettingMinAndMaxValuesOnArrayFields.test.d.ts +0 -9
  58. package/build/esm/__tests__/behavioral/SettingMinAndMaxValuesOnArrayFields.test.js +0 -104
  59. package/build/esm/__tests__/behavioral/UsingSchemas.test.d.ts +0 -13
  60. package/build/esm/__tests__/behavioral/UsingSchemas.test.js +0 -281
  61. package/build/esm/__tests__/behavioral/UsingTheSchemaRegisteryForNamespacedSchemas.test.d.ts +0 -14
  62. package/build/esm/__tests__/behavioral/UsingTheSchemaRegisteryForNamespacedSchemas.test.js +0 -140
  63. package/build/esm/__tests__/behavioral/UsingTheSchemaRegistry.test.d.ts +0 -15
  64. package/build/esm/__tests__/behavioral/UsingTheSchemaRegistry.test.js +0 -117
  65. package/build/esm/__tests__/behavioral/ValidatingSchemaValues.test.d.ts +0 -28
  66. package/build/esm/__tests__/behavioral/ValidatingSchemaValues.test.js +0 -674
  67. package/build/esm/__tests__/data/personWithCars.d.ts +0 -188
  68. package/build/esm/__tests__/data/personWithCars.js +0 -163
  69. package/build/esm/__tests__/data/versionedPersonWithCars.d.ts +0 -323
  70. package/build/esm/__tests__/data/versionedPersonWithCars.js +0 -281
  71. package/build/esm/__tests__/implementation/BooleanField.test.d.ts +0 -6
  72. package/build/esm/__tests__/implementation/BooleanField.test.js +0 -59
  73. package/build/esm/__tests__/implementation/DurationField.test.d.ts +0 -7
  74. package/build/esm/__tests__/implementation/DurationField.test.js +0 -45
  75. package/build/esm/__tests__/implementation/EmailField.test.d.ts +0 -4
  76. package/build/esm/__tests__/implementation/EmailField.test.js +0 -39
  77. package/build/esm/__tests__/implementation/ErrorMapUtil.test.d.ts +0 -11
  78. package/build/esm/__tests__/implementation/ErrorMapUtil.test.js +0 -176
  79. package/build/esm/__tests__/implementation/FieldFactory.test.d.ts +0 -4
  80. package/build/esm/__tests__/implementation/FieldFactory.test.js +0 -35
  81. package/build/esm/__tests__/implementation/FileField.test.d.ts +0 -19
  82. package/build/esm/__tests__/implementation/FileField.test.js +0 -125
  83. package/build/esm/__tests__/implementation/NumberField.test.d.ts +0 -5
  84. package/build/esm/__tests__/implementation/NumberField.test.js +0 -54
  85. package/build/esm/__tests__/implementation/PhoneField.test.d.ts +0 -7
  86. package/build/esm/__tests__/implementation/PhoneField.test.js +0 -82
  87. package/build/esm/__tests__/implementation/SchemaFieldTransformingOptions.test.d.ts +0 -5
  88. package/build/esm/__tests__/implementation/SchemaFieldTransformingOptions.test.js +0 -209
  89. package/build/esm/__tests__/implementation/SchemaFieldValidation.test.d.ts +0 -8
  90. package/build/esm/__tests__/implementation/SchemaFieldValidation.test.js +0 -87
  91. package/build/esm/__tests__/implementation/SelectField.test.d.ts +0 -8
  92. package/build/esm/__tests__/implementation/SelectField.test.js +0 -127
  93. package/build/esm/__tests__/implementation/TextField.test.d.ts +0 -4
  94. package/build/esm/__tests__/implementation/TextField.test.js +0 -34
  95. package/build/esm/__tests__/implementation/ValidateErrorMessageFormatter.test.d.ts +0 -16
  96. package/build/esm/__tests__/implementation/ValidateErrorMessageFormatter.test.js +0 -216
@@ -1,77 +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 normalizeSchemaToIdWithVersion from '../../utilities/normalizeSchemaToIdWithVersion.js';
19
- export default class NormalizeToSchemaIdWithVersionTest extends AbstractSchemaTest {
20
- static functionExists() {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- assert.isFunction(normalizeSchemaToIdWithVersion);
23
- });
24
- }
25
- static testNormalizing(schemaOrIdWithVersion, expected) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- const actual = normalizeSchemaToIdWithVersion(schemaOrIdWithVersion);
28
- assert.isEqualDeep(actual, expected);
29
- });
30
- }
31
- }
32
- __decorate([
33
- test()
34
- ], NormalizeToSchemaIdWithVersionTest, "functionExists", null);
35
- __decorate([
36
- test('does nothing to idWithVersion', {
37
- id: 'test',
38
- }, {
39
- id: 'test',
40
- }),
41
- test('converts schema to idWithVersion', {
42
- id: 'test',
43
- fields: {
44
- textfield: {
45
- type: 'text',
46
- },
47
- },
48
- }, {
49
- id: 'test',
50
- }),
51
- test('maintains version', {
52
- id: 'test',
53
- version: '1.0',
54
- fields: {
55
- textfield: {
56
- type: 'text',
57
- },
58
- },
59
- }, {
60
- id: 'test',
61
- version: '1.0',
62
- }),
63
- test('maintains namespace and version', {
64
- id: 'test',
65
- version: '1.0',
66
- namespace: 'test',
67
- fields: {
68
- textfield: {
69
- type: 'text',
70
- },
71
- },
72
- }, {
73
- id: 'test',
74
- namespace: 'test',
75
- version: '1.0',
76
- })
77
- ], NormalizeToSchemaIdWithVersionTest, "testNormalizing", null);
@@ -1,8 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- export default class NormalizingSchemaValues extends AbstractSchemaTest {
3
- private static personSchema;
4
- protected static normalizesSimpleAsExpected(): void;
5
- protected static normalizeTypesAsExpected(): void;
6
- protected static normalizeAndCheckField(overrideValues: Record<string, any>, fieldName: string, expected: any): void;
7
- protected static honorsNotMakingSchemaEntitiesWithEntityValues(): void;
8
- }
@@ -1,148 +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 { test, assert } from '@sprucelabs/test';
8
- import StaticSchemaEntityImplementation from '../../index.js';
9
- import AbstractSchemaTest from '../../AbstractSchemaTest.js';
10
- import buildSchema from '../../utilities/buildSchema.js';
11
- import normalizeSchemaValues from '../../utilities/normalizeSchemaValues.js';
12
- export default class NormalizingSchemaValues extends AbstractSchemaTest {
13
- static normalizesSimpleAsExpected() {
14
- const values = normalizeSchemaValues(this.personSchema, {
15
- // @ts-ignore
16
- firstName: 12345,
17
- // @ts-ignore
18
- age: '10',
19
- nestedArraySchema: [{ field1: 'first' }, { field1: 'second' }],
20
- }, { shouldCreateEntityInstances: false });
21
- assert.isEqualDeep(values, {
22
- firstName: '12345',
23
- age: 10,
24
- boolean: undefined,
25
- privateBooleanField: undefined,
26
- nestedArraySchema: [{ field1: 'first' }, { field1: 'second' }],
27
- });
28
- }
29
- static normalizeTypesAsExpected() {
30
- const values = normalizeSchemaValues(this.personSchema, {
31
- firstName: 'tay',
32
- age: 0,
33
- nestedArraySchema: [{ field1: 'first' }, { field1: 'second' }],
34
- }, { shouldCreateEntityInstances: false });
35
- assert.isExactType(true);
36
- }
37
- static normalizeAndCheckField(overrideValues, fieldName, expected) {
38
- const values = normalizeSchemaValues(this.personSchema, Object.assign({ firstName: 'tay', age: 0, nestedArraySchema: [{ field1: 'first' }, { field1: 'second' }] }, overrideValues));
39
- //@ts-ignore
40
- assert.isEqual(values[fieldName], expected);
41
- }
42
- static honorsNotMakingSchemaEntitiesWithEntityValues() {
43
- const secondLevelSchema = buildSchema({
44
- id: 'nested-2nd-level-schema-entity',
45
- fields: {
46
- boolField: {
47
- type: 'boolean',
48
- },
49
- },
50
- });
51
- const schema = buildSchema({
52
- id: 'schema-entities',
53
- fields: {
54
- related: {
55
- type: 'schema',
56
- isArray: true,
57
- isRequired: true,
58
- options: {
59
- schema: {
60
- id: 'nested-schema-entities',
61
- fields: {
62
- textField: {
63
- type: 'text',
64
- },
65
- nested: {
66
- type: 'schema',
67
- options: {
68
- schema: secondLevelSchema,
69
- },
70
- },
71
- },
72
- },
73
- },
74
- },
75
- },
76
- });
77
- const values = normalizeSchemaValues(schema, {
78
- related: [
79
- {
80
- textField: 'hello!',
81
- nested: new StaticSchemaEntityImplementation(secondLevelSchema, {
82
- boolField: true,
83
- }),
84
- },
85
- ],
86
- }, { shouldCreateEntityInstances: false });
87
- assert.isFalse(values.related[0] instanceof StaticSchemaEntityImplementation);
88
- assert.isFalse(values.related[0].nested instanceof StaticSchemaEntityImplementation);
89
- assert.isEqualDeep(values, {
90
- related: [
91
- {
92
- textField: 'hello!',
93
- nested: { boolField: true },
94
- },
95
- ],
96
- });
97
- }
98
- }
99
- NormalizingSchemaValues.personSchema = buildSchema({
100
- id: 'testPerson',
101
- name: 'A test person',
102
- fields: {
103
- firstName: {
104
- type: 'text',
105
- isRequired: true,
106
- },
107
- age: {
108
- type: 'number',
109
- },
110
- boolean: {
111
- type: 'boolean',
112
- },
113
- privateBooleanField: {
114
- type: 'boolean',
115
- isPrivate: true,
116
- },
117
- nestedArraySchema: {
118
- type: 'schema',
119
- isArray: true,
120
- options: {
121
- schema: {
122
- id: 'nested-schema',
123
- name: 'Nested',
124
- fields: {
125
- field1: {
126
- type: 'text',
127
- },
128
- },
129
- },
130
- },
131
- },
132
- },
133
- });
134
- __decorate([
135
- test()
136
- ], NormalizingSchemaValues, "normalizesSimpleAsExpected", null);
137
- __decorate([
138
- test()
139
- ], NormalizingSchemaValues, "normalizeTypesAsExpected", null);
140
- __decorate([
141
- test('normalizes boolean with string false to false', { boolean: 'false' }, 'boolean', false),
142
- test('normalizes boolean with string true to true', { boolean: 'true' }, 'boolean', true),
143
- test('normalizes private boolean with string false to false', { privateBooleanField: 'false' }, 'privateBooleanField', false),
144
- test('normalizes private boolean with string true to true', { privateBooleanField: 'true' }, 'privateBooleanField', true)
145
- ], NormalizingSchemaValues, "normalizeAndCheckField", null);
146
- __decorate([
147
- test()
148
- ], NormalizingSchemaValues, "honorsNotMakingSchemaEntitiesWithEntityValues", null);
@@ -1,6 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- export default class ResetsSchemasEveryTest extends AbstractSchemaTest {
3
- protected static beforeEach(): Promise<void>;
4
- protected static importPersonWithCar(): void;
5
- protected static importPersonWithCarASecondTime(): void;
6
- }
@@ -1,45 +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 { assert, test } from '@sprucelabs/test';
17
- import AbstractSchemaTest from '../../AbstractSchemaTest.js';
18
- import buildPersonWithCars from '../data/personWithCars.js';
19
- export default class ResetsSchemasEveryTest extends AbstractSchemaTest {
20
- static beforeEach() {
21
- const _super = Object.create(null, {
22
- beforeEach: { get: () => super.beforeEach }
23
- });
24
- return __awaiter(this, void 0, void 0, function* () {
25
- yield _super.beforeEach.call(this);
26
- assert.isEqual(this.registry.getTrackingCount(), 0);
27
- });
28
- }
29
- static importPersonWithCar() {
30
- assert.isEqual(this.registry.getTrackingCount(), 0);
31
- buildPersonWithCars();
32
- assert.isEqual(this.registry.getTrackingCount(), 3);
33
- }
34
- static importPersonWithCarASecondTime() {
35
- assert.isEqual(this.registry.getTrackingCount(), 0);
36
- buildPersonWithCars();
37
- assert.isEqual(this.registry.getTrackingCount(), 3);
38
- }
39
- }
40
- __decorate([
41
- test()
42
- ], ResetsSchemasEveryTest, "importPersonWithCar", null);
43
- __decorate([
44
- test()
45
- ], ResetsSchemasEveryTest, "importPersonWithCarASecondTime", null);
@@ -1,9 +0,0 @@
1
- import AbstractSpruceTest from '@sprucelabs/test';
2
- import { Schema } from '../../schemas.static.types';
3
- export default class SchemaDefaultValuesTest extends AbstractSpruceTest {
4
- protected static textAndSelectDefaultValues(): void;
5
- protected static defaultValueTests(definition: Schema, expectedDefaultValues: Record<string, any>): void;
6
- protected static defaultValueTypeTests(): void;
7
- protected static canGetDefaultValuesFromSchemaWithRequiredFields(): void;
8
- protected static canGetDefaultValuesForUnionFields(): void;
9
- }
@@ -1,138 +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, { test, assert } from '@sprucelabs/test';
8
- import StaticSchemaEntityImplementation from '../../StaticSchemaEntityImplementation.js';
9
- import buildSchema from '../../utilities/buildSchema.js';
10
- import defaultSchemaValues from '../../utilities/defaultSchemaValues.js';
11
- import buildPersonWithCars from '../data/personWithCars.js';
12
- StaticSchemaEntityImplementation.enableDuplicateCheckWhenTracking = false;
13
- // we don't need these registered
14
- const { personSchema, carSchema } = buildPersonWithCars();
15
- export default class SchemaDefaultValuesTest extends AbstractSpruceTest {
16
- static textAndSelectDefaultValues() {
17
- let fieldName;
18
- // make sure types are 100% (only works if they are currently undefined)
19
- assert.isType(fieldName);
20
- }
21
- static defaultValueTests(definition, expectedDefaultValues) {
22
- const schema = new StaticSchemaEntityImplementation(definition);
23
- const defaultValues = schema.getDefaultValues();
24
- assert.isEqualDeep(defaultValues, expectedDefaultValues);
25
- }
26
- static defaultValueTypeTests() {
27
- const schema = new StaticSchemaEntityImplementation(personSchema);
28
- const defaultValues = schema.getDefaultValues();
29
- const defaultValuesWithoutSchemas = schema.getDefaultValues({
30
- shouldCreateEntityInstances: false,
31
- });
32
- assert.isFunction(defaultValues.optionalIsArrayCarOrTruckWithDefaultValue[0].get);
33
- assert.isEqual(defaultValuesWithoutSchemas.optionalIsArrayCarOrTruckWithDefaultValue[0]
34
- .schemaId, 'car');
35
- assert.isEqual(defaultValuesWithoutSchemas.optionalIsArrayCarOrTruckWithDefaultValue[0]
36
- .values.name, 'fast car');
37
- const carEntity = new StaticSchemaEntityImplementation(carSchema, {
38
- name: 'fast car',
39
- });
40
- assert.isType(defaultValues);
41
- assert.isEqualDeep(defaultValues.optionalIsArrayCarOrTruckWithDefaultValue, [carEntity]);
42
- assert.isType(defaultValuesWithoutSchemas);
43
- assert.isType(defaultValues);
44
- }
45
- static canGetDefaultValuesFromSchemaWithRequiredFields() {
46
- const avatar = buildSchema({
47
- id: 'sprucebotAvatar',
48
- name: 'Sprucebot avatar',
49
- description: '',
50
- fields: {
51
- size: {
52
- type: 'select',
53
- label: 'Size',
54
- isRequired: true,
55
- defaultValue: 'medium',
56
- options: {
57
- choices: [
58
- {
59
- value: 'small',
60
- label: 'Small',
61
- },
62
- {
63
- value: 'medium',
64
- label: 'Medium',
65
- },
66
- {
67
- value: 'large',
68
- label: 'Large',
69
- },
70
- ],
71
- },
72
- },
73
- stateOfMind: {
74
- type: 'select',
75
- label: 'State of mind',
76
- isRequired: true,
77
- defaultValue: 'chill',
78
- options: {
79
- choices: [
80
- {
81
- value: 'chill',
82
- label: 'Chill - Sprucebot is saying something informative or a salutation',
83
- },
84
- {
85
- value: 'contemplative',
86
- label: 'Contemplative - Sprucebot is loading or sending data',
87
- },
88
- {
89
- value: 'accomplished',
90
- label: 'Accomplished - Sprucebot is celebrating because a process has finished',
91
- },
92
- ],
93
- },
94
- },
95
- },
96
- });
97
- const defaults = defaultSchemaValues(avatar);
98
- assert.isEqualDeep(defaults, { size: 'medium', stateOfMind: 'chill' });
99
- }
100
- static canGetDefaultValuesForUnionFields() {
101
- const schema = new StaticSchemaEntityImplementation(personSchema);
102
- const { optionalIsArrayCarOrTruckWithDefaultValue, optionalCarOrTruckWithDefaultValue, } = schema.getDefaultValues();
103
- assert.isFunction(optionalCarOrTruckWithDefaultValue.get);
104
- assert.isEqual(optionalIsArrayCarOrTruckWithDefaultValue.length, 1, '');
105
- assert.isEqual(optionalCarOrTruckWithDefaultValue.schemaId === 'car' &&
106
- optionalCarOrTruckWithDefaultValue.get('name'), 'fast car');
107
- assert.isEqual(optionalIsArrayCarOrTruckWithDefaultValue[0] &&
108
- optionalIsArrayCarOrTruckWithDefaultValue[0].schemaId === 'car' &&
109
- optionalIsArrayCarOrTruckWithDefaultValue[0].get('name'), 'fast car');
110
- }
111
- }
112
- __decorate([
113
- test('Test typing on default values (test will always pass, lint will fail)')
114
- ], SchemaDefaultValuesTest, "textAndSelectDefaultValues", null);
115
- __decorate([
116
- test('Gets default values while creating schema instances', personSchema, {
117
- optionalCarWithDefaultValue: new StaticSchemaEntityImplementation(carSchema, {
118
- name: 'fast car',
119
- }),
120
- optionalSelectWithDefaultValue: 'hello',
121
- optionalTextWithDefaultValue: 'world',
122
- optionalIsArrayCarOrTruckWithDefaultValue: [
123
- new StaticSchemaEntityImplementation(carSchema, { name: 'fast car' }),
124
- ],
125
- optionalCarOrTruckWithDefaultValue: new StaticSchemaEntityImplementation(carSchema, {
126
- name: 'fast car',
127
- }),
128
- })
129
- ], SchemaDefaultValuesTest, "defaultValueTests", null);
130
- __decorate([
131
- test('Can get default typed correctly (test will pass, lint will fail)')
132
- ], SchemaDefaultValuesTest, "defaultValueTypeTests", null);
133
- __decorate([
134
- test()
135
- ], SchemaDefaultValuesTest, "canGetDefaultValuesFromSchemaWithRequiredFields", null);
136
- __decorate([
137
- test()
138
- ], SchemaDefaultValuesTest, "canGetDefaultValuesForUnionFields", null);
@@ -1,4 +0,0 @@
1
- import AbstractSpruceTest from '@sprucelabs/test';
2
- export default class SelectOptionsToHashTest extends AbstractSpruceTest {
3
- protected static testCreatingOptionHashes(): Promise<void>;
4
- }
@@ -1,43 +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 { selectChoicesToHash, schemaChoicesToHash, } from '../../utilities/selectChoicesToHash.js';
18
- import buildPersonWithCars from '../data/personWithCars.js';
19
- export default class SelectOptionsToHashTest extends AbstractSpruceTest {
20
- static testCreatingOptionHashes() {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const { personSchema } = buildPersonWithCars();
23
- const options = personSchema.fields.optionalSelect.options.choices;
24
- const optionsHash = selectChoicesToHash(options);
25
- assert.isType(optionsHash);
26
- assert.isType(optionsHash);
27
- assert.isEqualDeep(optionsHash, { foo: 'Foo', bar: 'Bar' });
28
- const optionsHash2 = schemaChoicesToHash(personSchema, 'optionalSelect');
29
- const optionsHash3 = schemaChoicesToHash(personSchema, 'optionalSelectWithDefaultValue');
30
- const fieldName = 'optionalSelectWithDefaultValue';
31
- const fieldName2 = 'optionalSelect';
32
- assert.isType(fieldName);
33
- assert.isType(fieldName2);
34
- assert.isType(optionsHash2);
35
- assert.isEqualDeep(optionsHash2, { foo: 'Foo', bar: 'Bar' });
36
- assert.isType(optionsHash3);
37
- assert.isEqualDeep(optionsHash3, { hello: 'world', goodbye: 'darling' });
38
- });
39
- }
40
- }
41
- __decorate([
42
- test()
43
- ], SelectOptionsToHashTest, "testCreatingOptionHashes", null);
@@ -1,9 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- export default class SettingMinAndMaxValuesOnArrayFieldsTest extends AbstractSchemaTest {
3
- protected static defaultsToOneValueRequired(): void;
4
- protected static failsWhenMissing(): void;
5
- protected static defaultOneValueRequiredPassesWithOneValue(): void;
6
- protected static minArrayLengthZero(): void;
7
- protected static minArrayLength2ThrowsWithLessThan(): void;
8
- protected static passesWithMoreThanMin(): void;
9
- }
@@ -1,104 +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 { test, assert } from '@sprucelabs/test';
8
- import { errorAssertUtil } from '@sprucelabs/test-utils';
9
- import AbstractSchemaTest from '../../AbstractSchemaTest.js';
10
- import validationErrorAssertUtil from '../../tests/validationErrorAssert.utility.js';
11
- import buildSchema from '../../utilities/buildSchema.js';
12
- import validateSchemaValues from '../../utilities/validateSchemaValues.js';
13
- const noMinOrMaxSchema = buildSchema({
14
- id: 'noMinOrMax',
15
- fields: {
16
- favoriteColors: {
17
- type: 'text',
18
- isArray: true,
19
- isRequired: true,
20
- },
21
- },
22
- });
23
- const zeroMinValuesSchema = buildSchema({
24
- id: 'zeroMinValues',
25
- fields: {
26
- favoriteColors: {
27
- type: 'text',
28
- isArray: true,
29
- isRequired: true,
30
- minArrayLength: 0,
31
- },
32
- },
33
- });
34
- const twoMinValuesSchema = buildSchema({
35
- id: 'twoMinValues',
36
- fields: {
37
- favoriteColors: {
38
- type: 'text',
39
- isArray: true,
40
- isRequired: true,
41
- minArrayLength: 2,
42
- },
43
- },
44
- });
45
- const zeroMinTwoRequiredFields = buildSchema({
46
- id: 'zeroMinTwoRequiredFields',
47
- fields: {
48
- name: {
49
- type: 'text',
50
- isRequired: true,
51
- },
52
- favoriteColors: {
53
- type: 'text',
54
- isArray: true,
55
- isRequired: true,
56
- minArrayLength: 0,
57
- },
58
- },
59
- });
60
- export default class SettingMinAndMaxValuesOnArrayFieldsTest extends AbstractSchemaTest {
61
- static defaultsToOneValueRequired() {
62
- const err = assert.doesThrow(() => validateSchemaValues(noMinOrMaxSchema, { favoriteColors: [] }));
63
- errorAssertUtil.assertError(err, 'VALIDATION_FAILED');
64
- }
65
- static failsWhenMissing() {
66
- const err = assert.doesThrow(() => validateSchemaValues(zeroMinTwoRequiredFields, {}));
67
- validationErrorAssertUtil.assertError(err, {
68
- missing: ['name', 'favoriteColors'],
69
- });
70
- }
71
- static defaultOneValueRequiredPassesWithOneValue() {
72
- validateSchemaValues(noMinOrMaxSchema, { favoriteColors: ['pink'] });
73
- }
74
- static minArrayLengthZero() {
75
- validateSchemaValues(zeroMinValuesSchema, { favoriteColors: [] });
76
- }
77
- static minArrayLength2ThrowsWithLessThan() {
78
- const err = assert.doesThrow(() => validateSchemaValues(twoMinValuesSchema, { favoriteColors: ['purple'] }));
79
- errorAssertUtil.assertError(err, 'VALIDATION_FAILED');
80
- }
81
- static passesWithMoreThanMin() {
82
- validateSchemaValues(twoMinValuesSchema, {
83
- favoriteColors: ['pink', 'purple'],
84
- });
85
- }
86
- }
87
- __decorate([
88
- test()
89
- ], SettingMinAndMaxValuesOnArrayFieldsTest, "defaultsToOneValueRequired", null);
90
- __decorate([
91
- test()
92
- ], SettingMinAndMaxValuesOnArrayFieldsTest, "failsWhenMissing", null);
93
- __decorate([
94
- test()
95
- ], SettingMinAndMaxValuesOnArrayFieldsTest, "defaultOneValueRequiredPassesWithOneValue", null);
96
- __decorate([
97
- test()
98
- ], SettingMinAndMaxValuesOnArrayFieldsTest, "minArrayLengthZero", null);
99
- __decorate([
100
- test()
101
- ], SettingMinAndMaxValuesOnArrayFieldsTest, "minArrayLength2ThrowsWithLessThan", null);
102
- __decorate([
103
- test()
104
- ], SettingMinAndMaxValuesOnArrayFieldsTest, "passesWithMoreThanMin", null);
@@ -1,13 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- export default class SchemaTest extends AbstractSchemaTest {
3
- protected static testBasicValidation(): Promise<void>;
4
- protected static testMissingKeys(fieldToDelete: string, expectedErrors: string[]): Promise<void>;
5
- protected static canIsArrayValue(): Promise<void>;
6
- protected static getSetArrays(): void;
7
- protected static testTransformingValuesToValueTypes(): void;
8
- protected static testValuesTypesAgainstObjectLiteral(): void;
9
- protected static testFullValuesTypes(): void;
10
- protected static testGettingOptionsByField(): void;
11
- protected static canCorrectlyTypeSchemaWithOneRequiredField(): void;
12
- protected static testGenerics(): void;
13
- }