@api-client/core 0.18.58 → 0.18.59

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 (42) hide show
  1. package/build/src/decorators/observed.d.ts.map +1 -1
  2. package/build/src/decorators/observed.js +15 -1
  3. package/build/src/decorators/observed.js.map +1 -1
  4. package/build/src/modeling/actions/CreateAction.d.ts +2 -0
  5. package/build/src/modeling/actions/CreateAction.d.ts.map +1 -1
  6. package/build/src/modeling/actions/CreateAction.js +6 -0
  7. package/build/src/modeling/actions/CreateAction.js.map +1 -1
  8. package/build/src/modeling/actions/DeleteAction.d.ts +2 -0
  9. package/build/src/modeling/actions/DeleteAction.d.ts.map +1 -1
  10. package/build/src/modeling/actions/DeleteAction.js +6 -0
  11. package/build/src/modeling/actions/DeleteAction.js.map +1 -1
  12. package/build/src/modeling/actions/ListAction.d.ts +2 -0
  13. package/build/src/modeling/actions/ListAction.d.ts.map +1 -1
  14. package/build/src/modeling/actions/ListAction.js +8 -2
  15. package/build/src/modeling/actions/ListAction.js.map +1 -1
  16. package/build/src/modeling/actions/ReadAction.d.ts +2 -0
  17. package/build/src/modeling/actions/ReadAction.d.ts.map +1 -1
  18. package/build/src/modeling/actions/ReadAction.js +6 -0
  19. package/build/src/modeling/actions/ReadAction.js.map +1 -1
  20. package/build/src/modeling/actions/SearchAction.d.ts +2 -0
  21. package/build/src/modeling/actions/SearchAction.d.ts.map +1 -1
  22. package/build/src/modeling/actions/SearchAction.js +6 -0
  23. package/build/src/modeling/actions/SearchAction.js.map +1 -1
  24. package/build/src/modeling/actions/UpdateAction.d.ts +2 -0
  25. package/build/src/modeling/actions/UpdateAction.d.ts.map +1 -1
  26. package/build/src/modeling/actions/UpdateAction.js +6 -0
  27. package/build/src/modeling/actions/UpdateAction.js.map +1 -1
  28. package/build/src/modeling/rules/index.d.ts +3 -2
  29. package/build/src/modeling/rules/index.d.ts.map +1 -1
  30. package/build/src/modeling/rules/index.js +2 -1
  31. package/build/src/modeling/rules/index.js.map +1 -1
  32. package/build/tsconfig.tsbuildinfo +1 -1
  33. package/data/models/example-generator-api.json +27 -27
  34. package/package.json +1 -1
  35. package/src/decorators/observed.ts +15 -1
  36. package/src/modeling/actions/CreateAction.ts +8 -0
  37. package/src/modeling/actions/DeleteAction.ts +8 -0
  38. package/src/modeling/actions/ListAction.ts +10 -2
  39. package/src/modeling/actions/ReadAction.ts +8 -0
  40. package/src/modeling/actions/SearchAction.ts +8 -0
  41. package/src/modeling/actions/UpdateAction.ts +8 -0
  42. package/tests/unit/decorators/observed.spec.ts +42 -0
@@ -42062,9 +42062,6 @@
42062
42062
  "@id": "#209"
42063
42063
  },
42064
42064
  {
42065
- "@id": "#206"
42066
- },
42067
- {
42068
42065
  "@id": "#191"
42069
42066
  },
42070
42067
  {
@@ -42080,6 +42077,9 @@
42080
42077
  "@id": "#203"
42081
42078
  },
42082
42079
  {
42080
+ "@id": "#206"
42081
+ },
42082
+ {
42083
42083
  "@id": "#209"
42084
42084
  }
42085
42085
  ],
@@ -42810,16 +42810,16 @@
42810
42810
  "@id": "#219"
42811
42811
  },
42812
42812
  {
42813
- "@id": "#219"
42813
+ "@id": "#210"
42814
42814
  },
42815
42815
  {
42816
- "@id": "#216"
42816
+ "@id": "#213"
42817
42817
  },
42818
42818
  {
42819
- "@id": "#210"
42819
+ "@id": "#216"
42820
42820
  },
42821
42821
  {
42822
- "@id": "#213"
42822
+ "@id": "#219"
42823
42823
  }
42824
42824
  ],
42825
42825
  "doc:root": false,
@@ -43436,7 +43436,7 @@
43436
43436
  "doc:ExternalDomainElement",
43437
43437
  "doc:DomainElement"
43438
43438
  ],
43439
- "doc:raw": "addressType: 'REGISTERED-OFFICE-ADDRESS'\nstreetName: 'UITBREIDINGSTRAAT'\nhouseNumber: '84'\nhouseNumberAddition: '/1'\npostalCode: '2600'\ncity: 'BERCHEM (ANTWERPEN)'\ncountry: 'Belgium'\ncountryCode: 'BE'\nfullFormatedAddress: \"UITBREIDINGSTRAAT 84 /1, 2600 BERCHEM (ANTWERPEN), BELIUM\"\n",
43439
+ "doc:raw": "countryCode: \"BE\"\ngraydonEnterpriseId: 1057155523\nregistrationId: \"0422319093\"\nvatNumber: \"BE0422319093\"\ngraydonCompanyId: \"0422319093\"\nisBranchOffice: false\n",
43440
43440
  "core:mediaType": "application/yaml",
43441
43441
  "sourcemaps:sources": [
43442
43442
  {
@@ -43457,7 +43457,7 @@
43457
43457
  "doc:ExternalDomainElement",
43458
43458
  "doc:DomainElement"
43459
43459
  ],
43460
- "doc:raw": "code: '5'\ndescription: 'Limited company'\n",
43460
+ "doc:raw": "addressType: 'REGISTERED-OFFICE-ADDRESS'\nstreetName: 'UITBREIDINGSTRAAT'\nhouseNumber: '84'\nhouseNumberAddition: '/1'\npostalCode: '2600'\ncity: 'BERCHEM (ANTWERPEN)'\ncountry: 'Belgium'\ncountryCode: 'BE'\nfullFormatedAddress: \"UITBREIDINGSTRAAT 84 /1, 2600 BERCHEM (ANTWERPEN), BELIUM\"\n",
43461
43461
  "core:mediaType": "application/yaml",
43462
43462
  "sourcemaps:sources": [
43463
43463
  {
@@ -43478,7 +43478,7 @@
43478
43478
  "doc:ExternalDomainElement",
43479
43479
  "doc:DomainElement"
43480
43480
  ],
43481
- "doc:raw": "class: '3'\ndescription: '150 - 300'\nnumberOfFte: 5500\nnumberOfEmployees: 5232\n",
43481
+ "doc:raw": "code: '5'\ndescription: 'Limited company'\n",
43482
43482
  "core:mediaType": "application/yaml",
43483
43483
  "sourcemaps:sources": [
43484
43484
  {
@@ -43499,7 +43499,7 @@
43499
43499
  "doc:ExternalDomainElement",
43500
43500
  "doc:DomainElement"
43501
43501
  ],
43502
- "doc:raw": "code: 'J'\ndescription: 'Information and communication'\n",
43502
+ "doc:raw": "class: '3'\ndescription: '150 - 300'\nnumberOfFte: 5500\nnumberOfEmployees: 5232\n",
43503
43503
  "core:mediaType": "application/yaml",
43504
43504
  "sourcemaps:sources": [
43505
43505
  {
@@ -43520,7 +43520,7 @@
43520
43520
  "doc:ExternalDomainElement",
43521
43521
  "doc:DomainElement"
43522
43522
  ],
43523
- "doc:raw": "code: '7487'\ndescription: 'Financial and insurance activities'\ntype: \"PRIMARY\"\nclassificationCode: 'BE_NACEBEL2008'\nactivityGroupCode: 'ABCDE'\n",
43523
+ "doc:raw": "code: 'J'\ndescription: 'Information and communication'\n",
43524
43524
  "core:mediaType": "application/yaml",
43525
43525
  "sourcemaps:sources": [
43526
43526
  {
@@ -43541,7 +43541,7 @@
43541
43541
  "doc:ExternalDomainElement",
43542
43542
  "doc:DomainElement"
43543
43543
  ],
43544
- "doc:raw": "countryCode: \"BE\"\ngraydonEnterpriseId: 1057155523\nregistrationId: \"0422319093\"\nvatNumber: \"BE0422319093\"\ngraydonCompanyId: \"0422319093\"\nisBranchOffice: false\n",
43544
+ "doc:raw": "code: '7487'\ndescription: 'Financial and insurance activities'\ntype: \"PRIMARY\"\nclassificationCode: 'BE_NACEBEL2008'\nactivityGroupCode: 'ABCDE'\n",
43545
43545
  "core:mediaType": "application/yaml",
43546
43546
  "sourcemaps:sources": [
43547
43547
  {
@@ -44232,7 +44232,7 @@
44232
44232
  "doc:ExternalDomainElement",
44233
44233
  "doc:DomainElement"
44234
44234
  ],
44235
- "doc:raw": "-\n type: 'GENERAL'\n value: 'info@company.be'\n-\n type: 'IT_DEPT'\n value: 'it-service@company.be'\n",
44235
+ "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '22'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)22 000000'\n",
44236
44236
  "core:mediaType": "application/yaml",
44237
44237
  "sourcemaps:sources": [
44238
44238
  {
@@ -44253,7 +44253,7 @@
44253
44253
  "doc:ExternalDomainElement",
44254
44254
  "doc:DomainElement"
44255
44255
  ],
44256
- "doc:raw": "type: \"GENERAL\"\nvalue: \"www.company.be\"\n",
44256
+ "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\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": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
44277
+ "doc:raw": "-\n type: 'GENERAL'\n value: 'info@company.be'\n-\n type: 'IT_DEPT'\n value: 'it-service@company.be'\n",
44278
44278
  "core:mediaType": "application/yaml",
44279
44279
  "sourcemaps:sources": [
44280
44280
  {
@@ -44295,7 +44295,7 @@
44295
44295
  "doc:ExternalDomainElement",
44296
44296
  "doc:DomainElement"
44297
44297
  ],
44298
- "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '22'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)22 000000'\n",
44298
+ "doc:raw": "type: \"GENERAL\"\nvalue: \"www.company.be\"\n",
44299
44299
  "core:mediaType": "application/yaml",
44300
44300
  "sourcemaps:sources": [
44301
44301
  {
@@ -44756,32 +44756,32 @@
44756
44756
  {
44757
44757
  "@id": "#193/source-map/lexical/element_0",
44758
44758
  "sourcemaps:element": "amf://id#193",
44759
- "sourcemaps:value": "[(1,0)-(10,0)]"
44759
+ "sourcemaps:value": "[(1,0)-(7,0)]"
44760
44760
  },
44761
44761
  {
44762
44762
  "@id": "#196/source-map/lexical/element_0",
44763
44763
  "sourcemaps:element": "amf://id#196",
44764
- "sourcemaps:value": "[(1,0)-(3,0)]"
44764
+ "sourcemaps:value": "[(1,0)-(10,0)]"
44765
44765
  },
44766
44766
  {
44767
44767
  "@id": "#199/source-map/lexical/element_0",
44768
44768
  "sourcemaps:element": "amf://id#199",
44769
- "sourcemaps:value": "[(1,0)-(5,0)]"
44769
+ "sourcemaps:value": "[(1,0)-(3,0)]"
44770
44770
  },
44771
44771
  {
44772
44772
  "@id": "#202/source-map/lexical/element_0",
44773
44773
  "sourcemaps:element": "amf://id#202",
44774
- "sourcemaps:value": "[(1,0)-(3,0)]"
44774
+ "sourcemaps:value": "[(1,0)-(5,0)]"
44775
44775
  },
44776
44776
  {
44777
44777
  "@id": "#205/source-map/lexical/element_0",
44778
44778
  "sourcemaps:element": "amf://id#205",
44779
- "sourcemaps:value": "[(1,0)-(6,0)]"
44779
+ "sourcemaps:value": "[(1,0)-(3,0)]"
44780
44780
  },
44781
44781
  {
44782
44782
  "@id": "#208/source-map/lexical/element_0",
44783
44783
  "sourcemaps:element": "amf://id#208",
44784
- "sourcemaps:value": "[(1,0)-(7,0)]"
44784
+ "sourcemaps:value": "[(1,0)-(6,0)]"
44785
44785
  },
44786
44786
  {
44787
44787
  "@id": "#223/source-map/lexical/element_0",
@@ -45116,22 +45116,22 @@
45116
45116
  {
45117
45117
  "@id": "#212/source-map/lexical/element_0",
45118
45118
  "sourcemaps:element": "amf://id#212",
45119
- "sourcemaps:value": "[(1,0)-(7,0)]"
45119
+ "sourcemaps:value": "[(1,0)-(6,0)]"
45120
45120
  },
45121
45121
  {
45122
45122
  "@id": "#215/source-map/lexical/element_0",
45123
45123
  "sourcemaps:element": "amf://id#215",
45124
- "sourcemaps:value": "[(1,0)-(3,0)]"
45124
+ "sourcemaps:value": "[(1,0)-(6,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)-(6,0)]"
45129
+ "sourcemaps:value": "[(1,0)-(7,0)]"
45130
45130
  },
45131
45131
  {
45132
45132
  "@id": "#221/source-map/lexical/element_0",
45133
45133
  "sourcemaps:element": "amf://id#221",
45134
- "sourcemaps:value": "[(1,0)-(6,0)]"
45134
+ "sourcemaps:value": "[(1,0)-(3,0)]"
45135
45135
  },
45136
45136
  {
45137
45137
  "@id": "#338/source-map/synthesized-field/element_1",
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.58",
4
+ "version": "0.18.59",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
7
7
  "./browser.js": {
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  const reactiveSymbol = Symbol('reactive')
3
3
  const proxySymbol = Symbol('proxy')
4
+ const rawSymbol = Symbol('raw')
4
5
 
5
6
  interface DomainInstance {
6
7
  domain?: { notifyChange(): void }
@@ -38,6 +39,13 @@ export interface ObserveConfig {
38
39
  * @returns The not proxied object or undefined
39
40
  */
40
41
  export function toRaw<T extends object = object>(source: object, target: T): T | undefined {
42
+ if (target && (target as any)[rawSymbol]) {
43
+ let raw = (target as any)[rawSymbol]
44
+ while (raw && (raw as any)[rawSymbol]) {
45
+ raw = (raw as any)[rawSymbol]
46
+ }
47
+ return raw as T
48
+ }
41
49
  const proxies = Reflect.get(source, proxySymbol) as Map<object, object>
42
50
  if (!proxies) {
43
51
  return undefined
@@ -101,7 +109,7 @@ export function observed(config: ObserveConfig = {}): PropertyDecorator {
101
109
  }
102
110
 
103
111
  if (proxies.has(obj)) {
104
- return obj
112
+ return proxies.get(obj)
105
113
  }
106
114
 
107
115
  // eslint-disable-next-line @typescript-eslint/no-this-alias
@@ -109,6 +117,12 @@ export function observed(config: ObserveConfig = {}): PropertyDecorator {
109
117
 
110
118
  const proxy = new Proxy(obj, {
111
119
  get(target, prop) {
120
+ if (prop === proxySymbol) {
121
+ return Reflect.get(target, prop)
122
+ }
123
+ if (prop === rawSymbol) {
124
+ return target
125
+ }
112
126
  const value = Reflect.get(target, prop)
113
127
  return createDeepProxy.bind(targetObject)(value, notifyChange)
114
128
  },
@@ -27,4 +27,12 @@ export class CreateAction extends Action implements CreateActionSchema {
27
27
  kind: 'create',
28
28
  }
29
29
  }
30
+
31
+ static isCreateAction(action: Action): action is CreateAction {
32
+ return action.kind === 'create'
33
+ }
34
+
35
+ static isCreateActionSchema(schema: ActionSchema): schema is CreateActionSchema {
36
+ return schema.kind === 'create'
37
+ }
30
38
  }
@@ -48,4 +48,12 @@ export class DeleteAction extends Action implements DeleteActionSchema {
48
48
  retentionPeriod: this.retentionPeriod,
49
49
  }
50
50
  }
51
+
52
+ static isDeleteAction(action: Action): action is DeleteAction {
53
+ return action.kind === 'delete'
54
+ }
55
+
56
+ static isDeleteActionSchema(schema: ActionSchema): schema is DeleteActionSchema {
57
+ return schema.kind === 'delete'
58
+ }
51
59
  }
@@ -32,8 +32,8 @@ export interface ListActionSchema extends ActionSchema {
32
32
  export class ListAction extends Action implements ListActionSchema {
33
33
  @observed() override accessor kind: 'list'
34
34
  @observed({ deep: true }) accessor pagination: PaginationStrategy
35
- @observed({ deep: true }) accessor filterableFields: string[]
36
- @observed({ deep: true }) accessor sortableFields: string[]
35
+ @observed({ deep: true }) accessor filterableFields: string[] = []
36
+ @observed({ deep: true }) accessor sortableFields: string[] = []
37
37
 
38
38
  constructor(state: Partial<ListActionSchema> = {}) {
39
39
  super(state)
@@ -55,4 +55,12 @@ export class ListAction extends Action implements ListActionSchema {
55
55
  sortableFields: structuredClone(toRaw(this, this.sortableFields)) as string[],
56
56
  }
57
57
  }
58
+
59
+ static isListAction(action: Action): action is ListAction {
60
+ return action.kind === 'list'
61
+ }
62
+
63
+ static isListActionSchema(schema: ActionSchema): schema is ListActionSchema {
64
+ return schema.kind === 'list'
65
+ }
58
66
  }
@@ -29,4 +29,12 @@ export class ReadAction extends Action implements ReadActionSchema {
29
29
  kind: 'read',
30
30
  }
31
31
  }
32
+
33
+ static isReadAction(action: Action): action is ReadAction {
34
+ return action.kind === 'read'
35
+ }
36
+
37
+ static isReadActionSchema(schema: ActionSchema): schema is ReadActionSchema {
38
+ return schema.kind === 'read'
39
+ }
32
40
  }
@@ -35,4 +35,12 @@ export class SearchAction extends Action implements SearchActionSchema {
35
35
  fields: structuredClone(toRaw(this, this.fields)) as string[],
36
36
  }
37
37
  }
38
+
39
+ static isSearchActionSchema(schema: ActionSchema): schema is SearchActionSchema {
40
+ return schema.kind === 'search'
41
+ }
42
+
43
+ static isSearchAction(action: Action): action is SearchAction {
44
+ return action.kind === 'search'
45
+ }
38
46
  }
@@ -38,4 +38,12 @@ export class UpdateAction extends Action implements UpdateActionSchema {
38
38
  allowedMethods: structuredClone(toRaw(this, this.allowedMethods)) as ('PUT' | 'PATCH')[],
39
39
  }
40
40
  }
41
+
42
+ static isUpdateAction(action: Action): action is UpdateAction {
43
+ return action.kind === 'update'
44
+ }
45
+
46
+ static isUpdateActionSchema(schema: ActionSchema): schema is UpdateActionSchema {
47
+ return schema.kind === 'update'
48
+ }
41
49
  }
@@ -446,6 +446,48 @@ test.group('toRaw function', () => {
446
446
  const raw = toRaw(instance, obj)
447
447
  assert.equal(raw, undefined)
448
448
  }).tags(['@decorators', '@toRaw', '@core', '@unit', '@fast'])
449
+
450
+ test('should handle nested deep proxies (regression test)', ({ assert }) => {
451
+ const mockDomain = {
452
+ notifyChange() {},
453
+ }
454
+
455
+ class Child {
456
+ name = 'child'
457
+ }
458
+
459
+ class Parent {
460
+ domain = mockDomain
461
+ @observed({ deep: true }) accessor child: Child
462
+
463
+ constructor() {
464
+ this.child = new Child()
465
+ }
466
+ }
467
+
468
+ class GrandParent {
469
+ domain = mockDomain
470
+ @observed({ deep: true }) accessor parent: Parent
471
+
472
+ constructor() {
473
+ this.parent = new Parent()
474
+ }
475
+ }
476
+
477
+ const gp = new GrandParent()
478
+ // gp.parent is a proxy
479
+ // gp.parent.child is a nested proxy (proxy of a proxy)
480
+ const childProxy = gp.parent.child
481
+
482
+ const raw = toRaw(gp.parent, childProxy)
483
+
484
+ assert.isDefined(raw)
485
+ assert.equal(raw?.name, 'child')
486
+
487
+ // Should be able to structure clone it (proving it's a clean object without proxy wrappers)
488
+ const cloned = structuredClone(raw)
489
+ assert.deepEqual(cloned, { name: 'child' })
490
+ }).tags(['@decorators', '@toRaw', '@core', '@unit', '@regression'])
449
491
  })
450
492
 
451
493
  test.group('edge cases and error conditions', () => {