@api-client/core 0.18.53 → 0.18.54

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.
@@ -42813,10 +42813,10 @@
42813
42813
  "@id": "#210"
42814
42814
  },
42815
42815
  {
42816
- "@id": "#213"
42816
+ "@id": "#216"
42817
42817
  },
42818
42818
  {
42819
- "@id": "#216"
42819
+ "@id": "#213"
42820
42820
  },
42821
42821
  {
42822
42822
  "@id": "#219"
@@ -44253,7 +44253,7 @@
44253
44253
  "doc:ExternalDomainElement",
44254
44254
  "doc:DomainElement"
44255
44255
  ],
44256
- "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
44256
+ "doc:raw": "-\n type: 'GENERAL'\n value: 'info@company.be'\n-\n type: 'IT_DEPT'\n value: 'it-service@company.be'\n",
44257
44257
  "core:mediaType": "application/yaml",
44258
44258
  "sourcemaps:sources": [
44259
44259
  {
@@ -44274,7 +44274,7 @@
44274
44274
  "doc:ExternalDomainElement",
44275
44275
  "doc:DomainElement"
44276
44276
  ],
44277
- "doc:raw": "-\n type: 'GENERAL'\n value: 'info@company.be'\n-\n type: 'IT_DEPT'\n value: 'it-service@company.be'\n",
44277
+ "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
44278
44278
  "core:mediaType": "application/yaml",
44279
44279
  "sourcemaps:sources": [
44280
44280
  {
@@ -45121,12 +45121,12 @@
45121
45121
  {
45122
45122
  "@id": "#215/source-map/lexical/element_0",
45123
45123
  "sourcemaps:element": "amf://id#215",
45124
- "sourcemaps:value": "[(1,0)-(6,0)]"
45124
+ "sourcemaps:value": "[(1,0)-(7,0)]"
45125
45125
  },
45126
45126
  {
45127
45127
  "@id": "#218/source-map/lexical/element_0",
45128
45128
  "sourcemaps:element": "amf://id#218",
45129
- "sourcemaps:value": "[(1,0)-(7,0)]"
45129
+ "sourcemaps:value": "[(1,0)-(6,0)]"
45130
45130
  },
45131
45131
  {
45132
45132
  "@id": "#221/source-map/lexical/element_0",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-client/core",
3
3
  "description": "The API Client's core client library. Works in NodeJS and in a ES enabled browser.",
4
- "version": "0.18.53",
4
+ "version": "0.18.54",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
7
7
  "./browser.js": {
@@ -29,6 +29,8 @@ export function addAutoField(entity: DomainEntity, autoField: string): DomainEle
29
29
  return addEmailField(entity)
30
30
  case 'name':
31
31
  return addNameField(entity)
32
+ case 'display-name':
33
+ return addDisplayNameField(entity)
32
34
  case 'description':
33
35
  return addDescriptionField(entity)
34
36
  case 'status':
@@ -49,6 +51,8 @@ export function addAutoField(entity: DomainEntity, autoField: string): DomainEle
49
51
  return addIsDeletedField(entity)
50
52
  case 'deleted':
51
53
  return addDeletedAtField(entity)
54
+ case 'role':
55
+ return addRoleField(entity)
52
56
  case 'first-name':
53
57
  return addFirstNameField(entity)
54
58
  case 'last-name':
@@ -70,8 +74,12 @@ export function addAutoField(entity: DomainEntity, autoField: string): DomainEle
70
74
  case 'images':
71
75
  return addImagesField(entity)
72
76
  case 'session-id':
77
+ // This was removed from the UI. We will not support session id configuration
78
+ // as the platform will handle it to separate the business logic from the transport layer.
73
79
  return addSessionIdField(entity)
74
80
  case 'expires-at':
81
+ // This was removed from the UI. We will not support expires at configuration
82
+ // as the platform will handle it to separate the business logic from the transport layer.
75
83
  return addExpiresAtField(entity)
76
84
  case 'unit-price':
77
85
  return addUnitPriceField(entity)
@@ -198,6 +206,21 @@ export function addNameField(entity: DomainEntity, info: Partial<IThing> = {}):
198
206
  return prop
199
207
  }
200
208
 
209
+ export function addDisplayNameField(entity: DomainEntity, info: Partial<IThing> = {}): DomainProperty {
210
+ const existing = findDisplayNameField(entity, true)
211
+ if (existing) {
212
+ return existing
213
+ }
214
+ const prop = entity.addProperty({
215
+ info: { name: 'display-name', displayName: 'Display Name', ...info },
216
+ type: 'string',
217
+ })
218
+ prop.addSemantic({
219
+ id: SemanticType.Name,
220
+ })
221
+ return prop
222
+ }
223
+
201
224
  /**
202
225
  * Adds a description field to the specified entity.
203
226
  * If a description field already exists, it returns the existing field.
@@ -472,6 +495,24 @@ export function addDeletedAtField(entity: DomainEntity, info: Partial<IThing> =
472
495
  return prop
473
496
  }
474
497
 
498
+ export function addRoleField(entity: DomainEntity, info: Partial<IThing> = {}): DomainProperty {
499
+ const existing = findRoleField(entity, true)
500
+ if (existing) {
501
+ return existing
502
+ }
503
+ const prop = entity.addProperty({
504
+ info: { name: 'role', displayName: 'Role', ...info },
505
+ type: 'string',
506
+ required: true,
507
+ index: true,
508
+ schema: { defaultValue: { type: 'literal', value: 'user' }, enum: ['user', 'admin'] },
509
+ })
510
+ prop.addSemantic({
511
+ id: SemanticType.UserRole,
512
+ })
513
+ return prop
514
+ }
515
+
475
516
  /**
476
517
  * Adds an is_deleted field to the specified entity.
477
518
  * If an is_deleted field already exists, it returns the existing field.
@@ -1134,6 +1175,10 @@ function findNameField(entity: DomainEntity, direct = false): DomainProperty | u
1134
1175
  return findPropertyField(entity, (property) => property.hasSemantic(SemanticType.Title), direct)
1135
1176
  }
1136
1177
 
1178
+ function findDisplayNameField(entity: DomainEntity, direct = false): DomainProperty | undefined {
1179
+ return findPropertyField(entity, (property) => property.hasSemantic(SemanticType.Name), direct)
1180
+ }
1181
+
1137
1182
  function findDescriptionField(entity: DomainEntity, direct = false): DomainProperty | undefined {
1138
1183
  return findPropertyField(entity, (property) => property.hasSemantic(SemanticType.Description), direct)
1139
1184
  }
@@ -1196,6 +1241,10 @@ function findDeletedAtField(entity: DomainEntity, direct = false): DomainPropert
1196
1241
  )
1197
1242
  }
1198
1243
 
1244
+ function findRoleField(entity: DomainEntity, direct = false): DomainProperty | undefined {
1245
+ return findPropertyField(entity, (property) => property.hasSemantic(SemanticType.UserRole), direct)
1246
+ }
1247
+
1199
1248
  function findIsDeletedField(entity: DomainEntity, direct = false): DomainProperty | undefined {
1200
1249
  return findPropertyField(entity, (property) => property.hasSemantic(SemanticType.DeletedFlag), direct)
1201
1250
  }
@@ -32,6 +32,8 @@ import {
32
32
  addUnitPriceField,
33
33
  addCurrencyAmountField,
34
34
  addRecommendedFields,
35
+ addDisplayNameField,
36
+ addRoleField,
35
37
  } from '../../../../src/modeling/helpers/Intelisense.js'
36
38
  import { SemanticType } from '../../../../src/modeling/Semantics.js'
37
39
 
@@ -402,6 +404,33 @@ test.group('addNameField()', () => {
402
404
  })
403
405
  })
404
406
 
407
+ test.group('addDisplayNameField()', () => {
408
+ test('creates new display name field when none exists', ({ assert }) => {
409
+ const entity = createTestEntity()
410
+ const field = addDisplayNameField(entity) as DomainProperty
411
+ assert.instanceOf(field, DomainProperty)
412
+ assert.equal(field.info.name, 'display-name')
413
+ assert.equal(field.info.displayName, 'Display Name')
414
+ assert.equal(field.type, 'string')
415
+ assert.isTrue(field.semantics.length > 0)
416
+ })
417
+
418
+ test('returns existing display name field when one exists', ({ assert }) => {
419
+ const entity = createTestEntity()
420
+ const firstField = addDisplayNameField(entity) as DomainProperty
421
+ const secondField = addDisplayNameField(entity) as DomainProperty
422
+ assert.equal(firstField, secondField)
423
+ assert.lengthOf([...entity.properties], 1)
424
+ })
425
+
426
+ test('adds semantic annotation', ({ assert }) => {
427
+ const entity = createTestEntity()
428
+ const field = addDisplayNameField(entity) as DomainProperty
429
+ const hasSemantic = field.hasSemantic(SemanticType.Name)
430
+ assert.isTrue(hasSemantic)
431
+ })
432
+ })
433
+
405
434
  test.group('addDescriptionField()', () => {
406
435
  test('creates new description field when none exists', ({ assert }) => {
407
436
  const entity = createTestEntity()
@@ -568,6 +597,36 @@ test.group('addDeletedAtField()', () => {
568
597
  })
569
598
  })
570
599
 
600
+ test.group('addRoleField()', () => {
601
+ test('creates new role field when none exists', ({ assert }) => {
602
+ const entity = createTestEntity()
603
+ const field = addRoleField(entity)
604
+ assert.instanceOf(field, DomainProperty)
605
+ assert.equal(field.info.name, 'role')
606
+ assert.equal(field.info.displayName, 'Role')
607
+ assert.equal(field.type, 'string')
608
+ assert.isTrue(field.index)
609
+ assert.deepEqual(field.schema?.defaultValue, { type: 'literal', value: 'user' })
610
+ assert.deepEqual(field.schema?.enum, ['user', 'admin'])
611
+ assert.isTrue(field.hasSemantic(SemanticType.UserRole))
612
+ })
613
+
614
+ test('returns existing role field when one exists', ({ assert }) => {
615
+ const entity = createTestEntity()
616
+ const firstField = addRoleField(entity)
617
+ const secondField = addRoleField(entity)
618
+ assert.equal(firstField, secondField)
619
+ assert.lengthOf([...entity.properties], 1)
620
+ })
621
+
622
+ test('merges custom info with defaults', ({ assert }) => {
623
+ const entity = createTestEntity()
624
+ const field = addRoleField(entity, { description: 'User role' })
625
+ assert.equal(field.info.name, 'role')
626
+ assert.equal(field.info.description, 'User role')
627
+ })
628
+ })
629
+
571
630
  test.group('addIsDeletedField()', () => {
572
631
  test('creates new is deleted field when none exists', ({ assert }) => {
573
632
  const entity = createTestEntity()