Commit 28ca32f
committed
feat(client-core-interfaces):
with `JsonStringify` and `JsonParse` utilities
Test cases added:
```text
JsonString
✔ `JsonString<string>` is assignable to `string`
✔ `string` is not assignable to `JsonString<unknown>`
✔ object is not assignable to `JsonString<unknown>`
is variant by T
✔ `JsonString<"literal">` is assignable to `JsonString<string>`
✔ `JsonString<Record<string, number>>` is assignable to `JsonString<Record<string, number | undefined>>`
✔ `JsonString<Record<string, number | undefined>>` is assignable to `JsonString<Record<string, unknown>>`
✔ `JsonString<bigint>` is assignable to `JsonString<unknown>`
is not contravariant by T
✔ `JsonString<string>` is not assignable to `JsonString<"literal">`
✔ `JsonString<Record<string, number | undefined>>` is not assignable to `JsonString<Record<string, number>>`
✔ `JsonString<unknown>` is not assignable to `JsonString<bigint>`
JsonStringify and JsonParse
expected usage
supports primitive types
✔ `boolean`
...
✔ branded `string`
✔ `JsonString<string>`
✔ `JsonString<{ arrayOfNumbers: number[] }>`
✔ `JsonString<Record<string, number>>`
✔ `JsonString<Record<string, number | undefined>>`
✔ `JsonString<bigint>`
✔ `JsonString<unknown>`
supports literal types
✔ `true`
✔ `false`
✔ `0`
✔ "string"
✔ `null`
✔ object with literals
✔ array of literals
✔ tuple of literals
✔ specific numeric enum value
✔ specific string enum value
✔ specific const heterogenous enum value
✔ specific computed enum value
supports array types
✔ array of `number`s
✔ readonly array of `number`s
✔ readonly array of simple objects
supports object types
✔ empty object
✔ object with `never`
✔ object with `boolean`
...
✔ `string`|`number` indexed record of `string`s
✔ `string`|`number` indexed record of objects
✔ templated record of `numbers`
✔ `string` indexed record of `number`|`string`s with known properties
✔ `string`|`number` indexed record of `strings` with known `number` property (unassignable)
✔ branded-`string` indexed of `boolean`s
...
✔ object with possible type recursion through union
✔ object with optional type recursion
✔ object with deep type recursion
✔ object with alternating type recursion
✔ simple non-null object json (NonNullJsonObjectWith<never>)
✔ simple read-only non-null object json (ReadonlyNonNullJsonObjectWith<never>)
✔ non-const enums
✔ object with `readonly`
✔ object with getter implemented via value
✔ object with setter implemented via value
✔ object with matched getter and setter implemented via value
✔ object with mismatched getter and setter implemented via value
class instance
✔ with public data (just cares about data)
object with optional property
✔ without property
✔ with undefined value
✔ with defined value
opaque Json types
✔ opaque serializable object
✔ opaque deserialized object
✔ opaque serializable and deserialized object
✔ opaque serializable unknown
✔ opaque deserialized unknown
✔ opaque serializable and deserialized unknown
✔ object with opaque serializable unknown
✔ object with opaque deserialized unknown
✔ recursive type with opaque serializable unknown
✔ recursive type with opaque deserialized unknown
✔ recursive type with opaque serializable and deserialized unknown
✔ recursive branded indexed object with OpaqueJsonDeserialized<unknown>
supports union types
✔ simple json (JsonTypeWith<never>)
✔ simple read-only json (ReadonlyJsonTypeWith<never>)
with NOT fully supported object types
✔ object with self reference throws on serialization
known defect expectations
✔ sparse array of supported types
✔ object with sparse array of supported types
getters and setters allowed but do not propagate
✔ object with `readonly` implemented via getter
✔ object with getter
✔ object with setter
✔ object with matched getter and setter
✔ object with mismatched getter and setter
class instance
with `ignore-inaccessible-members`
✔ with private data ignores private data (that propagates)
invalid input usage
assumptions
✔ const enums are never readable
unsupported types cause compiler error
✔ `undefined`
✔ `unknown`
✔ `symbol`
✔ `unique symbol`
✔ `bigint`
✔ function
✔ function with supported properties
✔ object and function
✔ object with function with supported properties
✔ object with object and function
✔ function with class instance with private data
✔ function with class instance with public data
✔ class instance with private data and is function
✔ class instance with public data and is function
✔ `object` (plain object)
✔ `void`
✔ branded `object`
✔ branded object with `string`
unions with unsupported primitive types
✔ `string | symbol`
✔ `bigint | string`
✔ `bigint | symbol`
✔ `number | bigint | symbol`
array
✔ array of `bigint`s
✔ array of `symbol`s
...
object
✔ object with exactly `bigint`
✔ object with optional `bigint`
✔ object with exactly `symbol`
...
✔ `string` indexed record of `unknown`
✔ `Partial<>` `string` indexed record of `unknown`
✔ `Partial<>` `string` indexed record of `numbers`
✔ `Partial<>` templated record of `numbers`
✔ object with recursion and `symbol`
✔ function object with recursion
✔ object and function with recursion
✔ nested function object with recursion
✔ nested object and function with recursion
✔ object with inherited recursion extended with unsupported properties
object with `undefined`
✔ as exact property type
✔ in union property
...
object with required `unknown`
✔ as exact property type
✔ as exact property type adjacent to recursion
✔ as exact property type in recursion
of class instance
✔ with private data
✔ with private method
✔ with private getter
✔ with private setter
✔ with public method
✔ with private data in optional recursion
opaque Json types requiring extra allowed types
✔ opaque serializable object with `bigint`
✔ opaque deserialized object with `bigint`
✔ opaque serializable and deserialized object with `bigint`
✔ opaque serializable object with number array expecting `bigint` support
✔ opaque deserialized object with number array expecting `bigint` support
✔ opaque serializable and deserialized object with number array expecting `bigint` support
common class instances
✔ Map
✔ ReadonlyMap
✔ Set
✔ ReadonlySet
Fluid types
✔ `IFluidHandle`
✔ object with `IFluidHandle`
special cases
✔ explicit `any` generic still limits allowed types
`number` edge cases
supported
✔ MIN_SAFE_INTEGER
✔ MAX_SAFE_INTEGER
✔ MIN_VALUE
✔ MAX_VALUE
resulting in `null`
✔ NaN
✔ +Infinity
✔ -Infinity
JsonDeserialized
positive compilation tests
supported primitive types are preserved
✔ `JsonString<string>`
✔ `JsonString<{ arrayOfNumbers: number[] }>`
✔ `JsonString<Record<string, number>>`
✔ `JsonString<Record<string, number | undefined>>`
✔ JsonString<bigint>
✔ JsonString<unknown>
JsonSerializable
positive compilation tests
supported primitive types
✔ `JsonString<string>`
✔ `JsonString<{ arrayOfNumbers: number[] }>`
✔ `JsonString<Record<string, number>>`
✔ `JsonString<Record<string, number | undefined>>`
✔ JsonString<bigint>
✔ JsonString<unknown>
```JsonString
1 parent 4c37ece commit 28ca32f
File tree
9 files changed
+3014
-40
lines changed- packages/common/core-interfaces
- src
- cjs
- test
9 files changed
+3014
-40
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
| 10 | + | |
| 11 | + | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
Lines changed: 44 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
211 | 213 | | |
212 | 214 | | |
213 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
214 | 222 | | |
215 | 223 | | |
216 | 224 | | |
| |||
220 | 228 | | |
221 | 229 | | |
222 | 230 | | |
223 | | - | |
224 | 231 | | |
225 | 232 | | |
226 | 233 | | |
| |||
368 | 375 | | |
369 | 376 | | |
370 | 377 | | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
371 | 408 | | |
372 | 409 | | |
373 | 410 | | |
| |||
516 | 553 | | |
517 | 554 | | |
518 | 555 | | |
| 556 | + | |
| 557 | + | |
519 | 558 | | |
520 | 559 | | |
521 | 560 | | |
522 | 561 | | |
523 | 562 | | |
| 563 | + | |
| 564 | + | |
524 | 565 | | |
525 | 566 | | |
526 | 567 | | |
| |||
1677 | 1718 | | |
1678 | 1719 | | |
1679 | 1720 | | |
1680 | | - | |
1681 | | - | |
1682 | | - | |
1683 | | - | |
1684 | | - | |
1685 | | - | |
1686 | | - | |
1687 | | - | |
1688 | | - | |
1689 | 1721 | | |
1690 | 1722 | | |
1691 | 1723 | | |
| |||
1708 | 1740 | | |
1709 | 1741 | | |
1710 | 1742 | | |
1711 | | - | |
1712 | | - | |
1713 | | - | |
1714 | | - | |
1715 | | - | |
1716 | | - | |
1717 | | - | |
1718 | | - | |
1719 | | - | |
1720 | | - | |
1721 | | - | |
1722 | | - | |
1723 | | - | |
1724 | 1743 | | |
1725 | 1744 | | |
1726 | | - | |
| 1745 | + | |
1727 | 1746 | | |
1728 | 1747 | | |
1729 | 1748 | | |
| |||
1732 | 1751 | | |
1733 | 1752 | | |
1734 | 1753 | | |
1735 | | - | |
| 1754 | + | |
1736 | 1755 | | |
1737 | 1756 | | |
1738 | 1757 | | |
| |||
Lines changed: 54 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
205 | 211 | | |
206 | 212 | | |
207 | 213 | | |
| |||
441 | 447 | | |
442 | 448 | | |
443 | 449 | | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
444 | 480 | | |
445 | 481 | | |
446 | 482 | | |
| |||
1566 | 1602 | | |
1567 | 1603 | | |
1568 | 1604 | | |
1569 | | - | |
1570 | | - | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
1571 | 1609 | | |
1572 | 1610 | | |
1573 | 1611 | | |
| |||
1576 | 1614 | | |
1577 | 1615 | | |
1578 | 1616 | | |
1579 | | - | |
1580 | | - | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
1581 | 1621 | | |
1582 | 1622 | | |
1583 | 1623 | | |
| |||
1593 | 1633 | | |
1594 | 1634 | | |
1595 | 1635 | | |
1596 | | - | |
1597 | | - | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
1598 | 1641 | | |
1599 | 1642 | | |
1600 | 1643 | | |
| |||
1611 | 1654 | | |
1612 | 1655 | | |
1613 | 1656 | | |
1614 | | - | |
1615 | | - | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
1616 | 1662 | | |
1617 | 1663 | | |
1618 | 1664 | | |
| |||
0 commit comments