@api-client/core 0.18.40 → 0.18.46

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.
@@ -4,16 +4,27 @@ import {
4
4
  type MockHandler,
5
5
  type SetupWorkerOptions,
6
6
  type InterceptOptions,
7
+ type SerializedRequest,
7
8
  } from '@jarrodek/amw'
8
9
  import type { IOrganization } from '../models/store/Organization.js'
9
10
  import type { GroupSchema } from '../models/store/Group.js'
10
11
  import type { IUser } from '../models/store/User.js'
11
12
  import type { InvitationSchema } from '../models/store/Invitation.js'
12
13
  import { type IFile, type FileBreadcrumb } from '../models/store/File.js'
13
- import type { ContextListResult, IBulkOperationResult } from '../events/BaseEvents.js'
14
+ import type { ContextChangeRecord, ContextListResult, IBulkOperationResult } from '../events/BaseEvents.js'
14
15
  import type { TrashEntry } from '../models/TrashEntry.js'
15
16
  import { RouteBuilder } from './RouteBuilder.js'
16
17
  import { ModelingMock } from '../mocking/ModelingMock.js'
18
+ import type {
19
+ DataCatalogSchema,
20
+ DataCatalogSchemaWithVersion,
21
+ DataCatalogStatus,
22
+ DataCatalogVersionInfo,
23
+ } from '../models/DataCatalog.js'
24
+ import type { DataCatalogVersionSchema } from '../models/DataCatalogVersion.js'
25
+ import { DataDomain, type DataDomainSchema } from '../modeling/DataDomain.js'
26
+ import type { ForeignDomainDependency } from '../modeling/types.js'
27
+ import { nanoid } from '../nanoid.js'
17
28
 
18
29
  export interface MockResult {
19
30
  /**
@@ -150,7 +161,7 @@ export class SdkMock {
150
161
  protected createDefaultResponse(
151
162
  status: number,
152
163
  headers?: Record<string, string>,
153
- body?: () => string,
164
+ body?: (req: SerializedRequest) => string,
154
165
  userConfig?: MockResult
155
166
  ): ResponseGenerator {
156
167
  let respond: ResponseGenerator
@@ -171,10 +182,10 @@ export class SdkMock {
171
182
  }
172
183
  if (!respond.body && userConfig?.forceBody && body) {
173
184
  // when body is missing and forceBody is set, generate the body
174
- respond.body = body()
185
+ respond.body = (req: SerializedRequest) => body(req)
175
186
  } else if (body && (!userConfig || !userConfig.response)) {
176
187
  // we set the body by default when the user config is missing
177
- respond.body = body()
188
+ respond.body = (req: SerializedRequest) => body(req)
178
189
  }
179
190
  return respond
180
191
  }
@@ -1362,4 +1373,342 @@ export class SdkMock {
1362
1373
  )
1363
1374
  },
1364
1375
  }
1376
+
1377
+ /**
1378
+ * Trash Data Catalog mocks.
1379
+ */
1380
+ dataCatalog = {
1381
+ list: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
1382
+ const { mock } = this
1383
+ const respond = this.createDefaultResponse(
1384
+ 200,
1385
+ { 'content-type': 'application/json' },
1386
+ () => {
1387
+ const obj: ContextListResult<DataCatalogSchemaWithVersion> = {
1388
+ items: this.gen.dataCatalog.dataCatalogsWithVersion(init?.size ?? 5),
1389
+ cursor: this.createCursorOption(init),
1390
+ }
1391
+ return JSON.stringify(obj)
1392
+ },
1393
+ init
1394
+ )
1395
+ await mock.add(
1396
+ {
1397
+ match: {
1398
+ uri: RouteBuilder.dataCatalog(),
1399
+ methods: ['GET'],
1400
+ },
1401
+ respond,
1402
+ },
1403
+ options
1404
+ )
1405
+ },
1406
+
1407
+ listVersions: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
1408
+ const { mock } = this
1409
+ const respond = this.createDefaultResponse(
1410
+ 200,
1411
+ { 'content-type': 'application/json' },
1412
+ () => {
1413
+ const obj: ContextListResult<DataCatalogVersionInfo> = {
1414
+ items: this.gen.dataCatalog.versionInfos(init?.size ?? 5),
1415
+ cursor: this.createCursorOption(init),
1416
+ }
1417
+ return JSON.stringify(obj)
1418
+ },
1419
+ init
1420
+ )
1421
+ await mock.add(
1422
+ {
1423
+ match: {
1424
+ uri: RouteBuilder.dataCatalogEntryVersions(':id'),
1425
+ methods: ['GET'],
1426
+ },
1427
+ respond,
1428
+ },
1429
+ options
1430
+ )
1431
+ },
1432
+
1433
+ publish: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
1434
+ const { mock } = this
1435
+ const respond = this.createDefaultResponse(
1436
+ 200,
1437
+ { 'content-type': 'application/json' },
1438
+ () => {
1439
+ const obj = this.gen.dataCatalog.dataCatalog()
1440
+ const result: ContextChangeRecord<DataCatalogSchema> = {
1441
+ key: obj.key,
1442
+ item: obj,
1443
+ kind: obj.kind,
1444
+ }
1445
+ return JSON.stringify(result)
1446
+ },
1447
+ init
1448
+ )
1449
+ await mock.add(
1450
+ {
1451
+ match: {
1452
+ uri: RouteBuilder.dataCatalog(),
1453
+ methods: ['POST'],
1454
+ },
1455
+ respond,
1456
+ },
1457
+ options
1458
+ )
1459
+ },
1460
+
1461
+ read: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
1462
+ const { mock } = this
1463
+ const respond = this.createDefaultResponse(
1464
+ 200,
1465
+ { 'content-type': 'application/json' },
1466
+ (req: SerializedRequest) => {
1467
+ const obj = this.gen.dataCatalog.dataCatalog({ key: req.params.id })
1468
+ return JSON.stringify(obj)
1469
+ },
1470
+ init
1471
+ )
1472
+ await mock.add(
1473
+ {
1474
+ match: {
1475
+ uri: RouteBuilder.dataCatalogEntry(':id'),
1476
+ methods: ['GET'],
1477
+ },
1478
+ respond,
1479
+ },
1480
+ options
1481
+ )
1482
+ },
1483
+
1484
+ deprecate: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
1485
+ const { mock } = this
1486
+ const respond = this.createDefaultResponse(
1487
+ 200,
1488
+ { 'content-type': 'application/json' },
1489
+ (req: SerializedRequest) => {
1490
+ const obj = this.gen.dataCatalog.dataCatalog({ key: req.params.id })
1491
+ const result: ContextChangeRecord<DataCatalogSchema> = {
1492
+ key: obj.key,
1493
+ item: obj,
1494
+ kind: obj.kind,
1495
+ }
1496
+ return JSON.stringify(result)
1497
+ },
1498
+ init
1499
+ )
1500
+ await mock.add(
1501
+ {
1502
+ match: {
1503
+ uri: RouteBuilder.dataCatalogDeprecate(':id'),
1504
+ methods: ['PUT'],
1505
+ },
1506
+ respond,
1507
+ },
1508
+ options
1509
+ )
1510
+ },
1511
+
1512
+ unpublish: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
1513
+ const { mock } = this
1514
+ const respond = this.createDefaultResponse(
1515
+ 200,
1516
+ { 'content-type': 'application/json' },
1517
+ (req: SerializedRequest) => {
1518
+ const obj = this.gen.dataCatalog.dataCatalog({ key: req.params.id })
1519
+ const result: ContextChangeRecord<DataCatalogSchema> = {
1520
+ key: obj.key,
1521
+ item: obj,
1522
+ kind: obj.kind,
1523
+ }
1524
+ return JSON.stringify(result)
1525
+ },
1526
+ init
1527
+ )
1528
+ await mock.add(
1529
+ {
1530
+ match: {
1531
+ uri: RouteBuilder.dataCatalogUnpublish(':id'),
1532
+ methods: ['PUT'],
1533
+ },
1534
+ respond,
1535
+ },
1536
+ options
1537
+ )
1538
+ },
1539
+
1540
+ publishVersion: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
1541
+ const { mock } = this
1542
+ const respond = this.createDefaultResponse(
1543
+ 200,
1544
+ { 'content-type': 'application/json' },
1545
+ (req: SerializedRequest) => {
1546
+ const raw = req.body as string
1547
+ const body = JSON.parse(raw) as DataCatalogVersionSchema
1548
+
1549
+ const result: ContextChangeRecord<DataCatalogVersionSchema> = {
1550
+ key: body.key,
1551
+ item: body,
1552
+ kind: body.kind,
1553
+ }
1554
+ return JSON.stringify(result)
1555
+ },
1556
+ init
1557
+ )
1558
+ await mock.add(
1559
+ {
1560
+ match: {
1561
+ uri: RouteBuilder.dataCatalogEntryVersions(':id'),
1562
+ methods: ['POST'],
1563
+ },
1564
+ respond,
1565
+ },
1566
+ options
1567
+ )
1568
+ },
1569
+
1570
+ readVersion: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
1571
+ const { mock } = this
1572
+ const respond = this.createDefaultResponse(
1573
+ 200,
1574
+ { 'content-type': 'application/json' },
1575
+ (req: SerializedRequest) => {
1576
+ const obj = this.gen.dataCatalog.dataCatalogVersion({ key: req.params.vid, catalogKey: req.params.id })
1577
+ return JSON.stringify(obj)
1578
+ },
1579
+ init
1580
+ )
1581
+ await mock.add(
1582
+ {
1583
+ match: {
1584
+ uri: RouteBuilder.dataCatalogVersion(':id', ':vid'),
1585
+ methods: ['GET'],
1586
+ },
1587
+ respond,
1588
+ },
1589
+ options
1590
+ )
1591
+ },
1592
+
1593
+ listDependencies: async (init?: MockListResult, options?: InterceptOptions): Promise<void> => {
1594
+ const { mock } = this
1595
+ const respond = this.createDefaultResponse(
1596
+ 200,
1597
+ { 'content-type': 'application/json' },
1598
+ (req: SerializedRequest) => {
1599
+ const requirements = JSON.parse(req.body as string) as { items: ForeignDomainDependency[] }
1600
+ const items: DataDomainSchema[] = []
1601
+ for (const item of requirements.items) {
1602
+ const domain = new DataDomain({
1603
+ key: item.key,
1604
+ info: { name: `Domain ${item.key}`, version: item.version },
1605
+ })
1606
+ items.push(domain.toJSON())
1607
+ }
1608
+ const obj: ContextListResult<DataDomainSchema> = {
1609
+ items: items,
1610
+ }
1611
+ return JSON.stringify(obj)
1612
+ },
1613
+ init
1614
+ )
1615
+ await mock.add(
1616
+ {
1617
+ match: {
1618
+ uri: RouteBuilder.dataCatalogDependencies(),
1619
+ methods: ['POST'],
1620
+ },
1621
+ respond,
1622
+ },
1623
+ options
1624
+ )
1625
+ },
1626
+
1627
+ deprecateVersion: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
1628
+ const { mock } = this
1629
+ const respond = this.createDefaultResponse(
1630
+ 200,
1631
+ { 'content-type': 'application/json' },
1632
+ (req: SerializedRequest) => {
1633
+ const obj = this.gen.dataCatalog.dataCatalogVersion({ key: req.params.vid, catalogKey: req.params.id })
1634
+ obj.deprecated = true
1635
+ obj.deprecatedAt = this.gen.faker.date.past().getTime()
1636
+ obj.deprecatedBy = nanoid()
1637
+ const info = JSON.parse(req.body as string) as { reason: string }
1638
+ obj.deprecationReason = info.reason
1639
+ const result: ContextChangeRecord<DataCatalogVersionSchema> = {
1640
+ key: obj.key,
1641
+ item: obj,
1642
+ kind: obj.kind,
1643
+ }
1644
+ return JSON.stringify(result)
1645
+ },
1646
+ init
1647
+ )
1648
+ await mock.add(
1649
+ {
1650
+ match: {
1651
+ uri: RouteBuilder.dataCatalogVersionDeprecate(':id', ':vid'),
1652
+ methods: ['PUT'],
1653
+ },
1654
+ respond,
1655
+ },
1656
+ options
1657
+ )
1658
+ },
1659
+
1660
+ unpublishVersion: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
1661
+ const { mock } = this
1662
+ const respond = this.createDefaultResponse(
1663
+ 200,
1664
+ { 'content-type': 'application/json' },
1665
+ (req: SerializedRequest) => {
1666
+ const obj = this.gen.dataCatalog.dataCatalogVersion({ key: req.params.vid, catalogKey: req.params.id })
1667
+ obj.unpublishedAt = this.gen.faker.date.past().getTime()
1668
+ obj.scope = 'private'
1669
+ const result: ContextChangeRecord<DataCatalogVersionSchema> = {
1670
+ key: obj.key,
1671
+ item: obj,
1672
+ kind: obj.kind,
1673
+ }
1674
+ return JSON.stringify(result)
1675
+ },
1676
+ init
1677
+ )
1678
+ await mock.add(
1679
+ {
1680
+ match: {
1681
+ uri: RouteBuilder.dataCatalogVersionUnpublish(':id', ':vid'),
1682
+ methods: ['PUT'],
1683
+ },
1684
+ respond,
1685
+ },
1686
+ options
1687
+ )
1688
+ },
1689
+
1690
+ checkPublicationStatus: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
1691
+ const { mock } = this
1692
+ const respond = this.createDefaultResponse(
1693
+ 200,
1694
+ { 'content-type': 'application/json' },
1695
+ () => {
1696
+ const obj = this.gen.dataCatalog.dataCatalog() as DataCatalogStatus
1697
+ obj.versions = this.gen.dataCatalog.versionInfos(1)
1698
+ return JSON.stringify(obj)
1699
+ },
1700
+ init
1701
+ )
1702
+ await mock.add(
1703
+ {
1704
+ match: {
1705
+ uri: RouteBuilder.dataCatalogStatus(':id'),
1706
+ methods: ['GET'],
1707
+ },
1708
+ respond,
1709
+ },
1710
+ options
1711
+ )
1712
+ },
1713
+ }
1365
1714
  }