@fluidframework/presence 2.81.0 → 2.82.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 (99) hide show
  1. package/dist/alpha.d.ts +1 -1
  2. package/dist/exposedUtilityTypes.d.ts +57 -5
  3. package/dist/exposedUtilityTypes.d.ts.map +1 -1
  4. package/dist/exposedUtilityTypes.js.map +1 -1
  5. package/dist/index.d.ts +3 -3
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/internalUtils.d.ts.map +1 -1
  9. package/dist/internalUtils.js.map +1 -1
  10. package/dist/latestMapTypes.d.ts +309 -0
  11. package/dist/latestMapTypes.d.ts.map +1 -0
  12. package/dist/latestMapTypes.js +8 -0
  13. package/dist/latestMapTypes.js.map +1 -0
  14. package/dist/latestMapValueManager.d.ts +4 -265
  15. package/dist/latestMapValueManager.d.ts.map +1 -1
  16. package/dist/latestMapValueManager.js +3 -4
  17. package/dist/latestMapValueManager.js.map +1 -1
  18. package/dist/latestTypes.d.ts +149 -0
  19. package/dist/latestTypes.d.ts.map +1 -0
  20. package/dist/latestTypes.js +7 -0
  21. package/dist/latestTypes.js.map +1 -0
  22. package/dist/latestValueManager.d.ts +1 -144
  23. package/dist/latestValueManager.d.ts.map +1 -1
  24. package/dist/latestValueManager.js +4 -5
  25. package/dist/latestValueManager.js.map +1 -1
  26. package/dist/latestValueTypes.d.ts +0 -11
  27. package/dist/latestValueTypes.d.ts.map +1 -1
  28. package/dist/latestValueTypes.js +0 -36
  29. package/dist/latestValueTypes.js.map +1 -1
  30. package/dist/legacy.alpha.d.ts +1 -1
  31. package/dist/notificationsManager.d.ts +15 -5
  32. package/dist/notificationsManager.d.ts.map +1 -1
  33. package/dist/notificationsManager.js +0 -4
  34. package/dist/notificationsManager.js.map +1 -1
  35. package/dist/notificationsManagerTypes.d.ts +7 -4
  36. package/dist/notificationsManagerTypes.d.ts.map +1 -1
  37. package/dist/notificationsManagerTypes.js.map +1 -1
  38. package/dist/packageVersion.d.ts +1 -1
  39. package/dist/packageVersion.js +1 -1
  40. package/dist/packageVersion.js.map +1 -1
  41. package/dist/stateFactory.d.ts +2 -2
  42. package/dist/stateFactory.d.ts.map +1 -1
  43. package/dist/stateFactory.js.map +1 -1
  44. package/dist/validatableTypes.d.ts.map +1 -1
  45. package/dist/validatableTypes.js.map +1 -1
  46. package/dist/validatedGetter.d.ts +18 -0
  47. package/dist/validatedGetter.d.ts.map +1 -0
  48. package/dist/validatedGetter.js +43 -0
  49. package/dist/validatedGetter.js.map +1 -0
  50. package/lib/alpha.d.ts +1 -1
  51. package/lib/exposedUtilityTypes.d.ts +57 -5
  52. package/lib/exposedUtilityTypes.d.ts.map +1 -1
  53. package/lib/exposedUtilityTypes.js.map +1 -1
  54. package/lib/index.d.ts +3 -3
  55. package/lib/index.d.ts.map +1 -1
  56. package/lib/index.js.map +1 -1
  57. package/lib/internalUtils.d.ts.map +1 -1
  58. package/lib/internalUtils.js.map +1 -1
  59. package/lib/latestMapTypes.d.ts +309 -0
  60. package/lib/latestMapTypes.d.ts.map +1 -0
  61. package/lib/latestMapTypes.js +7 -0
  62. package/lib/latestMapTypes.js.map +1 -0
  63. package/lib/latestMapValueManager.d.ts +4 -265
  64. package/lib/latestMapValueManager.d.ts.map +1 -1
  65. package/lib/latestMapValueManager.js +1 -2
  66. package/lib/latestMapValueManager.js.map +1 -1
  67. package/lib/latestTypes.d.ts +149 -0
  68. package/lib/latestTypes.d.ts.map +1 -0
  69. package/lib/latestTypes.js +6 -0
  70. package/lib/latestTypes.js.map +1 -0
  71. package/lib/latestValueManager.d.ts +1 -144
  72. package/lib/latestValueManager.d.ts.map +1 -1
  73. package/lib/latestValueManager.js +1 -2
  74. package/lib/latestValueManager.js.map +1 -1
  75. package/lib/latestValueTypes.d.ts +0 -11
  76. package/lib/latestValueTypes.d.ts.map +1 -1
  77. package/lib/latestValueTypes.js +1 -34
  78. package/lib/latestValueTypes.js.map +1 -1
  79. package/lib/legacy.alpha.d.ts +1 -1
  80. package/lib/notificationsManager.d.ts +15 -5
  81. package/lib/notificationsManager.d.ts.map +1 -1
  82. package/lib/notificationsManager.js +0 -4
  83. package/lib/notificationsManager.js.map +1 -1
  84. package/lib/notificationsManagerTypes.d.ts +7 -4
  85. package/lib/notificationsManagerTypes.d.ts.map +1 -1
  86. package/lib/notificationsManagerTypes.js.map +1 -1
  87. package/lib/packageVersion.d.ts +1 -1
  88. package/lib/packageVersion.js +1 -1
  89. package/lib/packageVersion.js.map +1 -1
  90. package/lib/stateFactory.d.ts +2 -2
  91. package/lib/stateFactory.d.ts.map +1 -1
  92. package/lib/stateFactory.js.map +1 -1
  93. package/lib/validatableTypes.d.ts.map +1 -1
  94. package/lib/validatableTypes.js.map +1 -1
  95. package/lib/validatedGetter.d.ts +18 -0
  96. package/lib/validatedGetter.d.ts.map +1 -0
  97. package/lib/validatedGetter.js +39 -0
  98. package/lib/validatedGetter.js.map +1 -0
  99. package/package.json +16 -16
@@ -1 +1 @@
1
- {"version":3,"file":"validatableTypes.d.ts","sourceRoot":"","sources":["../src/validatableTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,oBAAoB,EACpB,sBAAsB,EACtB,MAAM,0CAA0C,CAAC;AAElD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D;;GAEG;AACH,UAAU,mBAAmB,CAAC,MAAM;IACnC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,sBAAsB,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;CAE5D;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB,CAAC,MAAM,CAC/C,SAAQ,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAC,EACxF,mBAAmB,CAAC,MAAM,CAAC;CAAG;AAEhC;;;GAGG;AACH,MAAM,WAAW,wBAAw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,CAAC,CAAC,GAC3B,yBAAyB,CAAC,CAAC,CAAC,CAAC;AAEhC;;;;;;;;;;GAUG;AACH,MAAM,MAAM,yBAAyB,CACpC,CAAC,SACE,aAAa,CAAC,cAAc,CAAC,OAAO,CAAC,GACrC,aAAa,CAAC,kBAAkB,CAAC,OAAO,CAAC,GACzC,aAAa,CAAC,kBAAkB,CAAC,OAAO,CAAC,IAE5C,CAAC,SAAS,aAAa,CAAC,cAAc,CAAC,MAAM,MAAM,CAAC,GACjD,oBAAoB,CAAC,UAAU,CAC/B,CAAC,EACD,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC,EAE/B,yBAAyB,CAAC,MAAM,CAAC,EAEjC,oBAAoB,CAAC,mBAAmB,CACvC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG;IAClB,KAAK,EAAE;SACL,MAAM,IAAI,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,yBAAyB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;KAC3E,CAAC;CACF,CACD,CACD,GACA,CAAC,SACE,aAAa,CAAC,kBAAkB,CAAC,MAAM,MAAM,CAAC,GAC9C,aAAa,CAAC,kBAAkB,CAAC,MAAM,MAAM,CAAC,GAChD,oBAAoB,CAAC,mBAAmB,CACxC,IAAI,CAAC,CAAC,EAAE,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAC,GAAG,mBAAmB,CAAC,MAAM,CAAC,CACxE,GACA,KAAK,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"validatableTypes.js","sourceRoot":"","sources":["../src/validatableTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tInternalUtilityTypes,\n\tOpaqueJsonDeserialized,\n} from \"@fluidframework/core-interfaces/internal\";\n\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\n\n/**\n * Metadata for a value that may have been validated by a {@link StateSchemaValidator} function.\n */\ninterface ValidatableMetadata<TValue> {\n\t/**\n\t * Contains a validated value or undefined if `value` is invalid.\n\t *\n\t * This property will not be present if the data has not been validated.\n\t * If it is present and `undefined`, the value has been checked and found to be invalid.\n\t * Otherwise it will be the validated value.\n\t */\n\tvalidatedValue?: OpaqueJsonDeserialized<TValue> | undefined;\n\t// typeCheck: \"do you have me?\";\n}\n\n/**\n * Represents data with optional value that may have been validated by a\n * {@link StateSchemaValidator} function.\n */\nexport interface ValidatableOptionalState<TValue>\n\textends Omit<InternalTypes.ValueOptionalState<TValue>, keyof ValidatableMetadata<TValue>>,\n\t\tValidatableMetadata<TValue> {}\n\n/**\n * Represents data with required value that may have been validated by a\n * {@link StateSchemaValidator} function.\n */\nexport interface ValidatableRequiredState<TValue>\n\textends Omit<InternalTypes.ValueRequiredState<TValue>, keyof ValidatableMetadata<TValue>>,\n\t\tValidatableMetadata<TValue> {}\n\n/**\n * A directory of validatable values, where each value may be an optional\n * state or another directory.\n *\n * @remarks\n * The is the validatable version of {@link InternalTypes.ValueDirectory}.\n */\nexport interface ValidatableValueDirectory<T> {\n\trev: number;\n\titems: {\n\t\t// Caution: any particular item may or may not exist\n\t\t// Typescript does not support absent keys without forcing type to also be undefined.\n\t\t// See https://github.com/microsoft/TypeScript/issues/42810.\n\t\t[name: string | number]: ValidatableOptionalState<T> | ValidatableValueDirectory<T>;\n\t};\n}\n\n/**\n * Convenience type for a validatable required state or a directory of values.\n *\n * @remarks\n * This is the validatable version of {@link InternalTypes.ValueDirectoryOrState}.\n */\nexport type ValidatableValueDirectoryOrState<T> =\n\t| ValidatableRequiredState<T>\n\t| ValidatableValueDirectory<T>;\n\n/**\n * Transforms basic value datastore / protocol type into equivalent type\n * with validation support.\n *\n * @remarks\n * Use when some more specific or parameterized type equivalent of\n * `InternalTypes.Value(Directory|RequiredState|OptionalState)` is needed.\n *\n * Basically, wherever a `*ValueState` appears it is extended with\n * {@link ValidatableMetadata} to support validation.\n */\nexport type ValidatableValueStructure<\n\tT extends\n\t\t| InternalTypes.ValueDirectory<unknown>\n\t\t| InternalTypes.ValueRequiredState<unknown>\n\t\t| InternalTypes.ValueOptionalState<unknown>,\n> = T extends InternalTypes.ValueDirectory<infer TValue>\n\t? InternalUtilityTypes.IfSameType<\n\t\t\tT,\n\t\t\tInternalTypes.ValueDirectory<T>,\n\t\t\t// Use canonical type for exact match\n\t\t\tValidatableValueDirectory<TValue>,\n\t\t\t// Inexact match => recurse\n\t\t\tInternalUtilityTypes.FlattenIntersection<\n\t\t\t\tOmit<T, \"items\"> & {\n\t\t\t\t\titems: {\n\t\t\t\t\t\t[KItems in keyof T[\"items\"]]: ValidatableValueStructure<T[\"items\"][KItems]>;\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t>\n\t\t>\n\t: T extends\n\t\t\t\t| InternalTypes.ValueRequiredState<infer TValue>\n\t\t\t\t| InternalTypes.ValueOptionalState<infer TValue>\n\t\t? InternalUtilityTypes.FlattenIntersection<\n\t\t\t\tOmit<T, keyof ValidatableMetadata<TValue>> & ValidatableMetadata<TValue>\n\t\t\t>\n\t\t: never;\n"]}
1
+ {"version":3,"file":"validatableTypes.js","sourceRoot":"","sources":["../src/validatableTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tInternalUtilityTypes,\n\tOpaqueJsonDeserialized,\n} from \"@fluidframework/core-interfaces/internal\";\n\nimport type { InternalTypes } from \"./exposedInternalTypes.js\";\n\n/**\n * Metadata for a value that may have been validated by a {@link StateSchemaValidator} function.\n */\ninterface ValidatableMetadata<TValue> {\n\t/**\n\t * Contains a validated value or undefined if `value` is invalid.\n\t *\n\t * This property will not be present if the data has not been validated.\n\t * If it is present and `undefined`, the value has been checked and found to be invalid.\n\t * Otherwise it will be the validated value.\n\t */\n\tvalidatedValue?: OpaqueJsonDeserialized<TValue> | undefined;\n\t// typeCheck: \"do you have me?\";\n}\n\n/**\n * Represents data with optional value that may have been validated by a\n * {@link StateSchemaValidator} function.\n */\nexport interface ValidatableOptionalState<TValue>\n\textends Omit<InternalTypes.ValueOptionalState<TValue>, keyof ValidatableMetadata<TValue>>,\n\t\tValidatableMetadata<TValue> {}\n\n/**\n * Represents data with required value that may have been validated by a\n * {@link StateSchemaValidator} function.\n */\nexport interface ValidatableRequiredState<TValue>\n\textends Omit<InternalTypes.ValueRequiredState<TValue>, keyof ValidatableMetadata<TValue>>,\n\t\tValidatableMetadata<TValue> {}\n\n/**\n * A directory of validatable values, where each value may be an optional\n * state or another directory.\n *\n * @remarks\n * The is the validatable version of {@link InternalTypes.ValueDirectory}.\n */\nexport interface ValidatableValueDirectory<T> {\n\trev: number;\n\titems: {\n\t\t// Caution: any particular item may or may not exist\n\t\t// Typescript does not support absent keys without forcing type to also be undefined.\n\t\t// See https://github.com/microsoft/TypeScript/issues/42810.\n\t\t[name: string | number]: ValidatableOptionalState<T> | ValidatableValueDirectory<T>;\n\t};\n}\n\n/**\n * Convenience type for a validatable required state or a directory of values.\n *\n * @remarks\n * This is the validatable version of {@link InternalTypes.ValueDirectoryOrState}.\n */\nexport type ValidatableValueDirectoryOrState<T> =\n\t| ValidatableRequiredState<T>\n\t| ValidatableValueDirectory<T>;\n\n/**\n * Transforms basic value datastore / protocol type into equivalent type\n * with validation support.\n *\n * @remarks\n * Use when some more specific or parameterized type equivalent of\n * `InternalTypes.Value(Directory|RequiredState|OptionalState)` is needed.\n *\n * Basically, wherever a `*ValueState` appears it is extended with\n * {@link ValidatableMetadata} to support validation.\n */\nexport type ValidatableValueStructure<\n\tT extends\n\t\t| InternalTypes.ValueDirectory<unknown>\n\t\t| InternalTypes.ValueRequiredState<unknown>\n\t\t| InternalTypes.ValueOptionalState<unknown>,\n> =\n\tT extends InternalTypes.ValueDirectory<infer TValue>\n\t\t? InternalUtilityTypes.IfSameType<\n\t\t\t\tT,\n\t\t\t\tInternalTypes.ValueDirectory<T>,\n\t\t\t\t// Use canonical type for exact match\n\t\t\t\tValidatableValueDirectory<TValue>,\n\t\t\t\t// Inexact match => recurse\n\t\t\t\tInternalUtilityTypes.FlattenIntersection<\n\t\t\t\t\tOmit<T, \"items\"> & {\n\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\t[KItems in keyof T[\"items\"]]: ValidatableValueStructure<T[\"items\"][KItems]>;\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t>\n\t\t: T extends\n\t\t\t\t\t| InternalTypes.ValueRequiredState<infer TValue>\n\t\t\t\t\t| InternalTypes.ValueOptionalState<infer TValue>\n\t\t\t? InternalUtilityTypes.FlattenIntersection<\n\t\t\t\t\tOmit<T, keyof ValidatableMetadata<TValue>> & ValidatableMetadata<TValue>\n\t\t\t\t>\n\t\t\t: never;\n"]}
@@ -0,0 +1,18 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import type { DeepReadonly, JsonDeserialized } from "@fluidframework/core-interfaces/internal/exposedUtilityTypes";
6
+ import type { StateSchemaValidator } from "./latestValueTypes.js";
7
+ import type { ValidatableRequiredState } from "./validatableTypes.js";
8
+ /**
9
+ * Creates a getter for a state value that validates the data with a validator if one is provided. Otherwise the value
10
+ * is returned directly.
11
+ *
12
+ * @param clientState - The client state to be validated.
13
+ * @param validator - The validator function to run.
14
+ * @returns Either returns the value directly if a validator is not provided, or a function that will return the
15
+ * validated data.
16
+ */
17
+ export declare function createValidatedGetter<T>(clientState: ValidatableRequiredState<T>, validator: StateSchemaValidator<T> | undefined): (() => DeepReadonly<JsonDeserialized<T>> | undefined) | DeepReadonly<JsonDeserialized<T>>;
18
+ //# sourceMappingURL=validatedGetter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validatedGetter.d.ts","sourceRoot":"","sources":["../src/validatedGetter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,YAAY,EACZ,gBAAgB,EAEhB,MAAM,8DAA8D,CAAC;AAGtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAmBtE;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EACtC,WAAW,EAAE,wBAAwB,CAAC,CAAC,CAAC,EACxC,SAAS,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,SAAS,GAC5C,CAAC,MAAM,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAgB3F"}
@@ -0,0 +1,39 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { asDeeplyReadonlyDeserializedJson } from "./internalUtils.js";
6
+ function createGetterFunction(clientState, validator) {
7
+ return () => {
8
+ if (!("validatedValue" in clientState)) {
9
+ // Stored `value` has not been validated yet, so validate it and save the result.
10
+ clientState.validatedValue = validator(clientState.value);
11
+ }
12
+ return asDeeplyReadonlyDeserializedJson(clientState.validatedValue);
13
+ };
14
+ }
15
+ /**
16
+ * Creates a getter for a state value that validates the data with a validator if one is provided. Otherwise the value
17
+ * is returned directly.
18
+ *
19
+ * @param clientState - The client state to be validated.
20
+ * @param validator - The validator function to run.
21
+ * @returns Either returns the value directly if a validator is not provided, or a function that will return the
22
+ * validated data.
23
+ */
24
+ export function createValidatedGetter(clientState, validator) {
25
+ // No validator
26
+ if (validator === undefined) {
27
+ return asDeeplyReadonlyDeserializedJson(clientState.value);
28
+ }
29
+ // Avoid creating another function since one already exists on the item
30
+ if (typeof clientState.value === "function") {
31
+ return clientState.value;
32
+ }
33
+ // OpaqueJsonDeserialized<T> is just a branded alias of JsonDeserialized<T>. At runtime the functions are still passed
34
+ // JSON data, regardless of their type representation. Passing that data to a function that expects `unknown`, like
35
+ // the user-provided validator function, is always valid, so StateSchemaValidator and StateSchemaValidatorToOpaque are
36
+ // functionally equivalent.
37
+ return createGetterFunction(clientState, validator);
38
+ }
39
+ //# sourceMappingURL=validatedGetter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validatedGetter.js","sourceRoot":"","sources":["../src/validatedGetter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AAQtE,SAAS,oBAAoB,CAC5B,WAAwC,EACxC,SAA0C;IAE1C,OAAO,GAAkD,EAAE;QAC1D,IAAI,CAAC,CAAC,gBAAgB,IAAI,WAAW,CAAC,EAAE,CAAC;YACxC,iFAAiF;YACjF,WAAW,CAAC,cAAc,GAAG,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC3D,CAAC;QACD,OAAO,gCAAgC,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IACrE,CAAC,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CACpC,WAAwC,EACxC,SAA8C;IAE9C,eAAe;IACf,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,gCAAgC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED,uEAAuE;IACvE,IAAI,OAAO,WAAW,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;QAC7C,OAAO,WAAW,CAAC,KAAK,CAAC;IAC1B,CAAC;IAED,sHAAsH;IACtH,mHAAmH;IACnH,sHAAsH;IACtH,2BAA2B;IAC3B,OAAO,oBAAoB,CAAC,WAAW,EAAE,SAA4C,CAAC,CAAC;AACxF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tDeepReadonly,\n\tJsonDeserialized,\n\tOpaqueJsonDeserialized,\n} from \"@fluidframework/core-interfaces/internal/exposedUtilityTypes\";\n\nimport { asDeeplyReadonlyDeserializedJson } from \"./internalUtils.js\";\nimport type { StateSchemaValidator } from \"./latestValueTypes.js\";\nimport type { ValidatableRequiredState } from \"./validatableTypes.js\";\n\ntype StateSchemaValidatorToOpaque<T> = (\n\trawData: OpaqueJsonDeserialized<T>,\n) => OpaqueJsonDeserialized<T> | undefined;\n\nfunction createGetterFunction<T>(\n\tclientState: ValidatableRequiredState<T>,\n\tvalidator: StateSchemaValidatorToOpaque<T>,\n): () => DeepReadonly<JsonDeserialized<T>> | undefined {\n\treturn (): DeepReadonly<JsonDeserialized<T>> | undefined => {\n\t\tif (!(\"validatedValue\" in clientState)) {\n\t\t\t// Stored `value` has not been validated yet, so validate it and save the result.\n\t\t\tclientState.validatedValue = validator(clientState.value);\n\t\t}\n\t\treturn asDeeplyReadonlyDeserializedJson(clientState.validatedValue);\n\t};\n}\n\n/**\n * Creates a getter for a state value that validates the data with a validator if one is provided. Otherwise the value\n * is returned directly.\n *\n * @param clientState - The client state to be validated.\n * @param validator - The validator function to run.\n * @returns Either returns the value directly if a validator is not provided, or a function that will return the\n * validated data.\n */\nexport function createValidatedGetter<T>(\n\tclientState: ValidatableRequiredState<T>,\n\tvalidator: StateSchemaValidator<T> | undefined,\n): (() => DeepReadonly<JsonDeserialized<T>> | undefined) | DeepReadonly<JsonDeserialized<T>> {\n\t// No validator\n\tif (validator === undefined) {\n\t\treturn asDeeplyReadonlyDeserializedJson(clientState.value);\n\t}\n\n\t// Avoid creating another function since one already exists on the item\n\tif (typeof clientState.value === \"function\") {\n\t\treturn clientState.value;\n\t}\n\n\t// OpaqueJsonDeserialized<T> is just a branded alias of JsonDeserialized<T>. At runtime the functions are still passed\n\t// JSON data, regardless of their type representation. Passing that data to a function that expects `unknown`, like\n\t// the user-provided validator function, is always valid, so StateSchemaValidator and StateSchemaValidatorToOpaque are\n\t// functionally equivalent.\n\treturn createGetterFunction(clientState, validator as StateSchemaValidatorToOpaque<T>);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/presence",
3
- "version": "2.81.0",
3
+ "version": "2.82.0",
4
4
  "description": "A component for lightweight data sharing within a single session",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -73,30 +73,30 @@
73
73
  "temp-directory": "nyc/.nyc_output"
74
74
  },
75
75
  "dependencies": {
76
- "@fluid-internal/client-utils": "~2.81.0",
77
- "@fluidframework/container-definitions": "~2.81.0",
78
- "@fluidframework/container-runtime-definitions": "~2.81.0",
79
- "@fluidframework/core-interfaces": "~2.81.0",
80
- "@fluidframework/core-utils": "~2.81.0",
81
- "@fluidframework/fluid-static": "~2.81.0",
82
- "@fluidframework/id-compressor": "~2.81.0",
83
- "@fluidframework/runtime-definitions": "~2.81.0",
84
- "@fluidframework/telemetry-utils": "~2.81.0"
76
+ "@fluid-internal/client-utils": "~2.82.0",
77
+ "@fluidframework/container-definitions": "~2.82.0",
78
+ "@fluidframework/container-runtime-definitions": "~2.82.0",
79
+ "@fluidframework/core-interfaces": "~2.82.0",
80
+ "@fluidframework/core-utils": "~2.82.0",
81
+ "@fluidframework/fluid-static": "~2.82.0",
82
+ "@fluidframework/id-compressor": "~2.82.0",
83
+ "@fluidframework/runtime-definitions": "~2.82.0",
84
+ "@fluidframework/telemetry-utils": "~2.82.0"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@arethetypeswrong/cli": "^0.18.2",
88
88
  "@biomejs/biome": "~1.9.3",
89
- "@fluid-internal/mocha-test-setup": "~2.81.0",
89
+ "@fluid-internal/mocha-test-setup": "~2.82.0",
90
90
  "@fluid-tools/build-cli": "^0.63.0",
91
91
  "@fluidframework/build-common": "^2.0.3",
92
92
  "@fluidframework/build-tools": "^0.63.0",
93
- "@fluidframework/driver-definitions": "~2.81.0",
94
- "@fluidframework/eslint-config-fluid": "~2.81.0",
95
- "@fluidframework/test-runtime-utils": "~2.81.0",
96
- "@fluidframework/test-utils": "~2.81.0",
93
+ "@fluidframework/driver-definitions": "~2.82.0",
94
+ "@fluidframework/eslint-config-fluid": "~2.82.0",
95
+ "@fluidframework/test-runtime-utils": "~2.82.0",
96
+ "@fluidframework/test-utils": "~2.82.0",
97
97
  "@microsoft/api-extractor": "7.52.11",
98
98
  "@types/mocha": "^10.0.10",
99
- "@types/node": "^18.19.0",
99
+ "@types/node": "~20.19.30",
100
100
  "@types/sinon": "^17.0.3",
101
101
  "c8": "^10.1.3",
102
102
  "concurrently": "^9.2.1",