@fluidframework/core-interfaces 2.32.0 → 2.33.0

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 (64) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/api-report/core-interfaces.legacy.alpha.api.md +9 -9
  3. package/dist/deepReadonly.d.ts +56 -0
  4. package/dist/deepReadonly.d.ts.map +1 -0
  5. package/dist/deepReadonly.js +7 -0
  6. package/dist/deepReadonly.js.map +1 -0
  7. package/dist/exposedInternalUtilityTypes.d.ts +168 -3
  8. package/dist/exposedInternalUtilityTypes.d.ts.map +1 -1
  9. package/dist/exposedInternalUtilityTypes.js.map +1 -1
  10. package/dist/exposedUtilityTypes.d.ts +4 -2
  11. package/dist/exposedUtilityTypes.d.ts.map +1 -1
  12. package/dist/exposedUtilityTypes.js.map +1 -1
  13. package/dist/handles.d.ts +12 -0
  14. package/dist/handles.d.ts.map +1 -1
  15. package/dist/handles.js.map +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/internal.d.ts +10 -1
  20. package/dist/internal.d.ts.map +1 -1
  21. package/dist/internal.js.map +1 -1
  22. package/dist/jsonType.d.ts +28 -0
  23. package/dist/jsonType.d.ts.map +1 -1
  24. package/dist/jsonType.js.map +1 -1
  25. package/dist/shallowReadonly.d.ts +48 -0
  26. package/dist/shallowReadonly.d.ts.map +1 -0
  27. package/dist/shallowReadonly.js +7 -0
  28. package/dist/shallowReadonly.js.map +1 -0
  29. package/lib/deepReadonly.d.ts +56 -0
  30. package/lib/deepReadonly.d.ts.map +1 -0
  31. package/lib/deepReadonly.js +6 -0
  32. package/lib/deepReadonly.js.map +1 -0
  33. package/lib/exposedInternalUtilityTypes.d.ts +168 -3
  34. package/lib/exposedInternalUtilityTypes.d.ts.map +1 -1
  35. package/lib/exposedInternalUtilityTypes.js.map +1 -1
  36. package/lib/exposedUtilityTypes.d.ts +4 -2
  37. package/lib/exposedUtilityTypes.d.ts.map +1 -1
  38. package/lib/exposedUtilityTypes.js.map +1 -1
  39. package/lib/handles.d.ts +12 -0
  40. package/lib/handles.d.ts.map +1 -1
  41. package/lib/handles.js.map +1 -1
  42. package/lib/index.d.ts +1 -1
  43. package/lib/index.d.ts.map +1 -1
  44. package/lib/index.js.map +1 -1
  45. package/lib/internal.d.ts +10 -1
  46. package/lib/internal.d.ts.map +1 -1
  47. package/lib/internal.js.map +1 -1
  48. package/lib/jsonType.d.ts +28 -0
  49. package/lib/jsonType.d.ts.map +1 -1
  50. package/lib/jsonType.js.map +1 -1
  51. package/lib/shallowReadonly.d.ts +48 -0
  52. package/lib/shallowReadonly.d.ts.map +1 -0
  53. package/lib/shallowReadonly.js +6 -0
  54. package/lib/shallowReadonly.js.map +1 -0
  55. package/lib/tsdoc-metadata.json +1 -1
  56. package/package.json +3 -3
  57. package/src/deepReadonly.ts +76 -0
  58. package/src/exposedInternalUtilityTypes.ts +452 -5
  59. package/src/exposedUtilityTypes.ts +11 -2
  60. package/src/handles.ts +16 -0
  61. package/src/index.ts +1 -0
  62. package/src/internal.ts +15 -1
  63. package/src/jsonType.ts +36 -0
  64. package/src/shallowReadonly.ts +60 -0
package/src/jsonType.ts CHANGED
@@ -35,3 +35,39 @@ export type JsonTypeWith<T> =
35
35
  export type NonNullJsonObjectWith<T> =
36
36
  | { [key: string | number]: JsonTypeWith<T> }
37
37
  | JsonTypeWith<T>[];
38
+
39
+ /**
40
+ * Deeply immutable type that is encodable as JSON and deserializable from JSON.
41
+ *
42
+ * @typeParam TReadonlyAlternates - Additional [immutable] types that are supported.
43
+ *
44
+ * @remarks
45
+ * If `TReadonlyAlternates` is allowed as-is. So if it is not immutable, then result type
46
+ * is not wholly immutable.
47
+ *
48
+ * A `const` variable is still required to avoid top-level mutability. I.e.
49
+ * ```typescript
50
+ * let x: ReadonlyJsonTypeWith<never> = { a: 1 };
51
+ * ```
52
+ * does not prevent later `x = 5`. (Does prevent `x.a = 2`.)
53
+ *
54
+ * @beta
55
+ */
56
+ export type ReadonlyJsonTypeWith<TReadonlyAlternates> =
57
+ // eslint-disable-next-line @rushstack/no-new-null
58
+ | null
59
+ | boolean
60
+ | number
61
+ | string
62
+ | TReadonlyAlternates
63
+ | { readonly [key: string | number]: ReadonlyJsonTypeWith<TReadonlyAlternates> }
64
+ | readonly ReadonlyJsonTypeWith<TReadonlyAlternates>[];
65
+
66
+ /**
67
+ * Portion of {@link ReadonlyJsonTypeWith} that is an object (including array) and not null.
68
+ *
69
+ * @internal
70
+ */
71
+ export type ReadonlyNonNullJsonObjectWith<TReadonlyAlternates> =
72
+ | { readonly [key: string | number]: ReadonlyJsonTypeWith<TReadonlyAlternates> }
73
+ | readonly ReadonlyJsonTypeWith<TReadonlyAlternates>[];
@@ -0,0 +1,60 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import type {
7
+ InternalUtilityTypes,
8
+ ReadonlySupportedGenerics,
9
+ } from "./exposedInternalUtilityTypes.js";
10
+ import type { IFluidHandle } from "./handles.js";
11
+
12
+ /**
13
+ * Default set of generic that {@link ShallowReadonly} will apply shallow immutability
14
+ * to generic types.
15
+ *
16
+ * @privateRemarks
17
+ * WeakRef should be added when lib is updated to ES2021 or later.
18
+ *
19
+ * @system
20
+ */
21
+ export type ShallowReadonlySupportedGenericsDefault = Promise<unknown> | IFluidHandle;
22
+
23
+ /**
24
+ * Options for {@link ShallowReadonly}.
25
+ *
26
+ * @beta
27
+ */
28
+ export interface ShallowReadonlyOptions {
29
+ /**
30
+ * Union of Built-in and IFluidHandle whose generics will also be made shallowly immutable.
31
+ *
32
+ * The default value is `IFluidHandle` | `Promise`.
33
+ */
34
+ DeepenedGenerics?: ReadonlySupportedGenerics;
35
+ }
36
+
37
+ /**
38
+ * Transforms type to a shallowly immutable type.
39
+ *
40
+ * @remarks
41
+ * This utility type is similar to `Readonly<T>`, but also applies immutability to
42
+ * common generic types like `Map` and `Set`.
43
+ *
44
+ * Optionally, immutability can be applied to supported generics types. See
45
+ * {@link ShallowReadonlySupportedGenericsDefault} for generics that have
46
+ * immutability applied to generic type by default.
47
+ *
48
+ * @beta
49
+ */
50
+ export type ShallowReadonly<
51
+ T,
52
+ Options extends ShallowReadonlyOptions = {
53
+ DeepenedGenerics: ShallowReadonlySupportedGenericsDefault;
54
+ },
55
+ > = InternalUtilityTypes.ShallowReadonlyImpl<
56
+ T,
57
+ Options extends { DeepenedGenerics: unknown }
58
+ ? Options["DeepenedGenerics"]
59
+ : ShallowReadonlySupportedGenericsDefault
60
+ >;