@sprucelabs/schema 25.5.65 → 25.5.66

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 +11 -10
  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,111 +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 StaticSchemaEntityImplementation from '../../index.js';
18
- import AbstractSchemaTest from '../../AbstractSchemaTest.js';
19
- import normalizeSchemaValues from '../../utilities/normalizeSchemaValues.js';
20
- import buildPersonWithCars from '../data/personWithCars.js';
21
- const { carSchema } = buildPersonWithCars();
22
- export default class HandlesHidingPrivateFieldsTest extends AbstractSchemaTest {
23
- static typeMappingFieldNamesWorks() {
24
- let fieldName;
25
- assert.isExactType(true);
26
- }
27
- static typeMappingValuesWorks() {
28
- const person = {
29
- name: 'cool car',
30
- };
31
- assert.isTruthy(person);
32
- assert.isExactType(true);
33
- }
34
- static schemaCanDropPrivateFields() {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- const entity = new StaticSchemaEntityImplementation(carSchema, {
37
- name: 'cool car',
38
- privateField: 'Go away!',
39
- });
40
- const values = entity.getValues({ shouldIncludePrivateFields: false });
41
- //@ts-ignore
42
- assert.isFalsy(values.privateField);
43
- assert.isExactType(true);
44
- });
45
- }
46
- static schemaCanKeepPrivateFields() {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- const entity = new StaticSchemaEntityImplementation(carSchema, {
49
- name: 'cool car',
50
- privateField: 'Go away!',
51
- });
52
- const values = entity.getValues({ shouldIncludePrivateFields: true });
53
- assert.isExactType(true);
54
- });
55
- }
56
- static schemaCanDropPrivateFieldsWhenSelectingFields() {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- const entity = new StaticSchemaEntityImplementation(carSchema, {
59
- name: 'cool car',
60
- privateField: 'Go away!',
61
- onlyOnCar: 'yay',
62
- });
63
- const values = entity.getValues({
64
- shouldIncludePrivateFields: false,
65
- fields: ['onlyOnCar'],
66
- });
67
- //@ts-ignore
68
- assert.isFalsy(values.privateField);
69
- assert.isExactType(true);
70
- });
71
- }
72
- static normalizeCanDropPrivateFields() {
73
- const values = normalizeSchemaValues(carSchema, { name: 'sweet!', privateField: 'go away' }, { shouldIncludePrivateFields: false });
74
- //@ts-ignore
75
- assert.isFalsy(values.privateField);
76
- assert.isExactType(true);
77
- }
78
- static normalizeCanKeepPrivateFields() {
79
- const values = normalizeSchemaValues(carSchema, { name: 'sweet!', privateField: 'go away' }, { shouldIncludePrivateFields: true });
80
- assert.isEqual(values.privateField, 'go away');
81
- assert.isExactType(true);
82
- }
83
- static dropsPrivateFieldsWhileSelectingFields() {
84
- const values = normalizeSchemaValues(carSchema, { name: 'sweet!', privateField: 'go away', onlyOnCar: 'vroom' }, { shouldIncludePrivateFields: false, fields: ['onlyOnCar'] });
85
- assert.isExactType(true);
86
- }
87
- }
88
- __decorate([
89
- test()
90
- ], HandlesHidingPrivateFieldsTest, "typeMappingFieldNamesWorks", null);
91
- __decorate([
92
- test()
93
- ], HandlesHidingPrivateFieldsTest, "typeMappingValuesWorks", null);
94
- __decorate([
95
- test()
96
- ], HandlesHidingPrivateFieldsTest, "schemaCanDropPrivateFields", null);
97
- __decorate([
98
- test()
99
- ], HandlesHidingPrivateFieldsTest, "schemaCanKeepPrivateFields", null);
100
- __decorate([
101
- test()
102
- ], HandlesHidingPrivateFieldsTest, "schemaCanDropPrivateFieldsWhenSelectingFields", null);
103
- __decorate([
104
- test()
105
- ], HandlesHidingPrivateFieldsTest, "normalizeCanDropPrivateFields", null);
106
- __decorate([
107
- test()
108
- ], HandlesHidingPrivateFieldsTest, "normalizeCanKeepPrivateFields", null);
109
- __decorate([
110
- test()
111
- ], HandlesHidingPrivateFieldsTest, "dropsPrivateFieldsWhileSelectingFields", null);
@@ -1,9 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- export default class HandlesRelationshipsTest extends AbstractSchemaTest {
3
- protected static canDefineBasicRelationshipUsingTypes(): Promise<void>;
4
- protected static testGettingValueReturnsSchema(): void;
5
- protected static testIsArray(): void;
6
- protected static testingUnionOfSchemas(): void;
7
- protected static testUnionResolutionCreatingSchemas(): void;
8
- protected static testFieldWithCallback(): void;
9
- }
@@ -1,175 +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 SchemaField from '../../fields/SchemaField.js';
19
- import StaticSchemaEntityImplementation from '../../StaticSchemaEntityImplementation.js';
20
- import buildPersonWithCars from '../data/personWithCars.js';
21
- const { personSchema, carSchema } = buildPersonWithCars();
22
- export default class HandlesRelationshipsTest extends AbstractSchemaTest {
23
- static canDefineBasicRelationshipUsingTypes() {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const user = {
26
- name: 'go team',
27
- requiredCar: { name: 'go cart' },
28
- requiredIsArrayCars: [{ name: 'car 1' }, { name: 'car 2' }],
29
- requiredIsArrayCarOrTruck: [],
30
- };
31
- assert.isTruthy(user.name);
32
- assert.isTruthy(user.requiredCar);
33
- assert.isEqual(user.requiredCar.name, 'go cart');
34
- assert.isEqualDeep(user.requiredIsArrayCars, [
35
- { name: 'car 1' },
36
- { name: 'car 2' },
37
- ]);
38
- assert.isExactType(true);
39
- assert.isEqual(user.optionalCar, undefined);
40
- });
41
- }
42
- static testGettingValueReturnsSchema() {
43
- const person = new StaticSchemaEntityImplementation(personSchema, {
44
- requiredCar: { name: 'car', onlyOnCar: 'only on car!' },
45
- requiredIsArrayCars: [],
46
- requiredIsArrayCarOrTruck: [],
47
- });
48
- const car = person.get('requiredCar');
49
- assert.isTruthy(car);
50
- assert.isEqual(car.get('onlyOnCar'), 'only on car!');
51
- }
52
- static testIsArray() {
53
- const user = new StaticSchemaEntityImplementation(personSchema, {
54
- name: 'tay',
55
- requiredCar: { name: 'dirty car' },
56
- requiredIsArrayCarOrTruck: [],
57
- requiredIsArrayCars: [{ name: 'dirty car' }, { name: 'clean car' }],
58
- });
59
- let cars = user.get('requiredIsArrayCars');
60
- let firstCarValues = cars[0].getValues();
61
- assert.isEqualDeep(firstCarValues, {
62
- name: 'dirty car',
63
- onlyOnCar: undefined,
64
- privateField: undefined,
65
- });
66
- let carsFlat = user.get('requiredIsArrayCars', {
67
- shouldCreateEntityInstances: false,
68
- });
69
- assert.isEqualDeep(carsFlat, [
70
- {
71
- name: 'dirty car',
72
- onlyOnCar: undefined,
73
- privateField: undefined,
74
- },
75
- {
76
- name: 'clean car',
77
- onlyOnCar: undefined,
78
- privateField: undefined,
79
- },
80
- ]);
81
- // Test transforming to array works by setting isArray field to a single value
82
- // @ts-ignore
83
- user.values.requiredIsArrayCars = { name: 'scooter' };
84
- cars = user.get('requiredIsArrayCars');
85
- assert.isEqual(cars.length, 1);
86
- firstCarValues = cars[0].getValues();
87
- assert.isEqualDeep(firstCarValues, {
88
- name: 'scooter',
89
- onlyOnCar: undefined,
90
- privateField: undefined,
91
- });
92
- }
93
- static testingUnionOfSchemas() {
94
- const testSingleSchemaField = {
95
- schemaId: 'car',
96
- values: { name: 'fast car' },
97
- };
98
- if (testSingleSchemaField.schemaId === 'car') {
99
- assert.isEqual(testSingleSchemaField.values.name, 'fast car');
100
- }
101
- const testArraySchemaField = [
102
- { schemaId: 'car', values: { name: 'the car', onlyOnCar: 'so fast' } },
103
- {
104
- schemaId: 'truck',
105
- values: { name: 'the truck', onlyOnTruck: 'cary so much' },
106
- },
107
- ];
108
- testArraySchemaField.forEach((tool) => {
109
- if (tool.schemaId === 'truck') {
110
- assert.isEqual(tool.values.onlyOnTruck, 'cary so much');
111
- }
112
- });
113
- }
114
- static testUnionResolutionCreatingSchemas() {
115
- const person = new StaticSchemaEntityImplementation(personSchema, {
116
- requiredCar: { name: 'required name' },
117
- requiredIsArrayCars: [],
118
- requiredIsArrayCarOrTruck: [
119
- {
120
- schemaId: 'car',
121
- values: { name: 'fast car 1', onlyOnCar: 'so much fast' },
122
- },
123
- { schemaId: 'truck', values: { name: 'big truck 1' } },
124
- { schemaId: 'car', values: { name: 'fast car 2' } },
125
- {
126
- schemaId: 'truck',
127
- values: { name: 'big truck 2', onlyOnTruck: 'so much haul' },
128
- },
129
- ],
130
- });
131
- const requiredCarsOrTrucks = person.get('requiredIsArrayCarOrTruck');
132
- assert.isEqual(requiredCarsOrTrucks[0].schemaId, 'car');
133
- assert.isEqual(requiredCarsOrTrucks[1].schemaId, 'truck');
134
- assert.isEqual(requiredCarsOrTrucks[2].schemaId, 'car');
135
- assert.isEqual(requiredCarsOrTrucks[3].schemaId, 'truck');
136
- assert.isEqual(requiredCarsOrTrucks[0].schemaId === 'car' &&
137
- requiredCarsOrTrucks[0].get('name'), 'fast car 1');
138
- assert.isEqual(requiredCarsOrTrucks[3].schemaId === 'truck' &&
139
- requiredCarsOrTrucks[3].get('onlyOnTruck'), 'so much haul');
140
- }
141
- static testFieldWithCallback() {
142
- const person = new StaticSchemaEntityImplementation(personSchema);
143
- const car = new StaticSchemaEntityImplementation(carSchema, {
144
- name: 'fast',
145
- });
146
- person.set('optionalCarWithCallback', car.getValues());
147
- const carField = person
148
- .getNamedFields()
149
- .find((f) => f.name === 'optionalCarWithCallback');
150
- assert.isTruthy(carField);
151
- if (!carField) {
152
- return;
153
- }
154
- const ids = SchemaField.mapFieldDefinitionToSchemaIdsWithVersion(carField.field.definition);
155
- assert.isEqualDeep(ids, [{ id: carSchema.id }]);
156
- }
157
- }
158
- __decorate([
159
- test()
160
- ], HandlesRelationshipsTest, "canDefineBasicRelationshipUsingTypes", null);
161
- __decorate([
162
- test()
163
- ], HandlesRelationshipsTest, "testGettingValueReturnsSchema", null);
164
- __decorate([
165
- test()
166
- ], HandlesRelationshipsTest, "testIsArray", null);
167
- __decorate([
168
- test()
169
- ], HandlesRelationshipsTest, "testingUnionOfSchemas", null);
170
- __decorate([
171
- test()
172
- ], HandlesRelationshipsTest, "testUnionResolutionCreatingSchemas", null);
173
- __decorate([
174
- test()
175
- ], HandlesRelationshipsTest, "testFieldWithCallback", null);
@@ -1,4 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- export default class HandlesRequiredFieldsTest extends AbstractSchemaTest {
3
- protected static getsExpectedTypeBackFromOptionalFields(): Promise<void>;
4
- }
@@ -1,37 +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 StaticSchemaEntityImplementation from '../../StaticSchemaEntityImplementation.js';
19
- import buildPersonWithCars from '../data/personWithCars.js';
20
- export default class HandlesRequiredFieldsTest extends AbstractSchemaTest {
21
- static getsExpectedTypeBackFromOptionalFields() {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const { carSchema } = buildPersonWithCars();
24
- const car = new StaticSchemaEntityImplementation(carSchema, {
25
- name: 'taco',
26
- onlyOnCar: 'bell',
27
- });
28
- const name = car.get('name');
29
- const onlyOnCar = car.get('onlyOnCar');
30
- assert.isType(name);
31
- assert.isType(onlyOnCar);
32
- });
33
- }
34
- }
35
- __decorate([
36
- test()
37
- ], HandlesRequiredFieldsTest, "getsExpectedTypeBackFromOptionalFields", null);
@@ -1,6 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- export default class HandlesVersionedRelationshipsTest extends AbstractSchemaTest {
3
- protected static canGetV1AndV2OfARelatedField(): Promise<void>;
4
- protected static throwsWhenMissingVersionInUnionFields(): Promise<void>;
5
- protected static canSetSchemaFieldToOneOfAFewVersions(): Promise<void>;
6
- }
@@ -1,102 +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 StaticSchemaEntityImplementation from '../../StaticSchemaEntityImplementation.js';
19
- import buildVersionedPersonWithCars from '../data/versionedPersonWithCars.js';
20
- export default class HandlesVersionedRelationshipsTest extends AbstractSchemaTest {
21
- static canGetV1AndV2OfARelatedField() {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const { personV1Schema, personV2Schema, carV1Schema, carV2Schema } = buildVersionedPersonWithCars();
24
- assert.isEqual(personV1Schema.id, personV2Schema.id);
25
- assert.isEqual(personV1Schema.version, 'v1');
26
- assert.isEqual(personV2Schema.version, 'v2');
27
- assert.isEqual(carV1Schema.id, carV2Schema.id);
28
- assert.isEqual(carV1Schema.version, 'v1');
29
- assert.isEqual(carV2Schema.version, 'v2');
30
- });
31
- }
32
- static throwsWhenMissingVersionInUnionFields() {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const { personV2Schema, carV1Schema, carV2Schema } = buildVersionedPersonWithCars();
35
- const carV1 = new StaticSchemaEntityImplementation(carV1Schema, {
36
- name: 'version 1',
37
- });
38
- const carV2 = new StaticSchemaEntityImplementation(carV2Schema, {
39
- name: 'version 2',
40
- newRequiredOnCar: 'is required',
41
- });
42
- assert.isEqual(carV1.version, 'v1');
43
- assert.isEqual(carV2.version, 'v2');
44
- const person = new StaticSchemaEntityImplementation(personV2Schema, {
45
- requiredCar: carV2.getValues(),
46
- optionalCarWithCallback: { schemaId: 'car', values: carV1.getValues() },
47
- optionalCarOrTruck: { schemaId: 'car', values: carV2.getValues() },
48
- });
49
- assert.doesThrow(() => person.getValues(), /version/gi);
50
- });
51
- }
52
- static canSetSchemaFieldToOneOfAFewVersions() {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const { personV2Schema, carV1Schema, carV2Schema } = buildVersionedPersonWithCars();
55
- const carV1 = new StaticSchemaEntityImplementation(carV1Schema, {
56
- name: 'version 1',
57
- });
58
- const carV2 = new StaticSchemaEntityImplementation(carV2Schema, {
59
- name: 'version 2',
60
- newRequiredOnCar: 'is required',
61
- });
62
- assert.isEqual(carV1.version, 'v1');
63
- assert.isEqual(carV2.version, 'v2');
64
- const person = new StaticSchemaEntityImplementation(personV2Schema, {
65
- requiredCar: carV2.getValues(),
66
- optionalCarWithCallback: {
67
- schemaId: 'car',
68
- version: carV1.version,
69
- values: carV1.getValues(),
70
- },
71
- optionalCarOrTruck: {
72
- schemaId: 'car',
73
- version: carV2.version,
74
- values: carV2.getValues(),
75
- },
76
- requiredIsArrayCars: [],
77
- requiredIsArrayCarOrTruck: [],
78
- });
79
- const values = person.getValues();
80
- assert.isTruthy(values);
81
- const car = person.get('optionalCarOrTruck');
82
- switch (car && car.schemaId) {
83
- case 'truck':
84
- assert.fail('should have resolved to car');
85
- break;
86
- case 'car': {
87
- const values = car.getValues();
88
- assert.isEqual(values.name, 'version 2');
89
- }
90
- }
91
- });
92
- }
93
- }
94
- __decorate([
95
- test()
96
- ], HandlesVersionedRelationshipsTest, "canGetV1AndV2OfARelatedField", null);
97
- __decorate([
98
- test()
99
- ], HandlesVersionedRelationshipsTest, "throwsWhenMissingVersionInUnionFields", null);
100
- __decorate([
101
- test()
102
- ], HandlesVersionedRelationshipsTest, "canSetSchemaFieldToOneOfAFewVersions", null);
@@ -1,8 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- export default class HandlesVersioningTest extends AbstractSchemaTest {
3
- protected static letsMeBuildASchemaWithSameNameAndVersions(): Promise<void>;
4
- private static buildSchemas;
5
- protected static canAccessSchemaById(): Promise<void>;
6
- protected static getsBackCorrectSchema(): Promise<void>;
7
- protected static throwsIfYouForgetAVersionOnAVersioned(): Promise<void>;
8
- }
@@ -1,93 +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 buildSchema from '../../utilities/buildSchema.js';
19
- export default class HandlesVersioningTest extends AbstractSchemaTest {
20
- static letsMeBuildASchemaWithSameNameAndVersions() {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const { wrenchV1, wrenchV2 } = this.buildSchemas();
23
- assert.isTruthy(wrenchV1);
24
- assert.isTruthy(wrenchV2);
25
- });
26
- }
27
- static buildSchemas() {
28
- const wrenchV1 = buildSchema({
29
- id: 'wrench',
30
- name: 'Wrench',
31
- version: 'v1',
32
- fields: {
33
- length: {
34
- type: 'number',
35
- },
36
- },
37
- });
38
- const wrenchV2 = buildSchema({
39
- id: 'wrench',
40
- name: 'Wrench',
41
- version: 'v2',
42
- fields: {
43
- length: {
44
- type: 'number',
45
- },
46
- diameter: {
47
- type: 'number',
48
- isRequired: true,
49
- },
50
- },
51
- });
52
- return { wrenchV1, wrenchV2 };
53
- }
54
- static canAccessSchemaById() {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- this.buildSchemas();
57
- const wrenchV1 = this.registry.getSchema('wrench', 'v1');
58
- const wrenchV2 = this.registry.getSchema('wrench', 'v2');
59
- assert.isTruthy(wrenchV1);
60
- assert.isTruthy(wrenchV2);
61
- });
62
- }
63
- static getsBackCorrectSchema() {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- this.buildSchemas();
66
- const wrenchV1 = this.registry.getSchema('wrench', 'v1');
67
- const wrenchV2 = this.registry.getSchema('wrench', 'v2');
68
- assert.isTruthy(wrenchV1);
69
- assert.isTruthy(wrenchV2);
70
- assert.isEqual(wrenchV1.id, 'wrench');
71
- assert.isEqual(wrenchV2.id, 'wrench');
72
- assert.isNotEqual(wrenchV1.version, wrenchV2.version);
73
- });
74
- }
75
- static throwsIfYouForgetAVersionOnAVersioned() {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- this.buildSchemas();
78
- assert.doesThrow(() => this.registry.getSchema('wrench'), /VERSION_NOT_FOUND/gi);
79
- });
80
- }
81
- }
82
- __decorate([
83
- test()
84
- ], HandlesVersioningTest, "letsMeBuildASchemaWithSameNameAndVersions", null);
85
- __decorate([
86
- test()
87
- ], HandlesVersioningTest, "canAccessSchemaById", null);
88
- __decorate([
89
- test()
90
- ], HandlesVersioningTest, "getsBackCorrectSchema", null);
91
- __decorate([
92
- test()
93
- ], HandlesVersioningTest, "throwsIfYouForgetAVersionOnAVersioned", null);
@@ -1,4 +0,0 @@
1
- import AbstractSpruceTest from '@sprucelabs/test';
2
- export default class IsIdWithVersionTest extends AbstractSpruceTest {
3
- protected static isIdWithVersion(): Promise<void>;
4
- }
@@ -1,30 +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 isIdWithVersion from '../../utilities/isIdWithVersion.js';
18
- export default class IsIdWithVersionTest extends AbstractSpruceTest {
19
- static isIdWithVersion() {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- assert.isTrue(isIdWithVersion({ id: 'test', version: 'hey' }));
22
- assert.isFalse(isIdWithVersion({ id: 'test', fields: {} }));
23
- //@ts-ignore
24
- assert.isFalse(isIdWithVersion({ id: 'test', dynamicFieldSignature: {} }));
25
- });
26
- }
27
- }
28
- __decorate([
29
- test()
30
- ], IsIdWithVersionTest, "isIdWithVersion", null);
@@ -1,4 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- export default class MakingFieldsOptionalTest extends AbstractSchemaTest {
3
- protected static makeFieldsOptional(): Promise<void>;
4
- }
@@ -1,57 +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 { buildSchema } from '../../index.js';
18
- import AbstractSchemaTest from '../../AbstractSchemaTest.js';
19
- import makeFieldsOptional from '../../utilities/makeFieldsOptional.js';
20
- const personSchema = buildSchema({
21
- id: 'person-with-all-required',
22
- name: 'Person (all required fields)',
23
- fields: {
24
- firstName: {
25
- type: 'text',
26
- isRequired: true,
27
- },
28
- lastName: {
29
- type: 'text',
30
- isRequired: true,
31
- },
32
- },
33
- });
34
- export default class MakingFieldsOptionalTest extends AbstractSchemaTest {
35
- static makeFieldsOptional() {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const optionalPerson = Object.assign(Object.assign({}, personSchema), { fields: Object.assign({}, makeFieldsOptional(personSchema.fields)) });
38
- assert.isEqualDeep(optionalPerson, {
39
- id: 'person-with-all-required',
40
- name: 'Person (all required fields)',
41
- fields: {
42
- firstName: {
43
- type: 'text',
44
- isRequired: false,
45
- },
46
- lastName: {
47
- type: 'text',
48
- isRequired: false,
49
- },
50
- },
51
- });
52
- });
53
- }
54
- }
55
- __decorate([
56
- test()
57
- ], MakingFieldsOptionalTest, "makeFieldsOptional", null);
@@ -1,6 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- import { Schema, SchemaIdWithVersion } from '../../schemas.static.types';
3
- export default class NormalizeToSchemaIdWithVersionTest extends AbstractSchemaTest {
4
- protected static functionExists(): Promise<void>;
5
- protected static testNormalizing(schemaOrIdWithVersion: Schema | SchemaIdWithVersion, expected: SchemaIdWithVersion): Promise<void>;
6
- }