@api-client/core 0.18.53 → 0.18.55
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.
- package/build/src/modeling/Semantics.d.ts +32 -5
- package/build/src/modeling/Semantics.d.ts.map +1 -1
- package/build/src/modeling/Semantics.js +129 -5
- package/build/src/modeling/Semantics.js.map +1 -1
- package/build/src/modeling/definitions/Country.d.ts +38 -0
- package/build/src/modeling/definitions/Country.d.ts.map +1 -0
- package/build/src/modeling/definitions/Country.js +22 -0
- package/build/src/modeling/definitions/Country.js.map +1 -0
- package/build/src/modeling/definitions/PostalCode.d.ts +48 -0
- package/build/src/modeling/definitions/PostalCode.d.ts.map +1 -0
- package/build/src/modeling/definitions/PostalCode.js +22 -0
- package/build/src/modeling/definitions/PostalCode.js.map +1 -0
- package/build/src/modeling/helpers/Intelisense.d.ts +7 -0
- package/build/src/modeling/helpers/Intelisense.d.ts.map +1 -1
- package/build/src/modeling/helpers/Intelisense.js +135 -0
- package/build/src/modeling/helpers/Intelisense.js.map +1 -1
- package/build/src/modeling/templates/verticals/business-services/ecommerce-domain.d.ts.map +1 -1
- package/build/src/modeling/templates/verticals/business-services/ecommerce-domain.js +10 -0
- package/build/src/modeling/templates/verticals/business-services/ecommerce-domain.js.map +1 -1
- package/build/src/modeling/templates/verticals/business-services/financial-services-domain.d.ts.map +1 -1
- package/build/src/modeling/templates/verticals/business-services/financial-services-domain.js +14 -2
- package/build/src/modeling/templates/verticals/business-services/financial-services-domain.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +12 -12
- package/package.json +1 -1
- package/src/modeling/Semantics.ts +132 -5
- package/src/modeling/definitions/Country.ts +62 -0
- package/src/modeling/definitions/PostalCode.ts +70 -0
- package/src/modeling/helpers/Intelisense.ts +144 -0
- package/src/modeling/templates/verticals/business-services/ecommerce-domain.ts +10 -0
- package/src/modeling/templates/verticals/business-services/financial-services-domain.ts +15 -2
- package/tests/unit/modeling/helpers/intellisense.spec.ts +268 -0
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
|
|
26
26
|
import { DataDomain } from '../../../DataDomain.js'
|
|
27
27
|
import { SemanticType } from '../../../Semantics.js'
|
|
28
|
+
import { createCountrySemantic, DEFAULT_COUNTRY_CONFIG } from '../../../definitions/Country.js'
|
|
29
|
+
import { createPostalCodeSemantic, DEFAULT_POSTAL_CODE_CONFIG } from '../../../definitions/PostalCode.js'
|
|
28
30
|
import {
|
|
29
31
|
addIdField,
|
|
30
32
|
addNameField,
|
|
@@ -262,24 +264,35 @@ export default function createFinancialServicesDomain(options: CreateTemplateOpt
|
|
|
262
264
|
info: { name: 'address', displayName: 'Address', description: 'Customer residential address' },
|
|
263
265
|
type: 'string',
|
|
264
266
|
required: true,
|
|
267
|
+
semantics: [{ id: SemanticType.StreetAddress }],
|
|
265
268
|
})
|
|
266
269
|
|
|
267
270
|
customerProfileEntity.addProperty({
|
|
268
271
|
info: { name: 'city', displayName: 'City', description: 'Customer city' },
|
|
269
272
|
type: 'string',
|
|
270
273
|
required: true,
|
|
274
|
+
semantics: [{ id: SemanticType.City }],
|
|
271
275
|
})
|
|
272
276
|
|
|
273
277
|
customerProfileEntity.addProperty({
|
|
274
|
-
info: { name: 'state', displayName: 'State', description: '
|
|
278
|
+
info: { name: 'state', displayName: 'State/Province', description: 'State or province' },
|
|
275
279
|
type: 'string',
|
|
276
280
|
required: true,
|
|
281
|
+
semantics: [{ id: SemanticType.Region }],
|
|
277
282
|
})
|
|
278
283
|
|
|
279
284
|
customerProfileEntity.addProperty({
|
|
280
|
-
info: { name: '
|
|
285
|
+
info: { name: 'postal_code', displayName: 'ZIP/Postal Code', description: 'ZIP or postal code' },
|
|
281
286
|
type: 'string',
|
|
282
287
|
required: true,
|
|
288
|
+
semantics: [createPostalCodeSemantic(DEFAULT_POSTAL_CODE_CONFIG)],
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
customerProfileEntity.addProperty({
|
|
292
|
+
info: { name: 'country', displayName: 'Country', description: 'Country name' },
|
|
293
|
+
type: 'string',
|
|
294
|
+
required: true,
|
|
295
|
+
semantics: [createCountrySemantic(DEFAULT_COUNTRY_CONFIG)],
|
|
283
296
|
})
|
|
284
297
|
|
|
285
298
|
customerProfileEntity.addProperty({
|
|
@@ -32,8 +32,17 @@ import {
|
|
|
32
32
|
addUnitPriceField,
|
|
33
33
|
addCurrencyAmountField,
|
|
34
34
|
addRecommendedFields,
|
|
35
|
+
addDisplayNameField,
|
|
36
|
+
addRoleField,
|
|
37
|
+
addCountryField,
|
|
38
|
+
addPostalCodeField,
|
|
39
|
+
addStreetAddressField,
|
|
40
|
+
addCityField,
|
|
41
|
+
addRegionField,
|
|
35
42
|
} from '../../../../src/modeling/helpers/Intelisense.js'
|
|
36
43
|
import { SemanticType } from '../../../../src/modeling/Semantics.js'
|
|
44
|
+
import { createCountrySemantic } from '../../../../src/modeling/definitions/Country.js'
|
|
45
|
+
import { createPostalCodeSemantic } from '../../../../src/modeling/definitions/PostalCode.js'
|
|
37
46
|
|
|
38
47
|
function createTestEntity(): DomainEntity {
|
|
39
48
|
const domain = new DataDomain({ key: 'test-domain', info: { name: 'Test Domain' } })
|
|
@@ -259,6 +268,46 @@ test.group('addAutoField()', () => {
|
|
|
259
268
|
assert.equal(field.type, 'number')
|
|
260
269
|
assert.isTrue(field.required)
|
|
261
270
|
})
|
|
271
|
+
|
|
272
|
+
test('adds street address field when autoField is "street-address"', ({ assert }) => {
|
|
273
|
+
const entity = createTestEntity()
|
|
274
|
+
const field = addAutoField(entity, 'street-address') as DomainProperty
|
|
275
|
+
assert.instanceOf(field, DomainProperty)
|
|
276
|
+
assert.equal(field.info.name, 'street_address')
|
|
277
|
+
assert.isTrue(field.hasSemantic(SemanticType.StreetAddress))
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
test('adds city field when autoField is "city"', ({ assert }) => {
|
|
281
|
+
const entity = createTestEntity()
|
|
282
|
+
const field = addAutoField(entity, 'city') as DomainProperty
|
|
283
|
+
assert.instanceOf(field, DomainProperty)
|
|
284
|
+
assert.equal(field.info.name, 'city')
|
|
285
|
+
assert.isTrue(field.hasSemantic(SemanticType.City))
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
test('adds postal code field when autoField is "postal-code"', ({ assert }) => {
|
|
289
|
+
const entity = createTestEntity()
|
|
290
|
+
const field = addAutoField(entity, 'postal-code') as DomainProperty
|
|
291
|
+
assert.instanceOf(field, DomainProperty)
|
|
292
|
+
assert.equal(field.info.name, 'postal_code')
|
|
293
|
+
assert.isTrue(field.hasSemantic(SemanticType.PostalCode))
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
test('adds country field when autoField is "country"', ({ assert }) => {
|
|
297
|
+
const entity = createTestEntity()
|
|
298
|
+
const field = addAutoField(entity, 'country') as DomainProperty
|
|
299
|
+
assert.instanceOf(field, DomainProperty)
|
|
300
|
+
assert.equal(field.info.name, 'country')
|
|
301
|
+
assert.isTrue(field.hasSemantic(SemanticType.Country))
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
test('adds region field when autoField is "region"', ({ assert }) => {
|
|
305
|
+
const entity = createTestEntity()
|
|
306
|
+
const field = addAutoField(entity, 'region') as DomainProperty
|
|
307
|
+
assert.instanceOf(field, DomainProperty)
|
|
308
|
+
assert.equal(field.info.name, 'region')
|
|
309
|
+
assert.isTrue(field.hasSemantic(SemanticType.Region))
|
|
310
|
+
})
|
|
262
311
|
})
|
|
263
312
|
|
|
264
313
|
test.group('addIdField()', () => {
|
|
@@ -402,6 +451,33 @@ test.group('addNameField()', () => {
|
|
|
402
451
|
})
|
|
403
452
|
})
|
|
404
453
|
|
|
454
|
+
test.group('addDisplayNameField()', () => {
|
|
455
|
+
test('creates new display name field when none exists', ({ assert }) => {
|
|
456
|
+
const entity = createTestEntity()
|
|
457
|
+
const field = addDisplayNameField(entity) as DomainProperty
|
|
458
|
+
assert.instanceOf(field, DomainProperty)
|
|
459
|
+
assert.equal(field.info.name, 'display-name')
|
|
460
|
+
assert.equal(field.info.displayName, 'Display Name')
|
|
461
|
+
assert.equal(field.type, 'string')
|
|
462
|
+
assert.isTrue(field.semantics.length > 0)
|
|
463
|
+
})
|
|
464
|
+
|
|
465
|
+
test('returns existing display name field when one exists', ({ assert }) => {
|
|
466
|
+
const entity = createTestEntity()
|
|
467
|
+
const firstField = addDisplayNameField(entity) as DomainProperty
|
|
468
|
+
const secondField = addDisplayNameField(entity) as DomainProperty
|
|
469
|
+
assert.equal(firstField, secondField)
|
|
470
|
+
assert.lengthOf([...entity.properties], 1)
|
|
471
|
+
})
|
|
472
|
+
|
|
473
|
+
test('adds semantic annotation', ({ assert }) => {
|
|
474
|
+
const entity = createTestEntity()
|
|
475
|
+
const field = addDisplayNameField(entity) as DomainProperty
|
|
476
|
+
const hasSemantic = field.hasSemantic(SemanticType.Name)
|
|
477
|
+
assert.isTrue(hasSemantic)
|
|
478
|
+
})
|
|
479
|
+
})
|
|
480
|
+
|
|
405
481
|
test.group('addDescriptionField()', () => {
|
|
406
482
|
test('creates new description field when none exists', ({ assert }) => {
|
|
407
483
|
const entity = createTestEntity()
|
|
@@ -568,6 +644,36 @@ test.group('addDeletedAtField()', () => {
|
|
|
568
644
|
})
|
|
569
645
|
})
|
|
570
646
|
|
|
647
|
+
test.group('addRoleField()', () => {
|
|
648
|
+
test('creates new role field when none exists', ({ assert }) => {
|
|
649
|
+
const entity = createTestEntity()
|
|
650
|
+
const field = addRoleField(entity)
|
|
651
|
+
assert.instanceOf(field, DomainProperty)
|
|
652
|
+
assert.equal(field.info.name, 'role')
|
|
653
|
+
assert.equal(field.info.displayName, 'Role')
|
|
654
|
+
assert.equal(field.type, 'string')
|
|
655
|
+
assert.isTrue(field.index)
|
|
656
|
+
assert.deepEqual(field.schema?.defaultValue, { type: 'literal', value: 'user' })
|
|
657
|
+
assert.deepEqual(field.schema?.enum, ['user', 'admin'])
|
|
658
|
+
assert.isTrue(field.hasSemantic(SemanticType.UserRole))
|
|
659
|
+
})
|
|
660
|
+
|
|
661
|
+
test('returns existing role field when one exists', ({ assert }) => {
|
|
662
|
+
const entity = createTestEntity()
|
|
663
|
+
const firstField = addRoleField(entity)
|
|
664
|
+
const secondField = addRoleField(entity)
|
|
665
|
+
assert.equal(firstField, secondField)
|
|
666
|
+
assert.lengthOf([...entity.properties], 1)
|
|
667
|
+
})
|
|
668
|
+
|
|
669
|
+
test('merges custom info with defaults', ({ assert }) => {
|
|
670
|
+
const entity = createTestEntity()
|
|
671
|
+
const field = addRoleField(entity, { description: 'User role' })
|
|
672
|
+
assert.equal(field.info.name, 'role')
|
|
673
|
+
assert.equal(field.info.description, 'User role')
|
|
674
|
+
})
|
|
675
|
+
})
|
|
676
|
+
|
|
571
677
|
test.group('addIsDeletedField()', () => {
|
|
572
678
|
test('creates new is deleted field when none exists', ({ assert }) => {
|
|
573
679
|
const entity = createTestEntity()
|
|
@@ -969,3 +1075,165 @@ test.group('addRecommendedFields()', () => {
|
|
|
969
1075
|
assert.isAtLeast([...entity.properties].length, initialFieldCount + 1)
|
|
970
1076
|
})
|
|
971
1077
|
})
|
|
1078
|
+
|
|
1079
|
+
test.group('addCountryField()', () => {
|
|
1080
|
+
test('creates new country field when none exists', ({ assert }) => {
|
|
1081
|
+
const entity = createTestEntity()
|
|
1082
|
+
const field = addCountryField(entity) as DomainProperty
|
|
1083
|
+
assert.instanceOf(field, DomainProperty)
|
|
1084
|
+
assert.equal(field.info.name, 'country')
|
|
1085
|
+
assert.equal(field.type, 'string')
|
|
1086
|
+
assert.isTrue(field.required)
|
|
1087
|
+
assert.isTrue(field.index)
|
|
1088
|
+
assert.isTrue(field.semantics.length > 0)
|
|
1089
|
+
})
|
|
1090
|
+
|
|
1091
|
+
test('returns existing country field when one exists', ({ assert }) => {
|
|
1092
|
+
const entity = createTestEntity()
|
|
1093
|
+
const existingField = entity.addProperty({
|
|
1094
|
+
info: { name: 'country', displayName: 'Country' },
|
|
1095
|
+
type: 'string',
|
|
1096
|
+
semantics: [createCountrySemantic()],
|
|
1097
|
+
})
|
|
1098
|
+
const field = addCountryField(entity)
|
|
1099
|
+
assert.equal(field, existingField)
|
|
1100
|
+
})
|
|
1101
|
+
|
|
1102
|
+
test('merges custom info with defaults', ({ assert }) => {
|
|
1103
|
+
const entity = createTestEntity()
|
|
1104
|
+
const field = addCountryField(entity, { description: 'Country code' }) as DomainProperty
|
|
1105
|
+
assert.equal(field.info.name, 'country')
|
|
1106
|
+
assert.equal(field.info.displayName, 'Country')
|
|
1107
|
+
assert.equal(field.info.description, 'Country code')
|
|
1108
|
+
})
|
|
1109
|
+
})
|
|
1110
|
+
|
|
1111
|
+
test.group('addPostalCodeField()', () => {
|
|
1112
|
+
test('creates new postal code field when none exists', ({ assert }) => {
|
|
1113
|
+
const entity = createTestEntity()
|
|
1114
|
+
const field = addPostalCodeField(entity) as DomainProperty
|
|
1115
|
+
assert.instanceOf(field, DomainProperty)
|
|
1116
|
+
assert.equal(field.info.name, 'postal_code')
|
|
1117
|
+
assert.equal(field.info.displayName, 'Postal Code')
|
|
1118
|
+
assert.equal(field.type, 'string')
|
|
1119
|
+
assert.isTrue(field.required)
|
|
1120
|
+
assert.isTrue(field.index)
|
|
1121
|
+
assert.isTrue(field.semantics.length > 0)
|
|
1122
|
+
})
|
|
1123
|
+
|
|
1124
|
+
test('returns existing postal code field when one exists', ({ assert }) => {
|
|
1125
|
+
const entity = createTestEntity()
|
|
1126
|
+
const existingField = entity.addProperty({
|
|
1127
|
+
info: { name: 'postal_code', displayName: 'Postal Code' },
|
|
1128
|
+
type: 'string',
|
|
1129
|
+
semantics: [createPostalCodeSemantic()],
|
|
1130
|
+
})
|
|
1131
|
+
const field = addPostalCodeField(entity)
|
|
1132
|
+
assert.equal(field, existingField)
|
|
1133
|
+
})
|
|
1134
|
+
|
|
1135
|
+
test('merges custom info with defaults', ({ assert }) => {
|
|
1136
|
+
const entity = createTestEntity()
|
|
1137
|
+
const field = addPostalCodeField(entity, { description: 'ZIP code' }) as DomainProperty
|
|
1138
|
+
assert.equal(field.info.name, 'postal_code')
|
|
1139
|
+
assert.equal(field.info.displayName, 'Postal Code')
|
|
1140
|
+
assert.equal(field.info.description, 'ZIP code')
|
|
1141
|
+
})
|
|
1142
|
+
})
|
|
1143
|
+
|
|
1144
|
+
test.group('addStreetAddressField()', () => {
|
|
1145
|
+
test('creates new street address field when none exists', ({ assert }) => {
|
|
1146
|
+
const entity = createTestEntity()
|
|
1147
|
+
const field = addStreetAddressField(entity) as DomainProperty
|
|
1148
|
+
assert.instanceOf(field, DomainProperty)
|
|
1149
|
+
assert.equal(field.info.name, 'street_address')
|
|
1150
|
+
assert.equal(field.info.displayName, 'Street Address')
|
|
1151
|
+
assert.equal(field.type, 'string')
|
|
1152
|
+
assert.isTrue(field.required)
|
|
1153
|
+
assert.isTrue(field.semantics.length > 0)
|
|
1154
|
+
})
|
|
1155
|
+
|
|
1156
|
+
test('returns existing street address field when one exists', ({ assert }) => {
|
|
1157
|
+
const entity = createTestEntity()
|
|
1158
|
+
const existingField = entity.addProperty({
|
|
1159
|
+
info: { name: 'street_address', displayName: 'Street Address' },
|
|
1160
|
+
type: 'string',
|
|
1161
|
+
semantics: [{ id: SemanticType.StreetAddress }],
|
|
1162
|
+
})
|
|
1163
|
+
const field = addStreetAddressField(entity)
|
|
1164
|
+
assert.equal(field, existingField)
|
|
1165
|
+
})
|
|
1166
|
+
|
|
1167
|
+
test('merges custom info with defaults', ({ assert }) => {
|
|
1168
|
+
const entity = createTestEntity()
|
|
1169
|
+
const field = addStreetAddressField(entity, { description: 'Street address XXX' }) as DomainProperty
|
|
1170
|
+
assert.equal(field.info.name, 'street_address')
|
|
1171
|
+
assert.equal(field.info.displayName, 'Street Address')
|
|
1172
|
+
assert.equal(field.info.description, 'Street address XXX')
|
|
1173
|
+
})
|
|
1174
|
+
})
|
|
1175
|
+
|
|
1176
|
+
test.group('addCityField()', () => {
|
|
1177
|
+
test('creates new city field when none exists', ({ assert }) => {
|
|
1178
|
+
const entity = createTestEntity()
|
|
1179
|
+
const field = addCityField(entity) as DomainProperty
|
|
1180
|
+
assert.instanceOf(field, DomainProperty)
|
|
1181
|
+
assert.equal(field.info.name, 'city')
|
|
1182
|
+
assert.equal(field.info.displayName, 'City')
|
|
1183
|
+
assert.equal(field.type, 'string')
|
|
1184
|
+
assert.isTrue(field.required)
|
|
1185
|
+
assert.isTrue(field.index)
|
|
1186
|
+
assert.isTrue(field.semantics.length > 0)
|
|
1187
|
+
})
|
|
1188
|
+
|
|
1189
|
+
test('returns existing city field when one exists', ({ assert }) => {
|
|
1190
|
+
const entity = createTestEntity()
|
|
1191
|
+
const existingField = entity.addProperty({
|
|
1192
|
+
info: { name: 'city', displayName: 'City' },
|
|
1193
|
+
type: 'string',
|
|
1194
|
+
semantics: [{ id: SemanticType.City }],
|
|
1195
|
+
})
|
|
1196
|
+
const field = addCityField(entity)
|
|
1197
|
+
assert.equal(field, existingField)
|
|
1198
|
+
})
|
|
1199
|
+
|
|
1200
|
+
test('merges custom info with defaults', ({ assert }) => {
|
|
1201
|
+
const entity = createTestEntity()
|
|
1202
|
+
const field = addCityField(entity, { description: 'City XXX' }) as DomainProperty
|
|
1203
|
+
assert.equal(field.info.name, 'city')
|
|
1204
|
+
assert.equal(field.info.displayName, 'City')
|
|
1205
|
+
assert.equal(field.info.description, 'City XXX')
|
|
1206
|
+
})
|
|
1207
|
+
})
|
|
1208
|
+
|
|
1209
|
+
test.group('addRegionField()', () => {
|
|
1210
|
+
test('creates new region field when none exists', ({ assert }) => {
|
|
1211
|
+
const entity = createTestEntity()
|
|
1212
|
+
const field = addRegionField(entity) as DomainProperty
|
|
1213
|
+
assert.instanceOf(field, DomainProperty)
|
|
1214
|
+
assert.equal(field.info.name, 'region')
|
|
1215
|
+
assert.equal(field.info.displayName, 'Region')
|
|
1216
|
+
assert.equal(field.type, 'string')
|
|
1217
|
+
assert.isTrue(field.index)
|
|
1218
|
+
assert.isTrue(field.semantics.length > 0)
|
|
1219
|
+
})
|
|
1220
|
+
|
|
1221
|
+
test('returns existing region field when one exists', ({ assert }) => {
|
|
1222
|
+
const entity = createTestEntity()
|
|
1223
|
+
const existingField = entity.addProperty({
|
|
1224
|
+
info: { name: 'region', displayName: 'Region' },
|
|
1225
|
+
type: 'string',
|
|
1226
|
+
semantics: [{ id: SemanticType.Region }],
|
|
1227
|
+
})
|
|
1228
|
+
const field = addRegionField(entity)
|
|
1229
|
+
assert.equal(field, existingField)
|
|
1230
|
+
})
|
|
1231
|
+
|
|
1232
|
+
test('merges custom info with defaults', ({ assert }) => {
|
|
1233
|
+
const entity = createTestEntity()
|
|
1234
|
+
const field = addRegionField(entity, { description: 'Region XXX' }) as DomainProperty
|
|
1235
|
+
assert.equal(field.info.name, 'region')
|
|
1236
|
+
assert.equal(field.info.displayName, 'Region')
|
|
1237
|
+
assert.equal(field.info.description, 'Region XXX')
|
|
1238
|
+
})
|
|
1239
|
+
})
|