@fluidframework/core-utils 2.80.0 → 2.81.0-374083
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.
- package/dist/assert.d.ts.map +1 -1
- package/dist/assert.js +18 -12
- package/dist/assert.js.map +1 -1
- package/dist/lazy.d.ts.map +1 -1
- package/dist/lazy.js +1 -0
- package/dist/lazy.js.map +1 -1
- package/eslint.config.mts +4 -4
- package/lib/assert.d.ts.map +1 -1
- package/lib/assert.js +18 -12
- package/lib/assert.js.map +1 -1
- package/lib/lazy.d.ts.map +1 -1
- package/lib/lazy.js +1 -0
- package/lib/lazy.js.map +1 -1
- package/package.json +7 -7
- package/src/assert.ts +20 -13
- package/src/lazy.ts +1 -0
- package/.eslintrc.cjs +0 -30
package/dist/assert.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,MAAM,CACrB,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,mBAAmB,CAAC,EAAE,MAAM,MAAM,GAChC,OAAO,CAAC,SAAS,CAInB;
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,MAAM,CACrB,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,mBAAmB,CAAC,EAAE,MAAM,MAAM,GAChC,OAAO,CAAC,SAAS,CAInB;AAoBD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,mBAAmB,CAAC,EAAE,MAAM,MAAM,GAAG,KAAK,CAExF;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,MAAM,IAAI,CAU9E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,IAAI,GAAG;IAAE,QAAQ,IAAI,MAAM,CAAA;CAAE,GAAG,IAAI,CAehF;AAID;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAQ/D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iCAAiC,IAAI,OAAO,CAM3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,UAAO,GAAG,IAAI,CAM1D"}
|
package/dist/assert.js
CHANGED
|
@@ -34,10 +34,26 @@ exports.emulateProductionBuild = exports.nonProductionConditionalsIncluded = exp
|
|
|
34
34
|
*/
|
|
35
35
|
function assert(condition, message, debugMessageBuilder) {
|
|
36
36
|
if (!condition) {
|
|
37
|
-
|
|
37
|
+
failPrivate(message, debugMessageBuilder);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
exports.assert = assert;
|
|
41
|
+
/**
|
|
42
|
+
* {@link fail}'s implementation, but extracted to avoid assert tagging trying to tag the use of it in `assert`.
|
|
43
|
+
*/
|
|
44
|
+
function failPrivate(message, debugMessageBuilder) {
|
|
45
|
+
let messageString = typeof message === "number" ? `0x${message.toString(16).padStart(3, "0")}` : message;
|
|
46
|
+
skipInProduction(() => {
|
|
47
|
+
if (debugMessageBuilder !== undefined) {
|
|
48
|
+
messageString = `${messageString}\nDebug Message: ${debugMessageBuilder()}`;
|
|
49
|
+
}
|
|
50
|
+
// Using console.log instead of console.error or console.warn since the latter two may break downstream users.
|
|
51
|
+
console.log(`Bug in Fluid Framework: Failed Assertion: ${messageString}`);
|
|
52
|
+
});
|
|
53
|
+
const error = new Error(messageString);
|
|
54
|
+
onAssertionError(error);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
41
57
|
/**
|
|
42
58
|
* Throw an error with a constant message.
|
|
43
59
|
* @remarks
|
|
@@ -55,17 +71,7 @@ exports.assert = assert;
|
|
|
55
71
|
* @internal
|
|
56
72
|
*/
|
|
57
73
|
function fail(message, debugMessageBuilder) {
|
|
58
|
-
|
|
59
|
-
skipInProduction(() => {
|
|
60
|
-
if (debugMessageBuilder !== undefined) {
|
|
61
|
-
messageString = `${messageString}\nDebug Message: ${debugMessageBuilder()}`;
|
|
62
|
-
}
|
|
63
|
-
// Using console.log instead of console.error or console.warn since the latter two may break downstream users.
|
|
64
|
-
console.log(`Bug in Fluid Framework: Failed Assertion: ${messageString}`);
|
|
65
|
-
});
|
|
66
|
-
const error = new Error(messageString);
|
|
67
|
-
onAssertionError(error);
|
|
68
|
-
throw error;
|
|
74
|
+
failPrivate(message, debugMessageBuilder);
|
|
69
75
|
}
|
|
70
76
|
exports.fail = fail;
|
|
71
77
|
function onAssertionError(error) {
|
package/dist/assert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,MAAM,CACrB,SAAkB,EAClB,OAAwB,EACxB,mBAAkC;IAElC,IAAI,CAAC,SAAS,EAAE,CAAC;QAChB,IAAI,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;IACpC,CAAC;AACF,CAAC;AARD,wBAQC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,IAAI,CAAC,OAAwB,EAAE,mBAAkC;IAChF,IAAI,aAAa,GAChB,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,QA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,WAAuB;IAChD,qBAAqB,CAAC,GAAG,EAAE;QAC1B,IAAI,2BAA2B,KAAK,CAAC;YAAE,WAAW,EAAE,CAAC;IACtD,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,iMAAiM;AACjM,0CAA0C;AAC1C,wBAAwB;AACxB,SAAS,qBAAqB,CAAC,WAAuB;IACrD,0FAA0F;IAC1F,6IAA6I;IAC7I,iIAAiI;IAEjI,sKAAsK;IACtK,0CAA0C;IAC1C,aAAa,CAAC,WAAW,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Asserts the specified condition.\n *\n * @param condition - The condition that should be true, if the condition is false an error will be thrown.\n * Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.\n * @param message - The message to include in the error when the condition does not hold.\n * A number should not be specified manually: use a string literal instead.\n * Before a release, policy-check should be run, which will convert any asserts still using strings to\n * use numbered error codes instead.\n * @param debugMessageBuilder - An optional function that can be used to build a debug message to include in the error in development builds.\n * Only executed if `condition` is false. `debugMessageBuilder` is not executed in production builds, see `skipInProduction` for details.\n * @remarks\n * Use this instead of the node 'assert' package, which requires polyfills and has a big impact on bundle sizes.\n *\n * Assertions using this API will be included in all configurations: there is no option to disable or optimize them out.\n * Thus this API is suitable for detecting conditions that should terminate the application and produce a useful diagnostic message.\n * It can be used to ensure bad states are detected early and to avoid data corruption or harder to debug errors.\n *\n * In cases where the assert is very unlikely to have an impact on production code but is still useful as documentation and for debugging, consider using {@link debugAssert} instead\n * to optimize bundle size.\n *\n * This API is not intended for use outside of the Fluid Framework client codebase: it will most likely be made internal in the future.\n * @privateRemarks\n * This should be deprecated (as a non internal API) then moved to purely internal.\n * When done, the `skipInProduction` reference above should be turned into a link.\n * @legacy @beta\n */\nexport function assert(\n\tcondition: boolean,\n\tmessage: string | number,\n\tdebugMessageBuilder?: () => string,\n): asserts condition {\n\tif (!condition) {\n\t\tfail(message, debugMessageBuilder);\n\t}\n}\n\n/**\n * Throw an error with a constant message.\n * @remarks\n * Works like {@link assert}, but errors unconditionally instead of taking in a condition.\n *\n * Unlike `assert`, this `fail` is not \"tagged\" by the assert tagging too by default.\n * Use a `assertTagging.config.mjs` file to enable this and any other assert tagging customizations as needed.\n *\n * Returns `never` so it can be used inline as part of an expression, or as a return value.\n * @example\n * ```ts\n * const x: number = numbersMap.get(\"foo\") ?? fail(\"foo missing from map\");\n * ```\n * @see {@link assert}\n * @internal\n */\nexport function fail(message: string | number, debugMessageBuilder?: () => string): never {\n\tlet messageString =\n\t\ttypeof message === \"number\" ? `0x${message.toString(16).padStart(3, \"0\")}` : message;\n\tskipInProduction(() => {\n\t\tif (debugMessageBuilder !== undefined) {\n\t\t\tmessageString = `${messageString}\\nDebug Message: ${debugMessageBuilder()}`;\n\t\t}\n\t\t// Using console.log instead of console.error or console.warn since the latter two may break downstream users.\n\t\tconsole.log(`Bug in Fluid Framework: Failed Assertion: ${messageString}`);\n\t});\n\tconst error = new Error(messageString);\n\tonAssertionError(error);\n\tthrow error;\n}\n\nfunction onAssertionError(error: Error): void {\n\tfor (const handler of firstChanceAssertionHandler) {\n\t\thandler(error);\n\t}\n}\n\nconst firstChanceAssertionHandler = new Set<(error: Error) => void>();\n\n/**\n * Add a callback which can be used to report an assertion before it is thrown.\n * @param handler - Called when an assertion occurs before the exception is thrown.\n * @returns a function to remove the handler.\n * @remarks\n * The callback runs just before the exception is thrown, which makes it a better place to report telemetry for Fluid Framework bugs than a catch block or an event like `window.onerror`.\n * Using this API to report telemetry is preferred over those approaches since it eliminates the risk of the exception being swallowed or obfuscated by an intermediate stack frame's catch block\n * or missed due to not having the right catch block or event handler.\n *\n * This does not replace the need for error handling elsewhere since errors (even bugs in Fluid) can cause other kinds of exceptions which this cannot run the callback for.\n * @example\n * ```ts\n * import { onAssertionFailure } from \"fluid-framework/alpha\";\n *\n * let firstAssertion: Error | undefined;\n *\n * onAssertionFailure((error: Error) => {\n * \tconst priorErrorNote =\n * \t\tfirstAssertion === undefined\n * \t\t\t? \"Please report this bug.\"\n * \t\t\t: `Might be caused due to prior error ${JSON.stringify(firstAssertion.message)} which should be investigated first.`;\n * \tconst message = `Encountered Bug in Fluid Framework: ${error.message}\\n${priorErrorNote}\\n${error.stack}`;\n * \tconsole.error(message);\n *\n * \tdebugger;\n * \tfirstAssertion ??= error;\n * });\n * ```\n * @alpha\n */\nexport function onAssertionFailure(handler: (error: Error) => void): () => void {\n\t// To avoid issues if the same callback is registered twice (mainly it not triggering twice and the first unregister removing it),\n\t// generate a wrapper around the handler.\n\tconst wrapper = (error: Error): void => {\n\t\thandler(error);\n\t};\n\tfirstChanceAssertionHandler.add(wrapper);\n\treturn () => {\n\t\tfirstChanceAssertionHandler.delete(wrapper);\n\t};\n}\n\n/**\n * Asserts that can be conditionally enabled in debug/development builds but will be optimized out of production builds.\n *\n * Enabled when {@link nonProductionConditionalsIncluded} is true.\n *\n * If the assert must be enforced/checked in production or enabled by default, use {@link assert} instead.\n *\n * @param predicate - A pure function that should return true if the condition holds, or a string or object describing the condition that failed.\n * This function will only be run in some configurations so it should be pure, and only used to detect bugs (when debugAssert are enabled), and must not be relied on to enforce the condition is true: for that use {@link assert}.\n * @remarks\n * Exceptions thrown by this function must never be caught in production code, as that will result in different behavior when testing and when running optimized builds.\n * The `predicate` function must be pure (have no side-effects) to ensure that the behavior of code is the same regardless of if the asserts are disabled, enabled or optimized out.\n *\n * These asserts are enabled by default in debug builds: this introduces risk that code may behave differently when they are disabled or optimized out.\n * To mitigate this risk, these asserts can be disabled in debug builds by calling {@link configureDebugAsserts} or {@link emulateProductionBuild}.\n * This allows testing with the asserts both enabled and disabled to help ensure that code does not depend on them being enabled.\n *\n * Apps (or other performance sensitive scenarios) packaged in a way that does not {@link nonProductionConditionalsIncluded|skip non-production code}\n * can use the same approaches to disable these asserts to reduce performance overhead.\n *\n * @privateRemarks\n * This design was chosen to accomplish two main goals:\n *\n * 1. Make it easy to compile debug asserts fully out of production builds.\n * For webpack this happens by default, avoiding the need for customers to do special configuration.\n * This is important for both performance and bundle size.\n *\n * 2. Make it easy to test (both manually and automated) with and without the predicates running.\n * This ensures it is possible to benefit from the asserts when enabled, but also test with them disabled to ensure this disablement doesn't cause bugs.\n *\n * The default behavior of having debugAsserts enabled helps ensure debugAsserts are effective at catching bugs during development and testing.\n * @internal\n */\nexport function debugAssert(predicate: () => true | { toString(): string }): void {\n\t// This is valid since the contract for this function is that \"predicate\" should be side effect free and never return non true in production scenarios:\n\t// it returning non-true indicates a bug is present, and that the validation it does to detect the bug is only desired in specific test/debug situations.\n\t// Production scenarios, where pure code is removed, should never hit a failing predicate, and thus this code should be side effect free.\n\tskipInProduction(() => {\n\t\tif (debugAssertsEnabled) {\n\t\t\tconst result = predicate();\n\t\t\tif (result !== true) {\n\t\t\t\tdebugger;\n\t\t\t\tconst error = new Error(`Debug assert failed: ${result.toString()}`);\n\t\t\t\tonAssertionError(error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t});\n}\n\nlet debugAssertsEnabled = true;\n\n/**\n * Enables {@link debugAssert} validation.\n * @remarks\n * Throws if debugAsserts have been optimized out.\n *\n * Disabling debugAsserts has two main use cases:\n *\n * 1. Testing that the code behaves correctly in a more production like configuration.\n * 2. Reducing performance overhead.\n *\n * Disabling debugAsserts does not make everything production like: see {@link emulateProductionBuild} for a way to disable more non-production code.\n *\n * @returns The previous state of debugAsserts.\n * @internal\n */\nexport function configureDebugAsserts(enabled: boolean): boolean {\n\tassert(\n\t\tnonProductionConditionalsIncluded(),\n\t\t0xab1 /* Debug asserts cannot be configured since they have been optimized out. */,\n\t);\n\tconst old = debugAssertsEnabled;\n\tdebugAssertsEnabled = enabled;\n\treturn old;\n}\n\n/**\n * Checks if non-production conditional code like {@link debugAssert} is included in this build.\n * @remarks\n * Such code can be optimized out by bundlers or by {@link emulateProductionBuild}: this checks if that has occurred.\n *\n * The non-production used by this library is annotated with `__PURE__` and `#__NO_SIDE_EFFECTS__` and has no return value and thus is removed by bundlers when optimizing based on these annotations.\n * Typically this means that such code is removed in production builds.\n * More details on these annotations can be found at {@link https://github.com/javascript-compiler-hints/compiler-notations-spec/tree/main}.\n * @privateRemarks\n * See {@link skipInProductionInner}.\n * @internal\n */\nexport function nonProductionConditionalsIncluded(): boolean {\n\tlet included = false;\n\tskipInProduction(() => {\n\t\tincluded = true;\n\t});\n\treturn included;\n}\n\n/**\n * Overrides the behavior code which optimizes out non-production conditional code like {@link debugAssert} and {@link nonProductionConditionalsIncluded}.\n *\n * Can be called multiple times. Will emulate production builds if called with `true` more times than `false`.\n * Emulation of production builds is disabled when enabled and disabled counts match (including at 0, by default).\n * It is an error to disable this more than it was enabled.\n *\n * @remarks\n * This is intended for testing that the code behaves correctly in production configurations.\n * Since tools like {@link debugAssert} typically add additional validation to help catch more bugs, tests should generally be run with such checks enabled (and thus emulateProductionBuild in its default disabled state).\n * However it is possible that some debugAsserts could accidentally change behavior and hide a bug.\n * This function provides a way to globally disable the debugAsserts so it is possible to run test suites in a production like mode without having to do a production bundling of them.\n *\n * To avoid introducing additional risk that code does production-specific logic using this setting, the actual setting is not exposed.\n * The intended use is that a pipeline could enable this before running the test suite (for example based on a CLI flag).\n * Such a run may have to also use some filtering to skip any tests which explicity check development only tooling, possibly via {@link nonProductionConditionalsIncluded} or some other mechanism like a test tag.\n *\n * @privateRemarks\n * See {@link skipInProduction}.\n *\n * This design, with a counter, was picked so that it's always safe for some scope to opt in when trying to test production behavior,\n * and it should be basically impossible to accidentally fail to test the production mode when trying to.\n * Some tests or test suites may want to run in production mode and they can use this API to opt in (via before and after hooks for example).\n * Additionally something might want to opt into production mode at some other level (for example test running the entire test suite again with production mode enabled).\n * In such setups, it's important that tests which were explicitly opting in don't accidentally disable production mode for the rest of the run when ending if something higher level enabled it.\n *\n * The approach taken with `configureDebugAsserts` is a bit more flexible, allowing both opt in and opt out, but also more error prone.\n * This API, `emulateProductionBuild` provides a more restrictive but less error prone option targeted at being a final defense for detecting cases where production mode causes issues.\n * It catches some cases `configureDebugAsserts` can't, like dependency on side effects of failing asserts debug message callback.\n * @internal\n */\nexport function emulateProductionBuild(enable = true): void {\n\temulateProductionBuildCount += enable ? 1 : -1;\n\tassert(\n\t\temulateProductionBuildCount >= 0,\n\t\t0xc70 /* emulateProductionBuild disabled more than it was enabled */,\n\t);\n}\n\nlet emulateProductionBuildCount = 0;\n\n/**\n * {@link skipInProductionInner}, except can be disabled by {@link emulateProductionBuild}.\n */\nfunction skipInProduction(conditional: () => void): void {\n\tskipInProductionInner(() => {\n\t\tif (emulateProductionBuildCount === 0) conditional();\n\t});\n}\n\n/**\n * Run `conditional` only in debug/development (non optimized/minified) builds, but optimize it out of production builds.\n *\n * @param conditional - This function will only be run in some configurations so it should be pure (at least in production scenarios).\n * It can be used to interact with debug only functionality that is also removed in production builds, or to do validation/testing/debugging that can be assumed to be sideeffect free in production where it might be removed.\n * @remarks\n * Great care must be taken when using this to ensure that bugs are not introduced which only occur when `conditional` is not run.\n * One way to do this is to provide an alternative way to disable the effects of `conditional` in development builds so both configurations can be tested:\n * {@link debugAssert} uses this pattern.\n *\n * @privateRemarks\n * Since this function has no built in option for toggling it in development for testing, it is not exported and is only used as a building block for other testable options.\n * There are some additional details about syntax and bundler support in https://github.com/javascript-compiler-hints/compiler-notations-spec/tree/main .\n * This code uses both NO_SIDE_EFFECTS and PURE to maximize compatibility: for any bundler supporting both they are redundant.\n */\n// Using the exact syntax from https://github.com/javascript-compiler-hints/compiler-notations-spec/blob/main/no-side-effects-notation-spec.md to maximize compatibility with tree-shaking tools.\n// eslint-disable-next-line spaced-comment\n/*#__NO_SIDE_EFFECTS__*/\nfunction skipInProductionInner(conditional: () => void): void {\n\t// Here __PURE__ annotation is used to indicate that is is safe to optimize out this call.\n\t// This is valid since the contract for this function is that \"conditional\" should be side effect free if it were run in production scenarios\n\t// See https://webpack.js.org/guides/tree-shaking/#mark-a-function-call-as-side-effect-free for documentation on this annotation.\n\n\t// Using the exact syntax from https://webpack.js.org/guides/tree-shaking/#mark-a-function-call-as-side-effect-free to maximize compatibility with tree-shaking tools.\n\t// eslint-disable-next-line spaced-comment\n\t/*#__PURE__*/ conditional();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,MAAM,CACrB,SAAkB,EAClB,OAAwB,EACxB,mBAAkC;IAElC,IAAI,CAAC,SAAS,EAAE,CAAC;QAChB,WAAW,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;IAC3C,CAAC;AACF,CAAC;AARD,wBAQC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,OAAwB,EAAE,mBAAkC;IAChF,IAAI,aAAa,GAChB,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IACtF,gBAAgB,CAAC,GAAG,EAAE;QACrB,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;YACvC,aAAa,GAAG,GAAG,aAAa,oBAAoB,mBAAmB,EAAE,EAAE,CAAC;QAC7E,CAAC;QACD,8GAA8G;QAC9G,OAAO,CAAC,GAAG,CAAC,6CAA6C,aAAa,EAAE,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC;IACH,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;IACvC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACxB,MAAM,KAAK,CAAC;AACb,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,IAAI,CAAC,OAAwB,EAAE,mBAAkC;IAChF,WAAW,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;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MAAM,CACL,iCAAiC,EAAE,EACnC,KAAK,CAAC,4EAA4E,CAClF,CAAC;IACF,MAAM,GAAG,GAAG,mBAAmB,CAAC;IAChC,mBAAmB,GAAG,OAAO,CAAC;IAC9B,OAAO,GAAG,CAAC;AACZ,CAAC;AARD,sDAQC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,iCAAiC;IAChD,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,gBAAgB,CAAC,GAAG,EAAE;QACrB,QAAQ,GAAG,IAAI,CAAC;IACjB,CAAC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AACjB,CAAC;AAND,8EAMC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,SAAgB,sBAAsB,CAAC,MAAM,GAAG,IAAI;IACnD,2BAA2B,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,MAAM,CACL,2BAA2B,IAAI,CAAC,EAChC,KAAK,CAAC,8DAA8D,CACpE,CAAC;AACH,CAAC;AAND,wDAMC;AAED,IAAI,2BAA2B,GAAG,CAAC,CAAC;AAEpC;;GAEG;AACH,SAAS,gBAAgB,CAAC,WAAuB;IAChD,qBAAqB,CAAC,GAAG,EAAE;QAC1B,IAAI,2BAA2B,KAAK,CAAC;YAAE,WAAW,EAAE,CAAC;IACtD,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,iMAAiM;AACjM,0CAA0C;AAC1C,wBAAwB;AACxB,SAAS,qBAAqB,CAAC,WAAuB;IACrD,0FAA0F;IAC1F,6IAA6I;IAC7I,iIAAiI;IAEjI,sKAAsK;IACtK,0CAA0C;IAC1C,aAAa,CAAC,WAAW,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Asserts the specified condition.\n *\n * @param condition - The condition that should be true, if the condition is false an error will be thrown.\n * Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.\n * @param message - The message to include in the error when the condition does not hold.\n * A number should not be specified manually: use a string literal instead.\n * Before a release, policy-check should be run, which will convert any asserts still using strings to\n * use numbered error codes instead.\n * @param debugMessageBuilder - An optional function that can be used to build a debug message to include in the error in development builds.\n * Only executed if `condition` is false. `debugMessageBuilder` is not executed in production builds, see `skipInProduction` for details.\n * @remarks\n * Use this instead of the node 'assert' package, which requires polyfills and has a big impact on bundle sizes.\n *\n * Assertions using this API will be included in all configurations: there is no option to disable or optimize them out.\n * Thus this API is suitable for detecting conditions that should terminate the application and produce a useful diagnostic message.\n * It can be used to ensure bad states are detected early and to avoid data corruption or harder to debug errors.\n *\n * In cases where the assert is very unlikely to have an impact on production code but is still useful as documentation and for debugging, consider using {@link debugAssert} instead\n * to optimize bundle size.\n *\n * This API is not intended for use outside of the Fluid Framework client codebase: it will most likely be made internal in the future.\n * @privateRemarks\n * This should be deprecated (as a non internal API) then moved to purely internal.\n * When done, the `skipInProduction` reference above should be turned into a link.\n * @legacy @beta\n */\nexport function assert(\n\tcondition: boolean,\n\tmessage: string | number,\n\tdebugMessageBuilder?: () => string,\n): asserts condition {\n\tif (!condition) {\n\t\tfailPrivate(message, debugMessageBuilder);\n\t}\n}\n\n/**\n * {@link fail}'s implementation, but extracted to avoid assert tagging trying to tag the use of it in `assert`.\n */\nfunction failPrivate(message: string | number, debugMessageBuilder?: () => string): never {\n\tlet messageString =\n\t\ttypeof message === \"number\" ? `0x${message.toString(16).padStart(3, \"0\")}` : message;\n\tskipInProduction(() => {\n\t\tif (debugMessageBuilder !== undefined) {\n\t\t\tmessageString = `${messageString}\\nDebug Message: ${debugMessageBuilder()}`;\n\t\t}\n\t\t// Using console.log instead of console.error or console.warn since the latter two may break downstream users.\n\t\tconsole.log(`Bug in Fluid Framework: Failed Assertion: ${messageString}`);\n\t});\n\tconst error = new Error(messageString);\n\tonAssertionError(error);\n\tthrow error;\n}\n\n/**\n * Throw an error with a constant message.\n * @remarks\n * Works like {@link assert}, but errors unconditionally instead of taking in a condition.\n *\n * Unlike `assert`, this `fail` is not \"tagged\" by the assert tagging too by default.\n * Use a `assertTagging.config.mjs` file to enable this and any other assert tagging customizations as needed.\n *\n * Returns `never` so it can be used inline as part of an expression, or as a return value.\n * @example\n * ```ts\n * const x: number = numbersMap.get(\"foo\") ?? fail(\"foo missing from map\");\n * ```\n * @see {@link assert}\n * @internal\n */\nexport function fail(message: string | number, debugMessageBuilder?: () => string): never {\n\tfailPrivate(message, debugMessageBuilder);\n}\n\nfunction onAssertionError(error: Error): void {\n\tfor (const handler of firstChanceAssertionHandler) {\n\t\thandler(error);\n\t}\n}\n\nconst firstChanceAssertionHandler = new Set<(error: Error) => void>();\n\n/**\n * Add a callback which can be used to report an assertion before it is thrown.\n * @param handler - Called when an assertion occurs before the exception is thrown.\n * @returns a function to remove the handler.\n * @remarks\n * The callback runs just before the exception is thrown, which makes it a better place to report telemetry for Fluid Framework bugs than a catch block or an event like `window.onerror`.\n * Using this API to report telemetry is preferred over those approaches since it eliminates the risk of the exception being swallowed or obfuscated by an intermediate stack frame's catch block\n * or missed due to not having the right catch block or event handler.\n *\n * This does not replace the need for error handling elsewhere since errors (even bugs in Fluid) can cause other kinds of exceptions which this cannot run the callback for.\n * @example\n * ```ts\n * import { onAssertionFailure } from \"fluid-framework/alpha\";\n *\n * let firstAssertion: Error | undefined;\n *\n * onAssertionFailure((error: Error) => {\n * \tconst priorErrorNote =\n * \t\tfirstAssertion === undefined\n * \t\t\t? \"Please report this bug.\"\n * \t\t\t: `Might be caused due to prior error ${JSON.stringify(firstAssertion.message)} which should be investigated first.`;\n * \tconst message = `Encountered Bug in Fluid Framework: ${error.message}\\n${priorErrorNote}\\n${error.stack}`;\n * \tconsole.error(message);\n *\n * \tdebugger;\n * \tfirstAssertion ??= error;\n * });\n * ```\n * @alpha\n */\nexport function onAssertionFailure(handler: (error: Error) => void): () => void {\n\t// To avoid issues if the same callback is registered twice (mainly it not triggering twice and the first unregister removing it),\n\t// generate a wrapper around the handler.\n\tconst wrapper = (error: Error): void => {\n\t\thandler(error);\n\t};\n\tfirstChanceAssertionHandler.add(wrapper);\n\treturn () => {\n\t\tfirstChanceAssertionHandler.delete(wrapper);\n\t};\n}\n\n/**\n * Asserts that can be conditionally enabled in debug/development builds but will be optimized out of production builds.\n *\n * Enabled when {@link nonProductionConditionalsIncluded} is true.\n *\n * If the assert must be enforced/checked in production or enabled by default, use {@link assert} instead.\n *\n * @param predicate - A pure function that should return true if the condition holds, or a string or object describing the condition that failed.\n * This function will only be run in some configurations so it should be pure, and only used to detect bugs (when debugAssert are enabled), and must not be relied on to enforce the condition is true: for that use {@link assert}.\n * @remarks\n * Exceptions thrown by this function must never be caught in production code, as that will result in different behavior when testing and when running optimized builds.\n * The `predicate` function must be pure (have no side-effects) to ensure that the behavior of code is the same regardless of if the asserts are disabled, enabled or optimized out.\n *\n * These asserts are enabled by default in debug builds: this introduces risk that code may behave differently when they are disabled or optimized out.\n * To mitigate this risk, these asserts can be disabled in debug builds by calling {@link configureDebugAsserts} or {@link emulateProductionBuild}.\n * This allows testing with the asserts both enabled and disabled to help ensure that code does not depend on them being enabled.\n *\n * Apps (or other performance sensitive scenarios) packaged in a way that does not {@link nonProductionConditionalsIncluded|skip non-production code}\n * can use the same approaches to disable these asserts to reduce performance overhead.\n *\n * @privateRemarks\n * This design was chosen to accomplish two main goals:\n *\n * 1. Make it easy to compile debug asserts fully out of production builds.\n * For webpack this happens by default, avoiding the need for customers to do special configuration.\n * This is important for both performance and bundle size.\n *\n * 2. Make it easy to test (both manually and automated) with and without the predicates running.\n * This ensures it is possible to benefit from the asserts when enabled, but also test with them disabled to ensure this disablement doesn't cause bugs.\n *\n * The default behavior of having debugAsserts enabled helps ensure debugAsserts are effective at catching bugs during development and testing.\n * @internal\n */\nexport function debugAssert(predicate: () => true | { toString(): string }): void {\n\t// This is valid since the contract for this function is that \"predicate\" should be side effect free and never return non true in production scenarios:\n\t// it returning non-true indicates a bug is present, and that the validation it does to detect the bug is only desired in specific test/debug situations.\n\t// Production scenarios, where pure code is removed, should never hit a failing predicate, and thus this code should be side effect free.\n\tskipInProduction(() => {\n\t\tif (debugAssertsEnabled) {\n\t\t\tconst result = predicate();\n\t\t\tif (result !== true) {\n\t\t\t\tdebugger;\n\t\t\t\tconst error = new Error(`Debug assert failed: ${result.toString()}`);\n\t\t\t\tonAssertionError(error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t});\n}\n\nlet debugAssertsEnabled = true;\n\n/**\n * Enables {@link debugAssert} validation.\n * @remarks\n * Throws if debugAsserts have been optimized out.\n *\n * Disabling debugAsserts has two main use cases:\n *\n * 1. Testing that the code behaves correctly in a more production like configuration.\n * 2. Reducing performance overhead.\n *\n * Disabling debugAsserts does not make everything production like: see {@link emulateProductionBuild} for a way to disable more non-production code.\n *\n * @returns The previous state of debugAsserts.\n * @internal\n */\nexport function configureDebugAsserts(enabled: boolean): boolean {\n\tassert(\n\t\tnonProductionConditionalsIncluded(),\n\t\t0xab1 /* Debug asserts cannot be configured since they have been optimized out. */,\n\t);\n\tconst old = debugAssertsEnabled;\n\tdebugAssertsEnabled = enabled;\n\treturn old;\n}\n\n/**\n * Checks if non-production conditional code like {@link debugAssert} is included in this build.\n * @remarks\n * Such code can be optimized out by bundlers or by {@link emulateProductionBuild}: this checks if that has occurred.\n *\n * The non-production used by this library is annotated with `__PURE__` and `#__NO_SIDE_EFFECTS__` and has no return value and thus is removed by bundlers when optimizing based on these annotations.\n * Typically this means that such code is removed in production builds.\n * More details on these annotations can be found at {@link https://github.com/javascript-compiler-hints/compiler-notations-spec/tree/main}.\n * @privateRemarks\n * See {@link skipInProductionInner}.\n * @internal\n */\nexport function nonProductionConditionalsIncluded(): boolean {\n\tlet included = false;\n\tskipInProduction(() => {\n\t\tincluded = true;\n\t});\n\treturn included;\n}\n\n/**\n * Overrides the behavior code which optimizes out non-production conditional code like {@link debugAssert} and {@link nonProductionConditionalsIncluded}.\n *\n * Can be called multiple times. Will emulate production builds if called with `true` more times than `false`.\n * Emulation of production builds is disabled when enabled and disabled counts match (including at 0, by default).\n * It is an error to disable this more than it was enabled.\n *\n * @remarks\n * This is intended for testing that the code behaves correctly in production configurations.\n * Since tools like {@link debugAssert} typically add additional validation to help catch more bugs, tests should generally be run with such checks enabled (and thus emulateProductionBuild in its default disabled state).\n * However it is possible that some debugAsserts could accidentally change behavior and hide a bug.\n * This function provides a way to globally disable the debugAsserts so it is possible to run test suites in a production like mode without having to do a production bundling of them.\n *\n * To avoid introducing additional risk that code does production-specific logic using this setting, the actual setting is not exposed.\n * The intended use is that a pipeline could enable this before running the test suite (for example based on a CLI flag).\n * Such a run may have to also use some filtering to skip any tests which explicity check development only tooling, possibly via {@link nonProductionConditionalsIncluded} or some other mechanism like a test tag.\n *\n * @privateRemarks\n * See {@link skipInProduction}.\n *\n * This design, with a counter, was picked so that it's always safe for some scope to opt in when trying to test production behavior,\n * and it should be basically impossible to accidentally fail to test the production mode when trying to.\n * Some tests or test suites may want to run in production mode and they can use this API to opt in (via before and after hooks for example).\n * Additionally something might want to opt into production mode at some other level (for example test running the entire test suite again with production mode enabled).\n * In such setups, it's important that tests which were explicitly opting in don't accidentally disable production mode for the rest of the run when ending if something higher level enabled it.\n *\n * The approach taken with `configureDebugAsserts` is a bit more flexible, allowing both opt in and opt out, but also more error prone.\n * This API, `emulateProductionBuild` provides a more restrictive but less error prone option targeted at being a final defense for detecting cases where production mode causes issues.\n * It catches some cases `configureDebugAsserts` can't, like dependency on side effects of failing asserts debug message callback.\n * @internal\n */\nexport function emulateProductionBuild(enable = true): void {\n\temulateProductionBuildCount += enable ? 1 : -1;\n\tassert(\n\t\temulateProductionBuildCount >= 0,\n\t\t0xc70 /* emulateProductionBuild disabled more than it was enabled */,\n\t);\n}\n\nlet emulateProductionBuildCount = 0;\n\n/**\n * {@link skipInProductionInner}, except can be disabled by {@link emulateProductionBuild}.\n */\nfunction skipInProduction(conditional: () => void): void {\n\tskipInProductionInner(() => {\n\t\tif (emulateProductionBuildCount === 0) conditional();\n\t});\n}\n\n/**\n * Run `conditional` only in debug/development (non optimized/minified) builds, but optimize it out of production builds.\n *\n * @param conditional - This function will only be run in some configurations so it should be pure (at least in production scenarios).\n * It can be used to interact with debug only functionality that is also removed in production builds, or to do validation/testing/debugging that can be assumed to be sideeffect free in production where it might be removed.\n * @remarks\n * Great care must be taken when using this to ensure that bugs are not introduced which only occur when `conditional` is not run.\n * One way to do this is to provide an alternative way to disable the effects of `conditional` in development builds so both configurations can be tested:\n * {@link debugAssert} uses this pattern.\n *\n * @privateRemarks\n * Since this function has no built in option for toggling it in development for testing, it is not exported and is only used as a building block for other testable options.\n * There are some additional details about syntax and bundler support in https://github.com/javascript-compiler-hints/compiler-notations-spec/tree/main .\n * This code uses both NO_SIDE_EFFECTS and PURE to maximize compatibility: for any bundler supporting both they are redundant.\n */\n// Using the exact syntax from https://github.com/javascript-compiler-hints/compiler-notations-spec/blob/main/no-side-effects-notation-spec.md to maximize compatibility with tree-shaking tools.\n// eslint-disable-next-line spaced-comment\n/*#__NO_SIDE_EFFECTS__*/\nfunction skipInProductionInner(conditional: () => void): void {\n\t// Here __PURE__ annotation is used to indicate that is is safe to optimize out this call.\n\t// This is valid since the contract for this function is that \"conditional\" should be side effect free if it were run in production scenarios\n\t// See https://webpack.js.org/guides/tree-shaking/#mark-a-function-call-as-side-effect-free for documentation on this annotation.\n\n\t// Using the exact syntax from https://webpack.js.org/guides/tree-shaking/#mark-a-function-call-as-side-effect-free to maximize compatibility with tree-shaking tools.\n\t// eslint-disable-next-line spaced-comment\n\t/*#__PURE__*/ conditional();\n}\n"]}
|
package/dist/lazy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,qBAAa,IAAI,CAAC,CA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C,SAAS,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC;YAK/D,UAAU;CAOxB"}
|
package/dist/lazy.js
CHANGED
|
@@ -75,6 +75,7 @@ class LazyPromise {
|
|
|
75
75
|
return this.getPromise().finally(...arguments);
|
|
76
76
|
}
|
|
77
77
|
async getPromise() {
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if result is a falsy value
|
|
78
79
|
if (this.result === undefined) {
|
|
79
80
|
this.result = this.execute();
|
|
80
81
|
}
|
package/dist/lazy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.js","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;GAGG;AACH,MAAa,IAAI;IAGhB;;;OAGG;IACH,YAAoC,cAAuB;QAAvB,mBAAc,GAAd,cAAc,CAAS;QALnD,eAAU,GAAY,KAAK,CAAC;IAK0B,CAAC;IAE/D;;OAEG;IACH,IAAW,SAAS;QACnB,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACf,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QACrC,CAAC;QACD,oEAAoE;QACpE,OAAO,IAAI,CAAC,MAAO,CAAC;IACrB,CAAC;CACD;AA3BD,oBA2BC;AAED;;;;;;GAMG;AACH,MAAa,WAAW;IACvB,2EAA2E;IAC3E,IAAW,CAAC,MAAM,CAAC,WAAW,CAAC;QAC9B,OAAO,sBAAsB,CAAC;IAC/B,CAAC;IAID,YAAoC,OAAyB;QAAzB,YAAO,GAAP,OAAO,CAAkB;IAAG,CAAC;IAEjE,+CAA+C;IACxC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,CAAC;QACD,oEAAoE;QACpE,OAAO,IAAI,CAAC,MAAO,CAAC;IACrB,CAAC;CACD;AA3BD,oBA2BC;AAED;;;;;;GAMG;AACH,MAAa,WAAW;IACvB,2EAA2E;IAC3E,IAAW,CAAC,MAAM,CAAC,WAAW,CAAC;QAC9B,OAAO,sBAAsB,CAAC;IAC/B,CAAC;IAID,YAAoC,OAAyB;QAAzB,YAAO,GAAP,OAAO,CAAkB;IAAG,CAAC;IAEjE,+CAA+C;IACxC,KAAK,CAAC,IAAI;IAChB,kDAAkD;IAClD,WAAiF;IACjF,6CAA6C;IAC7C,sFAAsF;IACtF,UAAmF;QAEnF,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,CAAqB,GAAG,SAAS,CAAC,CAAC;IACjE,CAAC;IAEM,KAAK,CAAC,KAAK;IACjB,6CAA6C;IAC7C,sFAAsF;IACtF,UAAiF;QAEjF,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,KAAK,CAAU,GAAG,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,kDAAkD;IAC3C,KAAK,CAAC,OAAO,CAAC,SAA2C;QAC/D,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;IAChD,CAAC;IAEO,KAAK,CAAC,UAAU;QACvB,sIAAsI;QACtI,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC9B,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD;AA5CD,kCA4CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Helper class for lazy initialized values. Ensures the value is only generated once, and remain immutable.\n * @internal\n */\nexport class Lazy<T> {\n\tprivate _value: T | undefined;\n\tprivate _evaluated: boolean = false;\n\t/**\n\t * Instantiates an instance of Lazy<T>.\n\t * @param valueGenerator - The function that will generate the value when value is accessed the first time.\n\t */\n\tpublic constructor(private readonly valueGenerator: () => T) {}\n\n\t/**\n\t * Return true if the value as been generated, otherwise false.\n\t */\n\tpublic get evaluated(): boolean {\n\t\treturn this._evaluated;\n\t}\n\n\t/**\n\t * Get the value. If this is the first call the value will be generated.\n\t */\n\tpublic get value(): T {\n\t\tif (!this._evaluated) {\n\t\t\tthis._evaluated = true;\n\t\t\tthis._value = this.valueGenerator();\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this._value!;\n\t}\n}\n\n/**\n * A lazy evaluated promise. The execute function is delayed until\n * the promise is used, e.g. await, then, catch ...\n * The execute function is only called once.\n * All calls are then proxied to the promise returned by the execute method.\n * @legacy @beta\n */\nexport class LazyPromise<T> implements Promise<T> {\n\t// eslint-disable-next-line @typescript-eslint/class-literal-property-style\n\tpublic get [Symbol.toStringTag](): string {\n\t\treturn \"[object LazyPromise]\";\n\t}\n\n\tprivate result: Promise<T> | undefined;\n\n\tpublic constructor(private readonly execute: () => Promise<T>) {}\n\n\t// eslint-disable-next-line unicorn/no-thenable\n\tpublic async then<TResult1 = T, TResult2 = never>(\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tonfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n\t\t// TODO: Use `unknown` instead (API breaking)\n\t\t// eslint-disable-next-line @rushstack/no-new-null, @typescript-eslint/no-explicit-any\n\t\tonrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n\t): Promise<TResult1 | TResult2> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().then<TResult1, TResult2>(...arguments);\n\t}\n\n\tpublic async catch<TResult = never>(\n\t\t// TODO: Use `unknown` instead (API breaking)\n\t\t// eslint-disable-next-line @rushstack/no-new-null, @typescript-eslint/no-explicit-any\n\t\tonrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined,\n\t): Promise<T | TResult> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().catch<TResult>(...arguments);\n\t}\n\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async finally(onfinally?: (() => void) | null | undefined): Promise<T> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().finally(...arguments);\n\t}\n\n\tprivate async getPromise(): Promise<T> {\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if result is a falsy value\n\t\tif (this.result === undefined) {\n\t\t\tthis.result = this.execute();\n\t\t}\n\t\treturn this.result;\n\t}\n}\n"]}
|
package/eslint.config.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* To regenerate: pnpm tsx scripts/generate-flat-eslint-configs.ts --typescript
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
5
4
|
*/
|
|
5
|
+
|
|
6
6
|
import type { Linter } from "eslint";
|
|
7
7
|
import { strict } from "../../../common/build/eslint-config-fluid/flat.mts";
|
|
8
8
|
|
package/lib/assert.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,MAAM,CACrB,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,mBAAmB,CAAC,EAAE,MAAM,MAAM,GAChC,OAAO,CAAC,SAAS,CAInB;
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,MAAM,CACrB,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,mBAAmB,CAAC,EAAE,MAAM,MAAM,GAChC,OAAO,CAAC,SAAS,CAInB;AAoBD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,mBAAmB,CAAC,EAAE,MAAM,MAAM,GAAG,KAAK,CAExF;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,MAAM,IAAI,CAU9E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,IAAI,GAAG;IAAE,QAAQ,IAAI,MAAM,CAAA;CAAE,GAAG,IAAI,CAehF;AAID;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAQ/D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iCAAiC,IAAI,OAAO,CAM3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,UAAO,GAAG,IAAI,CAM1D"}
|
package/lib/assert.js
CHANGED
|
@@ -31,9 +31,25 @@
|
|
|
31
31
|
*/
|
|
32
32
|
export function assert(condition, message, debugMessageBuilder) {
|
|
33
33
|
if (!condition) {
|
|
34
|
-
|
|
34
|
+
failPrivate(message, debugMessageBuilder);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* {@link fail}'s implementation, but extracted to avoid assert tagging trying to tag the use of it in `assert`.
|
|
39
|
+
*/
|
|
40
|
+
function failPrivate(message, debugMessageBuilder) {
|
|
41
|
+
let messageString = typeof message === "number" ? `0x${message.toString(16).padStart(3, "0")}` : message;
|
|
42
|
+
skipInProduction(() => {
|
|
43
|
+
if (debugMessageBuilder !== undefined) {
|
|
44
|
+
messageString = `${messageString}\nDebug Message: ${debugMessageBuilder()}`;
|
|
45
|
+
}
|
|
46
|
+
// Using console.log instead of console.error or console.warn since the latter two may break downstream users.
|
|
47
|
+
console.log(`Bug in Fluid Framework: Failed Assertion: ${messageString}`);
|
|
48
|
+
});
|
|
49
|
+
const error = new Error(messageString);
|
|
50
|
+
onAssertionError(error);
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
37
53
|
/**
|
|
38
54
|
* Throw an error with a constant message.
|
|
39
55
|
* @remarks
|
|
@@ -51,17 +67,7 @@ export function assert(condition, message, debugMessageBuilder) {
|
|
|
51
67
|
* @internal
|
|
52
68
|
*/
|
|
53
69
|
export function fail(message, debugMessageBuilder) {
|
|
54
|
-
|
|
55
|
-
skipInProduction(() => {
|
|
56
|
-
if (debugMessageBuilder !== undefined) {
|
|
57
|
-
messageString = `${messageString}\nDebug Message: ${debugMessageBuilder()}`;
|
|
58
|
-
}
|
|
59
|
-
// Using console.log instead of console.error or console.warn since the latter two may break downstream users.
|
|
60
|
-
console.log(`Bug in Fluid Framework: Failed Assertion: ${messageString}`);
|
|
61
|
-
});
|
|
62
|
-
const error = new Error(messageString);
|
|
63
|
-
onAssertionError(error);
|
|
64
|
-
throw error;
|
|
70
|
+
failPrivate(message, debugMessageBuilder);
|
|
65
71
|
}
|
|
66
72
|
function onAssertionError(error) {
|
|
67
73
|
for (const handler of firstChanceAssertionHandler) {
|
package/lib/assert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,MAAM,CACrB,SAAkB,E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IACnD,2BAA2B,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,MAAM,CACL,2BAA2B,IAAI,CAAC,EAChC,KAAK,CAAC,8DAA8D,CACpE,CAAC;AACH,CAAC;AAED,IAAI,2BAA2B,GAAG,CAAC,CAAC;AAEpC;;GAEG;AACH,SAAS,gBAAgB,CAAC,WAAuB;IAChD,qBAAqB,CAAC,GAAG,EAAE;QAC1B,IAAI,2BAA2B,KAAK,CAAC;YAAE,WAAW,EAAE,CAAC;IACtD,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,iMAAiM;AACjM,0CAA0C;AAC1C,wBAAwB;AACxB,SAAS,qBAAqB,CAAC,WAAuB;IACrD,0FAA0F;IAC1F,6IAA6I;IAC7I,iIAAiI;IAEjI,sKAAsK;IACtK,0CAA0C;IAC1C,aAAa,CAAC,WAAW,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Asserts the specified condition.\n *\n * @param condition - The condition that should be true, if the condition is false an error will be thrown.\n * Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.\n * @param message - The message to include in the error when the condition does not hold.\n * A number should not be specified manually: use a string literal instead.\n * Before a release, policy-check should be run, which will convert any asserts still using strings to\n * use numbered error codes instead.\n * @param debugMessageBuilder - An optional function that can be used to build a debug message to include in the error in development builds.\n * Only executed if `condition` is false. `debugMessageBuilder` is not executed in production builds, see `skipInProduction` for details.\n * @remarks\n * Use this instead of the node 'assert' package, which requires polyfills and has a big impact on bundle sizes.\n *\n * Assertions using this API will be included in all configurations: there is no option to disable or optimize them out.\n * Thus this API is suitable for detecting conditions that should terminate the application and produce a useful diagnostic message.\n * It can be used to ensure bad states are detected early and to avoid data corruption or harder to debug errors.\n *\n * In cases where the assert is very unlikely to have an impact on production code but is still useful as documentation and for debugging, consider using {@link debugAssert} instead\n * to optimize bundle size.\n *\n * This API is not intended for use outside of the Fluid Framework client codebase: it will most likely be made internal in the future.\n * @privateRemarks\n * This should be deprecated (as a non internal API) then moved to purely internal.\n * When done, the `skipInProduction` reference above should be turned into a link.\n * @legacy @beta\n */\nexport function assert(\n\tcondition: boolean,\n\tmessage: string | number,\n\tdebugMessageBuilder?: () => string,\n): asserts condition {\n\tif (!condition) {\n\t\tfail(message, debugMessageBuilder);\n\t}\n}\n\n/**\n * Throw an error with a constant message.\n * @remarks\n * Works like {@link assert}, but errors unconditionally instead of taking in a condition.\n *\n * Unlike `assert`, this `fail` is not \"tagged\" by the assert tagging too by default.\n * Use a `assertTagging.config.mjs` file to enable this and any other assert tagging customizations as needed.\n *\n * Returns `never` so it can be used inline as part of an expression, or as a return value.\n * @example\n * ```ts\n * const x: number = numbersMap.get(\"foo\") ?? fail(\"foo missing from map\");\n * ```\n * @see {@link assert}\n * @internal\n */\nexport function fail(message: string | number, debugMessageBuilder?: () => string): never {\n\tlet messageString =\n\t\ttypeof message === \"number\" ? `0x${message.toString(16).padStart(3, \"0\")}` : message;\n\tskipInProduction(() => {\n\t\tif (debugMessageBuilder !== undefined) {\n\t\t\tmessageString = `${messageString}\\nDebug Message: ${debugMessageBuilder()}`;\n\t\t}\n\t\t// Using console.log instead of console.error or console.warn since the latter two may break downstream users.\n\t\tconsole.log(`Bug in Fluid Framework: Failed Assertion: ${messageString}`);\n\t});\n\tconst error = new Error(messageString);\n\tonAssertionError(error);\n\tthrow error;\n}\n\nfunction onAssertionError(error: Error): void {\n\tfor (const handler of firstChanceAssertionHandler) {\n\t\thandler(error);\n\t}\n}\n\nconst firstChanceAssertionHandler = new Set<(error: Error) => void>();\n\n/**\n * Add a callback which can be used to report an assertion before it is thrown.\n * @param handler - Called when an assertion occurs before the exception is thrown.\n * @returns a function to remove the handler.\n * @remarks\n * The callback runs just before the exception is thrown, which makes it a better place to report telemetry for Fluid Framework bugs than a catch block or an event like `window.onerror`.\n * Using this API to report telemetry is preferred over those approaches since it eliminates the risk of the exception being swallowed or obfuscated by an intermediate stack frame's catch block\n * or missed due to not having the right catch block or event handler.\n *\n * This does not replace the need for error handling elsewhere since errors (even bugs in Fluid) can cause other kinds of exceptions which this cannot run the callback for.\n * @example\n * ```ts\n * import { onAssertionFailure } from \"fluid-framework/alpha\";\n *\n * let firstAssertion: Error | undefined;\n *\n * onAssertionFailure((error: Error) => {\n * \tconst priorErrorNote =\n * \t\tfirstAssertion === undefined\n * \t\t\t? \"Please report this bug.\"\n * \t\t\t: `Might be caused due to prior error ${JSON.stringify(firstAssertion.message)} which should be investigated first.`;\n * \tconst message = `Encountered Bug in Fluid Framework: ${error.message}\\n${priorErrorNote}\\n${error.stack}`;\n * \tconsole.error(message);\n *\n * \tdebugger;\n * \tfirstAssertion ??= error;\n * });\n * ```\n * @alpha\n */\nexport function onAssertionFailure(handler: (error: Error) => void): () => void {\n\t// To avoid issues if the same callback is registered twice (mainly it not triggering twice and the first unregister removing it),\n\t// generate a wrapper around the handler.\n\tconst wrapper = (error: Error): void => {\n\t\thandler(error);\n\t};\n\tfirstChanceAssertionHandler.add(wrapper);\n\treturn () => {\n\t\tfirstChanceAssertionHandler.delete(wrapper);\n\t};\n}\n\n/**\n * Asserts that can be conditionally enabled in debug/development builds but will be optimized out of production builds.\n *\n * Enabled when {@link nonProductionConditionalsIncluded} is true.\n *\n * If the assert must be enforced/checked in production or enabled by default, use {@link assert} instead.\n *\n * @param predicate - A pure function that should return true if the condition holds, or a string or object describing the condition that failed.\n * This function will only be run in some configurations so it should be pure, and only used to detect bugs (when debugAssert are enabled), and must not be relied on to enforce the condition is true: for that use {@link assert}.\n * @remarks\n * Exceptions thrown by this function must never be caught in production code, as that will result in different behavior when testing and when running optimized builds.\n * The `predicate` function must be pure (have no side-effects) to ensure that the behavior of code is the same regardless of if the asserts are disabled, enabled or optimized out.\n *\n * These asserts are enabled by default in debug builds: this introduces risk that code may behave differently when they are disabled or optimized out.\n * To mitigate this risk, these asserts can be disabled in debug builds by calling {@link configureDebugAsserts} or {@link emulateProductionBuild}.\n * This allows testing with the asserts both enabled and disabled to help ensure that code does not depend on them being enabled.\n *\n * Apps (or other performance sensitive scenarios) packaged in a way that does not {@link nonProductionConditionalsIncluded|skip non-production code}\n * can use the same approaches to disable these asserts to reduce performance overhead.\n *\n * @privateRemarks\n * This design was chosen to accomplish two main goals:\n *\n * 1. Make it easy to compile debug asserts fully out of production builds.\n * For webpack this happens by default, avoiding the need for customers to do special configuration.\n * This is important for both performance and bundle size.\n *\n * 2. Make it easy to test (both manually and automated) with and without the predicates running.\n * This ensures it is possible to benefit from the asserts when enabled, but also test with them disabled to ensure this disablement doesn't cause bugs.\n *\n * The default behavior of having debugAsserts enabled helps ensure debugAsserts are effective at catching bugs during development and testing.\n * @internal\n */\nexport function debugAssert(predicate: () => true | { toString(): string }): void {\n\t// This is valid since the contract for this function is that \"predicate\" should be side effect free and never return non true in production scenarios:\n\t// it returning non-true indicates a bug is present, and that the validation it does to detect the bug is only desired in specific test/debug situations.\n\t// Production scenarios, where pure code is removed, should never hit a failing predicate, and thus this code should be side effect free.\n\tskipInProduction(() => {\n\t\tif (debugAssertsEnabled) {\n\t\t\tconst result = predicate();\n\t\t\tif (result !== true) {\n\t\t\t\tdebugger;\n\t\t\t\tconst error = new Error(`Debug assert failed: ${result.toString()}`);\n\t\t\t\tonAssertionError(error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t});\n}\n\nlet debugAssertsEnabled = true;\n\n/**\n * Enables {@link debugAssert} validation.\n * @remarks\n * Throws if debugAsserts have been optimized out.\n *\n * Disabling debugAsserts has two main use cases:\n *\n * 1. Testing that the code behaves correctly in a more production like configuration.\n * 2. Reducing performance overhead.\n *\n * Disabling debugAsserts does not make everything production like: see {@link emulateProductionBuild} for a way to disable more non-production code.\n *\n * @returns The previous state of debugAsserts.\n * @internal\n */\nexport function configureDebugAsserts(enabled: boolean): boolean {\n\tassert(\n\t\tnonProductionConditionalsIncluded(),\n\t\t0xab1 /* Debug asserts cannot be configured since they have been optimized out. */,\n\t);\n\tconst old = debugAssertsEnabled;\n\tdebugAssertsEnabled = enabled;\n\treturn old;\n}\n\n/**\n * Checks if non-production conditional code like {@link debugAssert} is included in this build.\n * @remarks\n * Such code can be optimized out by bundlers or by {@link emulateProductionBuild}: this checks if that has occurred.\n *\n * The non-production used by this library is annotated with `__PURE__` and `#__NO_SIDE_EFFECTS__` and has no return value and thus is removed by bundlers when optimizing based on these annotations.\n * Typically this means that such code is removed in production builds.\n * More details on these annotations can be found at {@link https://github.com/javascript-compiler-hints/compiler-notations-spec/tree/main}.\n * @privateRemarks\n * See {@link skipInProductionInner}.\n * @internal\n */\nexport function nonProductionConditionalsIncluded(): boolean {\n\tlet included = false;\n\tskipInProduction(() => {\n\t\tincluded = true;\n\t});\n\treturn included;\n}\n\n/**\n * Overrides the behavior code which optimizes out non-production conditional code like {@link debugAssert} and {@link nonProductionConditionalsIncluded}.\n *\n * Can be called multiple times. Will emulate production builds if called with `true` more times than `false`.\n * Emulation of production builds is disabled when enabled and disabled counts match (including at 0, by default).\n * It is an error to disable this more than it was enabled.\n *\n * @remarks\n * This is intended for testing that the code behaves correctly in production configurations.\n * Since tools like {@link debugAssert} typically add additional validation to help catch more bugs, tests should generally be run with such checks enabled (and thus emulateProductionBuild in its default disabled state).\n * However it is possible that some debugAsserts could accidentally change behavior and hide a bug.\n * This function provides a way to globally disable the debugAsserts so it is possible to run test suites in a production like mode without having to do a production bundling of them.\n *\n * To avoid introducing additional risk that code does production-specific logic using this setting, the actual setting is not exposed.\n * The intended use is that a pipeline could enable this before running the test suite (for example based on a CLI flag).\n * Such a run may have to also use some filtering to skip any tests which explicity check development only tooling, possibly via {@link nonProductionConditionalsIncluded} or some other mechanism like a test tag.\n *\n * @privateRemarks\n * See {@link skipInProduction}.\n *\n * This design, with a counter, was picked so that it's always safe for some scope to opt in when trying to test production behavior,\n * and it should be basically impossible to accidentally fail to test the production mode when trying to.\n * Some tests or test suites may want to run in production mode and they can use this API to opt in (via before and after hooks for example).\n * Additionally something might want to opt into production mode at some other level (for example test running the entire test suite again with production mode enabled).\n * In such setups, it's important that tests which were explicitly opting in don't accidentally disable production mode for the rest of the run when ending if something higher level enabled it.\n *\n * The approach taken with `configureDebugAsserts` is a bit more flexible, allowing both opt in and opt out, but also more error prone.\n * This API, `emulateProductionBuild` provides a more restrictive but less error prone option targeted at being a final defense for detecting cases where production mode causes issues.\n * It catches some cases `configureDebugAsserts` can't, like dependency on side effects of failing asserts debug message callback.\n * @internal\n */\nexport function emulateProductionBuild(enable = true): void {\n\temulateProductionBuildCount += enable ? 1 : -1;\n\tassert(\n\t\temulateProductionBuildCount >= 0,\n\t\t0xc70 /* emulateProductionBuild disabled more than it was enabled */,\n\t);\n}\n\nlet emulateProductionBuildCount = 0;\n\n/**\n * {@link skipInProductionInner}, except can be disabled by {@link emulateProductionBuild}.\n */\nfunction skipInProduction(conditional: () => void): void {\n\tskipInProductionInner(() => {\n\t\tif (emulateProductionBuildCount === 0) conditional();\n\t});\n}\n\n/**\n * Run `conditional` only in debug/development (non optimized/minified) builds, but optimize it out of production builds.\n *\n * @param conditional - This function will only be run in some configurations so it should be pure (at least in production scenarios).\n * It can be used to interact with debug only functionality that is also removed in production builds, or to do validation/testing/debugging that can be assumed to be sideeffect free in production where it might be removed.\n * @remarks\n * Great care must be taken when using this to ensure that bugs are not introduced which only occur when `conditional` is not run.\n * One way to do this is to provide an alternative way to disable the effects of `conditional` in development builds so both configurations can be tested:\n * {@link debugAssert} uses this pattern.\n *\n * @privateRemarks\n * Since this function has no built in option for toggling it in development for testing, it is not exported and is only used as a building block for other testable options.\n * There are some additional details about syntax and bundler support in https://github.com/javascript-compiler-hints/compiler-notations-spec/tree/main .\n * This code uses both NO_SIDE_EFFECTS and PURE to maximize compatibility: for any bundler supporting both they are redundant.\n */\n// Using the exact syntax from https://github.com/javascript-compiler-hints/compiler-notations-spec/blob/main/no-side-effects-notation-spec.md to maximize compatibility with tree-shaking tools.\n// eslint-disable-next-line spaced-comment\n/*#__NO_SIDE_EFFECTS__*/\nfunction skipInProductionInner(conditional: () => void): void {\n\t// Here __PURE__ annotation is used to indicate that is is safe to optimize out this call.\n\t// This is valid since the contract for this function is that \"conditional\" should be side effect free if it were run in production scenarios\n\t// See https://webpack.js.org/guides/tree-shaking/#mark-a-function-call-as-side-effect-free for documentation on this annotation.\n\n\t// Using the exact syntax from https://webpack.js.org/guides/tree-shaking/#mark-a-function-call-as-side-effect-free to maximize compatibility with tree-shaking tools.\n\t// eslint-disable-next-line spaced-comment\n\t/*#__PURE__*/ conditional();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,MAAM,CACrB,SAAkB,EAClB,OAAwB,EACxB,mBAAkC;IAElC,IAAI,CAAC,SAAS,EAAE,CAAC;QAChB,WAAW,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;IAC3C,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,OAAwB,EAAE,mBAAkC;IAChF,IAAI,aAAa,GAChB,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IACtF,gBAAgB,CAAC,GAAG,EAAE;QACrB,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;YACvC,aAAa,GAAG,GAAG,aAAa,oBAAoB,mBAAmB,EAAE,EAAE,CAAC;QAC7E,CAAC;QACD,8GAA8G;QAC9G,OAAO,CAAC,GAAG,CAAC,6CAA6C,aAAa,EAAE,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC;IACH,MAAM,KAAK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AEjI,sKAAsK;IACtK,0CAA0C;IAC1C,aAAa,CAAC,WAAW,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Asserts the specified condition.\n *\n * @param condition - The condition that should be true, if the condition is false an error will be thrown.\n * Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.\n * @param message - The message to include in the error when the condition does not hold.\n * A number should not be specified manually: use a string literal instead.\n * Before a release, policy-check should be run, which will convert any asserts still using strings to\n * use numbered error codes instead.\n * @param debugMessageBuilder - An optional function that can be used to build a debug message to include in the error in development builds.\n * Only executed if `condition` is false. `debugMessageBuilder` is not executed in production builds, see `skipInProduction` for details.\n * @remarks\n * Use this instead of the node 'assert' package, which requires polyfills and has a big impact on bundle sizes.\n *\n * Assertions using this API will be included in all configurations: there is no option to disable or optimize them out.\n * Thus this API is suitable for detecting conditions that should terminate the application and produce a useful diagnostic message.\n * It can be used to ensure bad states are detected early and to avoid data corruption or harder to debug errors.\n *\n * In cases where the assert is very unlikely to have an impact on production code but is still useful as documentation and for debugging, consider using {@link debugAssert} instead\n * to optimize bundle size.\n *\n * This API is not intended for use outside of the Fluid Framework client codebase: it will most likely be made internal in the future.\n * @privateRemarks\n * This should be deprecated (as a non internal API) then moved to purely internal.\n * When done, the `skipInProduction` reference above should be turned into a link.\n * @legacy @beta\n */\nexport function assert(\n\tcondition: boolean,\n\tmessage: string | number,\n\tdebugMessageBuilder?: () => string,\n): asserts condition {\n\tif (!condition) {\n\t\tfailPrivate(message, debugMessageBuilder);\n\t}\n}\n\n/**\n * {@link fail}'s implementation, but extracted to avoid assert tagging trying to tag the use of it in `assert`.\n */\nfunction failPrivate(message: string | number, debugMessageBuilder?: () => string): never {\n\tlet messageString =\n\t\ttypeof message === \"number\" ? `0x${message.toString(16).padStart(3, \"0\")}` : message;\n\tskipInProduction(() => {\n\t\tif (debugMessageBuilder !== undefined) {\n\t\t\tmessageString = `${messageString}\\nDebug Message: ${debugMessageBuilder()}`;\n\t\t}\n\t\t// Using console.log instead of console.error or console.warn since the latter two may break downstream users.\n\t\tconsole.log(`Bug in Fluid Framework: Failed Assertion: ${messageString}`);\n\t});\n\tconst error = new Error(messageString);\n\tonAssertionError(error);\n\tthrow error;\n}\n\n/**\n * Throw an error with a constant message.\n * @remarks\n * Works like {@link assert}, but errors unconditionally instead of taking in a condition.\n *\n * Unlike `assert`, this `fail` is not \"tagged\" by the assert tagging too by default.\n * Use a `assertTagging.config.mjs` file to enable this and any other assert tagging customizations as needed.\n *\n * Returns `never` so it can be used inline as part of an expression, or as a return value.\n * @example\n * ```ts\n * const x: number = numbersMap.get(\"foo\") ?? fail(\"foo missing from map\");\n * ```\n * @see {@link assert}\n * @internal\n */\nexport function fail(message: string | number, debugMessageBuilder?: () => string): never {\n\tfailPrivate(message, debugMessageBuilder);\n}\n\nfunction onAssertionError(error: Error): void {\n\tfor (const handler of firstChanceAssertionHandler) {\n\t\thandler(error);\n\t}\n}\n\nconst firstChanceAssertionHandler = new Set<(error: Error) => void>();\n\n/**\n * Add a callback which can be used to report an assertion before it is thrown.\n * @param handler - Called when an assertion occurs before the exception is thrown.\n * @returns a function to remove the handler.\n * @remarks\n * The callback runs just before the exception is thrown, which makes it a better place to report telemetry for Fluid Framework bugs than a catch block or an event like `window.onerror`.\n * Using this API to report telemetry is preferred over those approaches since it eliminates the risk of the exception being swallowed or obfuscated by an intermediate stack frame's catch block\n * or missed due to not having the right catch block or event handler.\n *\n * This does not replace the need for error handling elsewhere since errors (even bugs in Fluid) can cause other kinds of exceptions which this cannot run the callback for.\n * @example\n * ```ts\n * import { onAssertionFailure } from \"fluid-framework/alpha\";\n *\n * let firstAssertion: Error | undefined;\n *\n * onAssertionFailure((error: Error) => {\n * \tconst priorErrorNote =\n * \t\tfirstAssertion === undefined\n * \t\t\t? \"Please report this bug.\"\n * \t\t\t: `Might be caused due to prior error ${JSON.stringify(firstAssertion.message)} which should be investigated first.`;\n * \tconst message = `Encountered Bug in Fluid Framework: ${error.message}\\n${priorErrorNote}\\n${error.stack}`;\n * \tconsole.error(message);\n *\n * \tdebugger;\n * \tfirstAssertion ??= error;\n * });\n * ```\n * @alpha\n */\nexport function onAssertionFailure(handler: (error: Error) => void): () => void {\n\t// To avoid issues if the same callback is registered twice (mainly it not triggering twice and the first unregister removing it),\n\t// generate a wrapper around the handler.\n\tconst wrapper = (error: Error): void => {\n\t\thandler(error);\n\t};\n\tfirstChanceAssertionHandler.add(wrapper);\n\treturn () => {\n\t\tfirstChanceAssertionHandler.delete(wrapper);\n\t};\n}\n\n/**\n * Asserts that can be conditionally enabled in debug/development builds but will be optimized out of production builds.\n *\n * Enabled when {@link nonProductionConditionalsIncluded} is true.\n *\n * If the assert must be enforced/checked in production or enabled by default, use {@link assert} instead.\n *\n * @param predicate - A pure function that should return true if the condition holds, or a string or object describing the condition that failed.\n * This function will only be run in some configurations so it should be pure, and only used to detect bugs (when debugAssert are enabled), and must not be relied on to enforce the condition is true: for that use {@link assert}.\n * @remarks\n * Exceptions thrown by this function must never be caught in production code, as that will result in different behavior when testing and when running optimized builds.\n * The `predicate` function must be pure (have no side-effects) to ensure that the behavior of code is the same regardless of if the asserts are disabled, enabled or optimized out.\n *\n * These asserts are enabled by default in debug builds: this introduces risk that code may behave differently when they are disabled or optimized out.\n * To mitigate this risk, these asserts can be disabled in debug builds by calling {@link configureDebugAsserts} or {@link emulateProductionBuild}.\n * This allows testing with the asserts both enabled and disabled to help ensure that code does not depend on them being enabled.\n *\n * Apps (or other performance sensitive scenarios) packaged in a way that does not {@link nonProductionConditionalsIncluded|skip non-production code}\n * can use the same approaches to disable these asserts to reduce performance overhead.\n *\n * @privateRemarks\n * This design was chosen to accomplish two main goals:\n *\n * 1. Make it easy to compile debug asserts fully out of production builds.\n * For webpack this happens by default, avoiding the need for customers to do special configuration.\n * This is important for both performance and bundle size.\n *\n * 2. Make it easy to test (both manually and automated) with and without the predicates running.\n * This ensures it is possible to benefit from the asserts when enabled, but also test with them disabled to ensure this disablement doesn't cause bugs.\n *\n * The default behavior of having debugAsserts enabled helps ensure debugAsserts are effective at catching bugs during development and testing.\n * @internal\n */\nexport function debugAssert(predicate: () => true | { toString(): string }): void {\n\t// This is valid since the contract for this function is that \"predicate\" should be side effect free and never return non true in production scenarios:\n\t// it returning non-true indicates a bug is present, and that the validation it does to detect the bug is only desired in specific test/debug situations.\n\t// Production scenarios, where pure code is removed, should never hit a failing predicate, and thus this code should be side effect free.\n\tskipInProduction(() => {\n\t\tif (debugAssertsEnabled) {\n\t\t\tconst result = predicate();\n\t\t\tif (result !== true) {\n\t\t\t\tdebugger;\n\t\t\t\tconst error = new Error(`Debug assert failed: ${result.toString()}`);\n\t\t\t\tonAssertionError(error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t});\n}\n\nlet debugAssertsEnabled = true;\n\n/**\n * Enables {@link debugAssert} validation.\n * @remarks\n * Throws if debugAsserts have been optimized out.\n *\n * Disabling debugAsserts has two main use cases:\n *\n * 1. Testing that the code behaves correctly in a more production like configuration.\n * 2. Reducing performance overhead.\n *\n * Disabling debugAsserts does not make everything production like: see {@link emulateProductionBuild} for a way to disable more non-production code.\n *\n * @returns The previous state of debugAsserts.\n * @internal\n */\nexport function configureDebugAsserts(enabled: boolean): boolean {\n\tassert(\n\t\tnonProductionConditionalsIncluded(),\n\t\t0xab1 /* Debug asserts cannot be configured since they have been optimized out. */,\n\t);\n\tconst old = debugAssertsEnabled;\n\tdebugAssertsEnabled = enabled;\n\treturn old;\n}\n\n/**\n * Checks if non-production conditional code like {@link debugAssert} is included in this build.\n * @remarks\n * Such code can be optimized out by bundlers or by {@link emulateProductionBuild}: this checks if that has occurred.\n *\n * The non-production used by this library is annotated with `__PURE__` and `#__NO_SIDE_EFFECTS__` and has no return value and thus is removed by bundlers when optimizing based on these annotations.\n * Typically this means that such code is removed in production builds.\n * More details on these annotations can be found at {@link https://github.com/javascript-compiler-hints/compiler-notations-spec/tree/main}.\n * @privateRemarks\n * See {@link skipInProductionInner}.\n * @internal\n */\nexport function nonProductionConditionalsIncluded(): boolean {\n\tlet included = false;\n\tskipInProduction(() => {\n\t\tincluded = true;\n\t});\n\treturn included;\n}\n\n/**\n * Overrides the behavior code which optimizes out non-production conditional code like {@link debugAssert} and {@link nonProductionConditionalsIncluded}.\n *\n * Can be called multiple times. Will emulate production builds if called with `true` more times than `false`.\n * Emulation of production builds is disabled when enabled and disabled counts match (including at 0, by default).\n * It is an error to disable this more than it was enabled.\n *\n * @remarks\n * This is intended for testing that the code behaves correctly in production configurations.\n * Since tools like {@link debugAssert} typically add additional validation to help catch more bugs, tests should generally be run with such checks enabled (and thus emulateProductionBuild in its default disabled state).\n * However it is possible that some debugAsserts could accidentally change behavior and hide a bug.\n * This function provides a way to globally disable the debugAsserts so it is possible to run test suites in a production like mode without having to do a production bundling of them.\n *\n * To avoid introducing additional risk that code does production-specific logic using this setting, the actual setting is not exposed.\n * The intended use is that a pipeline could enable this before running the test suite (for example based on a CLI flag).\n * Such a run may have to also use some filtering to skip any tests which explicity check development only tooling, possibly via {@link nonProductionConditionalsIncluded} or some other mechanism like a test tag.\n *\n * @privateRemarks\n * See {@link skipInProduction}.\n *\n * This design, with a counter, was picked so that it's always safe for some scope to opt in when trying to test production behavior,\n * and it should be basically impossible to accidentally fail to test the production mode when trying to.\n * Some tests or test suites may want to run in production mode and they can use this API to opt in (via before and after hooks for example).\n * Additionally something might want to opt into production mode at some other level (for example test running the entire test suite again with production mode enabled).\n * In such setups, it's important that tests which were explicitly opting in don't accidentally disable production mode for the rest of the run when ending if something higher level enabled it.\n *\n * The approach taken with `configureDebugAsserts` is a bit more flexible, allowing both opt in and opt out, but also more error prone.\n * This API, `emulateProductionBuild` provides a more restrictive but less error prone option targeted at being a final defense for detecting cases where production mode causes issues.\n * It catches some cases `configureDebugAsserts` can't, like dependency on side effects of failing asserts debug message callback.\n * @internal\n */\nexport function emulateProductionBuild(enable = true): void {\n\temulateProductionBuildCount += enable ? 1 : -1;\n\tassert(\n\t\temulateProductionBuildCount >= 0,\n\t\t0xc70 /* emulateProductionBuild disabled more than it was enabled */,\n\t);\n}\n\nlet emulateProductionBuildCount = 0;\n\n/**\n * {@link skipInProductionInner}, except can be disabled by {@link emulateProductionBuild}.\n */\nfunction skipInProduction(conditional: () => void): void {\n\tskipInProductionInner(() => {\n\t\tif (emulateProductionBuildCount === 0) conditional();\n\t});\n}\n\n/**\n * Run `conditional` only in debug/development (non optimized/minified) builds, but optimize it out of production builds.\n *\n * @param conditional - This function will only be run in some configurations so it should be pure (at least in production scenarios).\n * It can be used to interact with debug only functionality that is also removed in production builds, or to do validation/testing/debugging that can be assumed to be sideeffect free in production where it might be removed.\n * @remarks\n * Great care must be taken when using this to ensure that bugs are not introduced which only occur when `conditional` is not run.\n * One way to do this is to provide an alternative way to disable the effects of `conditional` in development builds so both configurations can be tested:\n * {@link debugAssert} uses this pattern.\n *\n * @privateRemarks\n * Since this function has no built in option for toggling it in development for testing, it is not exported and is only used as a building block for other testable options.\n * There are some additional details about syntax and bundler support in https://github.com/javascript-compiler-hints/compiler-notations-spec/tree/main .\n * This code uses both NO_SIDE_EFFECTS and PURE to maximize compatibility: for any bundler supporting both they are redundant.\n */\n// Using the exact syntax from https://github.com/javascript-compiler-hints/compiler-notations-spec/blob/main/no-side-effects-notation-spec.md to maximize compatibility with tree-shaking tools.\n// eslint-disable-next-line spaced-comment\n/*#__NO_SIDE_EFFECTS__*/\nfunction skipInProductionInner(conditional: () => void): void {\n\t// Here __PURE__ annotation is used to indicate that is is safe to optimize out this call.\n\t// This is valid since the contract for this function is that \"conditional\" should be side effect free if it were run in production scenarios\n\t// See https://webpack.js.org/guides/tree-shaking/#mark-a-function-call-as-side-effect-free for documentation on this annotation.\n\n\t// Using the exact syntax from https://webpack.js.org/guides/tree-shaking/#mark-a-function-call-as-side-effect-free to maximize compatibility with tree-shaking tools.\n\t// eslint-disable-next-line spaced-comment\n\t/*#__PURE__*/ condit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,KAAK,EAGjC,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GAC/E,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC;IAMV,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC;YAK/D,UAAU;CAOxB"}
|
package/lib/lazy.js
CHANGED
|
@@ -71,6 +71,7 @@ export class LazyPromise {
|
|
|
71
71
|
return this.getPromise().finally(...arguments);
|
|
72
72
|
}
|
|
73
73
|
async getPromise() {
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if result is a falsy value
|
|
74
75
|
if (this.result === undefined) {
|
|
75
76
|
this.result = this.execute();
|
|
76
77
|
}
|
package/lib/lazy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.js","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,OAAO,IAAI;IAGhB;;;OAGG;IACH,YAAoC,cAAuB;QAAvB,mBAAc,GAAd,cAAc,CAAS;QALnD,eAAU,GAAY,KAAK,CAAC;IAK0B,CAAC;IAE/D;;OAEG;IACH,IAAW,SAAS;QACnB,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACf,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QACrC,CAAC;QACD,oEAAoE;QACpE,OAAO,IAAI,CAAC,MAAO,CAAC;IACrB,CAAC;CACD;AAED;;;;;;GAMG;AACH,MAAM,OAAO,WAAW;IACvB,2EAA2E;IAC3E,IAAW,CAAC,MAAM,CAAC,WAAW,CAAC;QAC9B,OAAO,sBAAsB,CAAC;IAC/B,CAAC;IAID,YAAoC,OAAyB;QAAzB,YAAO,GAAP,OAAO,CAAkB;IAAG,CAAC;IAEjE,+CAA+C;IACxC,KAAK,CAAC,IAAI;IAChB,kDAAkD;IAClD,WAAiF;IACjF,6CAA6C;IAC7C,sFAAsF;IACtF,UAAmF;QAEnF,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,CAAqB,GAAG,SAAS,CAAC,CAAC;IACjE,CAAC;IAEM,KAAK,CAAC,KAAK;IACjB,6CAA6C;IAC7C,sFAAsF;IACtF,UAAiF;QAEjF,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,KAAK,CAAU,GAAG,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,kDAAkD;IAC3C,KAAK,CAAC,OAAO,CAAC,SAA2C;QAC/D,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;IAChD,CAAC;IAEO,KAAK,CAAC,UAAU;QACvB,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC9B,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Helper class for lazy initialized values. Ensures the value is only generated once, and remain immutable.\n * @internal\n */\nexport class Lazy<T> {\n\tprivate _value: T | undefined;\n\tprivate _evaluated: boolean = false;\n\t/**\n\t * Instantiates an instance of Lazy<T>.\n\t * @param valueGenerator - The function that will generate the value when value is accessed the first time.\n\t */\n\tpublic constructor(private readonly valueGenerator: () => T) {}\n\n\t/**\n\t * Return true if the value as been generated, otherwise false.\n\t */\n\tpublic get evaluated(): boolean {\n\t\treturn this._evaluated;\n\t}\n\n\t/**\n\t * Get the value. If this is the first call the value will be generated.\n\t */\n\tpublic get value(): T {\n\t\tif (!this._evaluated) {\n\t\t\tthis._evaluated = true;\n\t\t\tthis._value = this.valueGenerator();\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this._value!;\n\t}\n}\n\n/**\n * A lazy evaluated promise. The execute function is delayed until\n * the promise is used, e.g. await, then, catch ...\n * The execute function is only called once.\n * All calls are then proxied to the promise returned by the execute method.\n * @legacy @beta\n */\nexport class LazyPromise<T> implements Promise<T> {\n\t// eslint-disable-next-line @typescript-eslint/class-literal-property-style\n\tpublic get [Symbol.toStringTag](): string {\n\t\treturn \"[object LazyPromise]\";\n\t}\n\n\tprivate result: Promise<T> | undefined;\n\n\tpublic constructor(private readonly execute: () => Promise<T>) {}\n\n\t// eslint-disable-next-line unicorn/no-thenable\n\tpublic async then<TResult1 = T, TResult2 = never>(\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tonfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n\t\t// TODO: Use `unknown` instead (API breaking)\n\t\t// eslint-disable-next-line @rushstack/no-new-null, @typescript-eslint/no-explicit-any\n\t\tonrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n\t): Promise<TResult1 | TResult2> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().then<TResult1, TResult2>(...arguments);\n\t}\n\n\tpublic async catch<TResult = never>(\n\t\t// TODO: Use `unknown` instead (API breaking)\n\t\t// eslint-disable-next-line @rushstack/no-new-null, @typescript-eslint/no-explicit-any\n\t\tonrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined,\n\t): Promise<T | TResult> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().catch<TResult>(...arguments);\n\t}\n\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async finally(onfinally?: (() => void) | null | undefined): Promise<T> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().finally(...arguments);\n\t}\n\n\tprivate async getPromise(): Promise<T> {\n\t\tif (this.result === undefined) {\n\t\t\tthis.result = this.execute();\n\t\t}\n\t\treturn this.result;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lazy.js","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,OAAO,IAAI;IAGhB;;;OAGG;IACH,YAAoC,cAAuB;QAAvB,mBAAc,GAAd,cAAc,CAAS;QALnD,eAAU,GAAY,KAAK,CAAC;IAK0B,CAAC;IAE/D;;OAEG;IACH,IAAW,SAAS;QACnB,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACf,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QACrC,CAAC;QACD,oEAAoE;QACpE,OAAO,IAAI,CAAC,MAAO,CAAC;IACrB,CAAC;CACD;AAED;;;;;;GAMG;AACH,MAAM,OAAO,WAAW;IACvB,2EAA2E;IAC3E,IAAW,CAAC,MAAM,CAAC,WAAW,CAAC;QAC9B,OAAO,sBAAsB,CAAC;IAC/B,CAAC;IAID,YAAoC,OAAyB;QAAzB,YAAO,GAAP,OAAO,CAAkB;IAAG,CAAC;IAEjE,+CAA+C;IACxC,KAAK,CAAC,IAAI;IAChB,kDAAkD;IAClD,WAAiF;IACjF,6CAA6C;IAC7C,sFAAsF;IACtF,UAAmF;QAEnF,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,CAAqB,GAAG,SAAS,CAAC,CAAC;IACjE,CAAC;IAEM,KAAK,CAAC,KAAK;IACjB,6CAA6C;IAC7C,sFAAsF;IACtF,UAAiF;QAEjF,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,KAAK,CAAU,GAAG,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,kDAAkD;IAC3C,KAAK,CAAC,OAAO,CAAC,SAA2C;QAC/D,8CAA8C;QAC9C,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;IAChD,CAAC;IAEO,KAAK,CAAC,UAAU;QACvB,sIAAsI;QACtI,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC9B,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Helper class for lazy initialized values. Ensures the value is only generated once, and remain immutable.\n * @internal\n */\nexport class Lazy<T> {\n\tprivate _value: T | undefined;\n\tprivate _evaluated: boolean = false;\n\t/**\n\t * Instantiates an instance of Lazy<T>.\n\t * @param valueGenerator - The function that will generate the value when value is accessed the first time.\n\t */\n\tpublic constructor(private readonly valueGenerator: () => T) {}\n\n\t/**\n\t * Return true if the value as been generated, otherwise false.\n\t */\n\tpublic get evaluated(): boolean {\n\t\treturn this._evaluated;\n\t}\n\n\t/**\n\t * Get the value. If this is the first call the value will be generated.\n\t */\n\tpublic get value(): T {\n\t\tif (!this._evaluated) {\n\t\t\tthis._evaluated = true;\n\t\t\tthis._value = this.valueGenerator();\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this._value!;\n\t}\n}\n\n/**\n * A lazy evaluated promise. The execute function is delayed until\n * the promise is used, e.g. await, then, catch ...\n * The execute function is only called once.\n * All calls are then proxied to the promise returned by the execute method.\n * @legacy @beta\n */\nexport class LazyPromise<T> implements Promise<T> {\n\t// eslint-disable-next-line @typescript-eslint/class-literal-property-style\n\tpublic get [Symbol.toStringTag](): string {\n\t\treturn \"[object LazyPromise]\";\n\t}\n\n\tprivate result: Promise<T> | undefined;\n\n\tpublic constructor(private readonly execute: () => Promise<T>) {}\n\n\t// eslint-disable-next-line unicorn/no-thenable\n\tpublic async then<TResult1 = T, TResult2 = never>(\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tonfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n\t\t// TODO: Use `unknown` instead (API breaking)\n\t\t// eslint-disable-next-line @rushstack/no-new-null, @typescript-eslint/no-explicit-any\n\t\tonrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n\t): Promise<TResult1 | TResult2> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().then<TResult1, TResult2>(...arguments);\n\t}\n\n\tpublic async catch<TResult = never>(\n\t\t// TODO: Use `unknown` instead (API breaking)\n\t\t// eslint-disable-next-line @rushstack/no-new-null, @typescript-eslint/no-explicit-any\n\t\tonrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined,\n\t): Promise<T | TResult> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().catch<TResult>(...arguments);\n\t}\n\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async finally(onfinally?: (() => void) | null | undefined): Promise<T> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().finally(...arguments);\n\t}\n\n\tprivate async getPromise(): Promise<T> {\n\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if result is a falsy value\n\t\tif (this.result === undefined) {\n\t\t\tthis.result = this.execute();\n\t\t}\n\t\treturn this.result;\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/core-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.81.0-374083",
|
|
4
4
|
"description": "Not intended for use outside the Fluid client repo.",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -69,13 +69,13 @@
|
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
71
71
|
"@biomejs/biome": "~1.9.3",
|
|
72
|
-
"@fluid-internal/mocha-test-setup": "
|
|
73
|
-
"@fluid-tools/benchmark": "^0.
|
|
74
|
-
"@fluid-tools/build-cli": "^0.
|
|
72
|
+
"@fluid-internal/mocha-test-setup": "2.81.0-374083",
|
|
73
|
+
"@fluid-tools/benchmark": "^0.52.0",
|
|
74
|
+
"@fluid-tools/build-cli": "^0.63.0",
|
|
75
75
|
"@fluidframework/build-common": "^2.0.3",
|
|
76
|
-
"@fluidframework/build-tools": "^0.
|
|
77
|
-
"@fluidframework/core-utils-previous": "npm:@fluidframework/core-utils@2.
|
|
78
|
-
"@fluidframework/eslint-config-fluid": "
|
|
76
|
+
"@fluidframework/build-tools": "^0.63.0",
|
|
77
|
+
"@fluidframework/core-utils-previous": "npm:@fluidframework/core-utils@2.80.0",
|
|
78
|
+
"@fluidframework/eslint-config-fluid": "2.81.0-374083",
|
|
79
79
|
"@microsoft/api-extractor": "7.52.11",
|
|
80
80
|
"@types/mocha": "^10.0.10",
|
|
81
81
|
"@types/node": "^18.19.0",
|
package/src/assert.ts
CHANGED
|
@@ -36,10 +36,28 @@ export function assert(
|
|
|
36
36
|
debugMessageBuilder?: () => string,
|
|
37
37
|
): asserts condition {
|
|
38
38
|
if (!condition) {
|
|
39
|
-
|
|
39
|
+
failPrivate(message, debugMessageBuilder);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* {@link fail}'s implementation, but extracted to avoid assert tagging trying to tag the use of it in `assert`.
|
|
45
|
+
*/
|
|
46
|
+
function failPrivate(message: string | number, debugMessageBuilder?: () => string): never {
|
|
47
|
+
let messageString =
|
|
48
|
+
typeof message === "number" ? `0x${message.toString(16).padStart(3, "0")}` : message;
|
|
49
|
+
skipInProduction(() => {
|
|
50
|
+
if (debugMessageBuilder !== undefined) {
|
|
51
|
+
messageString = `${messageString}\nDebug Message: ${debugMessageBuilder()}`;
|
|
52
|
+
}
|
|
53
|
+
// Using console.log instead of console.error or console.warn since the latter two may break downstream users.
|
|
54
|
+
console.log(`Bug in Fluid Framework: Failed Assertion: ${messageString}`);
|
|
55
|
+
});
|
|
56
|
+
const error = new Error(messageString);
|
|
57
|
+
onAssertionError(error);
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
|
|
43
61
|
/**
|
|
44
62
|
* Throw an error with a constant message.
|
|
45
63
|
* @remarks
|
|
@@ -57,18 +75,7 @@ export function assert(
|
|
|
57
75
|
* @internal
|
|
58
76
|
*/
|
|
59
77
|
export function fail(message: string | number, debugMessageBuilder?: () => string): never {
|
|
60
|
-
|
|
61
|
-
typeof message === "number" ? `0x${message.toString(16).padStart(3, "0")}` : message;
|
|
62
|
-
skipInProduction(() => {
|
|
63
|
-
if (debugMessageBuilder !== undefined) {
|
|
64
|
-
messageString = `${messageString}\nDebug Message: ${debugMessageBuilder()}`;
|
|
65
|
-
}
|
|
66
|
-
// Using console.log instead of console.error or console.warn since the latter two may break downstream users.
|
|
67
|
-
console.log(`Bug in Fluid Framework: Failed Assertion: ${messageString}`);
|
|
68
|
-
});
|
|
69
|
-
const error = new Error(messageString);
|
|
70
|
-
onAssertionError(error);
|
|
71
|
-
throw error;
|
|
78
|
+
failPrivate(message, debugMessageBuilder);
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
function onAssertionError(error: Error): void {
|
package/src/lazy.ts
CHANGED
|
@@ -81,6 +81,7 @@ export class LazyPromise<T> implements Promise<T> {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
private async getPromise(): Promise<T> {
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- using ??= could change behavior if result is a falsy value
|
|
84
85
|
if (this.result === undefined) {
|
|
85
86
|
this.result = this.execute();
|
|
86
87
|
}
|
package/.eslintrc.cjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
module.exports = {
|
|
7
|
-
extends: [require.resolve("@fluidframework/eslint-config-fluid/strict"), "prettier"],
|
|
8
|
-
|
|
9
|
-
parserOptions: {
|
|
10
|
-
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
|
|
11
|
-
},
|
|
12
|
-
rules: {
|
|
13
|
-
// This has been disabled in the next eslint-config-fluid.
|
|
14
|
-
// Once the dependency here has been updated, this override can be removed.
|
|
15
|
-
"unicorn/numeric-separators-style": "off",
|
|
16
|
-
},
|
|
17
|
-
overrides: [
|
|
18
|
-
{
|
|
19
|
-
// Rules only for test files
|
|
20
|
-
files: ["*.spec.ts", "*.test.ts", "src/test/**"],
|
|
21
|
-
rules: {
|
|
22
|
-
// Test files are run in node only so additional node libraries can be used.
|
|
23
|
-
"import-x/no-nodejs-modules": ["error", { allow: ["node:assert", "node:process"] }],
|
|
24
|
-
|
|
25
|
-
// Does not work well with describe/it block scoping
|
|
26
|
-
"unicorn/consistent-function-scoping": "off",
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
};
|