@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,281 +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 { errorAssertUtil } from '@sprucelabs/test-utils';
18
- import { unset } from 'lodash';
19
- import AbstractSchemaTest from '../../AbstractSchemaTest.js';
20
- import StaticSchemaEntityImplementation from '../../StaticSchemaEntityImplementation.js';
21
- import buildSchema from '../../utilities/buildSchema.js';
22
- import isSchemaValid from '../../utilities/isSchemaValid.js';
23
- import validateSchema from '../../utilities/validateSchema.js';
24
- import buildPersonWithCars from '../data/personWithCars.js';
25
- StaticSchemaEntityImplementation.enableDuplicateCheckWhenTracking = false;
26
- const { personSchema, truckSchema } = buildPersonWithCars();
27
- const nestedSchemas = buildSchema({
28
- id: 'contract',
29
- name: 'contract',
30
- fields: {
31
- requiredArrayField: {
32
- type: 'schema',
33
- isArray: true,
34
- isRequired: true,
35
- options: {
36
- schema: {
37
- id: 'nested',
38
- name: 'Nested',
39
- fields: {
40
- fieldOnNested: {
41
- type: 'text',
42
- isRequired: true,
43
- },
44
- },
45
- },
46
- },
47
- },
48
- },
49
- });
50
- const nestedSingleRequiredFieldSchemas = buildSchema({
51
- id: 'singleRequiredField',
52
- name: 'single required field',
53
- fields: {
54
- contract: {
55
- type: 'schema',
56
- isRequired: true,
57
- options: {
58
- schema: nestedSchemas,
59
- },
60
- },
61
- },
62
- });
63
- export default class SchemaTest extends AbstractSchemaTest {
64
- static testBasicValidation() {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- const schema = {
67
- id: 'simple-test',
68
- name: 'Simple Test Schema',
69
- };
70
- assert.isFalse(isSchemaValid(schema), 'Bad definition incorrectly passed valid check');
71
- });
72
- }
73
- static testMissingKeys(fieldToDelete, expectedErrors) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- const schema = buildSchema({
76
- id: 'missing-fields',
77
- name: 'missing name',
78
- fields: {
79
- firstName: {
80
- type: 'text',
81
- },
82
- lastName: {
83
- type: 'text',
84
- },
85
- },
86
- });
87
- unset(schema, fieldToDelete);
88
- const error = assert.doesThrow(() => validateSchema(schema));
89
- errorAssertUtil.assertError(error, 'INVALID_SCHEMA', {
90
- errors: expectedErrors,
91
- });
92
- });
93
- }
94
- static canIsArrayValue() {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- const schema = buildSchema({
97
- id: 'is-array-test',
98
- name: 'is array',
99
- fields: {
100
- name: {
101
- type: 'text',
102
- label: 'Name',
103
- value: 'Tay',
104
- },
105
- nicknames: {
106
- type: 'text',
107
- label: 'Nick names',
108
- isArray: true,
109
- value: ['Tay', 'Taylor'],
110
- },
111
- anotherName: {
112
- type: 'number',
113
- label: 'Favorite numbers',
114
- isArray: true,
115
- value: [10, 5, 5],
116
- },
117
- schemaField: {
118
- type: 'schema',
119
- label: 'Favorite numbers',
120
- isArray: true,
121
- options: {
122
- schema: {
123
- id: 'nested',
124
- name: 'Nested',
125
- fields: {},
126
- },
127
- },
128
- },
129
- },
130
- });
131
- assert.isTrue(isSchemaValid(schema));
132
- });
133
- }
134
- static getSetArrays() {
135
- const entity = new StaticSchemaEntityImplementation({
136
- id: 'missing-fields',
137
- name: 'missing name',
138
- fields: {
139
- name: {
140
- type: 'text',
141
- isArray: false,
142
- value: 'tay',
143
- },
144
- favoriteColors: {
145
- type: 'text',
146
- isArray: true,
147
- value: ['black'],
148
- },
149
- },
150
- });
151
- let values = entity.getValues({ fields: ['name'] });
152
- assert.isEqual(values.name, 'tay');
153
- assert.isUndefined(
154
- //@ts-ignore
155
- values.favoriteColors, 'getValues did not filter by fields');
156
- entity.set('favoriteColors', ['test']);
157
- assert.isEqualDeep(entity.get('favoriteColors'), ['test'], 'Did not set value correctly');
158
- // @ts-ignore
159
- entity.set('favoriteColors', 'test2');
160
- assert.isEqualDeep(entity.get('favoriteColors'), ['test2'], 'Did not set value correctly');
161
- entity.set('name', 'Taylor');
162
- assert.isEqualDeep(entity.getValues(), {
163
- name: 'Taylor',
164
- favoriteColors: ['test2'],
165
- });
166
- // @ts-ignore
167
- entity.setValues({ name: ['becca'], favoriteColors: 'blue' });
168
- const name = entity.get('name');
169
- assert.isEqual(name, 'becca');
170
- const colors = entity.get('favoriteColors');
171
- assert.isTrue(Array.isArray(colors), 'Getter did not transform colors into array');
172
- }
173
- static testTransformingValuesToValueTypes() {
174
- const schema = new StaticSchemaEntityImplementation({
175
- id: 'is-array-transform',
176
- name: 'transform tests',
177
- fields: {
178
- name: {
179
- type: 'text',
180
- isArray: false,
181
- value: 'tay',
182
- },
183
- favoriteColors: {
184
- type: 'text',
185
- isArray: true,
186
- value: ['blue'],
187
- },
188
- favoriteNumber: {
189
- type: 'number',
190
- },
191
- },
192
- });
193
- // @ts-ignore
194
- schema.set('favoriteColors', [1, 2, 3]);
195
- const favColors = schema.get('favoriteColors');
196
- assert.isEqualDeep(favColors, ['1', '2', '3']);
197
- // @ts-ignore
198
- schema.set('favoriteNumber', ['9', '8', '100']);
199
- const favNumber = schema.get('favoriteNumber');
200
- assert.isEqual(favNumber, 9, 'Schema did not transform array of strings to single number');
201
- }
202
- static testValuesTypesAgainstObjectLiteral() {
203
- const values = {
204
- name: 'test',
205
- onlyOnCar: null,
206
- };
207
- assert.isType(values);
208
- }
209
- static testFullValuesTypes() {
210
- const personEntity = new StaticSchemaEntityImplementation(personSchema);
211
- const values = personEntity.getValues({ shouldValidate: false });
212
- const valuesWithoutInstances = personEntity.getValues({
213
- shouldValidate: false,
214
- shouldCreateEntityInstances: false,
215
- });
216
- assert.isType(values);
217
- assert.isType(values);
218
- assert.isType(valuesWithoutInstances);
219
- }
220
- static testGettingOptionsByField() {
221
- const entity = new StaticSchemaEntityImplementation(personSchema);
222
- entity.set('name', 'a really long name that should get truncated');
223
- const name = entity.get('name', { byField: { name: { maxLength: 10 } } });
224
- assert.isEqual(name, 'a really l');
225
- }
226
- static canCorrectlyTypeSchemaWithOneRequiredField() {
227
- const values = {
228
- contract: {
229
- requiredArrayField: [],
230
- },
231
- };
232
- const { contract: { requiredArrayField }, } = values;
233
- function testFunc(_options) { }
234
- testFunc(requiredArrayField[0]);
235
- assert.isExactType(true);
236
- }
237
- static testGenerics() {
238
- const testObj = {
239
- payloadSchema: nestedSingleRequiredFieldSchemas,
240
- callback: (payload) => {
241
- const { requiredArrayField } = payload.contract;
242
- const mappedArray = requiredArrayField.map((item) => item.fieldOnNested);
243
- assert.isExactType(true);
244
- },
245
- };
246
- assert.isTruthy(testObj);
247
- }
248
- }
249
- __decorate([
250
- test()
251
- ], SchemaTest, "testBasicValidation", null);
252
- __decorate([
253
- test('Catches missing id', 'id', ['id_missing']),
254
- test('Catches missing fields', 'fields', [
255
- 'needs_fields_or_dynamic_field_signature',
256
- ])
257
- ], SchemaTest, "testMissingKeys", null);
258
- __decorate([
259
- test('Does isArray make value an array (test always passes, linting should fail if broken)')
260
- ], SchemaTest, "canIsArrayValue", null);
261
- __decorate([
262
- test()
263
- ], SchemaTest, "getSetArrays", null);
264
- __decorate([
265
- test()
266
- ], SchemaTest, "testTransformingValuesToValueTypes", null);
267
- __decorate([
268
- test()
269
- ], SchemaTest, "testValuesTypesAgainstObjectLiteral", null);
270
- __decorate([
271
- test()
272
- ], SchemaTest, "testFullValuesTypes", null);
273
- __decorate([
274
- test()
275
- ], SchemaTest, "testGettingOptionsByField", null);
276
- __decorate([
277
- test()
278
- ], SchemaTest, "canCorrectlyTypeSchemaWithOneRequiredField", null);
279
- __decorate([
280
- test()
281
- ], SchemaTest, "testGenerics", null);
@@ -1,14 +0,0 @@
1
- import { SchemaRegistry } from '../..';
2
- import AbstractSchemaTest from '../../AbstractSchemaTest';
3
- import { Schema } from '../../schemas.static.types';
4
- export default class UsingTheSchemaRegisteryForNamespacedSchemasTest extends AbstractSchemaTest {
5
- protected static registry: SchemaRegistry;
6
- protected static beforeEach(): Promise<void>;
7
- protected static throwsErrorIncludingNamespaceWhenNonFound(): void;
8
- protected static canRegisterNamespacedSchema(schemas: Schema[], lookups: {
9
- id: string;
10
- version?: string;
11
- namespace?: string;
12
- shouldMatchSchemaAtIdx: number;
13
- }[]): void;
14
- }
@@ -1,140 +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, SchemaRegistry } from '../../index.js';
18
- import AbstractSchemaTest from '../../AbstractSchemaTest.js';
19
- const namespacedUnVersionedPersonSchema = buildSchema({
20
- id: 'namespacedUnVersionedPerson',
21
- namespace: 'namespace-one',
22
- fields: {
23
- firstName: {
24
- type: 'text',
25
- },
26
- },
27
- });
28
- const namespaced2UnVersionedPersonSchema = buildSchema({
29
- id: 'namespacedUnVersionedPerson',
30
- namespace: 'namespace-two',
31
- fields: {
32
- firstName: {
33
- type: 'text',
34
- },
35
- },
36
- });
37
- const namespacedVersionedPersonSchema = buildSchema({
38
- id: 'namespacedUnVersionedPerson',
39
- namespace: 'namespace-one',
40
- version: 'v1',
41
- fields: {
42
- firstName: {
43
- type: 'text',
44
- },
45
- },
46
- });
47
- const namespaced2VersionedPersonSchema = buildSchema({
48
- id: 'namespacedUnVersionedPerson',
49
- namespace: 'namespace-one',
50
- version: 'v2',
51
- fields: {
52
- firstName: {
53
- type: 'text',
54
- },
55
- },
56
- });
57
- export default class UsingTheSchemaRegisteryForNamespacedSchemasTest extends AbstractSchemaTest {
58
- static beforeEach() {
59
- const _super = Object.create(null, {
60
- beforeEach: { get: () => super.beforeEach }
61
- });
62
- return __awaiter(this, void 0, void 0, function* () {
63
- yield _super.beforeEach.call(this);
64
- this.registry = new SchemaRegistry();
65
- });
66
- }
67
- static throwsErrorIncludingNamespaceWhenNonFound() {
68
- assert.doesThrow(() => this.registry.getSchema('made-up-id', '1.0', 'spruce'), /spruce.made-up-id\(version: 1.0\)/gi);
69
- assert.doesThrow(() => this.registry.getSchema('made-up-id', '1.0', 'spruce'), /1\.0/gi);
70
- assert.doesThrow(() => this.registry.getSchema('made-up-id', undefined, 'spruce'), /spruce/gi);
71
- }
72
- static canRegisterNamespacedSchema(schemas, lookups) {
73
- for (const schema of schemas) {
74
- this.registry.trackSchema(schema);
75
- }
76
- for (const lookup of lookups) {
77
- const gotPerson = this.registry.getSchema(lookup.id, lookup.version, lookup.namespace);
78
- assert.isTruthy(gotPerson);
79
- //@ts-ignore
80
- assert.isEqualDeep(schemas[lookup.shouldMatchSchemaAtIdx], gotPerson);
81
- }
82
- }
83
- }
84
- __decorate([
85
- test()
86
- ], UsingTheSchemaRegisteryForNamespacedSchemasTest, "throwsErrorIncludingNamespaceWhenNonFound", null);
87
- __decorate([
88
- test('Register 1 schema, 1 namespace', [namespacedUnVersionedPersonSchema], [
89
- {
90
- id: 'namespacedUnVersionedPerson',
91
- namespace: 'namespace-one',
92
- shouldMatchSchemaAtIdx: 0,
93
- },
94
- ]),
95
- test('Register 2 schemas with same id, 2 namespaces', [namespacedUnVersionedPersonSchema, namespaced2UnVersionedPersonSchema], [
96
- {
97
- id: 'namespacedUnVersionedPerson',
98
- namespace: 'namespace-two',
99
- shouldMatchSchemaAtIdx: 1,
100
- },
101
- {
102
- id: 'namespacedUnVersionedPerson',
103
- namespace: 'namespace-one',
104
- shouldMatchSchemaAtIdx: 0,
105
- },
106
- ]),
107
- test('Register 2 schemas with same id, 2 versions, 1 namespaces', [namespacedVersionedPersonSchema, namespaced2VersionedPersonSchema], [
108
- {
109
- id: 'namespacedUnVersionedPerson',
110
- version: 'v1',
111
- shouldMatchSchemaAtIdx: 0,
112
- },
113
- {
114
- id: 'namespacedUnVersionedPerson',
115
- version: 'v2',
116
- shouldMatchSchemaAtIdx: 1,
117
- },
118
- ]),
119
- test('Register 3 schemas with same id, 2 versions, 2 namespaces', [
120
- namespacedVersionedPersonSchema,
121
- namespaced2VersionedPersonSchema,
122
- namespaced2UnVersionedPersonSchema,
123
- ], [
124
- {
125
- id: 'namespacedUnVersionedPerson',
126
- version: 'v1',
127
- shouldMatchSchemaAtIdx: 0,
128
- },
129
- {
130
- id: 'namespacedUnVersionedPerson',
131
- version: 'v2',
132
- shouldMatchSchemaAtIdx: 1,
133
- },
134
- {
135
- id: 'namespacedUnVersionedPerson',
136
- namespace: 'namespace-two',
137
- shouldMatchSchemaAtIdx: 2,
138
- },
139
- ])
140
- ], UsingTheSchemaRegisteryForNamespacedSchemasTest, "canRegisterNamespacedSchema", null);
@@ -1,15 +0,0 @@
1
- import AbstractSpruceTest from '@sprucelabs/test';
2
- import SchemaRegistry from '../../singletons/SchemaRegistry';
3
- export default class UsingTheSchemaRegistryTest extends AbstractSpruceTest {
4
- protected static registry: SchemaRegistry;
5
- protected static beforeEach(): Promise<void>;
6
- protected static canAccessRegistryInstance(): void;
7
- protected static throwsWhenTrackingTwice(): void;
8
- protected static canRegisterUnVersionedSchema(): void;
9
- protected static canRegisterVersionAndUnVersionedSchema(): void;
10
- protected static schemasCanBeForgotten(): void;
11
- private static buildPersonsAllVersions;
12
- protected static versionedSchemasAreForgotten(): void;
13
- protected static canForgetAllSchemas(): void;
14
- protected static canGetAllSchemas(): void;
15
- }
@@ -1,117 +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, { assert, test } from '@sprucelabs/test';
17
- import SchemaRegistry from '../../singletons/SchemaRegistry.js';
18
- import buildPersonWithCars from '../data/personWithCars.js';
19
- import buildVersionedPersonWithCars from '../data/versionedPersonWithCars.js';
20
- export default class UsingTheSchemaRegistryTest extends AbstractSpruceTest {
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
- SchemaRegistry.getInstance().forgetAllSchemas();
28
- this.registry = new SchemaRegistry();
29
- });
30
- }
31
- static canAccessRegistryInstance() {
32
- assert.isTruthy(this.registry);
33
- }
34
- static throwsWhenTrackingTwice() {
35
- const { personSchema } = buildPersonWithCars();
36
- const { personV1Schema } = buildVersionedPersonWithCars();
37
- this.registry.trackSchema(personSchema);
38
- this.registry.trackSchema(personV1Schema);
39
- assert.doesThrow(() => this.registry.trackSchema(personSchema), /person/i);
40
- assert.doesThrow(() => this.registry.trackSchema(personV1Schema), /person\(version: v1\)/);
41
- }
42
- static canRegisterUnVersionedSchema() {
43
- const { personSchema } = buildPersonWithCars();
44
- this.registry.trackSchema(personSchema);
45
- const gotPerson = this.registry.getSchema(personSchema.id);
46
- assert.isEqualDeep(gotPerson, personSchema);
47
- }
48
- static canRegisterVersionAndUnVersionedSchema() {
49
- const { personSchema } = buildPersonWithCars();
50
- const { personV1Schema, personV2Schema } = buildVersionedPersonWithCars();
51
- this.registry.trackSchema(personSchema);
52
- this.registry.trackSchema(personV1Schema);
53
- this.registry.trackSchema(personV2Schema);
54
- assert.isEqualDeep(this.registry.getSchema(personSchema.id), personSchema);
55
- assert.isEqualDeep(this.registry.getSchema(personV1Schema.id, personV1Schema.version), personV1Schema);
56
- assert.isEqualDeep(this.registry.getSchema(personV2Schema.id, personV2Schema.version), personV2Schema);
57
- }
58
- static schemasCanBeForgotten() {
59
- const { personSchema } = buildPersonWithCars();
60
- this.registry.trackSchema(personSchema);
61
- this.registry.forgetSchema(personSchema.id);
62
- assert.doesThrow(() => this.registry.getSchema(personSchema.id), /'person'/);
63
- }
64
- static buildPersonsAllVersions() {
65
- const { personSchema } = buildPersonWithCars();
66
- const { personV1Schema, personV2Schema } = buildVersionedPersonWithCars();
67
- this.registry.trackSchema(personSchema);
68
- this.registry.trackSchema(personV1Schema);
69
- this.registry.trackSchema(personV2Schema);
70
- return { personSchema, personV1Schema, personV2Schema };
71
- }
72
- static versionedSchemasAreForgotten() {
73
- const { personSchema, personV1Schema, personV2Schema } = this.buildPersonsAllVersions();
74
- this.registry.forgetSchema(personSchema.id);
75
- assert.doesThrow(() => this.registry.getSchema(personSchema.id), /VERSION_NOT_FOUND/);
76
- assert.isEqualDeep(this.registry.getSchema(personV1Schema.id, personV1Schema.version), personV1Schema);
77
- assert.isEqualDeep(this.registry.getSchema(personV2Schema.id, personV2Schema.version), personV2Schema);
78
- this.registry.forgetSchema(personV2Schema.id, personV2Schema.version);
79
- assert.doesThrow(() => this.registry.getSchema(personV2Schema.id, personV2Schema.version), /VERSION_NOT_FOUND/);
80
- }
81
- static canForgetAllSchemas() {
82
- const { personSchema, personV1Schema, personV2Schema } = this.buildPersonsAllVersions();
83
- this.registry.forgetAllSchemas();
84
- for (const schema of [personSchema, personV1Schema, personV2Schema]) {
85
- assert.doesThrow(() => this.registry.getSchema(schema.id, schema.version), 'person');
86
- }
87
- }
88
- static canGetAllSchemas() {
89
- const { personSchema, personV1Schema, personV2Schema } = this.buildPersonsAllVersions();
90
- const pulled = this.registry.getAllSchemas();
91
- assert.isEqualDeep(pulled, [personSchema, personV1Schema, personV2Schema]);
92
- }
93
- }
94
- __decorate([
95
- test()
96
- ], UsingTheSchemaRegistryTest, "canAccessRegistryInstance", null);
97
- __decorate([
98
- test()
99
- ], UsingTheSchemaRegistryTest, "throwsWhenTrackingTwice", null);
100
- __decorate([
101
- test()
102
- ], UsingTheSchemaRegistryTest, "canRegisterUnVersionedSchema", null);
103
- __decorate([
104
- test()
105
- ], UsingTheSchemaRegistryTest, "canRegisterVersionAndUnVersionedSchema", null);
106
- __decorate([
107
- test()
108
- ], UsingTheSchemaRegistryTest, "schemasCanBeForgotten", null);
109
- __decorate([
110
- test()
111
- ], UsingTheSchemaRegistryTest, "versionedSchemasAreForgotten", null);
112
- __decorate([
113
- test()
114
- ], UsingTheSchemaRegistryTest, "canForgetAllSchemas", null);
115
- __decorate([
116
- test()
117
- ], UsingTheSchemaRegistryTest, "canGetAllSchemas", null);
@@ -1,28 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- export default class CanValidateSchemasTest extends AbstractSchemaTest {
3
- protected static beforeEach(): Promise<void>;
4
- protected static canValidateBasicSchemaValues(): Promise<void>;
5
- protected static canValidateSchemaWithArrayValues(): Promise<void>;
6
- protected static typesValidatedValues(): Promise<void>;
7
- protected static canValidateSpecificFields(): Promise<void>;
8
- protected static canCheckValidityWithoutThrowing(): Promise<void>;
9
- protected static canCheckValidityOnDynamicFieldsWithoutThrowing(): Promise<void>;
10
- protected static canCheckValidityOnSpecificFields(): Promise<void>;
11
- protected static failsOnSpecificFields(): Promise<void>;
12
- protected static passesWithValidPerson(): Promise<void>;
13
- protected static failsWithBadSchema(): Promise<void>;
14
- protected static failsWhenValidatingFieldsNotOnSchema(): Promise<void>;
15
- protected static givesInvalidFieldErrorWhenValidatingEmptyArrayNestedSchemas(): Promise<void>;
16
- protected static givesInvalidFieldErrorWhenValidatingNestedSchemas(): Promise<void>;
17
- protected static canValidateNestedArraySchema(): Promise<void>;
18
- protected static canValidateArrayOfUnionValuesMissingRequired(): Promise<void>;
19
- protected static canValidateArrayOfUnionValues(): Promise<void>;
20
- protected static canValidateArrayOfVersionedUnionValues(): Promise<void>;
21
- protected static canValidateArrayOfVersionedUnionValuesAndThrowsReallyHelpfulError(): Promise<void>;
22
- protected static throwsWhenAddingExtraFieldAtTopLevel(): void;
23
- protected static throwsWhenAddingExtraFieldInNestedSchema(): void;
24
- protected static validationErrorsAreTyped(): void;
25
- protected static printsSoPretty(): void;
26
- protected static dynamicSchemasHaveFieldNameInError(): void;
27
- protected static invalidFieldsGiveDescriptionsOnWhySomethingIsInvalid(): void;
28
- }