@fluidframework/odsp-driver 2.20.0 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -0
  3. package/dist/fetch.d.ts +5 -1
  4. package/dist/fetch.d.ts.map +1 -1
  5. package/dist/fetch.js +5 -9
  6. package/dist/fetch.js.map +1 -1
  7. package/dist/fetchSnapshot.d.ts +1 -1
  8. package/dist/fetchSnapshot.d.ts.map +1 -1
  9. package/dist/fetchSnapshot.js +8 -5
  10. package/dist/fetchSnapshot.js.map +1 -1
  11. package/dist/getFileLink.d.ts +1 -1
  12. package/dist/getFileLink.d.ts.map +1 -1
  13. package/dist/getFileLink.js +3 -3
  14. package/dist/getFileLink.js.map +1 -1
  15. package/dist/index.d.ts +0 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -3
  18. package/dist/index.js.map +1 -1
  19. package/dist/mockify.d.ts +60 -0
  20. package/dist/mockify.d.ts.map +1 -0
  21. package/dist/mockify.js +61 -0
  22. package/dist/mockify.js.map +1 -0
  23. package/dist/odspDelayLoadedDeltaStream.js +2 -2
  24. package/dist/odspDelayLoadedDeltaStream.js.map +1 -1
  25. package/dist/odspDocumentDeltaConnection.js +3 -3
  26. package/dist/odspDocumentDeltaConnection.js.map +1 -1
  27. package/dist/odspDocumentStorageManager.js +6 -6
  28. package/dist/odspDocumentStorageManager.js.map +1 -1
  29. package/dist/odspUtils.d.ts +3 -0
  30. package/dist/odspUtils.d.ts.map +1 -1
  31. package/dist/odspUtils.js +9 -9
  32. package/dist/odspUtils.js.map +1 -1
  33. package/dist/opsCaching.js +2 -2
  34. package/dist/opsCaching.js.map +1 -1
  35. package/dist/packageVersion.d.ts +1 -1
  36. package/dist/packageVersion.js +1 -1
  37. package/dist/packageVersion.js.map +1 -1
  38. package/dist/prefetchLatestSnapshot.js +1 -1
  39. package/dist/prefetchLatestSnapshot.js.map +1 -1
  40. package/dist/retryUtils.js +4 -4
  41. package/dist/retryUtils.js.map +1 -1
  42. package/dist/socketModule.d.ts +2 -1
  43. package/dist/socketModule.d.ts.map +1 -1
  44. package/dist/socketModule.js +2 -3
  45. package/dist/socketModule.js.map +1 -1
  46. package/dist/vroom.d.ts +1 -1
  47. package/dist/vroom.d.ts.map +1 -1
  48. package/dist/vroom.js +3 -3
  49. package/dist/vroom.js.map +1 -1
  50. package/lib/fetch.d.ts +5 -1
  51. package/lib/fetch.d.ts.map +1 -1
  52. package/lib/fetch.js +5 -5
  53. package/lib/fetch.js.map +1 -1
  54. package/lib/fetchSnapshot.d.ts +1 -1
  55. package/lib/fetchSnapshot.d.ts.map +1 -1
  56. package/lib/fetchSnapshot.js +8 -4
  57. package/lib/fetchSnapshot.js.map +1 -1
  58. package/lib/getFileLink.d.ts +1 -1
  59. package/lib/getFileLink.d.ts.map +1 -1
  60. package/lib/getFileLink.js +3 -2
  61. package/lib/getFileLink.js.map +1 -1
  62. package/lib/index.d.ts +0 -1
  63. package/lib/index.d.ts.map +1 -1
  64. package/lib/index.js +0 -1
  65. package/lib/index.js.map +1 -1
  66. package/lib/mockify.d.ts +60 -0
  67. package/lib/mockify.d.ts.map +1 -0
  68. package/lib/mockify.js +57 -0
  69. package/lib/mockify.js.map +1 -0
  70. package/lib/odspDelayLoadedDeltaStream.js +3 -3
  71. package/lib/odspDelayLoadedDeltaStream.js.map +1 -1
  72. package/lib/odspDocumentDeltaConnection.js +4 -4
  73. package/lib/odspDocumentDeltaConnection.js.map +1 -1
  74. package/lib/odspDocumentStorageManager.js +7 -7
  75. package/lib/odspDocumentStorageManager.js.map +1 -1
  76. package/lib/odspUtils.d.ts +3 -0
  77. package/lib/odspUtils.d.ts.map +1 -1
  78. package/lib/odspUtils.js +9 -9
  79. package/lib/odspUtils.js.map +1 -1
  80. package/lib/opsCaching.js +3 -3
  81. package/lib/opsCaching.js.map +1 -1
  82. package/lib/packageVersion.d.ts +1 -1
  83. package/lib/packageVersion.js +1 -1
  84. package/lib/packageVersion.js.map +1 -1
  85. package/lib/prefetchLatestSnapshot.js +2 -2
  86. package/lib/prefetchLatestSnapshot.js.map +1 -1
  87. package/lib/retryUtils.js +5 -5
  88. package/lib/retryUtils.js.map +1 -1
  89. package/lib/socketModule.d.ts +2 -1
  90. package/lib/socketModule.d.ts.map +1 -1
  91. package/lib/socketModule.js +2 -3
  92. package/lib/socketModule.js.map +1 -1
  93. package/lib/vroom.d.ts +1 -1
  94. package/lib/vroom.d.ts.map +1 -1
  95. package/lib/vroom.js +3 -2
  96. package/lib/vroom.js.map +1 -1
  97. package/package.json +17 -19
  98. package/src/fetch.ts +5 -11
  99. package/src/fetchSnapshot.ts +79 -73
  100. package/src/getFileLink.ts +56 -53
  101. package/src/index.ts +0 -1
  102. package/src/mockify.ts +67 -0
  103. package/src/odspDelayLoadedDeltaStream.ts +3 -3
  104. package/src/odspDocumentDeltaConnection.ts +4 -4
  105. package/src/odspDocumentStorageManager.ts +7 -7
  106. package/src/odspUtils.ts +10 -10
  107. package/src/opsCaching.ts +3 -3
  108. package/src/packageVersion.ts +1 -1
  109. package/src/prefetchLatestSnapshot.ts +2 -2
  110. package/src/retryUtils.ts +5 -5
  111. package/src/socketModule.ts +3 -3
  112. package/src/vroom.ts +92 -89
  113. package/dist/odspDocumentServiceFactoryWithCodeSplit.d.ts +0 -16
  114. package/dist/odspDocumentServiceFactoryWithCodeSplit.d.ts.map +0 -1
  115. package/dist/odspDocumentServiceFactoryWithCodeSplit.js +0 -20
  116. package/dist/odspDocumentServiceFactoryWithCodeSplit.js.map +0 -1
  117. package/lib/odspDocumentServiceFactoryWithCodeSplit.d.ts +0 -16
  118. package/lib/odspDocumentServiceFactoryWithCodeSplit.d.ts.map +0 -1
  119. package/lib/odspDocumentServiceFactoryWithCodeSplit.js +0 -16
  120. package/lib/odspDocumentServiceFactoryWithCodeSplit.js.map +0 -1
  121. package/src/odspDocumentServiceFactoryWithCodeSplit.ts +0 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copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performance } from \"@fluid-internal/client-utils\";\nimport { ITelemetryLoggerExt } from \"@fluidframework/telemetry-utils/internal\";\n\n// ISequencedDocumentMessage\nexport interface IMessage {\n\tsequenceNumber: number;\n}\n\nexport type CacheEntry = (IMessage | undefined)[];\n\nexport interface IBatch {\n\tremainingSlots: number;\n\tbatchData: CacheEntry;\n\t/**\n\t * Tells if this batch is dirty, i.e. it contains ops that were not flushed to cache\n\t */\n\tdirty: boolean;\n}\n\nexport interface ICache {\n\twrite(batchNumber: string, data: string): Promise<void>;\n\tread(batchNumber: string): Promise<string | undefined>;\n\tremove(): void;\n}\n\nexport class OpsCache {\n\tprivate readonly batches: Map<number, null | IBatch> = new Map();\n\tprivate timer: ReturnType<typeof setTimeout> | undefined;\n\n\tconstructor(\n\t\tstartingSequenceNumber: number,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly cache: ICache,\n\t\tprivate readonly batchSize: number,\n\t\tprivate readonly timerGranularity: number,\n\t\tprivate totalOpsToCache: number,\n\t) {\n\t\t/**\n\t\t * Initial batch is a special case because it will never be full - all ops prior (inclusive) to\n\t\t * `startingSequenceNumber` are never going to show up (undefined)\n\t\t */\n\t\tconst remainingSlots =\n\t\t\tthis.batchSize - this.getPositionInBatchArray(startingSequenceNumber) - 1;\n\t\tif (remainingSlots !== 0) {\n\t\t\tthis.batches.set(this.getBatchNumber(startingSequenceNumber), {\n\t\t\t\tremainingSlots,\n\t\t\t\tbatchData: this.initializeNewBatchDataArray(),\n\t\t\t\tdirty: false,\n\t\t\t});\n\t\t}\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.batches.clear();\n\t\tif (this.timer !== undefined) {\n\t\t\tclearTimeout(this.timer);\n\t\t\tthis.timer = undefined;\n\t\t}\n\t}\n\n\tpublic flushOps(): void {\n\t\tfor (const [key, value] of this.batches) {\n\t\t\t// Don't flush if the batch has no ops, already flushed or has empty slots at both beginning and end.\n\t\t\tif (\n\t\t\t\tvalue === null ||\n\t\t\t\t!value.dirty ||\n\t\t\t\tvalue.batchData.length === 0 ||\n\t\t\t\t(value.batchData[0] === undefined &&\n\t\t\t\t\tvalue.batchData[value.batchData.length - 1] === undefined)\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvalue.dirty = false;\n\t\t\tthis.write(key, value);\n\t\t}\n\t}\n\n\tpublic addOps(ops: IMessage[]): void {\n\t\tif (this.totalOpsToCache <= 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const op of ops) {\n\t\t\tconst batchNumber = this.getBatchNumber(op.sequenceNumber);\n\t\t\tconst positionInBatch = this.getPositionInBatchArray(op.sequenceNumber);\n\n\t\t\tlet currentBatch = this.batches.get(batchNumber);\n\n\t\t\tif (currentBatch === undefined) {\n\t\t\t\tcurrentBatch = {\n\t\t\t\t\tremainingSlots: this.batchSize - 1,\n\t\t\t\t\tbatchData: this.initializeNewBatchDataArray(),\n\t\t\t\t\tdirty: true,\n\t\t\t\t};\n\t\t\t\tcurrentBatch.batchData[positionInBatch] = op;\n\t\t\t\tthis.batches.set(batchNumber, currentBatch);\n\t\t\t} else if (\n\t\t\t\tcurrentBatch !== null &&\n\t\t\t\tcurrentBatch.batchData[positionInBatch] === undefined\n\t\t\t) {\n\t\t\t\tcurrentBatch.batchData[positionInBatch] = op;\n\t\t\t\tcurrentBatch.remainingSlots--;\n\t\t\t\tcurrentBatch.dirty = true;\n\t\t\t} else {\n\t\t\t\t// Either batch was flushed or this op was already there - nothing to do!\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (currentBatch.remainingSlots === 0) {\n\t\t\t\t// batch is full, flush to cache\n\t\t\t\tthis.write(batchNumber, currentBatch);\n\t\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\t\tthis.batches.set(batchNumber, null);\n\t\t\t} else {\n\t\t\t\tthis.scheduleTimer();\n\t\t\t}\n\n\t\t\tthis.totalOpsToCache--;\n\t\t\tif (this.totalOpsToCache === 0) {\n\t\t\t\tthis.logger.sendPerformanceEvent({ eventName: \"CacheOpsLimitHit\" });\n\t\t\t\tthis.cache.remove();\n\t\t\t\tthis.dispose();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves ops from cache\n\t * @param from - inclusive\n\t * @param to - exclusive\n\t * @returns ops retrieved\n\t */\n\tprivate async getCore(from: number, to?: number): Promise<IMessage[]> {\n\t\tconst messages: IMessage[] = [];\n\t\tlet batchNumber = this.getBatchNumber(from);\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\tconst res = await this.cache.read(`${this.batchSize}_${batchNumber}`);\n\t\t\tif (res === undefined) {\n\t\t\t\treturn messages;\n\t\t\t}\n\t\t\tconst result: CacheEntry = JSON.parse(res) as CacheEntry;\n\t\t\tconst prevMessagesLength = messages.length;\n\t\t\tfor (const op of result) {\n\t\t\t\t// Note that we write out undefined, but due to JSON.stringify, it turns into null!\n\t\t\t\tif (op) {\n\t\t\t\t\tif (to !== undefined && op.sequenceNumber >= to) {\n\t\t\t\t\t\treturn messages;\n\t\t\t\t\t}\n\t\t\t\t\tif (messages.length === 0) {\n\t\t\t\t\t\tif (op.sequenceNumber > from) {\n\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t} else if (op.sequenceNumber < from) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tmessages.push(op);\n\t\t\t\t} else if (messages.length > 0) {\n\t\t\t\t\t// If there is any gap, return the messages till now.\n\t\t\t\t\treturn messages;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If we didn't get any op from this batch, then return messages till now. As it tells us that,\n\t\t\t// either the first message \"from\" is not present in cache or a gap will occur from 1 batch to next.\n\t\t\tif (prevMessagesLength === messages.length) {\n\t\t\t\treturn messages;\n\t\t\t}\n\t\t\tbatchNumber++;\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves ops from cache\n\t * @param from - inclusive\n\t * @param to - exclusive\n\t * @returns ops retrieved\n\t */\n\tpublic async get(from: number, to?: number): Promise<IMessage[]> {\n\t\tconst start = performance.now();\n\n\t\tconst messages = await this.getCore(from, to);\n\n\t\tconst duration = performance.now() - start;\n\t\tif (messages.length > 0 || duration > 1000) {\n\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\teventName: \"CacheOpsUsed\",\n\t\t\t\tfrom,\n\t\t\t\tto,\n\t\t\t\tlength: messages.length,\n\t\t\t\tduration,\n\t\t\t});\n\t\t}\n\t\treturn messages;\n\t}\n\n\tprotected write(batchNumber: number, payload: IBatch): void {\n\t\t// Errors are caught and logged by PersistedCacheWithErrorHandling that sits\n\t\t// in the adapter chain of cache adapters\n\t\tthis.cache\n\t\t\t.write(`${this.batchSize}_${batchNumber}`, JSON.stringify(payload.batchData))\n\t\t\t.catch(() => {\n\t\t\t\tthis.totalOpsToCache = 0;\n\t\t\t});\n\t}\n\n\tprotected scheduleTimer(): void {\n\t\tif (!this.timer && this.timerGranularity > 0) {\n\t\t\tthis.timer = setTimeout(() => {\n\t\t\t\tthis.timer = undefined;\n\t\t\t\tthis.flushOps();\n\t\t\t}, this.timerGranularity);\n\t\t}\n\t}\n\n\tprivate getBatchNumber(sequenceNumber: number): number {\n\t\treturn Math.floor(sequenceNumber / this.batchSize);\n\t}\n\n\tprivate getPositionInBatchArray(sequenceNumber: number): number {\n\t\treturn sequenceNumber % this.batchSize;\n\t}\n\n\tprivate initializeNewBatchDataArray(): IMessage[] {\n\t\tconst tempArray: IMessage[] = [];\n\t\ttempArray.length = this.batchSize; // fill with empty, undefined elements\n\t\treturn tempArray;\n\t}\n}\n"]}
1
+ {"version":3,"file":"opsCaching.js","sourceRoot":"","sources":["../src/opsCaching.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA8D;AAyB9D,MAAa,QAAQ;IAIpB,YACC,sBAA8B,EACb,MAA2B,E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,CAAC;IACjB,CAAC;IAES,KAAK,CAAC,WAAmB,EAAE,OAAe;QACnD,4EAA4E;QAC5E,yCAAyC;QACzC,IAAI,CAAC,KAAK;aACR,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,IAAI,WAAW,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;aAC5E,KAAK,CAAC,GAAG,EAAE;YACX,IAAI,CAAC,eAAe,GAAG,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IAES,aAAa;QACtB,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,gBAAgB,GAAG,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC5B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;gBACvB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACjB,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC3B,CAAC;IACF,CAAC;IAEO,cAAc,CAAC,cAAsB;QAC5C,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;IAEO,uBAAuB,CAAC,cAAsB;QACrD,OAAO,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC;IACxC,CAAC;IAEO,2BAA2B;QAClC,MAAM,SAAS,GAAe,EAAE,CAAC;QACjC,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,sCAAsC;QACzE,OAAO,SAAS,CAAC;IAClB,CAAC;CACD;AA5MD,4BA4MC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performanceNow } from \"@fluid-internal/client-utils\";\nimport { ITelemetryLoggerExt } from \"@fluidframework/telemetry-utils/internal\";\n\n// ISequencedDocumentMessage\nexport interface IMessage {\n\tsequenceNumber: number;\n}\n\nexport type CacheEntry = (IMessage | undefined)[];\n\nexport interface IBatch {\n\tremainingSlots: number;\n\tbatchData: CacheEntry;\n\t/**\n\t * Tells if this batch is dirty, i.e. it contains ops that were not flushed to cache\n\t */\n\tdirty: boolean;\n}\n\nexport interface ICache {\n\twrite(batchNumber: string, data: string): Promise<void>;\n\tread(batchNumber: string): Promise<string | undefined>;\n\tremove(): void;\n}\n\nexport class OpsCache {\n\tprivate readonly batches: Map<number, null | IBatch> = new Map();\n\tprivate timer: ReturnType<typeof setTimeout> | undefined;\n\n\tconstructor(\n\t\tstartingSequenceNumber: number,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly cache: ICache,\n\t\tprivate readonly batchSize: number,\n\t\tprivate readonly timerGranularity: number,\n\t\tprivate totalOpsToCache: number,\n\t) {\n\t\t/**\n\t\t * Initial batch is a special case because it will never be full - all ops prior (inclusive) to\n\t\t * `startingSequenceNumber` are never going to show up (undefined)\n\t\t */\n\t\tconst remainingSlots =\n\t\t\tthis.batchSize - this.getPositionInBatchArray(startingSequenceNumber) - 1;\n\t\tif (remainingSlots !== 0) {\n\t\t\tthis.batches.set(this.getBatchNumber(startingSequenceNumber), {\n\t\t\t\tremainingSlots,\n\t\t\t\tbatchData: this.initializeNewBatchDataArray(),\n\t\t\t\tdirty: false,\n\t\t\t});\n\t\t}\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.batches.clear();\n\t\tif (this.timer !== undefined) {\n\t\t\tclearTimeout(this.timer);\n\t\t\tthis.timer = undefined;\n\t\t}\n\t}\n\n\tpublic flushOps(): void {\n\t\tfor (const [key, value] of this.batches) {\n\t\t\t// Don't flush if the batch has no ops, already flushed or has empty slots at both beginning and end.\n\t\t\tif (\n\t\t\t\tvalue === null ||\n\t\t\t\t!value.dirty ||\n\t\t\t\tvalue.batchData.length === 0 ||\n\t\t\t\t(value.batchData[0] === undefined &&\n\t\t\t\t\tvalue.batchData[value.batchData.length - 1] === undefined)\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvalue.dirty = false;\n\t\t\tthis.write(key, value);\n\t\t}\n\t}\n\n\tpublic addOps(ops: IMessage[]): void {\n\t\tif (this.totalOpsToCache <= 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const op of ops) {\n\t\t\tconst batchNumber = this.getBatchNumber(op.sequenceNumber);\n\t\t\tconst positionInBatch = this.getPositionInBatchArray(op.sequenceNumber);\n\n\t\t\tlet currentBatch = this.batches.get(batchNumber);\n\n\t\t\tif (currentBatch === undefined) {\n\t\t\t\tcurrentBatch = {\n\t\t\t\t\tremainingSlots: this.batchSize - 1,\n\t\t\t\t\tbatchData: this.initializeNewBatchDataArray(),\n\t\t\t\t\tdirty: true,\n\t\t\t\t};\n\t\t\t\tcurrentBatch.batchData[positionInBatch] = op;\n\t\t\t\tthis.batches.set(batchNumber, currentBatch);\n\t\t\t} else if (\n\t\t\t\tcurrentBatch !== null &&\n\t\t\t\tcurrentBatch.batchData[positionInBatch] === undefined\n\t\t\t) {\n\t\t\t\tcurrentBatch.batchData[positionInBatch] = op;\n\t\t\t\tcurrentBatch.remainingSlots--;\n\t\t\t\tcurrentBatch.dirty = true;\n\t\t\t} else {\n\t\t\t\t// Either batch was flushed or this op was already there - nothing to do!\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (currentBatch.remainingSlots === 0) {\n\t\t\t\t// batch is full, flush to cache\n\t\t\t\tthis.write(batchNumber, currentBatch);\n\t\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\t\tthis.batches.set(batchNumber, null);\n\t\t\t} else {\n\t\t\t\tthis.scheduleTimer();\n\t\t\t}\n\n\t\t\tthis.totalOpsToCache--;\n\t\t\tif (this.totalOpsToCache === 0) {\n\t\t\t\tthis.logger.sendPerformanceEvent({ eventName: \"CacheOpsLimitHit\" });\n\t\t\t\tthis.cache.remove();\n\t\t\t\tthis.dispose();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves ops from cache\n\t * @param from - inclusive\n\t * @param to - exclusive\n\t * @returns ops retrieved\n\t */\n\tprivate async getCore(from: number, to?: number): Promise<IMessage[]> {\n\t\tconst messages: IMessage[] = [];\n\t\tlet batchNumber = this.getBatchNumber(from);\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\tconst res = await this.cache.read(`${this.batchSize}_${batchNumber}`);\n\t\t\tif (res === undefined) {\n\t\t\t\treturn messages;\n\t\t\t}\n\t\t\tconst result: CacheEntry = JSON.parse(res) as CacheEntry;\n\t\t\tconst prevMessagesLength = messages.length;\n\t\t\tfor (const op of result) {\n\t\t\t\t// Note that we write out undefined, but due to JSON.stringify, it turns into null!\n\t\t\t\tif (op) {\n\t\t\t\t\tif (to !== undefined && op.sequenceNumber >= to) {\n\t\t\t\t\t\treturn messages;\n\t\t\t\t\t}\n\t\t\t\t\tif (messages.length === 0) {\n\t\t\t\t\t\tif (op.sequenceNumber > from) {\n\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t} else if (op.sequenceNumber < from) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tmessages.push(op);\n\t\t\t\t} else if (messages.length > 0) {\n\t\t\t\t\t// If there is any gap, return the messages till now.\n\t\t\t\t\treturn messages;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If we didn't get any op from this batch, then return messages till now. As it tells us that,\n\t\t\t// either the first message \"from\" is not present in cache or a gap will occur from 1 batch to next.\n\t\t\tif (prevMessagesLength === messages.length) {\n\t\t\t\treturn messages;\n\t\t\t}\n\t\t\tbatchNumber++;\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves ops from cache\n\t * @param from - inclusive\n\t * @param to - exclusive\n\t * @returns ops retrieved\n\t */\n\tpublic async get(from: number, to?: number): Promise<IMessage[]> {\n\t\tconst start = performanceNow();\n\n\t\tconst messages = await this.getCore(from, to);\n\n\t\tconst duration = performanceNow() - start;\n\t\tif (messages.length > 0 || duration > 1000) {\n\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\teventName: \"CacheOpsUsed\",\n\t\t\t\tfrom,\n\t\t\t\tto,\n\t\t\t\tlength: messages.length,\n\t\t\t\tduration,\n\t\t\t});\n\t\t}\n\t\treturn messages;\n\t}\n\n\tprotected write(batchNumber: number, payload: IBatch): void {\n\t\t// Errors are caught and logged by PersistedCacheWithErrorHandling that sits\n\t\t// in the adapter chain of cache adapters\n\t\tthis.cache\n\t\t\t.write(`${this.batchSize}_${batchNumber}`, JSON.stringify(payload.batchData))\n\t\t\t.catch(() => {\n\t\t\t\tthis.totalOpsToCache = 0;\n\t\t\t});\n\t}\n\n\tprotected scheduleTimer(): void {\n\t\tif (!this.timer && this.timerGranularity > 0) {\n\t\t\tthis.timer = setTimeout(() => {\n\t\t\t\tthis.timer = undefined;\n\t\t\t\tthis.flushOps();\n\t\t\t}, this.timerGranularity);\n\t\t}\n\t}\n\n\tprivate getBatchNumber(sequenceNumber: number): number {\n\t\treturn Math.floor(sequenceNumber / this.batchSize);\n\t}\n\n\tprivate getPositionInBatchArray(sequenceNumber: number): number {\n\t\treturn sequenceNumber % this.batchSize;\n\t}\n\n\tprivate initializeNewBatchDataArray(): IMessage[] {\n\t\tconst tempArray: IMessage[] = [];\n\t\ttempArray.length = this.batchSize; // fill with empty, undefined elements\n\t\treturn tempArray;\n\t}\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/odsp-driver";
8
- export declare const pkgVersion = "2.20.0";
8
+ export declare const pkgVersion = "2.22.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluidframework/odsp-driver";
11
- exports.pkgVersion = "2.20.0";
11
+ exports.pkgVersion = "2.22.0";
12
12
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,6BAA6B,CAAC;AACxC,QAAA,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/odsp-driver\";\nexport const pkgVersion = \"2.20.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,6BAA6B,CAAC;AACxC,QAAA,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/odsp-driver\";\nexport const pkgVersion = \"2.22.0\";\n"]}
@@ -61,7 +61,7 @@ async function prefetchLatestSnapshot(resolvedUrl, getStorageToken, persistedCac
61
61
  };
62
62
  const removeEntries = async () => persistedCache.removeEntries(snapshotKey.file);
63
63
  return internal_3.PerformanceEvent.timedExecAsync(odspLogger, { eventName: "PrefetchLatestSnapshot" }, async () => {
64
- const prefetchStartTime = client_utils_1.performance.now();
64
+ const prefetchStartTime = (0, client_utils_1.performanceNow)();
65
65
  // Add the deferred promise to the cache, so that it can be leveraged while loading the container.
66
66
  const snapshotContentsWithEpochP = new internal_1.Deferred();
67
67
  const nonPersistentCacheKey = (0, internal_2.getKeyForCacheEntry)(snapshotKey);
@@ -1 +1 @@
1
- {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BAAM,EAAC,CAAC,CAAC,aAAa,EAAE,KAAK,CAAC,mDAAmD,CAAC,CAAC;YACnF,0BAA0B,CAAC,OAAO,CAAC;gBAClC,GAAG,KAAK;gBACR,UAAU,EAAE,aAAa;gBACzB,iBAAiB;aACjB,CAAC,CAAC;YACH,IAAA,iBAAM,EAAC,MAAM,KAAK,SAAS,EAAE,KAAK,CAAC,kCAAkC,CAAC,CAAC;YACvE,MAAM,MAAM,CAAC;YACb,6CAA6C;YAC7C,kGAAkG;YAClG,6FAA6F;YAC7F,mGAAmG;YACnG,kGAAkG;YAClG,mGAAmG;YACnG,2FAA2F;YAC3F,+FAA+F;YAC/F,qCAAqC;YACrC,UAAU,CAAC,GAAG,EAAE;gBACf,0BAA0B,EAAE,MAAM,CAAC,qBAAqB,CAAC,CAAC;YAC3D,CAAC,EAAE,IAAI,CAAC,CAAC;QACV,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAChB,+DAA+D;YAC/D,0BAA0B,EAAE,MAAM,CAAC,qBAAqB,CAAC,CAAC;YAC1D,0BAA0B,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACzC,MAAM,KAAK,CAAC;QACb,CAAC,CAAC,CAAC;QACJ,OAAO,IAAI,CAAC;IACb,CAAC,CACD,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACvB,UAAU,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,6BAA6B,EAAE,EAAE,KAAK,CAAC,CAAC;QAC/E,OAAO,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;AACJ,CAAC;AAxHD,wDAwHC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performance } from \"@fluid-internal/client-utils\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport { IResolvedUrl } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tIOdspResolvedUrl,\n\tIOdspUrlParts,\n\tIPersistedCache,\n\tISnapshotOptions,\n\tOdspResourceTokenFetchOptions,\n\tTokenFetcher,\n\tgetKeyForCacheEntry,\n\ttype InstrumentedStorageTokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tPerformanceEvent,\n\tcreateChildMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { IVersionedValueWithEpoch } from \"./contracts.js\";\nimport {\n\tISnapshotRequestAndResponseOptions,\n\tSnapshotFormatSupportType,\n\tdownloadSnapshot,\n\tfetchSnapshotWithRedeem,\n} from \"./fetchSnapshot.js\";\nimport { IPrefetchSnapshotContents } from \"./odspCache.js\";\nimport { OdspDocumentServiceFactory } from \"./odspDocumentServiceFactory.js\";\nimport {\n\tcreateCacheSnapshotKey,\n\tcreateOdspLogger,\n\tgetOdspResolvedUrl,\n\tsnapshotWithLoadingGroupIdSupported,\n\ttoInstrumentedOdspStorageTokenFetcher,\n\ttype TokenFetchOptionsEx,\n} from \"./odspUtils.js\";\n\n/**\n * Function to prefetch the snapshot and cached it in the persistant cache, so that when the container is loaded\n * the cached latest snapshot could be used and removes the network call from the critical path.\n *\n * @param resolvedUrl - Resolved url to fetch the snapshot.\n * @param getStorageToken - function that can provide the storage token for a given site. This is\n * is also referred to as the \"VROOM\" token in SPO.\n * @param persistedCache - Cache to store the fetched snapshot.\n * @param forceAccessTokenViaAuthorizationHeader - @deprecated Not used, true value always used instead. Whether to force passing given token via authorization header.\n * @param logger - Logger to have telemetry events.\n * @param hostSnapshotFetchOptions - Options to fetch the snapshot if any. Otherwise default will be used.\n * @param enableRedeemFallback - True to have the sharing link redeem fallback in case the Trees Latest/Redeem\n * 1RT call fails with redeem error. During fallback it will first redeem the sharing link and then make\n * the Trees latest call.\n * Note: this can be considered deprecated - it will be replaced with `snapshotFormatFetchType`.\n * @param fetchBinarySnapshotFormat - Control if we want to fetch binary format snapshot.\n * @param snapshotFormatFetchType - Snapshot format to fetch.\n * @param odspDocumentServiceFactory - factory to access the non persistent cache and store the prefetch promise.\n *\n * @returns `true` if the snapshot is cached, `false` otherwise.\n * @legacy\n * @alpha\n */\nexport async function prefetchLatestSnapshot(\n\tresolvedUrl: IResolvedUrl,\n\tgetStorageToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\tpersistedCache: IPersistedCache,\n\tforceAccessTokenViaAuthorizationHeader: boolean,\n\tlogger: ITelemetryBaseLogger,\n\thostSnapshotFetchOptions: ISnapshotOptions | undefined,\n\tenableRedeemFallback: boolean = true,\n\tfetchBinarySnapshotFormat?: boolean,\n\tsnapshotFormatFetchType?: SnapshotFormatSupportType,\n\todspDocumentServiceFactory?: OdspDocumentServiceFactory,\n): Promise<boolean> {\n\tconst mc = createChildMonitoringContext({ logger, namespace: \"PrefetchSnapshot\" });\n\tconst odspLogger = createOdspLogger(mc.logger);\n\tconst useGroupIdsForSnapshotFetch = snapshotWithLoadingGroupIdSupported(mc.config);\n\t// For prefetch, we just want to fetch the ungrouped data and want to use the new API if the\n\t// feature gate is set, so provide an empty array.\n\tconst loadingGroupIds = useGroupIdsForSnapshotFetch ? [] : undefined;\n\tconst odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);\n\n\tconst resolvedUrlData: IOdspUrlParts = {\n\t\tsiteUrl: odspResolvedUrl.siteUrl,\n\t\tdriveId: odspResolvedUrl.driveId,\n\t\titemId: odspResolvedUrl.itemId,\n\t};\n\tconst getAuthHeader = toInstrumentedOdspStorageTokenFetcher(\n\t\todspLogger,\n\t\tresolvedUrlData,\n\t\tgetStorageToken,\n\t);\n\n\tconst snapshotDownloader = async (\n\t\tfinalOdspResolvedUrl: IOdspResolvedUrl,\n\t\tstorageTokenFetcher: InstrumentedStorageTokenFetcher,\n\t\ttokenFetchOptions: TokenFetchOptionsEx,\n\t\tloadingGroupId: string[] | undefined,\n\t\tsnapshotOptions: ISnapshotOptions | undefined,\n\t\tcontroller?: AbortController,\n\t): Promise<ISnapshotRequestAndResponseOptions> => {\n\t\treturn downloadSnapshot(\n\t\t\tfinalOdspResolvedUrl,\n\t\t\tstorageTokenFetcher,\n\t\t\ttokenFetchOptions,\n\t\t\tloadingGroupId,\n\t\t\tsnapshotOptions,\n\t\t\tundefined,\n\t\t\tcontroller,\n\t\t);\n\t};\n\tconst snapshotKey = createCacheSnapshotKey(odspResolvedUrl, useGroupIdsForSnapshotFetch);\n\tlet cacheP: Promise<void> | undefined;\n\tlet snapshotEpoch: string | undefined;\n\tconst putInCache = async (valueWithEpoch: IVersionedValueWithEpoch): Promise<void> => {\n\t\tsnapshotEpoch = valueWithEpoch.fluidEpoch;\n\t\tcacheP = persistedCache.put(snapshotKey, valueWithEpoch);\n\t\treturn cacheP;\n\t};\n\n\tconst removeEntries = async (): Promise<void> =>\n\t\tpersistedCache.removeEntries(snapshotKey.file);\n\treturn PerformanceEvent.timedExecAsync(\n\t\todspLogger,\n\t\t{ eventName: \"PrefetchLatestSnapshot\" },\n\t\tasync () => {\n\t\t\tconst prefetchStartTime = performance.now();\n\t\t\t// Add the deferred promise to the cache, so that it can be leveraged while loading the container.\n\t\t\tconst snapshotContentsWithEpochP = new Deferred<IPrefetchSnapshotContents>();\n\t\t\tconst nonPersistentCacheKey = getKeyForCacheEntry(snapshotKey);\n\t\t\tconst snapshotNonPersistentCache =\n\t\t\t\todspDocumentServiceFactory?.snapshotPrefetchResultCache;\n\t\t\tsnapshotNonPersistentCache?.add(\n\t\t\t\tnonPersistentCacheKey,\n\t\t\t\tasync () => snapshotContentsWithEpochP.promise,\n\t\t\t);\n\t\t\tawait fetchSnapshotWithRedeem(\n\t\t\t\todspResolvedUrl,\n\t\t\t\tgetAuthHeader,\n\t\t\t\thostSnapshotFetchOptions,\n\t\t\t\tforceAccessTokenViaAuthorizationHeader,\n\t\t\t\todspLogger,\n\t\t\t\tsnapshotDownloader,\n\t\t\t\tputInCache,\n\t\t\t\tremoveEntries,\n\t\t\t\tloadingGroupIds,\n\t\t\t\tenableRedeemFallback,\n\t\t\t)\n\t\t\t\t.then(async (value) => {\n\t\t\t\t\tassert(!!snapshotEpoch, 0x585 /* prefetched snapshot should have a valid epoch */);\n\t\t\t\t\tsnapshotContentsWithEpochP.resolve({\n\t\t\t\t\t\t...value,\n\t\t\t\t\t\tfluidEpoch: snapshotEpoch,\n\t\t\t\t\t\tprefetchStartTime,\n\t\t\t\t\t});\n\t\t\t\t\tassert(cacheP !== undefined, 0x1e7 /* \"caching was not performed!\" */);\n\t\t\t\t\tawait cacheP;\n\t\t\t\t\t// Schedule it to remove from cache after 5s.\n\t\t\t\t\t// 1. While it's in snapshotNonPersistentCache: Load flow will use this value and will not attempt\n\t\t\t\t\t// to fetch snapshot from network again. That's the best from perf POV, but cache will not be\n\t\t\t\t\t// updated if we keep it in this cache, thus we want to eventually remove snapshot from this cache.\n\t\t\t\t\t// 2. After it's removed from snapshotNonPersistentCache: snapshot is present in persistent cache,\n\t\t\t\t\t// so we sill still use it (in accordance with cache policy controlled by host). But load flow will\n\t\t\t\t\t// also fetch snapshot (in parallel) from storage and update cache. This is fine long term,\n\t\t\t\t\t// but is an extra cost (unneeded network call). However since it is 5s older, new network call\n\t\t\t\t\t// will update the snapshot in cache.\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tsnapshotNonPersistentCache?.remove(nonPersistentCacheKey);\n\t\t\t\t\t}, 5000);\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\t// Remove it from the non persistent cache if an error occured.\n\t\t\t\t\tsnapshotNonPersistentCache?.remove(nonPersistentCacheKey);\n\t\t\t\t\tsnapshotContentsWithEpochP.reject(error);\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t\treturn true;\n\t\t},\n\t).catch(async (error) => {\n\t\todspLogger.sendErrorEvent({ eventName: \"PrefetchLatestSnapshotError\" }, error);\n\t\treturn false;\n\t});\n}\n"]}
1
+ {"version":3,"file":"prefetchLatestSnapshot.js","sourceRoot":"","sources":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DAAmD,CAAC,CAAC;YACnF,0BAA0B,CAAC,OAAO,CAAC;gBAClC,GAAG,KAAK;gBACR,UAAU,EAAE,aAAa;gBACzB,iBAAiB;aACjB,CAAC,CAAC;YACH,IAAA,iBAAM,EAAC,MAAM,KAAK,SAAS,EAAE,KAAK,CAAC,kCAAkC,CAAC,CAAC;YACvE,MAAM,MAAM,CAAC;YACb,6CAA6C;YAC7C,kGAAkG;YAClG,6FAA6F;YAC7F,mGAAmG;YACnG,kGAAkG;YAClG,mGAAmG;YACnG,2FAA2F;YAC3F,+FAA+F;YAC/F,qCAAqC;YACrC,UAAU,CAAC,GAAG,EAAE;gBACf,0BAA0B,EAAE,MAAM,CAAC,qBAAqB,CAAC,CAAC;YAC3D,CAAC,EAAE,IAAI,CAAC,CAAC;QACV,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAChB,+DAA+D;YAC/D,0BAA0B,EAAE,MAAM,CAAC,qBAAqB,CAAC,CAAC;YAC1D,0BAA0B,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACzC,MAAM,KAAK,CAAC;QACb,CAAC,CAAC,CAAC;QACJ,OAAO,IAAI,CAAC;IACb,CAAC,CACD,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACvB,UAAU,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,6BAA6B,EAAE,EAAE,KAAK,CAAC,CAAC;QAC/E,OAAO,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;AACJ,CAAC;AAxHD,wDAwHC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performanceNow } from \"@fluid-internal/client-utils\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport { IResolvedUrl } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tIOdspResolvedUrl,\n\tIOdspUrlParts,\n\tIPersistedCache,\n\tISnapshotOptions,\n\tOdspResourceTokenFetchOptions,\n\tTokenFetcher,\n\tgetKeyForCacheEntry,\n\ttype InstrumentedStorageTokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tPerformanceEvent,\n\tcreateChildMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { IVersionedValueWithEpoch } from \"./contracts.js\";\nimport {\n\tISnapshotRequestAndResponseOptions,\n\tSnapshotFormatSupportType,\n\tdownloadSnapshot,\n\tfetchSnapshotWithRedeem,\n} from \"./fetchSnapshot.js\";\nimport { IPrefetchSnapshotContents } from \"./odspCache.js\";\nimport { OdspDocumentServiceFactory } from \"./odspDocumentServiceFactory.js\";\nimport {\n\tcreateCacheSnapshotKey,\n\tcreateOdspLogger,\n\tgetOdspResolvedUrl,\n\tsnapshotWithLoadingGroupIdSupported,\n\ttoInstrumentedOdspStorageTokenFetcher,\n\ttype TokenFetchOptionsEx,\n} from \"./odspUtils.js\";\n\n/**\n * Function to prefetch the snapshot and cached it in the persistant cache, so that when the container is loaded\n * the cached latest snapshot could be used and removes the network call from the critical path.\n *\n * @param resolvedUrl - Resolved url to fetch the snapshot.\n * @param getStorageToken - function that can provide the storage token for a given site. This is\n * is also referred to as the \"VROOM\" token in SPO.\n * @param persistedCache - Cache to store the fetched snapshot.\n * @param forceAccessTokenViaAuthorizationHeader - @deprecated Not used, true value always used instead. Whether to force passing given token via authorization header.\n * @param logger - Logger to have telemetry events.\n * @param hostSnapshotFetchOptions - Options to fetch the snapshot if any. Otherwise default will be used.\n * @param enableRedeemFallback - True to have the sharing link redeem fallback in case the Trees Latest/Redeem\n * 1RT call fails with redeem error. During fallback it will first redeem the sharing link and then make\n * the Trees latest call.\n * Note: this can be considered deprecated - it will be replaced with `snapshotFormatFetchType`.\n * @param fetchBinarySnapshotFormat - Control if we want to fetch binary format snapshot.\n * @param snapshotFormatFetchType - Snapshot format to fetch.\n * @param odspDocumentServiceFactory - factory to access the non persistent cache and store the prefetch promise.\n *\n * @returns `true` if the snapshot is cached, `false` otherwise.\n * @legacy\n * @alpha\n */\nexport async function prefetchLatestSnapshot(\n\tresolvedUrl: IResolvedUrl,\n\tgetStorageToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\tpersistedCache: IPersistedCache,\n\tforceAccessTokenViaAuthorizationHeader: boolean,\n\tlogger: ITelemetryBaseLogger,\n\thostSnapshotFetchOptions: ISnapshotOptions | undefined,\n\tenableRedeemFallback: boolean = true,\n\tfetchBinarySnapshotFormat?: boolean,\n\tsnapshotFormatFetchType?: SnapshotFormatSupportType,\n\todspDocumentServiceFactory?: OdspDocumentServiceFactory,\n): Promise<boolean> {\n\tconst mc = createChildMonitoringContext({ logger, namespace: \"PrefetchSnapshot\" });\n\tconst odspLogger = createOdspLogger(mc.logger);\n\tconst useGroupIdsForSnapshotFetch = snapshotWithLoadingGroupIdSupported(mc.config);\n\t// For prefetch, we just want to fetch the ungrouped data and want to use the new API if the\n\t// feature gate is set, so provide an empty array.\n\tconst loadingGroupIds = useGroupIdsForSnapshotFetch ? [] : undefined;\n\tconst odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);\n\n\tconst resolvedUrlData: IOdspUrlParts = {\n\t\tsiteUrl: odspResolvedUrl.siteUrl,\n\t\tdriveId: odspResolvedUrl.driveId,\n\t\titemId: odspResolvedUrl.itemId,\n\t};\n\tconst getAuthHeader = toInstrumentedOdspStorageTokenFetcher(\n\t\todspLogger,\n\t\tresolvedUrlData,\n\t\tgetStorageToken,\n\t);\n\n\tconst snapshotDownloader = async (\n\t\tfinalOdspResolvedUrl: IOdspResolvedUrl,\n\t\tstorageTokenFetcher: InstrumentedStorageTokenFetcher,\n\t\ttokenFetchOptions: TokenFetchOptionsEx,\n\t\tloadingGroupId: string[] | undefined,\n\t\tsnapshotOptions: ISnapshotOptions | undefined,\n\t\tcontroller?: AbortController,\n\t): Promise<ISnapshotRequestAndResponseOptions> => {\n\t\treturn downloadSnapshot(\n\t\t\tfinalOdspResolvedUrl,\n\t\t\tstorageTokenFetcher,\n\t\t\ttokenFetchOptions,\n\t\t\tloadingGroupId,\n\t\t\tsnapshotOptions,\n\t\t\tundefined,\n\t\t\tcontroller,\n\t\t);\n\t};\n\tconst snapshotKey = createCacheSnapshotKey(odspResolvedUrl, useGroupIdsForSnapshotFetch);\n\tlet cacheP: Promise<void> | undefined;\n\tlet snapshotEpoch: string | undefined;\n\tconst putInCache = async (valueWithEpoch: IVersionedValueWithEpoch): Promise<void> => {\n\t\tsnapshotEpoch = valueWithEpoch.fluidEpoch;\n\t\tcacheP = persistedCache.put(snapshotKey, valueWithEpoch);\n\t\treturn cacheP;\n\t};\n\n\tconst removeEntries = async (): Promise<void> =>\n\t\tpersistedCache.removeEntries(snapshotKey.file);\n\treturn PerformanceEvent.timedExecAsync(\n\t\todspLogger,\n\t\t{ eventName: \"PrefetchLatestSnapshot\" },\n\t\tasync () => {\n\t\t\tconst prefetchStartTime = performanceNow();\n\t\t\t// Add the deferred promise to the cache, so that it can be leveraged while loading the container.\n\t\t\tconst snapshotContentsWithEpochP = new Deferred<IPrefetchSnapshotContents>();\n\t\t\tconst nonPersistentCacheKey = getKeyForCacheEntry(snapshotKey);\n\t\t\tconst snapshotNonPersistentCache =\n\t\t\t\todspDocumentServiceFactory?.snapshotPrefetchResultCache;\n\t\t\tsnapshotNonPersistentCache?.add(\n\t\t\t\tnonPersistentCacheKey,\n\t\t\t\tasync () => snapshotContentsWithEpochP.promise,\n\t\t\t);\n\t\t\tawait fetchSnapshotWithRedeem(\n\t\t\t\todspResolvedUrl,\n\t\t\t\tgetAuthHeader,\n\t\t\t\thostSnapshotFetchOptions,\n\t\t\t\tforceAccessTokenViaAuthorizationHeader,\n\t\t\t\todspLogger,\n\t\t\t\tsnapshotDownloader,\n\t\t\t\tputInCache,\n\t\t\t\tremoveEntries,\n\t\t\t\tloadingGroupIds,\n\t\t\t\tenableRedeemFallback,\n\t\t\t)\n\t\t\t\t.then(async (value) => {\n\t\t\t\t\tassert(!!snapshotEpoch, 0x585 /* prefetched snapshot should have a valid epoch */);\n\t\t\t\t\tsnapshotContentsWithEpochP.resolve({\n\t\t\t\t\t\t...value,\n\t\t\t\t\t\tfluidEpoch: snapshotEpoch,\n\t\t\t\t\t\tprefetchStartTime,\n\t\t\t\t\t});\n\t\t\t\t\tassert(cacheP !== undefined, 0x1e7 /* \"caching was not performed!\" */);\n\t\t\t\t\tawait cacheP;\n\t\t\t\t\t// Schedule it to remove from cache after 5s.\n\t\t\t\t\t// 1. While it's in snapshotNonPersistentCache: Load flow will use this value and will not attempt\n\t\t\t\t\t// to fetch snapshot from network again. That's the best from perf POV, but cache will not be\n\t\t\t\t\t// updated if we keep it in this cache, thus we want to eventually remove snapshot from this cache.\n\t\t\t\t\t// 2. After it's removed from snapshotNonPersistentCache: snapshot is present in persistent cache,\n\t\t\t\t\t// so we sill still use it (in accordance with cache policy controlled by host). But load flow will\n\t\t\t\t\t// also fetch snapshot (in parallel) from storage and update cache. This is fine long term,\n\t\t\t\t\t// but is an extra cost (unneeded network call). However since it is 5s older, new network call\n\t\t\t\t\t// will update the snapshot in cache.\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tsnapshotNonPersistentCache?.remove(nonPersistentCacheKey);\n\t\t\t\t\t}, 5000);\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\t// Remove it from the non persistent cache if an error occured.\n\t\t\t\t\tsnapshotNonPersistentCache?.remove(nonPersistentCacheKey);\n\t\t\t\t\tsnapshotContentsWithEpochP.reject(error);\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t\treturn true;\n\t\t},\n\t).catch(async (error) => {\n\t\todspLogger.sendErrorEvent({ eventName: \"PrefetchLatestSnapshotError\" }, error);\n\t\treturn false;\n\t});\n}\n"]}
@@ -15,7 +15,7 @@ const epochTracker_js_1 = require("./epochTracker.js");
15
15
  */
16
16
  async function runWithRetry(api, callName, logger, checkDisposed) {
17
17
  let retryAfter = 1000;
18
- const start = client_utils_1.performance.now();
18
+ const start = (0, client_utils_1.performanceNow)();
19
19
  let lastError;
20
20
  for (let attempts = 1;; attempts++) {
21
21
  if (checkDisposed !== undefined) {
@@ -28,7 +28,7 @@ async function runWithRetry(api, callName, logger, checkDisposed) {
28
28
  eventName: "MultipleRetries",
29
29
  callName,
30
30
  attempts,
31
- duration: client_utils_1.performance.now() - start,
31
+ duration: (0, client_utils_1.performanceNow)() - start,
32
32
  }, lastError);
33
33
  }
34
34
  return result;
@@ -48,7 +48,7 @@ async function runWithRetry(api, callName, logger, checkDisposed) {
48
48
  eventName: `${callName}_firstFailed`,
49
49
  callName,
50
50
  attempts,
51
- duration: client_utils_1.performance.now() - start, // record total wait time.
51
+ duration: (0, client_utils_1.performanceNow)() - start, // record total wait time.
52
52
  }, error);
53
53
  }
54
54
  // Retry for retriable 409 coherency errors or serviceReadOnly errors. These errors are always retriable
@@ -67,7 +67,7 @@ async function runWithRetry(api, callName, logger, checkDisposed) {
67
67
  : "ServiceReadonlyErrorTooManyRetries",
68
68
  callName,
69
69
  attempts,
70
- duration: client_utils_1.performance.now() - start, // record total wait time.
70
+ duration: (0, client_utils_1.performanceNow)() - start, // record total wait time.
71
71
  }, error);
72
72
  // Fail hard.
73
73
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
@@ -1 +1 @@
1
- {"version":3,"file":"retryUtils.js","sourceRoot":"","sources":["../src/retryUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA2D;AAC3D,kEAA4D;AAC5D,oEAG+C;AAC/C,+EAAkF;AAGlF,uDAAiD;AAEjD;;GAEG;AACI,KAAK,UAAU,YAAY,CACjC,GAAqB,EACrB,QAAgB,EAChB,MAA2B,EAC3B,aAA0B;IAE1B,IAAI,UAAU,GAAG,IAAI,CAAC;IACtB,MAAM,KAAK,GAAG,0BAAW,CAAC,GAAG,EAAE,CAAC;IAChC,IAAI,SAAkB,CAAC;IACvB,KAAK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YAC/E,oFAAoF;YACpF,uEAAuE;YACvE,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;gBACpB,MAAM,CAAC,cAAc,CACpB;oBACC,SAAS,EAAE,cAAc;wBACxB,CAAC,CAAC,8BAA8B;wBAChC,CAAC,CAAC,oCAAoC;oBACvC,QAAQ;oBACR,QAAQ;oBACR,QAAQ,EAAE,0BAAW,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,0BAA0B;iBAC/D,EACD,KAAK,CACL,CAAC;gBACF,aAAa;gBACb,sEAAsE;gBACtE,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC;gBACvB,MAAM,KAAK,CAAC;YACb,CAAC;YAED,UAAU,GAAG,IAAA,iCAAsB,EAAC,KAAK,CAAC,IAAI,UAAU,CAAC;YACzD,MAAM,IAAA,gBAAK,EAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;YACpC,UAAU,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YACrD,SAAS,GAAG,KAAK,CAAC;QACnB,CAAC;IACF,CAAC;AACF,CAAC;AArFD,oCAqFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performance } from \"@fluid-internal/client-utils\";\nimport { delay } from \"@fluidframework/core-utils/internal\";\nimport {\n\tcanRetryOnError,\n\tgetRetryDelayFromError,\n} from \"@fluidframework/driver-utils/internal\";\nimport { OdspErrorTypes } from \"@fluidframework/odsp-driver-definitions/internal\";\nimport { ITelemetryLoggerExt } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { Odsp409Error } from \"./epochTracker.js\";\n\n/**\n * This method retries only for retriable coherency and service read only errors.\n */\nexport async function runWithRetry<T>(\n\tapi: () => Promise<T>,\n\tcallName: string,\n\tlogger: ITelemetryLoggerExt,\n\tcheckDisposed?: () => void,\n): Promise<T> {\n\tlet retryAfter = 1000;\n\tconst start = performance.now();\n\tlet lastError: unknown;\n\tfor (let attempts = 1; ; attempts++) {\n\t\tif (checkDisposed !== undefined) {\n\t\t\tcheckDisposed();\n\t\t}\n\t\ttry {\n\t\t\tconst result = await api();\n\t\t\tif (attempts > 1) {\n\t\t\t\tlogger.sendTelemetryEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: \"MultipleRetries\",\n\t\t\t\t\t\tcallName,\n\t\t\t\t\t\tattempts,\n\t\t\t\t\t\tduration: performance.now() - start,\n\t\t\t\t\t},\n\t\t\t\t\tlastError,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn result;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t} catch (error: any) {\n\t\t\tconst canRetry = canRetryOnError(error);\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\tconst coherencyError = error?.[Odsp409Error] === true;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\tconst serviceReadonlyError = error?.errorType === OdspErrorTypes.serviceReadOnly;\n\n\t\t\t// logging the first failed retry instead of every attempt. We want to avoid filling telemetry\n\t\t\t// when we have tight loop of retrying in offline mode, but we also want to know what caused\n\t\t\t// the failure in the first place\n\t\t\tif (attempts === 1) {\n\t\t\t\tlogger.sendTelemetryEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: `${callName}_firstFailed`,\n\t\t\t\t\t\tcallName,\n\t\t\t\t\t\tattempts,\n\t\t\t\t\t\tduration: performance.now() - start, // record total wait time.\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Retry for retriable 409 coherency errors or serviceReadOnly errors. These errors are always retriable\n\t\t\t// unless someone specifically set canRetry = false on the error like in fetchSnapshot() flow. So in\n\t\t\t// that case don't retry.\n\t\t\tif (!((coherencyError || serviceReadonlyError) && canRetry)) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\t// SPO itself does number of retries internally before returning 409 to client.\n\t\t\t// That multiplied to 5 suggests need to reconsider current design, as client spends\n\t\t\t// too much time / bandwidth doing the same thing without any progress.\n\t\t\tif (attempts === 5) {\n\t\t\t\tlogger.sendErrorEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: coherencyError\n\t\t\t\t\t\t\t? \"CoherencyErrorTooManyRetries\"\n\t\t\t\t\t\t\t: \"ServiceReadonlyErrorTooManyRetries\",\n\t\t\t\t\t\tcallName,\n\t\t\t\t\t\tattempts,\n\t\t\t\t\t\tduration: performance.now() - start, // record total wait time.\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t\t// Fail hard.\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\terror.canRetry = false;\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tretryAfter = getRetryDelayFromError(error) ?? retryAfter;\n\t\t\tawait delay(Math.floor(retryAfter));\n\t\t\tretryAfter += (retryAfter / 4) * (1 + Math.random());\n\t\t\tlastError = error;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"retryUtils.js","sourceRoot":"","sources":["../src/retryUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA8D;AAC9D,kEAA4D;AAC5D,oEAG+C;AAC/C,+EAAkF;AAGlF,uDAAiD;AAEjD;;GAEG;AACI,KAAK,UAAU,YAAY,CACjC,GAAqB,EACrB,QAAgB,EAChB,MAA2B,EAC3B,aAA0B;IAE1B,IAAI,UAAU,GAAG,IAAI,CAAC;IACtB,MAAM,KAAK,GAAG,IAAA,6BAAc,GAAE,CAAC;IAC/B,IAAI,SAAkB,CAAC;IACvB,KAAK,IAAI,QAAQ,GAAG,CAAC,GAAI,QAAQ,EAAE,EAAE,CAAC;QACrC,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;YACjC,aAAa,EAAE,CAAC;QACjB,CAAC;QACD,IAAI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BAChC,CAAC,CAAC,oCAAoC;oBACvC,QAAQ;oBACR,QAAQ;oBACR,QAAQ,EAAE,IAAA,6BAAc,GAAE,GAAG,KAAK,EAAE,0BAA0B;iBAC9D,EACD,KAAK,CACL,CAAC;gBACF,aAAa;gBACb,sEAAsE;gBACtE,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC;gBACvB,MAAM,KAAK,CAAC;YACb,CAAC;YAED,UAAU,GAAG,IAAA,iCAAsB,EAAC,KAAK,CAAC,IAAI,UAAU,CAAC;YACzD,MAAM,IAAA,gBAAK,EAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;YACpC,UAAU,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YACrD,SAAS,GAAG,KAAK,CAAC;QACnB,CAAC;IACF,CAAC;AACF,CAAC;AArFD,oCAqFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performanceNow } from \"@fluid-internal/client-utils\";\nimport { delay } from \"@fluidframework/core-utils/internal\";\nimport {\n\tcanRetryOnError,\n\tgetRetryDelayFromError,\n} from \"@fluidframework/driver-utils/internal\";\nimport { OdspErrorTypes } from \"@fluidframework/odsp-driver-definitions/internal\";\nimport { ITelemetryLoggerExt } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { Odsp409Error } from \"./epochTracker.js\";\n\n/**\n * This method retries only for retriable coherency and service read only errors.\n */\nexport async function runWithRetry<T>(\n\tapi: () => Promise<T>,\n\tcallName: string,\n\tlogger: ITelemetryLoggerExt,\n\tcheckDisposed?: () => void,\n): Promise<T> {\n\tlet retryAfter = 1000;\n\tconst start = performanceNow();\n\tlet lastError: unknown;\n\tfor (let attempts = 1; ; attempts++) {\n\t\tif (checkDisposed !== undefined) {\n\t\t\tcheckDisposed();\n\t\t}\n\t\ttry {\n\t\t\tconst result = await api();\n\t\t\tif (attempts > 1) {\n\t\t\t\tlogger.sendTelemetryEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: \"MultipleRetries\",\n\t\t\t\t\t\tcallName,\n\t\t\t\t\t\tattempts,\n\t\t\t\t\t\tduration: performanceNow() - start,\n\t\t\t\t\t},\n\t\t\t\t\tlastError,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn result;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t} catch (error: any) {\n\t\t\tconst canRetry = canRetryOnError(error);\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\tconst coherencyError = error?.[Odsp409Error] === true;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\tconst serviceReadonlyError = error?.errorType === OdspErrorTypes.serviceReadOnly;\n\n\t\t\t// logging the first failed retry instead of every attempt. We want to avoid filling telemetry\n\t\t\t// when we have tight loop of retrying in offline mode, but we also want to know what caused\n\t\t\t// the failure in the first place\n\t\t\tif (attempts === 1) {\n\t\t\t\tlogger.sendTelemetryEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: `${callName}_firstFailed`,\n\t\t\t\t\t\tcallName,\n\t\t\t\t\t\tattempts,\n\t\t\t\t\t\tduration: performanceNow() - start, // record total wait time.\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Retry for retriable 409 coherency errors or serviceReadOnly errors. These errors are always retriable\n\t\t\t// unless someone specifically set canRetry = false on the error like in fetchSnapshot() flow. So in\n\t\t\t// that case don't retry.\n\t\t\tif (!((coherencyError || serviceReadonlyError) && canRetry)) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\t// SPO itself does number of retries internally before returning 409 to client.\n\t\t\t// That multiplied to 5 suggests need to reconsider current design, as client spends\n\t\t\t// too much time / bandwidth doing the same thing without any progress.\n\t\t\tif (attempts === 5) {\n\t\t\t\tlogger.sendErrorEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: coherencyError\n\t\t\t\t\t\t\t? \"CoherencyErrorTooManyRetries\"\n\t\t\t\t\t\t\t: \"ServiceReadonlyErrorTooManyRetries\",\n\t\t\t\t\t\tcallName,\n\t\t\t\t\t\tattempts,\n\t\t\t\t\t\tduration: performanceNow() - start, // record total wait time.\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t\t// Fail hard.\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\terror.canRetry = false;\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tretryAfter = getRetryDelayFromError(error) ?? retryAfter;\n\t\t\tawait delay(Math.floor(retryAfter));\n\t\t\tretryAfter += (retryAfter / 4) * (1 + Math.random());\n\t\t\tlastError = error;\n\t\t}\n\t}\n}\n"]}
@@ -3,5 +3,6 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { io } from "socket.io-client";
6
- export declare const SocketIOClientStatic: typeof io;
6
+ import { type Mockable } from "./mockify.js";
7
+ export declare const SocketIOClientStatic: Mockable<typeof io>;
7
8
  //# sourceMappingURL=socketModule.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"socketModule.d.ts","sourceRoot":"","sources":["../src/socketModule.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAItC,eAAO,MAAM,oBAAoB,WAAK,CAAC"}
1
+ {"version":3,"file":"socketModule.d.ts","sourceRoot":"","sources":["../src/socketModule.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAEtC,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEtD,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAe,CAAC"}
@@ -6,7 +6,6 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.SocketIOClientStatic = void 0;
8
8
  const socket_io_client_1 = require("socket.io-client");
9
- // Import is required for side-effects.
10
- // eslint-disable-next-line unicorn/prefer-export-from
11
- exports.SocketIOClientStatic = socket_io_client_1.io;
9
+ const mockify_js_1 = require("./mockify.js");
10
+ exports.SocketIOClientStatic = (0, mockify_js_1.mockify)(socket_io_client_1.io);
12
11
  //# sourceMappingURL=socketModule.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"socketModule.js","sourceRoot":"","sources":["../src/socketModule.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uDAAsC;AAEtC,uCAAuC;AACvC,sDAAsD;AACzC,QAAA,oBAAoB,GAAG,qBAAE,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { io } from \"socket.io-client\";\n\n// Import is required for side-effects.\n// eslint-disable-next-line unicorn/prefer-export-from\nexport const SocketIOClientStatic = io;\n"]}
1
+ {"version":3,"file":"socketModule.js","sourceRoot":"","sources":["../src/socketModule.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uDAAsC;AAEtC,6CAAsD;AAEzC,QAAA,oBAAoB,GAAwB,IAAA,oBAAO,EAAC,qBAAE,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { io } from \"socket.io-client\";\n\nimport { mockify, type Mockable } from \"./mockify.js\";\n\nexport const SocketIOClientStatic: Mockable<typeof io> = mockify(io);\n"]}
package/dist/vroom.d.ts CHANGED
@@ -23,5 +23,5 @@ import { TokenFetchOptionsEx } from "./odspUtils.js";
23
23
  * This is optional and used only when collab session is being joined by client acting in app-only mode (i.e. without user context).
24
24
  * If not specified client display name is extracted from the access token that is used to join session.
25
25
  */
26
- export declare function fetchJoinSession(urlParts: IOdspUrlParts, path: string, method: "GET" | "POST", logger: ITelemetryLoggerExt, getAuthHeader: InstrumentedStorageTokenFetcher, epochTracker: EpochTracker, requestSocketToken: boolean, options: TokenFetchOptionsEx, disableJoinSessionRefresh: boolean | undefined, isRefreshingJoinSession: boolean, displayName: string | undefined): Promise<ISocketStorageDiscovery>;
26
+ export declare const fetchJoinSession: import("./mockify.js").Mockable<(urlParts: IOdspUrlParts, path: string, method: "GET" | "POST", logger: ITelemetryLoggerExt, getAuthHeader: InstrumentedStorageTokenFetcher, epochTracker: EpochTracker, requestSocketToken: boolean, options: TokenFetchOptionsEx, disableJoinSessionRefresh: boolean | undefined, isRefreshingJoinSession: boolean, displayName: string | undefined) => Promise<ISocketStorageDiscovery>>;
27
27
  //# sourceMappingURL=vroom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vroom.d.ts","sourceRoot":"","sources":["../src/vroom.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,aAAa,EACb,uBAAuB,EACvB,+BAA+B,EAC/B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EACN,mBAAmB,EAEnB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAQrD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,gBAAgB,CACrC,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,KAAK,GAAG,MAAM,EACtB,MAAM,EAAE,mBAAmB,EAC3B,aAAa,EAAE,+BAA+B,EAC9C,YAAY,EAAE,YAAY,EAC1B,kBAAkB,EAAE,OAAO,EAC3B,OAAO,EAAE,mBAAmB,EAC5B,yBAAyB,EAAE,OAAO,GAAG,SAAS,EAC9C,uBAAuB,EAAE,OAAO,EAChC,WAAW,EAAE,MAAM,GAAG,SAAS,GAC7B,OAAO,CAAC,uBAAuB,CAAC,CAoFlC"}
1
+ {"version":3,"file":"vroom.d.ts","sourceRoot":"","sources":["../src/vroom.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,aAAa,EACb,uBAAuB,EACvB,+BAA+B,EAC/B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EACN,mBAAmB,EAEnB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAQrD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,gBAAgB,6CAEjB,aAAa,QACjB,MAAM,UACJ,KAAK,GAAG,MAAM,UACd,mBAAmB,iBACZ,+BAA+B,gBAChC,YAAY,sBACN,OAAO,WAClB,mBAAmB,6BACD,OAAO,GAAG,SAAS,2BACrB,OAAO,eACnB,MAAM,GAAG,SAAS,KAC7B,QAAQ,uBAAuB,CAAC,CAqFnC,CAAC"}
package/dist/vroom.js CHANGED
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.fetchJoinSession = void 0;
8
8
  const internal_1 = require("@fluidframework/telemetry-utils/internal");
9
9
  const uuid_1 = require("uuid");
10
+ const mockify_js_1 = require("./mockify.js");
10
11
  const odspUrlHelper_js_1 = require("./odspUrlHelper.js");
11
12
  const retryUtils_js_1 = require("./retryUtils.js");
12
13
  /**
@@ -26,7 +27,7 @@ const retryUtils_js_1 = require("./retryUtils.js");
26
27
  * This is optional and used only when collab session is being joined by client acting in app-only mode (i.e. without user context).
27
28
  * If not specified client display name is extracted from the access token that is used to join session.
28
29
  */
29
- async function fetchJoinSession(urlParts, path, method, logger, getAuthHeader, epochTracker, requestSocketToken, options, disableJoinSessionRefresh, isRefreshingJoinSession, displayName) {
30
+ exports.fetchJoinSession = (0, mockify_js_1.mockify)(async (urlParts, path, method, logger, getAuthHeader, epochTracker, requestSocketToken, options, disableJoinSessionRefresh, isRefreshingJoinSession, displayName) => {
30
31
  const apiRoot = (0, odspUrlHelper_js_1.getApiRoot)(new URL(urlParts.siteUrl));
31
32
  const url = `${apiRoot}/drives/${urlParts.driveId}/items/${urlParts.itemId}/${path}?ump=1`;
32
33
  const authHeader = await getAuthHeader({ ...options, request: { url, method } }, "JoinSession");
@@ -85,6 +86,5 @@ async function fetchJoinSession(urlParts, path, method, logger, getAuthHeader, e
85
86
  }
86
87
  return response.content;
87
88
  });
88
- }
89
- exports.fetchJoinSession = fetchJoinSession;
89
+ });
90
90
  //# sourceMappingURL=vroom.js.map
package/dist/vroom.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vroom.js","sourceRoot":"","sources":["../src/vroom.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,uEAGkD;AAClD,+BAAkC;AAGlC,yDAAgD;AAEhD,mDAA+C;AAO/C;;;;;;;;;;;;;;;;GAgBG;AACI,KAAK,UAAU,gBAAgB,CACrC,QAAuB,EACvB,IAAY,EACZ,MAAsB,EACtB,MAA2B,EAC3B,aAA8C,EAC9C,YAA0B,EAC1B,kBAA2B,EAC3B,OAA4B,EAC5B,yBAA8C,EAC9C,uBAAgC,EAChC,WAA+B;IAE/B,MAAM,OAAO,GAAG,IAAA,6BAAU,EAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,MAAM,GAAG,GAAG,GAAG,OAAO,WAAW,QAAQ,CAAC,OAAO,UAAU,QAAQ,CAAC,MAAM,IAAI,IAAI,QAAQ,CAAC;IAC3F,MAAM,UAAU,GAAG,MAAM,aAAa,CACrC,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EACxC,aAAa,CACb,CAAC;IAEF,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO;QACxC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,QAA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AAgC,YAAY,EAAE;SAC9D,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,IAAA,4BAAY,EAClC,KAAK,IAAI,EAAE,CACV,YAAY,CAAC,mBAAmB,CAC/B,GAAG,EACH,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,EACnC,aAAa,EACb,IAAI,CACJ,EACF,aAAa,EACb,MAAM,CACN,CAAC;QAEF,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAC;QACxD,kEAAkE;QAClE,MAAM,iBAAiB,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAElD,8BAA8B;QAC9B,KAAK,CAAC,GAAG,CAAC;YACT,GAAG,QAAQ,CAAC,UAAU;YACtB,2CAA2C;YAC3C,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC;YACnC,iBAAiB;YACjB,6BAA6B,EAAE,QAAQ,CAAC,OAAO,CAAC,6BAA6B;SAC7E,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,OAAO,CAAC,eAAe,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACpE,QAAQ,CAAC,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC;QAC9D,CAAC;QAED,OAAO,QAAQ,CAAC,OAAO,CAAC;IACzB,CAAC,CACD,CAAC;AACH,CAAC;AAhGD,4CAgGC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseProperties } from \"@fluidframework/core-interfaces\";\nimport {\n\tIOdspUrlParts,\n\tISocketStorageDiscovery,\n\tInstrumentedStorageTokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { v4 as uuid } from \"uuid\";\n\nimport { EpochTracker } from \"./epochTracker.js\";\nimport { getApiRoot } from \"./odspUrlHelper.js\";\nimport { TokenFetchOptionsEx } from \"./odspUtils.js\";\nimport { runWithRetry } from \"./retryUtils.js\";\n\ninterface IJoinSessionBody {\n\trequestSocketToken?: boolean;\n\tdisplayName?: string;\n}\n\n/**\n * Makes join session call on SPO to get information about the web socket for a document\n * @param urlParts - The SPO drive id, itemId, siteUrl that this request should be made against\n * @param path - The API path that is relevant to this request\n * @param method - The type of request, such as GET or POST\n * @param logger - A logger to use for this request\n * @param getAuthHeader - A function that is able to provide the access token for this request\n * @param epochTracker - fetch wrapper which incorporates epoch logic around joinSession call\n * @param requestSocketToken - flag indicating whether joinSession is expected to return access token\n * which is used when establishing websocket connection with collab session backend service.\n * @param options - Options to fetch the token.\n * @param disableJoinSessionRefresh - Whether the caller wants to disable refreshing join session periodically.\n * @param isRefreshingJoinSession - whether call is to refresh the session before expiry.\n * @param displayName - display name used to identify client joining a session.\n * This is optional and used only when collab session is being joined by client acting in app-only mode (i.e. without user context).\n * If not specified client display name is extracted from the access token that is used to join session.\n */\nexport async function fetchJoinSession(\n\turlParts: IOdspUrlParts,\n\tpath: string,\n\tmethod: \"GET\" | \"POST\",\n\tlogger: ITelemetryLoggerExt,\n\tgetAuthHeader: InstrumentedStorageTokenFetcher,\n\tepochTracker: EpochTracker,\n\trequestSocketToken: boolean,\n\toptions: TokenFetchOptionsEx,\n\tdisableJoinSessionRefresh: boolean | undefined,\n\tisRefreshingJoinSession: boolean,\n\tdisplayName: string | undefined,\n): Promise<ISocketStorageDiscovery> {\n\tconst apiRoot = getApiRoot(new URL(urlParts.siteUrl));\n\tconst url = `${apiRoot}/drives/${urlParts.driveId}/items/${urlParts.itemId}/${path}?ump=1`;\n\tconst authHeader = await getAuthHeader(\n\t\t{ ...options, request: { url, method } },\n\t\t\"JoinSession\",\n\t);\n\n\tconst tokenRefreshProps = options.refresh\n\t\t? { hasClaims: !!options.claims, hasTenantId: !!options.tenantId }\n\t\t: {};\n\tconst details: ITelemetryBaseProperties = {\n\t\trefreshedToken: options.refresh,\n\t\trequestSocketToken,\n\t\t...tokenRefreshProps,\n\t\trefreshingSession: isRefreshingJoinSession,\n\t};\n\n\treturn PerformanceEvent.timedExecAsync(\n\t\tlogger,\n\t\t{\n\t\t\teventName: \"JoinSession\",\n\t\t\tattempts: options.refresh ? 2 : 1,\n\t\t\tdetails: JSON.stringify(details),\n\t\t\t...tokenRefreshProps,\n\t\t},\n\t\tasync (event) => {\n\t\t\tconst formBoundary = uuid();\n\t\t\tlet postBody = `--${formBoundary}\\r\\n`;\n\t\t\tpostBody += `Authorization: ${authHeader}\\r\\n`;\n\t\t\tpostBody += `X-HTTP-Method-Override: POST\\r\\n`;\n\t\t\tpostBody += `Content-Type: application/json\\r\\n`;\n\t\t\tif (!disableJoinSessionRefresh) {\n\t\t\t\tpostBody += `prefer: FluidRemoveCheckAccess\\r\\n`;\n\t\t\t}\n\t\t\tpostBody += `_post: 1\\r\\n`;\n\n\t\t\tlet requestBody: IJoinSessionBody | undefined;\n\t\t\tif (requestSocketToken) {\n\t\t\t\trequestBody = { ...requestBody, requestSocketToken: true };\n\t\t\t}\n\t\t\tif (displayName) {\n\t\t\t\trequestBody = { ...requestBody, displayName };\n\t\t\t}\n\t\t\tif (requestBody) {\n\t\t\t\tpostBody += `\\r\\n${JSON.stringify(requestBody)}\\r\\n`;\n\t\t\t}\n\t\t\tpostBody += `\\r\\n--${formBoundary}--`;\n\t\t\tconst headers: { [index: string]: string } = {\n\t\t\t\t\"Content-Type\": `multipart/form-data;boundary=${formBoundary}`,\n\t\t\t};\n\n\t\t\tconst response = await runWithRetry(\n\t\t\t\tasync () =>\n\t\t\t\t\tepochTracker.fetchAndParseAsJSON<ISocketStorageDiscovery>(\n\t\t\t\t\t\turl,\n\t\t\t\t\t\t{ method, headers, body: postBody },\n\t\t\t\t\t\t\"joinSession\",\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t),\n\t\t\t\t\"joinSession\",\n\t\t\t\tlogger,\n\t\t\t);\n\n\t\t\tconst socketUrl = response.content.deltaStreamSocketUrl;\n\t\t\t// expecting socketUrl to be something like https://{hostName}/...\n\t\t\tconst webSocketHostName = socketUrl.split(\"/\")[2];\n\n\t\t\t// TODO SPO-specific telemetry\n\t\t\tevent.end({\n\t\t\t\t...response.propsToLog,\n\t\t\t\t// pushV2 websocket urls will contain pushf\n\t\t\t\tpushv2: socketUrl.includes(\"pushf\"),\n\t\t\t\twebSocketHostName,\n\t\t\t\trefreshSessionDurationSeconds: response.content.refreshSessionDurationSeconds,\n\t\t\t});\n\n\t\t\tif (response.content.runtimeTenantId && !response.content.tenantId) {\n\t\t\t\tresponse.content.tenantId = response.content.runtimeTenantId;\n\t\t\t}\n\n\t\t\treturn response.content;\n\t\t},\n\t);\n}\n"]}
1
+ {"version":3,"file":"vroom.js","sourceRoot":"","sources":["../src/vroom.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,uEAGkD;AAClD,+BAAkC;AAGlC,6CAAuC;AACvC,yDAAgD;AAEhD,mDAA+C;AAO/C;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,gBAAgB,GAAG,IAAA,oBAAO,EACtC,KAAK,EACJ,QAAuB,EACvB,IAAY,EACZ,MAAsB,EACtB,MAA2B,EAC3B,aAA8C,EAC9C,YAA0B,EAC1B,kBAA2B,EAC3B,OAA4B,EAC5B,yBAA8C,EAC9C,uBAAgC,EAChC,WAA+B,EACI,EAAE;IACrC,MAAM,OAAO,GAAG,IAAA,6BAAU,EAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,MAAM,GAAG,GAAG,GAAG,OAAO,WAAW,QAAQ,CAAC,OAAO,UAAU,QAAQ,CAAC,MAAM,IAAI,IAAI,QAAQ,CAAC;IAC3F,MAAM,UAAU,GAAG,MAAM,aAAa,CACrC,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,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elemetryBaseProperties } from \"@fluidframework/core-interfaces\";\nimport {\n\tIOdspUrlParts,\n\tISocketStorageDiscovery,\n\tInstrumentedStorageTokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { v4 as uuid } from \"uuid\";\n\nimport { EpochTracker } from \"./epochTracker.js\";\nimport { mockify } from \"./mockify.js\";\nimport { getApiRoot } from \"./odspUrlHelper.js\";\nimport { TokenFetchOptionsEx } from \"./odspUtils.js\";\nimport { runWithRetry } from \"./retryUtils.js\";\n\ninterface IJoinSessionBody {\n\trequestSocketToken?: boolean;\n\tdisplayName?: string;\n}\n\n/**\n * Makes join session call on SPO to get information about the web socket for a document\n * @param urlParts - The SPO drive id, itemId, siteUrl that this request should be made against\n * @param path - The API path that is relevant to this request\n * @param method - The type of request, such as GET or POST\n * @param logger - A logger to use for this request\n * @param getAuthHeader - A function that is able to provide the access token for this request\n * @param epochTracker - fetch wrapper which incorporates epoch logic around joinSession call\n * @param requestSocketToken - flag indicating whether joinSession is expected to return access token\n * which is used when establishing websocket connection with collab session backend service.\n * @param options - Options to fetch the token.\n * @param disableJoinSessionRefresh - Whether the caller wants to disable refreshing join session periodically.\n * @param isRefreshingJoinSession - whether call is to refresh the session before expiry.\n * @param displayName - display name used to identify client joining a session.\n * This is optional and used only when collab session is being joined by client acting in app-only mode (i.e. without user context).\n * If not specified client display name is extracted from the access token that is used to join session.\n */\nexport const fetchJoinSession = mockify(\n\tasync (\n\t\turlParts: IOdspUrlParts,\n\t\tpath: string,\n\t\tmethod: \"GET\" | \"POST\",\n\t\tlogger: ITelemetryLoggerExt,\n\t\tgetAuthHeader: InstrumentedStorageTokenFetcher,\n\t\tepochTracker: EpochTracker,\n\t\trequestSocketToken: boolean,\n\t\toptions: TokenFetchOptionsEx,\n\t\tdisableJoinSessionRefresh: boolean | undefined,\n\t\tisRefreshingJoinSession: boolean,\n\t\tdisplayName: string | undefined,\n\t): Promise<ISocketStorageDiscovery> => {\n\t\tconst apiRoot = getApiRoot(new URL(urlParts.siteUrl));\n\t\tconst url = `${apiRoot}/drives/${urlParts.driveId}/items/${urlParts.itemId}/${path}?ump=1`;\n\t\tconst authHeader = await getAuthHeader(\n\t\t\t{ ...options, request: { url, method } },\n\t\t\t\"JoinSession\",\n\t\t);\n\n\t\tconst tokenRefreshProps = options.refresh\n\t\t\t? { hasClaims: !!options.claims, hasTenantId: !!options.tenantId }\n\t\t\t: {};\n\t\tconst details: ITelemetryBaseProperties = {\n\t\t\trefreshedToken: options.refresh,\n\t\t\trequestSocketToken,\n\t\t\t...tokenRefreshProps,\n\t\t\trefreshingSession: isRefreshingJoinSession,\n\t\t};\n\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tlogger,\n\t\t\t{\n\t\t\t\teventName: \"JoinSession\",\n\t\t\t\tattempts: options.refresh ? 2 : 1,\n\t\t\t\tdetails: JSON.stringify(details),\n\t\t\t\t...tokenRefreshProps,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst formBoundary = uuid();\n\t\t\t\tlet postBody = `--${formBoundary}\\r\\n`;\n\t\t\t\tpostBody += `Authorization: ${authHeader}\\r\\n`;\n\t\t\t\tpostBody += `X-HTTP-Method-Override: POST\\r\\n`;\n\t\t\t\tpostBody += `Content-Type: application/json\\r\\n`;\n\t\t\t\tif (!disableJoinSessionRefresh) {\n\t\t\t\t\tpostBody += `prefer: FluidRemoveCheckAccess\\r\\n`;\n\t\t\t\t}\n\t\t\t\tpostBody += `_post: 1\\r\\n`;\n\n\t\t\t\tlet requestBody: IJoinSessionBody | undefined;\n\t\t\t\tif (requestSocketToken) {\n\t\t\t\t\trequestBody = { ...requestBody, requestSocketToken: true };\n\t\t\t\t}\n\t\t\t\tif (displayName) {\n\t\t\t\t\trequestBody = { ...requestBody, displayName };\n\t\t\t\t}\n\t\t\t\tif (requestBody) {\n\t\t\t\t\tpostBody += `\\r\\n${JSON.stringify(requestBody)}\\r\\n`;\n\t\t\t\t}\n\t\t\t\tpostBody += `\\r\\n--${formBoundary}--`;\n\t\t\t\tconst headers: { [index: string]: string } = {\n\t\t\t\t\t\"Content-Type\": `multipart/form-data;boundary=${formBoundary}`,\n\t\t\t\t};\n\n\t\t\t\tconst response = await runWithRetry(\n\t\t\t\t\tasync () =>\n\t\t\t\t\t\tepochTracker.fetchAndParseAsJSON<ISocketStorageDiscovery>(\n\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t\t{ method, headers, body: postBody },\n\t\t\t\t\t\t\t\"joinSession\",\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t),\n\t\t\t\t\t\"joinSession\",\n\t\t\t\t\tlogger,\n\t\t\t\t);\n\n\t\t\t\tconst socketUrl = response.content.deltaStreamSocketUrl;\n\t\t\t\t// expecting socketUrl to be something like https://{hostName}/...\n\t\t\t\tconst webSocketHostName = socketUrl.split(\"/\")[2];\n\n\t\t\t\t// TODO SPO-specific telemetry\n\t\t\t\tevent.end({\n\t\t\t\t\t...response.propsToLog,\n\t\t\t\t\t// pushV2 websocket urls will contain pushf\n\t\t\t\t\tpushv2: socketUrl.includes(\"pushf\"),\n\t\t\t\t\twebSocketHostName,\n\t\t\t\t\trefreshSessionDurationSeconds: response.content.refreshSessionDurationSeconds,\n\t\t\t\t});\n\n\t\t\t\tif (response.content.runtimeTenantId && !response.content.tenantId) {\n\t\t\t\t\tresponse.content.tenantId = response.content.runtimeTenantId;\n\t\t\t\t}\n\n\t\t\t\treturn response.content;\n\t\t\t},\n\t\t);\n\t},\n);\n"]}
package/lib/fetch.d.ts CHANGED
@@ -2,5 +2,9 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- export declare const fetch: (request: RequestInfo, config?: RequestInit) => Promise<Response>;
5
+ /**
6
+ * @deprecated - Do not use. This is a temporary workaround to allow Pages
7
+ * webpack replacement to continue functioning without error.
8
+ */
9
+ export declare const fetch: typeof globalThis.fetch;
6
10
  //# sourceMappingURL=fetch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,eAAO,MAAM,KAAK,YAAmB,WAAW,WAAW,WAAW,KAAG,QAAQ,QAAQ,CACC,CAAC"}
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,KAAK,yBAAmB,CAAC"}
package/lib/fetch.js CHANGED
@@ -2,9 +2,9 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { default as nodeFetch, } from "node-fetch";
6
- // The only purpose of this helper is to work around the slight misalignments between the
7
- // Browser's fetch API and the 'node-fetch' package by wrapping the call to the 'node-fetch' API
8
- // in the browser's types from 'lib.dom.d.ts'.
9
- export const fetch = async (request, config) => nodeFetch(request, config);
5
+ /**
6
+ * @deprecated - Do not use. This is a temporary workaround to allow Pages
7
+ * webpack replacement to continue functioning without error.
8
+ */
9
+ export const fetch = globalThis.fetch;
10
10
  //# sourceMappingURL=fetch.js.map
package/lib/fetch.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAGN,OAAO,IAAI,SAAS,GACpB,MAAM,YAAY,CAAC;AAEpB,yFAAyF;AACzF,gGAAgG;AAChG,8CAA8C;AAC9C,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EAAE,OAAoB,EAAE,MAAoB,EAAqB,EAAE,CAC5F,SAAS,CAAC,OAA2B,EAAE,MAA0B,CAAwB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tRequestInfo as FetchRequestInfo,\n\tRequestInit as FetchRequestInit,\n\tdefault as nodeFetch,\n} from \"node-fetch\";\n\n// The only purpose of this helper is to work around the slight misalignments between the\n// Browser's fetch API and the 'node-fetch' package by wrapping the call to the 'node-fetch' API\n// in the browser's types from 'lib.dom.d.ts'.\nexport const fetch = async (request: RequestInfo, config?: RequestInit): Promise<Response> =>\n\tnodeFetch(request as FetchRequestInfo, config as FetchRequestInit) as unknown as Response;\n"]}
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * @deprecated - Do not use. This is a temporary workaround to allow Pages\n * webpack replacement to continue functioning without error.\n */\nexport const fetch = globalThis.fetch;\n"]}
@@ -59,6 +59,6 @@ export declare function validateBlobsAndTrees(snapshot: IOdspSnapshot): void;
59
59
  * @param epochTracker - epoch tracker used to add/validate epoch in the network call.
60
60
  * @returns fetched snapshot.
61
61
  */
62
- export declare function downloadSnapshot(odspResolvedUrl: IOdspResolvedUrl, getAuthHeader: InstrumentedStorageTokenFetcher, tokenFetchOptions: TokenFetchOptionsEx, loadingGroupIds: string[] | undefined, snapshotOptions: ISnapshotOptions | undefined, snapshotFormatFetchType?: SnapshotFormatSupportType, controller?: AbortController, epochTracker?: EpochTracker, scenarioName?: string): Promise<ISnapshotRequestAndResponseOptions>;
62
+ export declare const downloadSnapshot: import("./mockify.js").Mockable<(odspResolvedUrl: IOdspResolvedUrl, getAuthHeader: InstrumentedStorageTokenFetcher, tokenFetchOptions: TokenFetchOptionsEx, loadingGroupIds: string[] | undefined, snapshotOptions: ISnapshotOptions | undefined, snapshotFormatFetchType?: SnapshotFormatSupportType, controller?: AbortController, epochTracker?: EpochTracker, scenarioName?: string) => Promise<ISnapshotRequestAndResponseOptions>>;
63
63
  export {};
64
64
  //# sourceMappingURL=fetchSnapshot.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchSnapshot.d.ts","sourceRoot":"","sources":["../src/fetchSnapshot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,SAAS,EAAiB,MAAM,6CAA6C,CAAC;AAUvF,OAAO,EAEN,gBAAgB,EAChB,gBAAgB,EAChB,+BAA+B,EAE/B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EACN,mBAAmB,EAKnB,MAAM,0CAA0C,CAAC;AAQlD,OAAO,EACN,aAAa,EAEb,wBAAwB,EAExB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAKjD,OAAO,EACN,aAAa,EASb,KAAK,mBAAmB,EACxB,MAAM,gBAAgB,CAAC;AAGxB;;;;GAIG;AACH,oBAAY,yBAAyB;IACpC,IAAI,IAAI;IACR,MAAM,IAAI;IACV,aAAa,IAAI;CACjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAClC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,iBAAiB,EAAE,OAAO,EAC1B,sCAAsC,EAAE,OAAO,EAC/C,MAAM,EAAE,mBAAmB,EAC3B,kBAAkB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,GAClE,OAAO,CAAC,SAAS,CAAC,CAkBpB;AAED,wBAAsB,uBAAuB,CAC5C,eAAe,EAAE,gBAAgB,EACjC,mBAAmB,EAAE,+BAA+B,EACpD,eAAe,EAAE,gBAAgB,GAAG,SAAS,EAC7C,sCAAsC,EAAE,OAAO,EAC/C,MAAM,EAAE,mBAAmB,EAC3B,kBAAkB,EAAE,CACnB,oBAAoB,EAAE,gBAAgB,EACtC,aAAa,EAAE,+BAA+B,EAC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rC,eAAe,EAAE,gBAAgB,GAAG,SAAS,EAC7C,UAAU,CAAC,EAAE,eAAe,KACxB,OAAO,CAAC,kCAAkC,CAAC,EAChD,UAAU,EAAE,CAAC,cAAc,EAAE,wBAAwB,KAAK,OAAO,CAAC,IAAI,CAAC,EACvE,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAClC,eAAe,EAAE,MAAM,EAAE,GAAG,SAAS,EACrC,oBAAoB,CAAC,EAAE,OAAO,GAC5B,OAAO,CAAC,SAAS,CAAC,CA2EpB;AAqYD,MAAM,WAAW,kCAAkC;IAClD,YAAY,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CAC5C;AAsCD,UAAU,UAAU;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,SAAS,GAAG,UAAU,GAAG;IAAE,gBAAgB,EAAE,MAAM,CAAA;CAAE,CAY3F;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,CASnE;AAiBD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,oDAEV,gBAAgB,iBAClB,+BAA+B,qBAC3B,mBAAmB,mBACrB,MAAM,EAAE,GAAG,SAAS,mBACpB,gBAAgB,GAAG,SAAS,4BACnB,yBAAyB,eACtC,eAAe,iBACb,YAAY,iBACZ,MAAM,KACnB,QAAQ,kCAAkC,CAAC,CA0E9C,CAAC"}
@@ -14,6 +14,7 @@ import { currentReadVersion, parseCompactSnapshotResponse, } from "./compactSnap
14
14
  import { persistedCacheValueVersion, } from "./contracts.js";
15
15
  import { getQueryString } from "./getQueryString.js";
16
16
  import { getHeadersWithAuth } from "./getUrlAndHeadersWithAuth.js";
17
+ import { mockify } from "./mockify.js";
17
18
  import { convertOdspSnapshotToSnapshotTreeAndBlobs } from "./odspSnapshotParser.js";
18
19
  import { checkForKnownServerFarmType } from "./odspUrlHelper.js";
19
20
  import { fetchAndParseAsJSONHelper, fetchHelper, getWithRetryForTokenRefresh, getWithRetryForTokenRefreshRepeat, isSnapshotFetchForLoadingGroup, measure, measureP, useLegacyFlowWithoutGroupsForSnapshotFetch, } from "./odspUtils.js";
@@ -445,13 +446,16 @@ function getTreeStatsCore(snapshotTree, stats) {
445
446
  * @param epochTracker - epoch tracker used to add/validate epoch in the network call.
446
447
  * @returns fetched snapshot.
447
448
  */
448
- export async function downloadSnapshot(odspResolvedUrl, getAuthHeader, tokenFetchOptions, loadingGroupIds, snapshotOptions, snapshotFormatFetchType, controller, epochTracker, scenarioName) {
449
+ export const downloadSnapshot = mockify(async (odspResolvedUrl, getAuthHeader, tokenFetchOptions, loadingGroupIds, snapshotOptions, snapshotFormatFetchType, controller, epochTracker, scenarioName) => {
449
450
  // back-compat: This block to be removed with #8784 when we only consume/consider odsp resolvers that are >= 0.51
450
451
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
451
452
  const sharingLinkToRedeem = odspResolvedUrl.sharingLinkToRedeem;
452
453
  if (sharingLinkToRedeem) {
453
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
454
- odspResolvedUrl.shareLinkInfo = { ...odspResolvedUrl.shareLinkInfo, sharingLinkToRedeem };
454
+ odspResolvedUrl.shareLinkInfo = {
455
+ ...odspResolvedUrl.shareLinkInfo,
456
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
457
+ sharingLinkToRedeem,
458
+ };
455
459
  }
456
460
  const snapshotUrl = odspResolvedUrl.endpoints.snapshotStorageUrl;
457
461
  const queryParams = { ump: 1 };
@@ -500,7 +504,7 @@ export async function downloadSnapshot(odspResolvedUrl, getAuthHeader, tokenFetc
500
504
  requestHeaders: headers,
501
505
  requestUrl: url,
502
506
  };
503
- }
507
+ });
504
508
  function isRedeemSharingLinkError(odspResolvedUrl, error) {
505
509
  if (odspResolvedUrl.shareLinkInfo?.sharingLinkToRedeem !== undefined &&
506
510
  typeof error === "object" &&