@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,191 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- import AbstractSpruceTest, { test, assert } from '@sprucelabs/test';
17
- import SchemaField from '../../fields/SchemaField.js';
18
- import { TemplateRenderAs, } from '../../types/template.types.js';
19
- import buildSchema from '../../utilities/buildSchema.js';
20
- export default class GeneratesRelationshipTemplatesTest extends AbstractSpruceTest {
21
- static testTemplateDetails(definition, renderAsValue, renderAsType, renderAsSchemaType) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const templateOptions = {
24
- language: 'ts',
25
- globalNamespace: 'SpruceSchemas',
26
- importAs: 'generated_test',
27
- templateItems: GeneratesRelationshipTemplatesTest.templateItems,
28
- definition: Object.assign(Object.assign({}, definition), { type: 'schema' }),
29
- renderAs: TemplateRenderAs.Type, // is overwritten below
30
- };
31
- const expected = {
32
- renderAsValue,
33
- renderAsType,
34
- renderAsSchemaType,
35
- };
36
- const rendersAs = Object.getOwnPropertyNames(TemplateRenderAs);
37
- rendersAs.forEach((renderAs) => {
38
- const options = Object.assign(Object.assign({}, templateOptions), {
39
- // @ts-ignore
40
- renderAs: TemplateRenderAs[renderAs] });
41
- const { valueType } = SchemaField.generateTemplateDetails(options);
42
- const exp = expected[`renderAs${renderAs}`];
43
- assert.isEqual(valueType, exp);
44
- });
45
- });
46
- }
47
- static throwsMissingVersion(definition) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- const templateOptions = {
50
- language: 'ts',
51
- globalNamespace: 'SpruceSchemas',
52
- importAs: 'generated_test',
53
- templateItems: GeneratesRelationshipTemplatesTest.templateItems,
54
- definition: Object.assign(Object.assign({}, definition), { type: 'schema' }),
55
- renderAs: TemplateRenderAs.Type, // is overwritten below
56
- };
57
- const rendersAs = Object.getOwnPropertyNames(TemplateRenderAs);
58
- yield Promise.all(rendersAs.map((renderAs) => __awaiter(this, void 0, void 0, function* () {
59
- const options = Object.assign(Object.assign({}, templateOptions), {
60
- // @ts-ignore
61
- renderAs: TemplateRenderAs[renderAs] });
62
- assert.doesThrow(() => SchemaField.generateTemplateDetails(options), /VERSION/);
63
- })));
64
- });
65
- }
66
- }
67
- GeneratesRelationshipTemplatesTest.wrenchV1Schema = buildSchema({
68
- id: 'wrench',
69
- name: 'Wrench',
70
- version: 'v1',
71
- fields: {
72
- wrenchSize: {
73
- type: 'number',
74
- label: 'Size',
75
- },
76
- },
77
- });
78
- GeneratesRelationshipTemplatesTest.wrenchV2Schema = buildSchema({
79
- id: 'wrench',
80
- name: 'Wrench',
81
- version: 'v2',
82
- fields: {
83
- wrenchSize: {
84
- type: 'number',
85
- label: 'Size',
86
- },
87
- },
88
- });
89
- GeneratesRelationshipTemplatesTest.screwdriverSchema = buildSchema({
90
- id: 'screwdriver',
91
- name: 'Screwdriver',
92
- fields: {
93
- isFlathead: {
94
- type: 'boolean',
95
- },
96
- screwdriverLength: {
97
- type: 'number',
98
- label: 'Length',
99
- },
100
- },
101
- });
102
- GeneratesRelationshipTemplatesTest.personSchema = buildSchema({
103
- id: 'union-person',
104
- name: 'Union Person',
105
- fields: {
106
- favoriteTool: {
107
- type: 'schema',
108
- options: {
109
- schemas: [
110
- GeneratesRelationshipTemplatesTest.wrenchV1Schema,
111
- GeneratesRelationshipTemplatesTest.wrenchV2Schema,
112
- GeneratesRelationshipTemplatesTest.screwdriverSchema,
113
- ],
114
- },
115
- },
116
- tools: {
117
- type: 'schema',
118
- isArray: true,
119
- options: {
120
- schemas: [
121
- GeneratesRelationshipTemplatesTest.wrenchV1Schema,
122
- GeneratesRelationshipTemplatesTest.wrenchV2Schema,
123
- GeneratesRelationshipTemplatesTest.screwdriverSchema,
124
- ],
125
- },
126
- },
127
- },
128
- });
129
- // the global template items[]
130
- GeneratesRelationshipTemplatesTest.templateItems = [
131
- {
132
- namePascal: 'UnionPerson',
133
- nameCamel: 'unionPerson',
134
- nameReadable: 'Union person',
135
- namespace: 'Core',
136
- id: GeneratesRelationshipTemplatesTest.personSchema.id,
137
- schema: GeneratesRelationshipTemplatesTest.personSchema,
138
- destinationDir: '#spruce/schemas',
139
- },
140
- {
141
- namePascal: 'Wrench',
142
- nameCamel: 'wrench',
143
- nameReadable: 'Wrench',
144
- namespace: 'Core',
145
- id: GeneratesRelationshipTemplatesTest.wrenchV1Schema.id,
146
- schema: GeneratesRelationshipTemplatesTest.wrenchV1Schema,
147
- destinationDir: '#spruce/schemas',
148
- },
149
- {
150
- namePascal: 'Wrench',
151
- nameCamel: 'wrench',
152
- nameReadable: 'Wrench',
153
- namespace: 'Core',
154
- id: GeneratesRelationshipTemplatesTest.wrenchV2Schema.id,
155
- schema: GeneratesRelationshipTemplatesTest.wrenchV2Schema,
156
- destinationDir: '#spruce/schemas',
157
- },
158
- {
159
- namePascal: 'screwdriver',
160
- nameCamel: 'screwdriver',
161
- nameReadable: 'Screwdriver',
162
- namespace: 'Core',
163
- id: GeneratesRelationshipTemplatesTest.screwdriverSchema.id,
164
- schema: GeneratesRelationshipTemplatesTest.screwdriverSchema,
165
- destinationDir: '#spruce/schemas',
166
- },
167
- ];
168
- __decorate([
169
- test('single value', {
170
- isArray: false,
171
- options: {
172
- schemaIds: [{ id: 'union-person' }, { id: 'wrench', version: 'v2' }],
173
- },
174
- }, '[unionPersonSchema, wrenchSchema_v2]', "{ schemaId: 'union-person', values: SpruceSchemas.Core.UnionPerson } | { schemaId: 'wrench', version: 'v2', values: SpruceSchemas.Core.v2.Wrench }", '(SpruceSchemas.Core.UnionPersonSchema | SpruceSchemas.Core.v2.WrenchSchema)[]'),
175
- test('is array', {
176
- isArray: true,
177
- options: {
178
- schemaIds: [{ id: 'union-person' }, { id: 'wrench', version: 'v1' }],
179
- },
180
- }, '[unionPersonSchema, wrenchSchema_v1]', "({ schemaId: 'union-person', values: SpruceSchemas.Core.UnionPerson } | { schemaId: 'wrench', version: 'v1', values: SpruceSchemas.Core.v1.Wrench })[]", '(SpruceSchemas.Core.UnionPersonSchema | SpruceSchemas.Core.v1.WrenchSchema)[]')
181
- ], GeneratesRelationshipTemplatesTest, "testTemplateDetails", null);
182
- __decorate([
183
- test('missing version non array value', {
184
- isArray: false,
185
- options: { schemaIds: [{ id: 'union-person' }, { id: 'wrench' }] },
186
- }),
187
- test('missing version array value', {
188
- isArray: true,
189
- options: { schemaId: { id: 'wrench' } },
190
- })
191
- ], GeneratesRelationshipTemplatesTest, "throwsMissingVersion", null);
@@ -1,7 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- export default class GettingFieldsOffASchemaTest extends AbstractSchemaTest {
3
- protected static throwsWithNothingPassed(): Promise<void>;
4
- protected static noFieldsThrows(): Promise<void>;
5
- protected static getsBacksFields(): Promise<void>;
6
- protected static getsBackMoreFields(): Promise<void>;
7
- }
@@ -1,88 +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 { buildSchema } from '../../index.js';
19
- import AbstractSchemaTest from '../../AbstractSchemaTest.js';
20
- import getFields from '../../utilities/getFields.js';
21
- const noFieldsSchema = buildSchema({
22
- id: 'noField',
23
- fields: {},
24
- });
25
- const withFieldsSchema = buildSchema({
26
- id: 'withField',
27
- fields: {
28
- firstName: {
29
- type: 'text',
30
- },
31
- },
32
- });
33
- const withManyFieldsSchema = buildSchema({
34
- id: 'withManyField',
35
- fields: {
36
- firstName: {
37
- type: 'text',
38
- },
39
- lastName: {
40
- type: 'text',
41
- },
42
- },
43
- });
44
- export default class GettingFieldsOffASchemaTest extends AbstractSchemaTest {
45
- static throwsWithNothingPassed() {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- //@ts-ignore
48
- const err = assert.doesThrow(() => getFields());
49
- errorAssertUtil.assertError(err, 'INVALID_PARAMETERS', {
50
- parameters: ['schema'],
51
- });
52
- });
53
- }
54
- static noFieldsThrows() {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- const err = assert.doesThrow(() => getFields(noFieldsSchema));
57
- errorAssertUtil.assertError(err, 'INVALID_PARAMETERS', {
58
- parameters: ['schema'],
59
- });
60
- });
61
- }
62
- static getsBacksFields() {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- const actual = getFields(withFieldsSchema);
65
- assert.isEqualDeep(actual, ['firstName']);
66
- assert.isExactType(true);
67
- });
68
- }
69
- static getsBackMoreFields() {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- const actual = getFields(withManyFieldsSchema);
72
- assert.isEqualDeep(actual, ['firstName', 'lastName']);
73
- assert.isExactType(true);
74
- });
75
- }
76
- }
77
- __decorate([
78
- test()
79
- ], GettingFieldsOffASchemaTest, "throwsWithNothingPassed", null);
80
- __decorate([
81
- test()
82
- ], GettingFieldsOffASchemaTest, "noFieldsThrows", null);
83
- __decorate([
84
- test()
85
- ], GettingFieldsOffASchemaTest, "getsBacksFields", null);
86
- __decorate([
87
- test()
88
- ], GettingFieldsOffASchemaTest, "getsBackMoreFields", null);
@@ -1,17 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- import { Schema } from '../../schemas.static.types';
3
- export default class HandlesDynamicFields extends AbstractSchemaTest {
4
- protected static canCreateSchemaEntityWithDynamicFields(): void;
5
- protected static optionalValuesTypeMapping(): void;
6
- protected static requiredValuesTypeMapping(): void;
7
- protected static typesStringValuesProperly(): void;
8
- protected static typesNumbersValuesProperly(): void;
9
- protected static typesRequiredNumbersValuesProperly(): void;
10
- protected static getValuesTransformation(schema: Schema, values: any, expected: any): void;
11
- protected static canValidate(): void;
12
- protected static canValidateUsingUtilityFunction(): void;
13
- protected static getsSets(): void;
14
- protected static throwsOnBadSet(): void;
15
- protected static typesAndNormalizedRelatedSchemasWithDynamicFields(): void;
16
- protected static typesAndNormalizesDynamicSchemas(): void;
17
- }
@@ -1,284 +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 { assert, test } from '@sprucelabs/test';
8
- import AbstractSchemaTest from '../../AbstractSchemaTest.js';
9
- import DynamicSchemaEntityImplementation from '../../DynamicSchemaEntityImplementation.js';
10
- import areSchemaValuesValid from '../../utilities/areSchemaValuesValid.js';
11
- import buildSchema from '../../utilities/buildSchema.js';
12
- import normalizeSchemaValues from '../../utilities/normalizeSchemaValues.js';
13
- import validateSchemaValues from '../../utilities/validateSchemaValues.js';
14
- const textDynamicSchema = buildSchema({
15
- id: 'textDynamic',
16
- name: 'Dynamic text based schema',
17
- dynamicFieldSignature: {
18
- type: 'text',
19
- keyName: 'key',
20
- },
21
- });
22
- const numberDynamicSchema = buildSchema({
23
- id: 'numberDynamic',
24
- name: 'Dynamic number based schema',
25
- dynamicFieldSignature: {
26
- type: 'number',
27
- keyName: 'key',
28
- },
29
- });
30
- const numberRequiredDynamicSchema = buildSchema({
31
- id: 'numberRequiredDynamic',
32
- name: 'Dynamic number based schema',
33
- dynamicFieldSignature: {
34
- type: 'number',
35
- isRequired: true,
36
- keyName: 'key',
37
- },
38
- });
39
- const arrayRequiredDynamicSchema = buildSchema({
40
- id: 'arrayRequiredDynamic',
41
- name: 'Dynamic number based schema',
42
- dynamicFieldSignature: {
43
- type: 'number',
44
- isRequired: true,
45
- isArray: true,
46
- keyName: 'key',
47
- },
48
- });
49
- export default class HandlesDynamicFields extends AbstractSchemaTest {
50
- static canCreateSchemaEntityWithDynamicFields() {
51
- const entity = new DynamicSchemaEntityImplementation(textDynamicSchema);
52
- assert.isTruthy(entity);
53
- }
54
- static optionalValuesTypeMapping() {
55
- const values = {
56
- hey: 5,
57
- };
58
- assert.isExactType(true);
59
- }
60
- static requiredValuesTypeMapping() {
61
- const values = {
62
- hey: 5,
63
- };
64
- assert.isExactType(true);
65
- assert.isExactType(false);
66
- }
67
- static typesStringValuesProperly() {
68
- const entity = new DynamicSchemaEntityImplementation(textDynamicSchema, {
69
- anything: 'foo',
70
- anythingElse: 'bar',
71
- });
72
- const values = entity.getValues();
73
- assert.isExactType(true);
74
- }
75
- static typesNumbersValuesProperly() {
76
- const entity = new DynamicSchemaEntityImplementation(numberDynamicSchema, {
77
- anything: 1,
78
- anythingElse: 3,
79
- });
80
- const values = entity.getValues();
81
- assert.isExactType(true);
82
- }
83
- static typesRequiredNumbersValuesProperly() {
84
- const entity = new DynamicSchemaEntityImplementation(numberRequiredDynamicSchema, {
85
- anything: 1,
86
- anythingElse: 3,
87
- });
88
- const values = entity.getValues();
89
- assert.isExactType(true);
90
- assert.isExactType(false);
91
- }
92
- static getValuesTransformation(schema, values, expected) {
93
- const entity = new DynamicSchemaEntityImplementation(schema, values);
94
- const actual = entity.getValues();
95
- assert.isEqualDeep(actual, expected);
96
- const entity2 = new DynamicSchemaEntityImplementation(schema);
97
- entity2.setValues(values);
98
- const actual2 = entity.getValues();
99
- assert.isEqualDeep(actual2, expected);
100
- }
101
- static canValidate() {
102
- const entity = new DynamicSchemaEntityImplementation(textDynamicSchema, {
103
- //@ts-ignore
104
- foo: { another: 'object' },
105
- });
106
- assert.doesThrow(() => entity.validate(), /should be a string/);
107
- assert.isFalse(entity.isValid());
108
- }
109
- static canValidateUsingUtilityFunction() {
110
- const values = {
111
- foo: { another: 'object' },
112
- };
113
- assert.doesThrow(() =>
114
- //@ts-ignore
115
- validateSchemaValues(textDynamicSchema, values, {
116
- shouldMapToParameterErrors: false,
117
- }), /should be a string/);
118
- //@ts-ignore
119
- assert.isFalse(areSchemaValuesValid(textDynamicSchema, values));
120
- }
121
- static getsSets() {
122
- const entity = new DynamicSchemaEntityImplementation(textDynamicSchema);
123
- entity.set('foo', 'bar');
124
- assert.isEqual(entity.get('foo'), 'bar');
125
- //@ts-ignore
126
- entity.set('bar', 3);
127
- assert.isEqual(entity.get('bar'), '3');
128
- }
129
- static throwsOnBadSet() {
130
- const entity = new DynamicSchemaEntityImplementation(numberDynamicSchema);
131
- assert.doesThrow(
132
- //@ts-ignore
133
- () => entity.set('foo', { hello: 'world' }), /not a number/);
134
- }
135
- static typesAndNormalizedRelatedSchemasWithDynamicFields() {
136
- const fullSchema = buildSchema({
137
- id: 'fullMessageAdapter',
138
- fields: {
139
- id: {
140
- type: 'id',
141
- isRequired: true,
142
- },
143
- dateCreated: {
144
- type: 'number',
145
- isRequired: true,
146
- },
147
- adapterName: {
148
- type: 'text',
149
- isRequired: true,
150
- },
151
- settings: {
152
- type: 'schema',
153
- isRequired: true,
154
- options: {
155
- schema: buildSchema({
156
- id: 'messageAdapterSettings',
157
- dynamicFieldSignature: {
158
- type: 'text',
159
- keyName: 'key',
160
- },
161
- }),
162
- },
163
- },
164
- },
165
- });
166
- const values = {
167
- id: '1',
168
- dateCreated: 2,
169
- adapterName: '3',
170
- settings: {},
171
- };
172
- values.settings.anything = 'true';
173
- assert.isExactType(true);
174
- const allValues = {
175
- id: '1',
176
- dateCreated: 2,
177
- adapterName: '3',
178
- settings: {
179
- first: 'first',
180
- },
181
- };
182
- assert.isExactType(true);
183
- const normalized = normalizeSchemaValues(fullSchema, {
184
- //@ts-ignore
185
- id: 1,
186
- //@ts-ignore
187
- dateCreated: '2',
188
- //@ts-ignore
189
- adapterName: 4,
190
- settings: {
191
- first: 'first',
192
- //@ts-ignore
193
- second: 2,
194
- },
195
- }, { shouldIncludePrivateFields: false });
196
- assert.isEqualDeep(normalized, {
197
- id: '1',
198
- dateCreated: 2,
199
- adapterName: '4',
200
- settings: {
201
- first: 'first',
202
- second: '2',
203
- },
204
- });
205
- }
206
- static typesAndNormalizesDynamicSchemas() {
207
- const fullSchema = buildSchema({
208
- id: 'aDynamicSchema',
209
- dynamicFieldSignature: {
210
- type: 'text',
211
- keyName: 'key',
212
- },
213
- });
214
- const values = {
215
- id: '1',
216
- dateCreated: 'hey',
217
- adapterName: '3',
218
- settings: 'there',
219
- };
220
- values.anything = 'true';
221
- assert.isExactType(true);
222
- const normalized = normalizeSchemaValues(fullSchema, {
223
- //@ts-ignore
224
- id: 1,
225
- //@ts-ignore
226
- dateCreated: '2',
227
- //@ts-ignore
228
- adapterName: 4,
229
- });
230
- assert.isEqualDeep(normalized, {
231
- id: '1',
232
- dateCreated: '2',
233
- adapterName: '4',
234
- });
235
- }
236
- }
237
- __decorate([
238
- test()
239
- ], HandlesDynamicFields, "canCreateSchemaEntityWithDynamicFields", null);
240
- __decorate([
241
- test()
242
- ], HandlesDynamicFields, "optionalValuesTypeMapping", null);
243
- __decorate([
244
- test()
245
- ], HandlesDynamicFields, "requiredValuesTypeMapping", null);
246
- __decorate([
247
- test()
248
- ], HandlesDynamicFields, "typesStringValuesProperly", null);
249
- __decorate([
250
- test()
251
- ], HandlesDynamicFields, "typesNumbersValuesProperly", null);
252
- __decorate([
253
- test()
254
- ], HandlesDynamicFields, "typesRequiredNumbersValuesProperly", null);
255
- __decorate([
256
- test('simple string passthrough', textDynamicSchema, { foo: 'bar', hello: 'world' }, { foo: 'bar', hello: 'world' }),
257
- test('simple number passthrough', numberDynamicSchema, { foo: 1, hello: 2 }, { foo: 1, hello: 2 }),
258
- test('transforms to strings', textDynamicSchema, { foo: 1, hello: 2 }, { foo: '1', hello: '2' }),
259
- test('transforms to numbers+array', arrayRequiredDynamicSchema, {
260
- foo: 1,
261
- bar: 2,
262
- }, {
263
- foo: [1],
264
- bar: [2],
265
- })
266
- ], HandlesDynamicFields, "getValuesTransformation", null);
267
- __decorate([
268
- test()
269
- ], HandlesDynamicFields, "canValidate", null);
270
- __decorate([
271
- test()
272
- ], HandlesDynamicFields, "canValidateUsingUtilityFunction", null);
273
- __decorate([
274
- test()
275
- ], HandlesDynamicFields, "getsSets", null);
276
- __decorate([
277
- test()
278
- ], HandlesDynamicFields, "throwsOnBadSet", null);
279
- __decorate([
280
- test()
281
- ], HandlesDynamicFields, "typesAndNormalizedRelatedSchemasWithDynamicFields", null);
282
- __decorate([
283
- test()
284
- ], HandlesDynamicFields, "typesAndNormalizesDynamicSchemas", null);
@@ -1,11 +0,0 @@
1
- import AbstractSchemaTest from '../../AbstractSchemaTest';
2
- export default class HandlesHidingPrivateFieldsTest extends AbstractSchemaTest {
3
- protected static typeMappingFieldNamesWorks(): void;
4
- protected static typeMappingValuesWorks(): void;
5
- protected static schemaCanDropPrivateFields(): Promise<void>;
6
- protected static schemaCanKeepPrivateFields(): Promise<void>;
7
- protected static schemaCanDropPrivateFieldsWhenSelectingFields(): Promise<void>;
8
- protected static normalizeCanDropPrivateFields(): void;
9
- protected static normalizeCanKeepPrivateFields(): void;
10
- protected static dropsPrivateFieldsWhileSelectingFields(): void;
11
- }