@fluidframework/odsp-driver 2.0.0-internal.2.2.0 → 2.0.0-internal.2.3.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.
- package/.eslintrc.js +1 -1
- package/dist/WriteBufferUtils.d.ts.map +1 -1
- package/dist/WriteBufferUtils.js +0 -1
- package/dist/WriteBufferUtils.js.map +1 -1
- package/dist/contractsPublic.d.ts.map +1 -1
- package/dist/contractsPublic.js.map +1 -1
- package/dist/createFile.d.ts +2 -6
- package/dist/createFile.d.ts.map +1 -1
- package/dist/createFile.js +13 -125
- package/dist/createFile.js.map +1 -1
- package/dist/createNewUtils.d.ts +16 -0
- package/dist/createNewUtils.d.ts.map +1 -1
- package/dist/createNewUtils.js +131 -1
- package/dist/createNewUtils.js.map +1 -1
- package/dist/fetchSnapshot.js +1 -1
- package/dist/fetchSnapshot.js.map +1 -1
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -1
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.js +1 -1
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -1
- package/dist/odspDelayLoadedDeltaStream.d.ts +75 -0
- package/dist/odspDelayLoadedDeltaStream.d.ts.map +1 -0
- package/dist/odspDelayLoadedDeltaStream.js +259 -0
- package/dist/odspDelayLoadedDeltaStream.js.map +1 -0
- package/dist/odspDocumentDeltaConnection.d.ts +1 -3
- package/dist/odspDocumentDeltaConnection.d.ts.map +1 -1
- package/dist/odspDocumentDeltaConnection.js +8 -7
- package/dist/odspDocumentDeltaConnection.js.map +1 -1
- package/dist/odspDocumentService.d.ts +10 -25
- package/dist/odspDocumentService.d.ts.map +1 -1
- package/dist/odspDocumentService.js +71 -204
- package/dist/odspDocumentService.js.map +1 -1
- package/dist/odspDocumentServiceFactory.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactory.js +1 -2
- package/dist/odspDocumentServiceFactory.js.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.d.ts +1 -3
- package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.js +3 -3
- package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
- package/dist/odspDocumentServiceFactoryWithCodeSplit.d.ts +4 -0
- package/dist/odspDocumentServiceFactoryWithCodeSplit.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactoryWithCodeSplit.js +5 -20
- package/dist/odspDocumentServiceFactoryWithCodeSplit.js.map +1 -1
- package/dist/odspDocumentStorageManager.d.ts.map +1 -1
- package/dist/odspDocumentStorageManager.js +0 -2
- package/dist/odspDocumentStorageManager.js.map +1 -1
- package/dist/odspDocumentStorageServiceBase.d.ts.map +1 -1
- package/dist/odspDocumentStorageServiceBase.js +0 -2
- package/dist/odspDocumentStorageServiceBase.js.map +1 -1
- package/dist/odspSummaryUploadManager.d.ts.map +1 -1
- package/dist/odspSummaryUploadManager.js +0 -2
- package/dist/odspSummaryUploadManager.js.map +1 -1
- package/dist/odspUtils.d.ts +10 -1
- package/dist/odspUtils.d.ts.map +1 -1
- package/dist/odspUtils.js +5 -1
- package/dist/odspUtils.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/zipItDataRepresentationUtils.d.ts.map +1 -1
- package/dist/zipItDataRepresentationUtils.js +0 -1
- package/dist/zipItDataRepresentationUtils.js.map +1 -1
- package/lib/WriteBufferUtils.d.ts.map +1 -1
- package/lib/WriteBufferUtils.js +0 -1
- package/lib/WriteBufferUtils.js.map +1 -1
- package/lib/contractsPublic.d.ts.map +1 -1
- package/lib/contractsPublic.js.map +1 -1
- package/lib/createFile.d.ts +2 -6
- package/lib/createFile.d.ts.map +1 -1
- package/lib/createFile.js +15 -126
- package/lib/createFile.js.map +1 -1
- package/lib/createNewUtils.d.ts +16 -0
- package/lib/createNewUtils.d.ts.map +1 -1
- package/lib/createNewUtils.js +129 -1
- package/lib/createNewUtils.js.map +1 -1
- package/lib/fetchSnapshot.js +1 -1
- package/lib/fetchSnapshot.js.map +1 -1
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -1
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.js +1 -1
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -1
- package/lib/odspDelayLoadedDeltaStream.d.ts +75 -0
- package/lib/odspDelayLoadedDeltaStream.d.ts.map +1 -0
- package/lib/odspDelayLoadedDeltaStream.js +255 -0
- package/lib/odspDelayLoadedDeltaStream.js.map +1 -0
- package/lib/odspDocumentDeltaConnection.d.ts +1 -3
- package/lib/odspDocumentDeltaConnection.d.ts.map +1 -1
- package/lib/odspDocumentDeltaConnection.js +8 -7
- package/lib/odspDocumentDeltaConnection.js.map +1 -1
- package/lib/odspDocumentService.d.ts +10 -25
- package/lib/odspDocumentService.d.ts.map +1 -1
- package/lib/odspDocumentService.js +56 -207
- package/lib/odspDocumentService.js.map +1 -1
- package/lib/odspDocumentServiceFactory.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactory.js +1 -2
- package/lib/odspDocumentServiceFactory.js.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.d.ts +1 -3
- package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.js +3 -3
- package/lib/odspDocumentServiceFactoryCore.js.map +1 -1
- package/lib/odspDocumentServiceFactoryWithCodeSplit.d.ts +4 -0
- package/lib/odspDocumentServiceFactoryWithCodeSplit.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactoryWithCodeSplit.js +5 -1
- package/lib/odspDocumentServiceFactoryWithCodeSplit.js.map +1 -1
- package/lib/odspDocumentStorageManager.d.ts.map +1 -1
- package/lib/odspDocumentStorageManager.js +0 -2
- package/lib/odspDocumentStorageManager.js.map +1 -1
- package/lib/odspDocumentStorageServiceBase.d.ts.map +1 -1
- package/lib/odspDocumentStorageServiceBase.js +0 -2
- package/lib/odspDocumentStorageServiceBase.js.map +1 -1
- package/lib/odspSummaryUploadManager.d.ts.map +1 -1
- package/lib/odspSummaryUploadManager.js +0 -2
- package/lib/odspSummaryUploadManager.js.map +1 -1
- package/lib/odspUtils.d.ts +10 -1
- package/lib/odspUtils.d.ts.map +1 -1
- package/lib/odspUtils.js +3 -0
- package/lib/odspUtils.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/zipItDataRepresentationUtils.d.ts.map +1 -1
- package/lib/zipItDataRepresentationUtils.js +0 -1
- package/lib/zipItDataRepresentationUtils.js.map +1 -1
- package/package.json +14 -14
- package/src/WriteBufferUtils.ts +0 -1
- package/src/contractsPublic.ts +0 -1
- package/src/createFile.ts +23 -168
- package/src/createNewUtils.ts +188 -2
- package/src/fetchSnapshot.ts +1 -1
- package/src/localOdspDriver/localOdspDocumentServiceFactory.ts +0 -1
- package/src/odspDelayLoadedDeltaStream.ts +359 -0
- package/src/odspDocumentDeltaConnection.ts +11 -8
- package/src/odspDocumentService.ts +63 -283
- package/src/odspDocumentServiceFactory.ts +0 -2
- package/src/odspDocumentServiceFactoryCore.ts +1 -3
- package/src/odspDocumentServiceFactoryWithCodeSplit.ts +4 -1
- package/src/odspDocumentStorageManager.ts +0 -4
- package/src/odspDocumentStorageServiceBase.ts +0 -3
- package/src/odspSummaryUploadManager.ts +0 -4
- package/src/odspUtils.ts +16 -1
- package/src/packageVersion.ts +1 -1
- package/src/zipItDataRepresentationUtils.ts +0 -1
- package/dist/getSocketIo.d.ts +0 -11
- package/dist/getSocketIo.d.ts.map +0 -1
- package/dist/getSocketIo.js +0 -20
- package/dist/getSocketIo.js.map +0 -1
- package/lib/getSocketIo.d.ts +0 -11
- package/lib/getSocketIo.d.ts.map +0 -1
- package/lib/getSocketIo.js +0 -13
- package/lib/getSocketIo.js.map +0 -1
- package/src/getSocketIo.ts +0 -14
package/.eslintrc.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
7
|
"extends": [
|
|
8
|
-
require.resolve("@fluidframework/eslint-config-fluid"), "prettier"
|
|
8
|
+
require.resolve("@fluidframework/eslint-config-fluid/minimal"), "prettier"
|
|
9
9
|
],
|
|
10
10
|
"parserOptions": {
|
|
11
11
|
"project": ["./tsconfig.json", "./src/test/tsconfig.json"]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WriteBufferUtils.d.ts","sourceRoot":"","sources":["../src/WriteBufferUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAOH,QAAQ,EACX,MAAM,gCAAgC,CAAC;AAExC;;;GAGG;AACH,qBAAa,WAAW;IACpB,SAAS,CAAC,IAAI,CAAC,EAAE,UAAU,CAAwB;IACnD,SAAS,CAAC,KAAK,SAAK;IAEpB,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM;IAiBpB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAI;IAWpC,IAAI,IAAI,UAAU;CAQ5B;
|
|
1
|
+
{"version":3,"file":"WriteBufferUtils.d.ts","sourceRoot":"","sources":["../src/WriteBufferUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAOH,QAAQ,EACX,MAAM,gCAAgC,CAAC;AAExC;;;GAGG;AACH,qBAAa,WAAW;IACpB,SAAS,CAAC,IAAI,CAAC,EAAE,UAAU,CAAwB;IACnD,SAAS,CAAC,KAAK,SAAK;IAEpB,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM;IAiBpB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAI;IAWpC,IAAI,IAAI,UAAU;CAQ5B;AAwDD;;;;;GAKG;AACF,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,UAezC;AA8GD,cAAM,kBAAmB,SAAQ,QAAQ;;IAK9B,SAAS,CAAC,MAAM,EAAE,WAAW;CAGvC;AAED,qBAAa,qBAAsB,SAAQ,kBAAkB;;IAKlD,SAAS,IAAI,UAAU;CAKjC"}
|
package/dist/WriteBufferUtils.js
CHANGED
|
@@ -54,7 +54,6 @@ class WriteBuffer {
|
|
|
54
54
|
exports.WriteBuffer = WriteBuffer;
|
|
55
55
|
// This list of maps below is reverse mapping of Marker Codes specified in zipItDataRepresentationUtils.ts file.
|
|
56
56
|
// We can also found them on server filestore code.
|
|
57
|
-
// eslint-disable-next-line max-len
|
|
58
57
|
// https://onedrive.visualstudio.com/SharePoint%20Online/_git/SPO?path=/cobalt/Base/Property/BinaryEncodedPropertyReader.cs&version=GBmaster&_a=contents
|
|
59
58
|
/**
|
|
60
59
|
* This contains mapping of number of bytes representing the corresponding string length to Marker Codes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WriteBufferUtils.js","sourceRoot":"","sources":["../src/WriteBufferUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AACjE,iFAQwC;AAExC;;;GAGG;AACH,MAAa,WAAW;IAAxB;QACc,SAAI,GAAgB,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QACzC,UAAK,GAAG,CAAC,CAAC;IAsCxB,CAAC;IApCa,IAAI,CAAC,IAAY;QACvB,IAAA,qBAAM,EAAC,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,KAAK,CAAC,4BAA4B,CAAC,CAAC;QACpE,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;QAChC,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM,EAAE;YACvB,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;YACpD,IAAI,KAAK,GAAG,CAAC,CAAC;YACd,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;YAC1B,OAAO,KAAK,GAAG,MAAM,EAAE;gBACnB,OAAO,CAAC,KAAK,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,MAAa,qBAAsB,SAAQ,kBAAkB;IACzD;QACI,KAAK,EAAE,CAAC;IACZ,CAAC;IAEM,SAAS;QACZ,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QACjC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxB,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;CACJ;AAVD,sDAUC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, IsoBuffer } from \"@fluidframework/common-utils\";\nimport {\n BlobCore,\n codeToBytesMap,\n getValueSafely,\n MarkerCodes,\n MarkerCodesEnd,\n MarkerCodesStart,\n NodeCore,\n} from \"./zipItDataRepresentationUtils\";\n\n/**\n * Buffer class, used to sequentially writ data.\n * Used by tree code to serialize tree into binary representation.\n */\nexport class WriteBuffer {\n protected data?: Uint8Array = new Uint8Array(4096);\n protected index = 0;\n\n protected push(code: number) {\n assert(this.data !== undefined, 0x225 /* \"Data should be there\" */);\n const length = this.data.length;\n if (this.index === length) {\n const newData = new Uint8Array(length * 1.2 + 4096);\n let index = 0;\n const oldData = this.data;\n while (index < length) {\n newData[index] = oldData[index];\n index++;\n }\n this.data = newData;\n }\n this.data[this.index] = code % 256;\n this.index++;\n }\n\n public write(codeArg: number, lengthArg = 1) {\n let code = codeArg;\n let length = lengthArg;\n while (length > 0) {\n this.push(code % 256);\n code = Math.floor(code / 256);\n length--;\n }\n assert(code === 0, 0x226 /* Should write complete data */);\n }\n\n public done(): Uint8Array {\n assert(this.data !== undefined, 0x227 /* \"Data should be there\" */);\n // We can slice it to have smaller memory representation.\n // But it will be way more expensive in terms of CPU cycles!\n const buffer = this.data.subarray(0, this.index);\n this.data = undefined;\n return buffer;\n }\n}\n\n// This list of maps below is reverse mapping of Marker Codes specified in zipItDataRepresentationUtils.ts file.\n// We can also found them on server filestore code.\n// eslint-disable-next-line max-len\n// https://onedrive.visualstudio.com/SharePoint%20Online/_git/SPO?path=/cobalt/Base/Property/BinaryEncodedPropertyReader.cs&version=GBmaster&_a=contents\n\n/**\n * This contains mapping of number of bytes representing the corresponding string length to Marker Codes.\n*/\nconst utf8StringBytesToCodeMap = {\n 0: 13,\n 1: 14,\n 2: 15,\n 4: 16,\n};\n\n/**\n * This contains mapping of number of bytes representing the corresponding length in which actual data(base64 string)\n * will be stored to Marker Codes.\n*/\nconst binaryBytesToCodeMap = {\n 0: 32,\n 1: 33,\n 2: 34,\n 4: 35,\n 8: 16,\n};\n\n/**\n * This contains mapping of number of bytes representing the corresponding const string id to Marker Codes.\n*/\nconst constStringBytesToCodeMap = {\n 1: 17,\n 2: 18,\n 4: 19,\n};\n\n/**\n * This contains mapping of number of bytes to Marker Codes representing the corresponding Integer.\n*/\nconst integerBytesToCodeMap = {\n 0: 1,\n 1: 3,\n 2: 5,\n 4: 7,\n 8: 9,\n};\n\n/**\n * This contains mapping of boolean to Marker Codes representing the corresponding bool value.\n*/\nconst boolToCodeMap = [\n 12, // false\n 11, // true\n];\n\n/**\n * Calculate how many bytes are required to encode an integer. This is always power of 2.\n * So if 6 bytes are required to store an integer than it will return 8. 0 is a special case for which we\n * return 0 as it is usually just represented by marker code and we don't store the actual data.\n * @param num - number to encode.\n */\n export function calcLength(numArg: number) {\n if (numArg === 0) {\n return 0;\n }\n let num = numArg;\n let lengthLen = 0;\n while (num > 0) {\n num = Math.floor(num / 256);\n lengthLen++;\n }\n let res = 1;\n while (res < lengthLen) {\n res *= 2;\n }\n return res;\n}\n\n/**\n * Implementation of serialization of blobs in buffer with Marker Codes etc.\n * @param buffer - Buffer to serialize to.\n * @param content - string to be serialized.\n * @param dictionary - Const strings dictionary to be used while serializing.\n */\n function serializeDictionaryString(buffer: WriteBuffer, content: string, dictionary: Map<string, number>) {\n let id = dictionary.get(content);\n let idLength: number;\n if (id === undefined) {\n const data = IsoBuffer.from(content, \"utf8\");\n const lengthOfDataLen = calcLength(data.length);\n\n id = dictionary.size + 1;\n idLength = calcLength(id);\n dictionary.set(content, id);\n const code = lengthOfDataLen > 1 || idLength > 1\n ? MarkerCodes.ConstStringDeclareBig\n : MarkerCodes.ConstStringDeclare;\n // Write marker code for const string.\n buffer.write(code);\n const bytes = getValueSafely(codeToBytesMap, code);\n assert(bytes >= lengthOfDataLen, 0x283 /* \"Length of data len should fit in the bytes from the map\" */);\n assert(bytes >= idLength, 0x284 /* \"Length of id should fit in the bytes from the map\" */);\n // Assign and write id for const string.\n buffer.write(id, bytes);\n // Write length of const string.\n buffer.write(data.length, bytes);\n // Write const string data.\n for (const element of data) {\n buffer.write(element);\n }\n } else {\n idLength = calcLength(id);\n }\n // Write Marker Code\n buffer.write(getValueSafely(constStringBytesToCodeMap, idLength));\n // Write id of const string\n buffer.write(id, idLength);\n}\n\nfunction serializeString(buffer: WriteBuffer, content: string, codeMap = binaryBytesToCodeMap) {\n serializeBlob(\n buffer,\n IsoBuffer.from(content, \"utf8\"),\n utf8StringBytesToCodeMap);\n}\n\n/**\n * Implementation of serialization of blobs in buffer with Marker Codes etc.\n * @param buffer - Buffer to serialize to.\n * @param blob - blob to be serialized.\n * @param dictionary - Const strings dictionary to be used while serializing.\n */\nfunction serializeBlob(buffer: WriteBuffer, data: Uint8Array, codeMap: Record<number, number> = binaryBytesToCodeMap) {\n const lengthOfDataLen = calcLength(data.length);\n // Write Marker code.\n buffer.write(getValueSafely(codeMap, lengthOfDataLen));\n // Write actual data if length greater than 0, otherwise Marker Code is enough.\n if (lengthOfDataLen > 0) {\n buffer.write(data.length, lengthOfDataLen);\n for (const element of data) {\n buffer.write(element);\n }\n }\n}\n\n/**\n * Implementation of serialization of nodes with Marker Codes etc.\n * @param buffer - Buffer to serialize to.\n * @param nodeCore - Node to be serialized.\n * @param dictionary - Const strings dictionary to be used while serializing.\n */\nfunction serializeNodeCore(buffer: WriteBuffer, nodeCore: NodeCore, dictionary: Map<string, number>) {\n for (const child of nodeCore.nodes) {\n if (child instanceof NodeCore) {\n // For a tree node start and end with set/list start and end marker codes.\n const startCode = MarkerCodesStart[child.type];\n const endCode = MarkerCodesEnd[child.type];\n assert(startCode !== undefined, 0x285 /* \"Start code should not undefined\" */);\n assert(endCode !== undefined, 0x286 /* \"End code should not undefined\" */);\n buffer.write(startCode);\n serializeNodeCore(buffer, child, dictionary);\n buffer.write(endCode);\n } else if (child instanceof BlobCore) {\n serializeBlob(buffer, child.buffer);\n } else if (typeof child === \"number\") {\n // Calculate length in which integer will be stored\n const len = calcLength(child);\n // Write corresponding Marker code for length of integer.\n buffer.write(getValueSafely(integerBytesToCodeMap, len));\n // Write actual number if greater than 0, otherwise Marker Code is enough.\n if (len > 0) {\n buffer.write(child, len);\n }\n } else if (typeof child === \"boolean\") {\n buffer.write(boolToCodeMap[child ? 1 : 0]);\n } else {\n assert(child._stringElement, 0x3dd /* Unsupported node type */);\n if (child.dictionary) {\n serializeDictionaryString(buffer, child.content, dictionary);\n } else {\n serializeString(buffer, child.content);\n }\n }\n }\n}\n\nclass NodeCoreSerializer extends NodeCore {\n constructor() {\n super();\n }\n\n public serialize(buffer: WriteBuffer) {\n serializeNodeCore(buffer, this, new Map<string, number>());\n }\n}\n\nexport class TreeBuilderSerializer extends NodeCoreSerializer {\n constructor() {\n super();\n }\n\n public serialize(): Uint8Array {\n const buffer = new WriteBuffer();\n super.serialize(buffer);\n return buffer.done();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"WriteBufferUtils.js","sourceRoot":"","sources":["../src/WriteBufferUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AACjE,iFAQwC;AAExC;;;GAGG;AACH,MAAa,WAAW;IAAxB;QACc,SAAI,GAAgB,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QACzC,UAAK,GAAG,CAAC,CAAC;IAsCxB,CAAC;IApCa,IAAI,CAAC,IAAY;QACvB,IAAA,qBAAM,EAAC,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,KAAK,CAAC,4BAA4B,CA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OAAO,EAAE,UAAU,CAAC,CAAC;aAChE;iBAAM;gBACH,eAAe,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;aAC1C;SACJ;KACJ;AACL,CAAC;AAED,MAAM,kBAAmB,SAAQ,uCAAQ;IACrC;QACI,KAAK,EAAE,CAAC;IACZ,CAAC;IAEM,SAAS,CAAC,MAAmB;QAChC,iBAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,EAAkB,CAAC,CAAC;IAC/D,CAAC;CACJ;AAED,MAAa,qBAAsB,SAAQ,kBAAkB;IACzD;QACI,KAAK,EAAE,CAAC;IACZ,CAAC;IAEM,SAAS;QACZ,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QACjC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxB,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;CACJ;AAVD,sDAUC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, IsoBuffer } from \"@fluidframework/common-utils\";\nimport {\n BlobCore,\n codeToBytesMap,\n getValueSafely,\n MarkerCodes,\n MarkerCodesEnd,\n MarkerCodesStart,\n NodeCore,\n} from \"./zipItDataRepresentationUtils\";\n\n/**\n * Buffer class, used to sequentially writ data.\n * Used by tree code to serialize tree into binary representation.\n */\nexport class WriteBuffer {\n protected data?: Uint8Array = new Uint8Array(4096);\n protected index = 0;\n\n protected push(code: number) {\n assert(this.data !== undefined, 0x225 /* \"Data should be there\" */);\n const length = this.data.length;\n if (this.index === length) {\n const newData = new Uint8Array(length * 1.2 + 4096);\n let index = 0;\n const oldData = this.data;\n while (index < length) {\n newData[index] = oldData[index];\n index++;\n }\n this.data = newData;\n }\n this.data[this.index] = code % 256;\n this.index++;\n }\n\n public write(codeArg: number, lengthArg = 1) {\n let code = codeArg;\n let length = lengthArg;\n while (length > 0) {\n this.push(code % 256);\n code = Math.floor(code / 256);\n length--;\n }\n assert(code === 0, 0x226 /* Should write complete data */);\n }\n\n public done(): Uint8Array {\n assert(this.data !== undefined, 0x227 /* \"Data should be there\" */);\n // We can slice it to have smaller memory representation.\n // But it will be way more expensive in terms of CPU cycles!\n const buffer = this.data.subarray(0, this.index);\n this.data = undefined;\n return buffer;\n }\n}\n\n// This list of maps below is reverse mapping of Marker Codes specified in zipItDataRepresentationUtils.ts file.\n// We can also found them on server filestore code.\n// https://onedrive.visualstudio.com/SharePoint%20Online/_git/SPO?path=/cobalt/Base/Property/BinaryEncodedPropertyReader.cs&version=GBmaster&_a=contents\n\n/**\n * This contains mapping of number of bytes representing the corresponding string length to Marker Codes.\n*/\nconst utf8StringBytesToCodeMap = {\n 0: 13,\n 1: 14,\n 2: 15,\n 4: 16,\n};\n\n/**\n * This contains mapping of number of bytes representing the corresponding length in which actual data(base64 string)\n * will be stored to Marker Codes.\n*/\nconst binaryBytesToCodeMap = {\n 0: 32,\n 1: 33,\n 2: 34,\n 4: 35,\n 8: 16,\n};\n\n/**\n * This contains mapping of number of bytes representing the corresponding const string id to Marker Codes.\n*/\nconst constStringBytesToCodeMap = {\n 1: 17,\n 2: 18,\n 4: 19,\n};\n\n/**\n * This contains mapping of number of bytes to Marker Codes representing the corresponding Integer.\n*/\nconst integerBytesToCodeMap = {\n 0: 1,\n 1: 3,\n 2: 5,\n 4: 7,\n 8: 9,\n};\n\n/**\n * This contains mapping of boolean to Marker Codes representing the corresponding bool value.\n*/\nconst boolToCodeMap = [\n 12, // false\n 11, // true\n];\n\n/**\n * Calculate how many bytes are required to encode an integer. This is always power of 2.\n * So if 6 bytes are required to store an integer than it will return 8. 0 is a special case for which we\n * return 0 as it is usually just represented by marker code and we don't store the actual data.\n * @param num - number to encode.\n */\n export function calcLength(numArg: number) {\n if (numArg === 0) {\n return 0;\n }\n let num = numArg;\n let lengthLen = 0;\n while (num > 0) {\n num = Math.floor(num / 256);\n lengthLen++;\n }\n let res = 1;\n while (res < lengthLen) {\n res *= 2;\n }\n return res;\n}\n\n/**\n * Implementation of serialization of blobs in buffer with Marker Codes etc.\n * @param buffer - Buffer to serialize to.\n * @param content - string to be serialized.\n * @param dictionary - Const strings dictionary to be used while serializing.\n */\n function serializeDictionaryString(buffer: WriteBuffer, content: string, dictionary: Map<string, number>) {\n let id = dictionary.get(content);\n let idLength: number;\n if (id === undefined) {\n const data = IsoBuffer.from(content, \"utf8\");\n const lengthOfDataLen = calcLength(data.length);\n\n id = dictionary.size + 1;\n idLength = calcLength(id);\n dictionary.set(content, id);\n const code = lengthOfDataLen > 1 || idLength > 1\n ? MarkerCodes.ConstStringDeclareBig\n : MarkerCodes.ConstStringDeclare;\n // Write marker code for const string.\n buffer.write(code);\n const bytes = getValueSafely(codeToBytesMap, code);\n assert(bytes >= lengthOfDataLen, 0x283 /* \"Length of data len should fit in the bytes from the map\" */);\n assert(bytes >= idLength, 0x284 /* \"Length of id should fit in the bytes from the map\" */);\n // Assign and write id for const string.\n buffer.write(id, bytes);\n // Write length of const string.\n buffer.write(data.length, bytes);\n // Write const string data.\n for (const element of data) {\n buffer.write(element);\n }\n } else {\n idLength = calcLength(id);\n }\n // Write Marker Code\n buffer.write(getValueSafely(constStringBytesToCodeMap, idLength));\n // Write id of const string\n buffer.write(id, idLength);\n}\n\nfunction serializeString(buffer: WriteBuffer, content: string, codeMap = binaryBytesToCodeMap) {\n serializeBlob(\n buffer,\n IsoBuffer.from(content, \"utf8\"),\n utf8StringBytesToCodeMap);\n}\n\n/**\n * Implementation of serialization of blobs in buffer with Marker Codes etc.\n * @param buffer - Buffer to serialize to.\n * @param blob - blob to be serialized.\n * @param dictionary - Const strings dictionary to be used while serializing.\n */\nfunction serializeBlob(buffer: WriteBuffer, data: Uint8Array, codeMap: Record<number, number> = binaryBytesToCodeMap) {\n const lengthOfDataLen = calcLength(data.length);\n // Write Marker code.\n buffer.write(getValueSafely(codeMap, lengthOfDataLen));\n // Write actual data if length greater than 0, otherwise Marker Code is enough.\n if (lengthOfDataLen > 0) {\n buffer.write(data.length, lengthOfDataLen);\n for (const element of data) {\n buffer.write(element);\n }\n }\n}\n\n/**\n * Implementation of serialization of nodes with Marker Codes etc.\n * @param buffer - Buffer to serialize to.\n * @param nodeCore - Node to be serialized.\n * @param dictionary - Const strings dictionary to be used while serializing.\n */\nfunction serializeNodeCore(buffer: WriteBuffer, nodeCore: NodeCore, dictionary: Map<string, number>) {\n for (const child of nodeCore.nodes) {\n if (child instanceof NodeCore) {\n // For a tree node start and end with set/list start and end marker codes.\n const startCode = MarkerCodesStart[child.type];\n const endCode = MarkerCodesEnd[child.type];\n assert(startCode !== undefined, 0x285 /* \"Start code should not undefined\" */);\n assert(endCode !== undefined, 0x286 /* \"End code should not undefined\" */);\n buffer.write(startCode);\n serializeNodeCore(buffer, child, dictionary);\n buffer.write(endCode);\n } else if (child instanceof BlobCore) {\n serializeBlob(buffer, child.buffer);\n } else if (typeof child === \"number\") {\n // Calculate length in which integer will be stored\n const len = calcLength(child);\n // Write corresponding Marker code for length of integer.\n buffer.write(getValueSafely(integerBytesToCodeMap, len));\n // Write actual number if greater than 0, otherwise Marker Code is enough.\n if (len > 0) {\n buffer.write(child, len);\n }\n } else if (typeof child === \"boolean\") {\n buffer.write(boolToCodeMap[child ? 1 : 0]);\n } else {\n assert(child._stringElement, 0x3dd /* Unsupported node type */);\n if (child.dictionary) {\n serializeDictionaryString(buffer, child.content, dictionary);\n } else {\n serializeString(buffer, child.content);\n }\n }\n }\n}\n\nclass NodeCoreSerializer extends NodeCore {\n constructor() {\n super();\n }\n\n public serialize(buffer: WriteBuffer) {\n serializeNodeCore(buffer, this, new Map<string, number>());\n }\n}\n\nexport class TreeBuilderSerializer extends NodeCoreSerializer {\n constructor() {\n super();\n }\n\n public serialize(): Uint8Array {\n const buffer = new WriteBuffer();\n super.serialize(buffer);\n return buffer.done();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contractsPublic.d.ts","sourceRoot":"","sources":["../src/contractsPublic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,MAAM,WAAW,yBAA0B,SAAQ,aAAa;IAC5D,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,oBAAY,iBAAiB;IAGzB,qBAAqB,0BAA0B;CAClD;AAED,MAAM,WAAW,kBAAkB;IAC/B,CAAC,iBAAiB,CAAC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACtD;AAED,oBAAY,qBAAqB;IAG7B,iBAAiB,wBAAwB;CAC5C;AAED,MAAM,WAAW,sBAAsB;IACnC,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CACtD;AAED,OAAO,QAAQ,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"contractsPublic.d.ts","sourceRoot":"","sources":["../src/contractsPublic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,MAAM,WAAW,yBAA0B,SAAQ,aAAa;IAC5D,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,oBAAY,iBAAiB;IAGzB,qBAAqB,0BAA0B;CAClD;AAED,MAAM,WAAW,kBAAkB;IAC/B,CAAC,iBAAiB,CAAC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACtD;AAED,oBAAY,qBAAqB;IAG7B,iBAAiB,wBAAwB;CAC5C;AAED,MAAM,WAAW,sBAAsB;IACnC,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CACtD;AAED,OAAO,QAAQ,iCAAiC,CAAC;IAC7C,UAAiB,cAAe,SAAQ,OAAO,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC;KAAI;CAC3G"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contractsPublic.js","sourceRoot":"","sources":["../src/contractsPublic.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAYH,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IACzB,yGAAyG;IACzG,sDAAsD;IACtD,oEAA+C,CAAA;AACnD,CAAC,EAJW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAI5B;AAMD,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC7B,oGAAoG;IACpG,wGAAwG;IACxG,kEAAyC,CAAA;AAC7C,CAAC,EAJW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAIhC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IOdspUrlParts } from \"@fluidframework/odsp-driver-definitions\";\n\nexport interface OdspFluidDataStoreLocator extends IOdspUrlParts {\n dataStorePath: string;\n appName?: string;\n containerPackageName?: string;\n fileVersion?: string;\n context?: string;\n}\n\nexport enum SharingLinkHeader {\n // Can be used in request made to resolver, to tell the resolver that the passed in URL is a sharing link\n // which can be redeemed at server to get permissions.\n isSharingLinkToRedeem = \"isSharingLinkToRedeem\",\n}\n\nexport interface ISharingLinkHeader {\n [SharingLinkHeader.isSharingLinkToRedeem]: boolean;\n}\n\nexport enum ClpCompliantAppHeader {\n // Can be used in request made to resolver, to tell the resolver that the host app is CLP compliant.\n // Odsp will not return Classified, labeled, or protected documents if the host app cannot support them.\n isClpCompliantApp = \"X-CLP-Compliant-App\",\n}\n\nexport interface IClpCompliantAppHeader {\n [ClpCompliantAppHeader.isClpCompliantApp]: boolean;\n}\n\ndeclare module \"@fluidframework/core-interfaces\" {\n
|
|
1
|
+
{"version":3,"file":"contractsPublic.js","sourceRoot":"","sources":["../src/contractsPublic.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAYH,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IACzB,yGAAyG;IACzG,sDAAsD;IACtD,oEAA+C,CAAA;AACnD,CAAC,EAJW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAI5B;AAMD,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC7B,oGAAoG;IACpG,wGAAwG;IACxG,kEAAyC,CAAA;AAC7C,CAAC,EAJW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAIhC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IOdspUrlParts } from \"@fluidframework/odsp-driver-definitions\";\n\nexport interface OdspFluidDataStoreLocator extends IOdspUrlParts {\n dataStorePath: string;\n appName?: string;\n containerPackageName?: string;\n fileVersion?: string;\n context?: string;\n}\n\nexport enum SharingLinkHeader {\n // Can be used in request made to resolver, to tell the resolver that the passed in URL is a sharing link\n // which can be redeemed at server to get permissions.\n isSharingLinkToRedeem = \"isSharingLinkToRedeem\",\n}\n\nexport interface ISharingLinkHeader {\n [SharingLinkHeader.isSharingLinkToRedeem]: boolean;\n}\n\nexport enum ClpCompliantAppHeader {\n // Can be used in request made to resolver, to tell the resolver that the host app is CLP compliant.\n // Odsp will not return Classified, labeled, or protected documents if the host app cannot support them.\n isClpCompliantApp = \"X-CLP-Compliant-App\",\n}\n\nexport interface IClpCompliantAppHeader {\n [ClpCompliantAppHeader.isClpCompliantApp]: boolean;\n}\n\ndeclare module \"@fluidframework/core-interfaces\" {\n export interface IRequestHeader extends Partial<ISharingLinkHeader>, Partial<IClpCompliantAppHeader> { }\n}\n"]}
|
package/dist/createFile.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { ISummaryTree } from "@fluidframework/protocol-definitions";
|
|
6
6
|
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { InstrumentedStorageTokenFetcher, IOdspResolvedUrl, IFileEntry } from "@fluidframework/odsp-driver-definitions";
|
|
8
|
+
import { ICreateFileResponse } from "./contracts";
|
|
9
9
|
import { INewFileInfo } from "./odspUtils";
|
|
10
10
|
import { EpochTracker } from "./epochTracker";
|
|
11
11
|
/**
|
|
@@ -15,8 +15,4 @@ import { EpochTracker } from "./epochTracker";
|
|
|
15
15
|
export declare function createNewFluidFile(getStorageToken: InstrumentedStorageTokenFetcher, newFileInfo: INewFileInfo, logger: ITelemetryLogger, createNewSummary: ISummaryTree | undefined, epochTracker: EpochTracker, fileEntry: IFileEntry, createNewCaching: boolean, forceAccessTokenViaAuthorizationHeader: boolean, isClpCompliantApp?: boolean, enableSingleRequestForShareLinkWithCreate?: boolean, enableShareLinkWithCreate?: boolean): Promise<IOdspResolvedUrl>;
|
|
16
16
|
export declare function createNewEmptyFluidFile(getStorageToken: InstrumentedStorageTokenFetcher, newFileInfo: INewFileInfo, logger: ITelemetryLogger, epochTracker: EpochTracker, forceAccessTokenViaAuthorizationHeader: boolean): Promise<string>;
|
|
17
17
|
export declare function createNewFluidFileFromSummary(getStorageToken: InstrumentedStorageTokenFetcher, newFileInfo: INewFileInfo, logger: ITelemetryLogger, createNewSummary: ISummaryTree, epochTracker: EpochTracker, forceAccessTokenViaAuthorizationHeader: boolean): Promise<ICreateFileResponse>;
|
|
18
|
-
/**
|
|
19
|
-
* Converts a summary tree to ODSP tree
|
|
20
|
-
*/
|
|
21
|
-
export declare function convertSummaryToSnapshotTreeForCreateNew(summary: ISummaryTree): IOdspSummaryTree;
|
|
22
18
|
//# sourceMappingURL=createFile.d.ts.map
|
package/dist/createFile.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFile.d.ts","sourceRoot":"","sources":["../src/createFile.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"createFile.d.ts","sourceRoot":"","sources":["../src/createFile.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,OAAO,EACH,+BAA+B,EAC/B,gBAAgB,EAKhB,UAAU,EACb,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EACH,mBAAmB,EACtB,MAAM,aAAa,CAAC;AAErB,OAAO,EAIH,YAAY,EAEf,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAY9C;;;GAGG;AACH,wBAAsB,kBAAkB,CACpC,eAAe,EAAE,+BAA+B,EAChD,WAAW,EAAE,YAAY,EACzB,MAAM,EAAE,gBAAgB,EACxB,gBAAgB,EAAE,YAAY,GAAG,SAAS,EAC1C,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,UAAU,EACrB,gBAAgB,EAAE,OAAO,EACzB,sCAAsC,EAAE,OAAO,EAC/C,iBAAiB,CAAC,EAAE,OAAO,EAC3B,yCAAyC,CAAC,EAAE,OAAO,EACnD,yBAAyB,CAAC,EAAE,OAAO,GACpC,OAAO,CAAC,gBAAgB,CAAC,CAoD3B;AAyDD,wBAAsB,uBAAuB,CACzC,eAAe,EAAE,+BAA+B,EAChD,WAAW,EAAE,YAAY,EACzB,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,YAAY,EAC1B,sCAAsC,EAAE,OAAO,GAChD,OAAO,CAAC,MAAM,CAAC,CAiDjB;AAED,wBAAsB,6BAA6B,CAC/C,eAAe,EAAE,+BAA+B,EAChD,WAAW,EAAE,YAAY,EACzB,MAAM,EAAE,gBAAgB,EACxB,gBAAgB,EAAE,YAAY,EAC9B,YAAY,EAAE,YAAY,EAC1B,sCAAsC,EAAE,OAAO,GAChD,OAAO,CAAC,mBAAmB,CAAC,CAiC9B"}
|
package/dist/createFile.js
CHANGED
|
@@ -4,12 +4,9 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
8
|
-
const uuid_1 = require("uuid");
|
|
7
|
+
exports.createNewFluidFileFromSummary = exports.createNewEmptyFluidFile = exports.createNewFluidFile = void 0;
|
|
9
8
|
const common_utils_1 = require("@fluidframework/common-utils");
|
|
10
9
|
const driver_utils_1 = require("@fluidframework/driver-utils");
|
|
11
|
-
const protocol_base_1 = require("@fluidframework/protocol-base");
|
|
12
|
-
const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
13
10
|
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
14
11
|
const odsp_driver_definitions_1 = require("@fluidframework/odsp-driver-definitions");
|
|
15
12
|
const driver_definitions_1 = require("@fluidframework/driver-definitions");
|
|
@@ -145,135 +142,26 @@ async function createNewFluidFileFromSummary(getStorageToken, newFileInfo, logge
|
|
|
145
142
|
const encodedFilename = encodeURIComponent(newFileInfo.filename);
|
|
146
143
|
const baseUrl = `${(0, odspUrlHelper_1.getApiRoot)((0, odspUtils_1.getOrigin)(newFileInfo.siteUrl))}/drives/${newFileInfo.driveId}/items/root:` +
|
|
147
144
|
`${filePath}/${encodedFilename}`;
|
|
148
|
-
const containerSnapshot = convertSummaryIntoContainerSnapshot(createNewSummary);
|
|
145
|
+
const containerSnapshot = (0, createNewUtils_1.convertSummaryIntoContainerSnapshot)(createNewSummary);
|
|
149
146
|
// Build share link parameter based on the createLinkType provided so that the
|
|
150
147
|
// snapshot api can create and return the share link along with creation of file in the response.
|
|
151
148
|
const createShareLinkParam = (0, odspUtils_1.buildOdspShareLinkReqParams)(newFileInfo.createLinkType);
|
|
152
149
|
const initialUrl = `${baseUrl}:/opStream/snapshots/snapshot${createShareLinkParam ? `?${createShareLinkParam}` : ""}`;
|
|
153
|
-
return (0,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
postBody += `X-HTTP-Method-Override: POST\r\n`;
|
|
164
|
-
postBody += `Content-Type: application/json\r\n`;
|
|
165
|
-
postBody += `_post: 1\r\n`;
|
|
166
|
-
postBody += `\r\n${snapshotBody}\r\n`;
|
|
167
|
-
postBody += `\r\n--${formBoundary}--`;
|
|
168
|
-
if (postBody.length <= odspUtils_1.maxUmpPostBodySize) {
|
|
169
|
-
const urlObj = new URL(initialUrl);
|
|
170
|
-
urlObj.searchParams.set("ump", "1");
|
|
171
|
-
url = urlObj.href;
|
|
172
|
-
headers = {
|
|
173
|
-
"Content-Type": `multipart/form-data;boundary=${formBoundary}`,
|
|
174
|
-
};
|
|
175
|
-
addInBody = true;
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
const parts = (0, getUrlAndHeadersWithAuth_1.getUrlAndHeadersWithAuth)(initialUrl, storageToken, forceAccessTokenViaAuthorizationHeader);
|
|
179
|
-
url = parts.url;
|
|
180
|
-
headers = Object.assign(Object.assign({}, parts.headers), { "Content-Type": "application/json" });
|
|
181
|
-
postBody = snapshotBody;
|
|
182
|
-
}
|
|
183
|
-
const fetchResponse = await (0, retryUtils_1.runWithRetry)(async () => epochTracker.fetchAndParseAsJSON(url, {
|
|
184
|
-
body: postBody,
|
|
185
|
-
headers,
|
|
186
|
-
method: "POST",
|
|
187
|
-
}, "createFile", addInBody), "createFile", logger);
|
|
188
|
-
const content = fetchResponse.content;
|
|
150
|
+
return (0, createNewUtils_1.createNewFluidContainerCore)({
|
|
151
|
+
containerSnapshot,
|
|
152
|
+
getStorageToken,
|
|
153
|
+
logger,
|
|
154
|
+
initialUrl,
|
|
155
|
+
forceAccessTokenViaAuthorizationHeader,
|
|
156
|
+
epochTracker,
|
|
157
|
+
telemetryName: "CreateNewFile",
|
|
158
|
+
fetchType: "createFile",
|
|
159
|
+
validateResponseCallback: content => {
|
|
189
160
|
if (!content || !content.itemId) {
|
|
190
161
|
throw new driver_utils_1.NonRetryableError("ODSP CreateFile call returned no item ID", driver_definitions_1.DriverErrorType.incorrectServerResponse, { driverVersion: packageVersion_1.pkgVersion });
|
|
191
162
|
}
|
|
192
|
-
|
|
193
|
-
return content;
|
|
194
|
-
});
|
|
163
|
+
}
|
|
195
164
|
});
|
|
196
165
|
}
|
|
197
166
|
exports.createNewFluidFileFromSummary = createNewFluidFileFromSummary;
|
|
198
|
-
function convertSummaryIntoContainerSnapshot(createNewSummary) {
|
|
199
|
-
var _a;
|
|
200
|
-
const appSummary = createNewSummary.tree[".app"];
|
|
201
|
-
const protocolSummary = createNewSummary.tree[".protocol"];
|
|
202
|
-
if (!(appSummary && protocolSummary)) {
|
|
203
|
-
throw new Error("App and protocol summary required for create new path!!");
|
|
204
|
-
}
|
|
205
|
-
const documentAttributes = (0, driver_utils_1.getDocAttributesFromProtocolSummary)(protocolSummary);
|
|
206
|
-
const attributesSummaryBlob = {
|
|
207
|
-
type: protocol_definitions_1.SummaryType.Blob,
|
|
208
|
-
content: JSON.stringify(documentAttributes),
|
|
209
|
-
};
|
|
210
|
-
protocolSummary.tree.attributes = attributesSummaryBlob;
|
|
211
|
-
const convertedCreateNewSummary = {
|
|
212
|
-
type: protocol_definitions_1.SummaryType.Tree,
|
|
213
|
-
tree: {
|
|
214
|
-
".protocol": protocolSummary,
|
|
215
|
-
".app": appSummary,
|
|
216
|
-
},
|
|
217
|
-
};
|
|
218
|
-
const snapshotTree = convertSummaryToSnapshotTreeForCreateNew(convertedCreateNewSummary);
|
|
219
|
-
const snapshot = {
|
|
220
|
-
entries: (_a = snapshotTree.entries) !== null && _a !== void 0 ? _a : [],
|
|
221
|
-
message: "app",
|
|
222
|
-
sequenceNumber: documentAttributes.sequenceNumber,
|
|
223
|
-
type: "container",
|
|
224
|
-
};
|
|
225
|
-
return snapshot;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Converts a summary tree to ODSP tree
|
|
229
|
-
*/
|
|
230
|
-
function convertSummaryToSnapshotTreeForCreateNew(summary) {
|
|
231
|
-
var _a;
|
|
232
|
-
const snapshotTree = {
|
|
233
|
-
type: "tree",
|
|
234
|
-
entries: [],
|
|
235
|
-
};
|
|
236
|
-
const keys = Object.keys(summary.tree);
|
|
237
|
-
for (const key of keys) {
|
|
238
|
-
const summaryObject = summary.tree[key];
|
|
239
|
-
let value;
|
|
240
|
-
// Tracks if an entry is unreferenced. Currently, only tree entries can be marked as unreferenced. If the
|
|
241
|
-
// property is not present, the tree entry is considered referenced. If the property is present and is true,
|
|
242
|
-
// the tree entry is considered unreferenced.
|
|
243
|
-
let unreferenced;
|
|
244
|
-
switch (summaryObject.type) {
|
|
245
|
-
case protocol_definitions_1.SummaryType.Tree: {
|
|
246
|
-
value = convertSummaryToSnapshotTreeForCreateNew(summaryObject);
|
|
247
|
-
unreferenced = summaryObject.unreferenced;
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
250
|
-
case protocol_definitions_1.SummaryType.Blob: {
|
|
251
|
-
const content = typeof summaryObject.content === "string" ?
|
|
252
|
-
summaryObject.content : (0, common_utils_1.Uint8ArrayToString)(summaryObject.content, "base64");
|
|
253
|
-
const encoding = typeof summaryObject.content === "string" ? "utf-8" : "base64";
|
|
254
|
-
value = {
|
|
255
|
-
type: "blob",
|
|
256
|
-
content,
|
|
257
|
-
encoding,
|
|
258
|
-
};
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
case protocol_definitions_1.SummaryType.Handle: {
|
|
262
|
-
throw new Error("No handle should be present for first summary!!");
|
|
263
|
-
}
|
|
264
|
-
default: {
|
|
265
|
-
throw new Error(`Unknown tree type ${summaryObject.type}`);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
const entry = {
|
|
269
|
-
path: encodeURIComponent(key),
|
|
270
|
-
type: (0, protocol_base_1.getGitType)(summaryObject),
|
|
271
|
-
value,
|
|
272
|
-
unreferenced,
|
|
273
|
-
};
|
|
274
|
-
(_a = snapshotTree.entries) === null || _a === void 0 ? void 0 : _a.push(entry);
|
|
275
|
-
}
|
|
276
|
-
return snapshotTree;
|
|
277
|
-
}
|
|
278
|
-
exports.convertSummaryToSnapshotTreeForCreateNew = convertSummaryToSnapshotTreeForCreateNew;
|
|
279
167
|
//# sourceMappingURL=createFile.js.map
|
package/dist/createFile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFile.js","sourceRoot":"","sources":["../src/createFile.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAkC;AAClC,+DAA0E;AAC1E,+DAAsG;AACtG,iEAA2D;AAC3D,+EAA+F;AAE/F,qEAAmE;AACnE,qFAQiD;AACjD,2EAAqE;AAQrE,yEAAsE;AACtE,2CAOqB;AAErB,mDAAgD;AAChD,mDAA6C;AAE7C,mEAAgE;AAChE,qDAA6E;AAC7E,6CAA4C;AAC5C,qDAA+D;AAC/D,uDAA0D;AAE1D,MAAM,iBAAiB,GAAG,CAAC,QAAgB,EAAW,EAAE;IACpD,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;IAC3C,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF;;;GAGG;AACI,KAAK,UAAU,kBAAkB,CACpC,eAAgD,EAChD,WAAyB,EACzB,MAAwB,EACxB,gBAA0C,EAC1C,YAA0B,EAC1B,SAAqB,EACrB,gBAAyB,EACzB,sCAA+C,EAC/C,iBAA2B,EAC3B,yCAAmD,EACnD,yBAAmC;IAEnC,+EAA+E;IAC/E,IAAI,iBAAiB,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE;QACzC,MAAM,IAAI,gCAAiB;QACvB,2CAA2C;QAC3C,gCAAg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4FAoDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { assert, Uint8ArrayToString } from \"@fluidframework/common-utils\";\nimport { getDocAttributesFromProtocolSummary, NonRetryableError } from \"@fluidframework/driver-utils\";\nimport { getGitType } from \"@fluidframework/protocol-base\";\nimport { SummaryType, ISummaryTree, ISummaryBlob } from \"@fluidframework/protocol-definitions\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n IFileEntry,\n InstrumentedStorageTokenFetcher,\n IOdspResolvedUrl,\n OdspErrorType,\n ShareLinkInfoType,\n ISharingLinkKind,\n ShareLinkTypes,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport {\n IOdspSummaryTree,\n OdspSummaryTreeValue,\n OdspSummaryTreeEntry,\n ICreateFileResponse,\n IOdspSummaryPayload,\n} from \"./contracts\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth\";\nimport {\n buildOdspShareLinkReqParams,\n createCacheSnapshotKey,\n getWithRetryForTokenRefresh,\n INewFileInfo,\n getOrigin,\n maxUmpPostBodySize,\n} from \"./odspUtils\";\nimport { ISnapshotContents } from \"./odspPublicUtils\";\nimport { createOdspUrl } from \"./createOdspUrl\";\nimport { getApiRoot } from \"./odspUrlHelper\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { OdspDriverUrlResolver } from \"./odspDriverUrlResolver\";\nimport { convertCreateNewSummaryTreeToTreeAndBlobs } from \"./createNewUtils\";\nimport { runWithRetry } from \"./retryUtils\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\nimport { ClpCompliantAppHeader } from \"./contractsPublic\";\n\nconst isInvalidFileName = (fileName: string): boolean => {\n const invalidCharsRegex = /[\"*/:<>?\\\\|]+/g;\n return !!fileName.match(invalidCharsRegex);\n};\n\n/**\n * Creates a new Fluid file.\n * Returns resolved url\n */\nexport async function createNewFluidFile(\n getStorageToken: InstrumentedStorageTokenFetcher,\n newFileInfo: INewFileInfo,\n logger: ITelemetryLogger,\n createNewSummary: ISummaryTree | undefined,\n epochTracker: EpochTracker,\n fileEntry: IFileEntry,\n createNewCaching: boolean,\n forceAccessTokenViaAuthorizationHeader: boolean,\n isClpCompliantApp?: boolean,\n enableSingleRequestForShareLinkWithCreate?: boolean,\n enableShareLinkWithCreate?: boolean,\n): Promise<IOdspResolvedUrl> {\n // Check for valid filename before the request to create file is actually made.\n if (isInvalidFileName(newFileInfo.filename)) {\n throw new NonRetryableError(\n // pre-0.58 error message: Invalid filename\n \"Invalid filename for createNew\", OdspErrorType.invalidFileNameError, { driverVersion });\n }\n\n let itemId: string;\n let summaryHandle: string = \"\";\n let shareLinkInfo: ShareLinkInfoType | undefined;\n if (createNewSummary === undefined) {\n itemId = await createNewEmptyFluidFile(\n getStorageToken, newFileInfo, logger, epochTracker, forceAccessTokenViaAuthorizationHeader);\n } else {\n const content = await createNewFluidFileFromSummary(\n getStorageToken,\n newFileInfo,\n logger,\n createNewSummary,\n epochTracker,\n forceAccessTokenViaAuthorizationHeader,\n );\n itemId = content.itemId;\n summaryHandle = content.id;\n\n shareLinkInfo = extractShareLinkData(\n newFileInfo.createLinkType,\n content,\n enableSingleRequestForShareLinkWithCreate,\n enableShareLinkWithCreate);\n }\n\n const odspUrl = createOdspUrl({ ...newFileInfo, itemId, dataStorePath: \"/\" });\n const resolver = new OdspDriverUrlResolver();\n const odspResolvedUrl = await resolver.resolve({\n url: odspUrl,\n headers: { [ClpCompliantAppHeader.isClpCompliantApp]: isClpCompliantApp },\n });\n fileEntry.docId = odspResolvedUrl.hashedDocumentId;\n fileEntry.resolvedUrl = odspResolvedUrl;\n\n odspResolvedUrl.shareLinkInfo = shareLinkInfo;\n\n if (createNewSummary !== undefined && createNewCaching) {\n assert(summaryHandle !== undefined, 0x203 /* \"Summary handle is undefined\" */);\n // converting summary and getting sequence number\n const snapshot: ISnapshotContents = convertCreateNewSummaryTreeToTreeAndBlobs(createNewSummary, summaryHandle);\n // caching the converted summary\n await epochTracker.put(createCacheSnapshotKey(odspResolvedUrl), snapshot);\n }\n return odspResolvedUrl;\n}\n\n/**\n * If user requested creation of a sharing link along with the creation of the file by providing either\n * createLinkType (now deprecated) or createLinkScope in the request parameters, extract and save\n * sharing link information from the response if it is available.\n * In case there was an error in creation of the sharing link, error is provided back in the response,\n * and does not impact the creation of file in ODSP.\n * @param requestedSharingLinkKind - Kind of sharing link requested to be created along with the creation of file.\n * @param response - Response object received from the /snapshot api call\n * @returns Sharing link information received in the response from a successful creation of a file.\n */\nfunction extractShareLinkData(\n requestedSharingLinkKind: ShareLinkTypes | ISharingLinkKind | undefined,\n response: ICreateFileResponse,\n enableSingleRequestForShareLinkWithCreate?: boolean,\n enableShareLinkWithCreate?: boolean,\n): ShareLinkInfoType | undefined {\n if (!requestedSharingLinkKind) {\n return;\n }\n let shareLinkInfo: ShareLinkInfoType | undefined;\n if (enableSingleRequestForShareLinkWithCreate) {\n const { sharing } = response;\n if (!sharing) {\n return;\n }\n shareLinkInfo = {\n createLink: {\n type: requestedSharingLinkKind,\n link: sharing.sharingLink ? {\n scope: sharing.sharingLink.scope,\n role: sharing.sharingLink.type,\n webUrl: sharing.sharingLink.webUrl,\n ...sharing.sharingLink,\n } : undefined,\n error: sharing.error,\n shareId: sharing.shareId,\n },\n };\n } else if (enableShareLinkWithCreate) {\n const { sharing, sharingLink, sharingLinkErrorReason } = response;\n if (!sharingLink && !sharingLinkErrorReason) {\n return;\n }\n shareLinkInfo = {\n createLink: {\n type: requestedSharingLinkKind,\n link: sharingLink,\n error: sharingLinkErrorReason,\n shareId: sharing?.shareId,\n },\n };\n }\n return shareLinkInfo;\n}\n\nexport async function createNewEmptyFluidFile(\n getStorageToken: InstrumentedStorageTokenFetcher,\n newFileInfo: INewFileInfo,\n logger: ITelemetryLogger,\n epochTracker: EpochTracker,\n forceAccessTokenViaAuthorizationHeader: boolean,\n): Promise<string> {\n const filePath = newFileInfo.filePath ? encodeURIComponent(`/${newFileInfo.filePath}`) : \"\";\n // add .tmp extension to empty file (host is expected to rename)\n const encodedFilename = encodeURIComponent(`${newFileInfo.filename}.tmp`);\n const initialUrl =\n `${getApiRoot(getOrigin(newFileInfo.siteUrl))}/drives/${newFileInfo.driveId}/items/root:/${filePath\n }/${encodedFilename}:/content?@name.conflictBehavior=rename&select=id,name,parentReference`;\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await getStorageToken(options, \"CreateNewFile\");\n\n return PerformanceEvent.timedExecAsync(\n logger,\n { eventName: \"createNewEmptyFile\" },\n async (event) => {\n const { url, headers } = getUrlAndHeadersWithAuth(\n initialUrl, storageToken, forceAccessTokenViaAuthorizationHeader);\n headers[\"Content-Type\"] = \"application/json\";\n\n const fetchResponse = await runWithRetry(\n async () => epochTracker.fetchAndParseAsJSON<ICreateFileResponse>(\n url,\n {\n body: undefined,\n headers,\n method: \"PUT\",\n },\n \"createFile\",\n ),\n \"createFile\",\n logger,\n );\n\n const content = fetchResponse.content;\n if (!content || !content.id) {\n throw new NonRetryableError(\n // pre-0.58 error message: ODSP CreateFile call returned no item ID\n \"ODSP CreateFile call returned no item ID (for empty file)\",\n DriverErrorType.incorrectServerResponse,\n { driverVersion });\n }\n event.end({\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n ...fetchResponse.propsToLog,\n });\n return content.id;\n },\n { end: true, cancel: \"error\" });\n });\n}\n\nexport async function createNewFluidFileFromSummary(\n getStorageToken: InstrumentedStorageTokenFetcher,\n newFileInfo: INewFileInfo,\n logger: ITelemetryLogger,\n createNewSummary: ISummaryTree,\n epochTracker: EpochTracker,\n forceAccessTokenViaAuthorizationHeader: boolean,\n): Promise<ICreateFileResponse> {\n const filePath = newFileInfo.filePath ? encodeURIComponent(`/${newFileInfo.filePath}`) : \"\";\n const encodedFilename = encodeURIComponent(newFileInfo.filename);\n const baseUrl =\n `${getApiRoot(getOrigin(newFileInfo.siteUrl))}/drives/${newFileInfo.driveId}/items/root:` +\n `${filePath}/${encodedFilename}`;\n\n const containerSnapshot = convertSummaryIntoContainerSnapshot(createNewSummary);\n\n // Build share link parameter based on the createLinkType provided so that the\n // snapshot api can create and return the share link along with creation of file in the response.\n const createShareLinkParam = buildOdspShareLinkReqParams(newFileInfo.createLinkType);\n const initialUrl =\n `${baseUrl}:/opStream/snapshots/snapshot${createShareLinkParam ? `?${createShareLinkParam}` : \"\"}`;\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await getStorageToken(options, \"CreateNewFile\");\n\n return PerformanceEvent.timedExecAsync(\n logger,\n { eventName: \"createNewFile\" },\n async (event) => {\n const snapshotBody = JSON.stringify(containerSnapshot);\n let url: string;\n let headers: { [index: string]: string; };\n let addInBody = false;\n const formBoundary = uuid();\n let postBody = `--${formBoundary}\\r\\n`;\n postBody += `Authorization: Bearer ${storageToken}\\r\\n`;\n postBody += `X-HTTP-Method-Override: POST\\r\\n`;\n postBody += `Content-Type: application/json\\r\\n`;\n postBody += `_post: 1\\r\\n`;\n postBody += `\\r\\n${snapshotBody}\\r\\n`;\n postBody += `\\r\\n--${formBoundary}--`;\n\n if (postBody.length <= maxUmpPostBodySize) {\n const urlObj = new URL(initialUrl);\n urlObj.searchParams.set(\"ump\", \"1\");\n url = urlObj.href;\n headers = {\n \"Content-Type\": `multipart/form-data;boundary=${formBoundary}`,\n };\n addInBody = true;\n } else {\n const parts = getUrlAndHeadersWithAuth(\n initialUrl, storageToken, forceAccessTokenViaAuthorizationHeader);\n url = parts.url;\n headers = {\n ...parts.headers,\n \"Content-Type\": \"application/json\",\n };\n postBody = snapshotBody;\n }\n\n const fetchResponse = await runWithRetry(\n async () => epochTracker.fetchAndParseAsJSON<ICreateFileResponse>(\n url,\n {\n body: postBody,\n headers,\n method: \"POST\",\n },\n \"createFile\",\n addInBody,\n ),\n \"createFile\",\n logger,\n );\n\n const content = fetchResponse.content;\n if (!content || !content.itemId) {\n throw new NonRetryableError(\n \"ODSP CreateFile call returned no item ID\",\n DriverErrorType.incorrectServerResponse,\n { driverVersion });\n }\n event.end({\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n attempts: options.refresh ? 2 : 1,\n ...fetchResponse.propsToLog,\n });\n return content;\n },\n );\n });\n}\n\nfunction convertSummaryIntoContainerSnapshot(createNewSummary: ISummaryTree) {\n const appSummary = createNewSummary.tree[\".app\"] as ISummaryTree;\n const protocolSummary = createNewSummary.tree[\".protocol\"] as ISummaryTree;\n if (!(appSummary && protocolSummary)) {\n throw new Error(\"App and protocol summary required for create new path!!\");\n }\n const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary);\n const attributesSummaryBlob: ISummaryBlob = {\n type: SummaryType.Blob,\n content: JSON.stringify(documentAttributes),\n };\n protocolSummary.tree.attributes = attributesSummaryBlob;\n const convertedCreateNewSummary: ISummaryTree = {\n type: SummaryType.Tree,\n tree: {\n \".protocol\": protocolSummary,\n \".app\": appSummary,\n },\n };\n const snapshotTree = convertSummaryToSnapshotTreeForCreateNew(convertedCreateNewSummary);\n const snapshot: IOdspSummaryPayload = {\n entries: snapshotTree.entries ?? [],\n message: \"app\",\n sequenceNumber: documentAttributes.sequenceNumber,\n type: \"container\",\n };\n return snapshot;\n}\n\n/**\n * Converts a summary tree to ODSP tree\n */\nexport function convertSummaryToSnapshotTreeForCreateNew(summary: ISummaryTree): IOdspSummaryTree {\n const snapshotTree: IOdspSummaryTree = {\n type: \"tree\",\n entries: [],\n };\n\n const keys = Object.keys(summary.tree);\n for (const key of keys) {\n const summaryObject = summary.tree[key];\n\n let value: OdspSummaryTreeValue;\n // Tracks if an entry is unreferenced. Currently, only tree entries can be marked as unreferenced. If the\n // property is not present, the tree entry is considered referenced. If the property is present and is true,\n // the tree entry is considered unreferenced.\n let unreferenced: true | undefined;\n\n switch (summaryObject.type) {\n case SummaryType.Tree: {\n value = convertSummaryToSnapshotTreeForCreateNew(summaryObject);\n unreferenced = summaryObject.unreferenced;\n break;\n }\n case SummaryType.Blob: {\n const content = typeof summaryObject.content === \"string\" ?\n summaryObject.content : Uint8ArrayToString(summaryObject.content, \"base64\");\n const encoding = typeof summaryObject.content === \"string\" ? \"utf-8\" : \"base64\";\n\n value = {\n type: \"blob\",\n content,\n encoding,\n };\n break;\n }\n case SummaryType.Handle: {\n throw new Error(\"No handle should be present for first summary!!\");\n }\n default: {\n throw new Error(`Unknown tree type ${summaryObject.type}`);\n }\n }\n\n const entry: OdspSummaryTreeEntry = {\n path: encodeURIComponent(key),\n type: getGitType(summaryObject),\n value,\n unreferenced,\n };\n snapshotTree.entries?.push(entry);\n }\n\n return snapshotTree;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"createFile.js","sourceRoot":"","sources":["../src/createFile.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AACtD,+DAAiE;AAGjE,qEAAmE;AACnE,qFAQiD;AACjD,2EAAqE;AAIrE,yEAAsE;AACtE,2CAMqB;AAErB,mDAAgD;AAChD,mDAA6C;AAE7C,mEAAgE;AAChE,qDAA+I;AAC/I,6CAA4C;AAC5C,qDAA+D;AAC/D,uDAA0D;AAE1D,MAAM,iBAAiB,GAAG,CAAC,QAAgB,EAAW,EAAE;IACpD,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;IAC3C,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF;;;GAGG;AACI,KAAK,UAAU,kBAAkB,CACpC,eAAgD,EAChD,WAAyB,EACzB,MAAwB,EACxB,gBAA0C,EAC1C,YAA0B,EAC1B,SAAqB,EACrB,gBAAyB,EACzB,sCAA+C,EAC/C,iBAA2B,EAC3B,yCAAmD,EACnD,yBAAmC;IAEnC,+EAA+E;IAC/E,IAAI,iBAAiB,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE;QACzC,MAAM,IAAI,gCAA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AAiB,GAAG,IAAA,oDAAmC,EAAC,gBAAgB,CAAC,CAAC;IAEhF,8EAA8E;IAC9E,iGAAiG;IACjG,MAAM,oBAAoB,GAAG,IAAA,uCAA2B,EAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IACrF,MAAM,UAAU,GACZ,GAAG,OAAO,gCAAgC,oBAAoB,CAAC,CAAC,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAEvG,OAAO,IAAA,4CAA2B,EAAsB;QACpD,iBAAiB;QACjB,eAAe;QACf,MAAM;QACN,UAAU;QACV,sCAAsC;QACtC,YAAY;QACZ,aAAa,EAAE,eAAe;QAC9B,SAAS,EAAE,YAAY;QACvB,wBAAwB,EAAE,OAAO,CAAC,EAAE;YAChC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;gBAC7B,MAAM,IAAI,gCAAiB,CACvB,0CAA0C,EAC1C,oCAAe,CAAC,uBAAuB,EACvC,EAAE,aAAa,EAAb,2BAAa,EAAE,CAAC,CAAC;aAC1B;QACL,CAAC;KACR,CAAC,CAAC;AACH,CAAC;AAxCD,sEAwCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { NonRetryableError } from \"@fluidframework/driver-utils\";\nimport { ISummaryTree } from \"@fluidframework/protocol-definitions\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n InstrumentedStorageTokenFetcher,\n IOdspResolvedUrl,\n OdspErrorType,\n ShareLinkInfoType,\n ISharingLinkKind,\n ShareLinkTypes,\n IFileEntry,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport {\n ICreateFileResponse,\n} from \"./contracts\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth\";\nimport {\n buildOdspShareLinkReqParams,\n createCacheSnapshotKey,\n getWithRetryForTokenRefresh,\n INewFileInfo,\n getOrigin\n} from \"./odspUtils\";\nimport { ISnapshotContents } from \"./odspPublicUtils\";\nimport { createOdspUrl } from \"./createOdspUrl\";\nimport { getApiRoot } from \"./odspUrlHelper\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { OdspDriverUrlResolver } from \"./odspDriverUrlResolver\";\nimport { convertCreateNewSummaryTreeToTreeAndBlobs, convertSummaryIntoContainerSnapshot, createNewFluidContainerCore } from \"./createNewUtils\";\nimport { runWithRetry } from \"./retryUtils\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\nimport { ClpCompliantAppHeader } from \"./contractsPublic\";\n\nconst isInvalidFileName = (fileName: string): boolean => {\n const invalidCharsRegex = /[\"*/:<>?\\\\|]+/g;\n return !!fileName.match(invalidCharsRegex);\n};\n\n/**\n * Creates a new Fluid file.\n * Returns resolved url\n */\nexport async function createNewFluidFile(\n getStorageToken: InstrumentedStorageTokenFetcher,\n newFileInfo: INewFileInfo,\n logger: ITelemetryLogger,\n createNewSummary: ISummaryTree | undefined,\n epochTracker: EpochTracker,\n fileEntry: IFileEntry,\n createNewCaching: boolean,\n forceAccessTokenViaAuthorizationHeader: boolean,\n isClpCompliantApp?: boolean,\n enableSingleRequestForShareLinkWithCreate?: boolean,\n enableShareLinkWithCreate?: boolean\n): Promise<IOdspResolvedUrl> {\n // Check for valid filename before the request to create file is actually made.\n if (isInvalidFileName(newFileInfo.filename)) {\n throw new NonRetryableError(\n // pre-0.58 error message: Invalid filename\n \"Invalid filename for createNew\", OdspErrorType.invalidFileNameError, { driverVersion });\n }\n\n let itemId: string;\n let summaryHandle: string = \"\";\n let shareLinkInfo: ShareLinkInfoType | undefined;\n if (createNewSummary === undefined) {\n itemId = await createNewEmptyFluidFile(\n getStorageToken, newFileInfo, logger, epochTracker, forceAccessTokenViaAuthorizationHeader);\n } else {\n const content = await createNewFluidFileFromSummary(\n getStorageToken,\n newFileInfo,\n logger,\n createNewSummary,\n epochTracker,\n forceAccessTokenViaAuthorizationHeader,\n );\n itemId = content.itemId;\n summaryHandle = content.id;\n\n shareLinkInfo = extractShareLinkData(\n newFileInfo.createLinkType,\n content,\n enableSingleRequestForShareLinkWithCreate,\n enableShareLinkWithCreate);\n }\n\n const odspUrl = createOdspUrl({ ...newFileInfo, itemId, dataStorePath: \"/\" });\n const resolver = new OdspDriverUrlResolver();\n const odspResolvedUrl = await resolver.resolve({\n url: odspUrl,\n headers: { [ClpCompliantAppHeader.isClpCompliantApp]: isClpCompliantApp },\n });\n fileEntry.docId = odspResolvedUrl.hashedDocumentId;\n fileEntry.resolvedUrl = odspResolvedUrl;\n\n odspResolvedUrl.shareLinkInfo = shareLinkInfo;\n\n if (createNewSummary !== undefined && createNewCaching) {\n assert(summaryHandle !== undefined, 0x203 /* \"Summary handle is undefined\" */);\n // converting summary and getting sequence number\n const snapshot: ISnapshotContents = convertCreateNewSummaryTreeToTreeAndBlobs(createNewSummary, summaryHandle);\n // caching the converted summary\n await epochTracker.put(createCacheSnapshotKey(odspResolvedUrl), snapshot);\n }\n return odspResolvedUrl;\n}\n\n/**\n * If user requested creation of a sharing link along with the creation of the file by providing either\n * createLinkType (now deprecated) or createLinkScope in the request parameters, extract and save\n * sharing link information from the response if it is available.\n * In case there was an error in creation of the sharing link, error is provided back in the response,\n * and does not impact the creation of file in ODSP.\n * @param requestedSharingLinkKind - Kind of sharing link requested to be created along with the creation of file.\n * @param response - Response object received from the /snapshot api call\n * @returns Sharing link information received in the response from a successful creation of a file.\n */\nfunction extractShareLinkData(\n requestedSharingLinkKind: ShareLinkTypes | ISharingLinkKind | undefined,\n response: ICreateFileResponse,\n enableSingleRequestForShareLinkWithCreate?: boolean,\n enableShareLinkWithCreate?: boolean,\n): ShareLinkInfoType | undefined {\n if (!requestedSharingLinkKind) {\n return;\n }\n let shareLinkInfo: ShareLinkInfoType | undefined;\n if (enableSingleRequestForShareLinkWithCreate) {\n const { sharing } = response;\n if (!sharing) {\n return;\n }\n shareLinkInfo = {\n createLink: {\n type: requestedSharingLinkKind,\n link: sharing.sharingLink ? {\n scope: sharing.sharingLink.scope,\n role: sharing.sharingLink.type,\n webUrl: sharing.sharingLink.webUrl,\n ...sharing.sharingLink,\n } : undefined,\n error: sharing.error,\n shareId: sharing.shareId,\n },\n };\n } else if (enableShareLinkWithCreate) {\n const { sharing, sharingLink, sharingLinkErrorReason } = response;\n if (!sharingLink && !sharingLinkErrorReason) {\n return;\n }\n shareLinkInfo = {\n createLink: {\n type: requestedSharingLinkKind,\n link: sharingLink,\n error: sharingLinkErrorReason,\n shareId: sharing?.shareId,\n },\n };\n }\n return shareLinkInfo;\n}\n\nexport async function createNewEmptyFluidFile(\n getStorageToken: InstrumentedStorageTokenFetcher,\n newFileInfo: INewFileInfo,\n logger: ITelemetryLogger,\n epochTracker: EpochTracker,\n forceAccessTokenViaAuthorizationHeader: boolean,\n): Promise<string> {\n const filePath = newFileInfo.filePath ? encodeURIComponent(`/${newFileInfo.filePath}`) : \"\";\n // add .tmp extension to empty file (host is expected to rename)\n const encodedFilename = encodeURIComponent(`${newFileInfo.filename}.tmp`);\n const initialUrl =\n `${getApiRoot(getOrigin(newFileInfo.siteUrl))}/drives/${newFileInfo.driveId}/items/root:/${filePath\n }/${encodedFilename}:/content?@name.conflictBehavior=rename&select=id,name,parentReference`;\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await getStorageToken(options, \"CreateNewFile\");\n\n return PerformanceEvent.timedExecAsync(\n logger,\n { eventName: \"createNewEmptyFile\" },\n async (event) => {\n const { url, headers } = getUrlAndHeadersWithAuth(\n initialUrl, storageToken, forceAccessTokenViaAuthorizationHeader);\n headers[\"Content-Type\"] = \"application/json\";\n\n const fetchResponse = await runWithRetry(\n async () => epochTracker.fetchAndParseAsJSON<ICreateFileResponse>(\n url,\n {\n body: undefined,\n headers,\n method: \"PUT\",\n },\n \"createFile\",\n ),\n \"createFile\",\n logger,\n );\n\n const content = fetchResponse.content;\n if (!content || !content.id) {\n throw new NonRetryableError(\n // pre-0.58 error message: ODSP CreateFile call returned no item ID\n \"ODSP CreateFile call returned no item ID (for empty file)\",\n DriverErrorType.incorrectServerResponse,\n { driverVersion });\n }\n event.end({\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n ...fetchResponse.propsToLog,\n });\n return content.id;\n },\n { end: true, cancel: \"error\" });\n });\n}\n\nexport async function createNewFluidFileFromSummary(\n getStorageToken: InstrumentedStorageTokenFetcher,\n newFileInfo: INewFileInfo,\n logger: ITelemetryLogger,\n createNewSummary: ISummaryTree,\n epochTracker: EpochTracker,\n forceAccessTokenViaAuthorizationHeader: boolean,\n): Promise<ICreateFileResponse> {\n const filePath = newFileInfo.filePath ? encodeURIComponent(`/${newFileInfo.filePath}`) : \"\";\n const encodedFilename = encodeURIComponent(newFileInfo.filename);\n const baseUrl =\n `${getApiRoot(getOrigin(newFileInfo.siteUrl))}/drives/${newFileInfo.driveId}/items/root:` +\n `${filePath}/${encodedFilename}`;\n\n const containerSnapshot = convertSummaryIntoContainerSnapshot(createNewSummary);\n\n // Build share link parameter based on the createLinkType provided so that the\n // snapshot api can create and return the share link along with creation of file in the response.\n const createShareLinkParam = buildOdspShareLinkReqParams(newFileInfo.createLinkType);\n const initialUrl =\n `${baseUrl}:/opStream/snapshots/snapshot${createShareLinkParam ? `?${createShareLinkParam}` : \"\"}`;\n\n return createNewFluidContainerCore<ICreateFileResponse>({\n containerSnapshot,\n getStorageToken,\n logger,\n initialUrl,\n forceAccessTokenViaAuthorizationHeader,\n epochTracker,\n telemetryName: \"CreateNewFile\",\n fetchType: \"createFile\",\n validateResponseCallback: content => {\n if (!content || !content.itemId) {\n throw new NonRetryableError(\n \"ODSP CreateFile call returned no item ID\",\n DriverErrorType.incorrectServerResponse,\n { driverVersion });\n }\n }\n});\n}\n"]}
|
package/dist/createNewUtils.d.ts
CHANGED
|
@@ -3,9 +3,25 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { ISummaryTree } from "@fluidframework/protocol-definitions";
|
|
6
|
+
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
7
|
+
import { InstrumentedStorageTokenFetcher } from "@fluidframework/odsp-driver-definitions";
|
|
8
|
+
import { IOdspSummaryPayload } from "./contracts";
|
|
6
9
|
import { ISnapshotContents } from "./odspPublicUtils";
|
|
10
|
+
import { EpochTracker, FetchType } from "./epochTracker";
|
|
7
11
|
/**
|
|
8
12
|
* Converts a summary(ISummaryTree) taken in detached container to snapshot tree and blobs
|
|
9
13
|
*/
|
|
10
14
|
export declare function convertCreateNewSummaryTreeToTreeAndBlobs(summary: ISummaryTree, treeId: string): ISnapshotContents;
|
|
15
|
+
export declare function convertSummaryIntoContainerSnapshot(createNewSummary: ISummaryTree): IOdspSummaryPayload;
|
|
16
|
+
export declare function createNewFluidContainerCore<T>(args: {
|
|
17
|
+
containerSnapshot: IOdspSummaryPayload;
|
|
18
|
+
getStorageToken: InstrumentedStorageTokenFetcher;
|
|
19
|
+
logger: ITelemetryLogger;
|
|
20
|
+
initialUrl: string;
|
|
21
|
+
forceAccessTokenViaAuthorizationHeader: boolean;
|
|
22
|
+
epochTracker: EpochTracker;
|
|
23
|
+
telemetryName: string;
|
|
24
|
+
fetchType: FetchType;
|
|
25
|
+
validateResponseCallback?: (content: T) => void;
|
|
26
|
+
}): Promise<T>;
|
|
11
27
|
//# sourceMappingURL=createNewUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNewUtils.d.ts","sourceRoot":"","sources":["../src/createNewUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,
|
|
1
|
+
{"version":3,"file":"createNewUtils.d.ts","sourceRoot":"","sources":["../src/createNewUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAgB,YAAY,EAA8B,MAAM,sCAAsC,CAAC;AAI9G,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAE1F,OAAO,EAAE,mBAAmB,EAAgE,MAAM,aAAa,CAAC;AAEhH,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIzD;;GAEG;AACH,wBAAgB,yCAAyC,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAgBlH;AAyCD,wBAAgB,mCAAmC,CAAC,gBAAgB,EAAE,YAAY,uBA2BjF;AA2DD,wBAAsB,2BAA2B,CAAC,CAAC,EAAE,IAAI,EAAE;IACvD,iBAAiB,EAAE,mBAAmB,CAAC;IACvC,eAAe,EAAE,+BAA+B,CAAC;IACjD,MAAM,EAAE,gBAAgB,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,sCAAsC,EAAE,OAAO,CAAC;IAChD,YAAY,EAAE,YAAY,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;IACrB,wBAAwB,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;CACnD,GAAG,OAAO,CAAC,CAAC,CAAC,CA+Eb"}
|
package/dist/createNewUtils.js
CHANGED
|
@@ -4,11 +4,16 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.convertCreateNewSummaryTreeToTreeAndBlobs = void 0;
|
|
7
|
+
exports.createNewFluidContainerCore = exports.convertSummaryIntoContainerSnapshot = exports.convertCreateNewSummaryTreeToTreeAndBlobs = void 0;
|
|
8
8
|
const uuid_1 = require("uuid");
|
|
9
9
|
const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
10
10
|
const driver_utils_1 = require("@fluidframework/driver-utils");
|
|
11
11
|
const common_utils_1 = require("@fluidframework/common-utils");
|
|
12
|
+
const protocol_base_1 = require("@fluidframework/protocol-base");
|
|
13
|
+
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
14
|
+
const odspUtils_1 = require("./odspUtils");
|
|
15
|
+
const getUrlAndHeadersWithAuth_1 = require("./getUrlAndHeadersWithAuth");
|
|
16
|
+
const retryUtils_1 = require("./retryUtils");
|
|
12
17
|
/**
|
|
13
18
|
* Converts a summary(ISummaryTree) taken in detached container to snapshot tree and blobs
|
|
14
19
|
*/
|
|
@@ -63,4 +68,129 @@ function convertCreateNewSummaryTreeToTreeAndBlobsCore(summary, blobs) {
|
|
|
63
68
|
}
|
|
64
69
|
return treeNode;
|
|
65
70
|
}
|
|
71
|
+
function convertSummaryIntoContainerSnapshot(createNewSummary) {
|
|
72
|
+
var _a;
|
|
73
|
+
const appSummary = createNewSummary.tree[".app"];
|
|
74
|
+
const protocolSummary = createNewSummary.tree[".protocol"];
|
|
75
|
+
if (!(appSummary && protocolSummary)) {
|
|
76
|
+
throw new Error("App and protocol summary required for create new path!!");
|
|
77
|
+
}
|
|
78
|
+
const documentAttributes = (0, driver_utils_1.getDocAttributesFromProtocolSummary)(protocolSummary);
|
|
79
|
+
const attributesSummaryBlob = {
|
|
80
|
+
type: protocol_definitions_1.SummaryType.Blob,
|
|
81
|
+
content: JSON.stringify(documentAttributes),
|
|
82
|
+
};
|
|
83
|
+
protocolSummary.tree.attributes = attributesSummaryBlob;
|
|
84
|
+
const convertedCreateNewSummary = {
|
|
85
|
+
type: protocol_definitions_1.SummaryType.Tree,
|
|
86
|
+
tree: {
|
|
87
|
+
".protocol": protocolSummary,
|
|
88
|
+
".app": appSummary,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
const snapshotTree = convertSummaryToSnapshotTreeForCreateNew(convertedCreateNewSummary);
|
|
92
|
+
const snapshot = {
|
|
93
|
+
entries: (_a = snapshotTree.entries) !== null && _a !== void 0 ? _a : [],
|
|
94
|
+
message: "app",
|
|
95
|
+
sequenceNumber: documentAttributes.sequenceNumber,
|
|
96
|
+
type: "container",
|
|
97
|
+
};
|
|
98
|
+
return snapshot;
|
|
99
|
+
}
|
|
100
|
+
exports.convertSummaryIntoContainerSnapshot = convertSummaryIntoContainerSnapshot;
|
|
101
|
+
/**
|
|
102
|
+
* Converts a summary tree to ODSP tree
|
|
103
|
+
*/
|
|
104
|
+
function convertSummaryToSnapshotTreeForCreateNew(summary) {
|
|
105
|
+
var _a;
|
|
106
|
+
const snapshotTree = {
|
|
107
|
+
type: "tree",
|
|
108
|
+
entries: [],
|
|
109
|
+
};
|
|
110
|
+
const keys = Object.keys(summary.tree);
|
|
111
|
+
for (const key of keys) {
|
|
112
|
+
const summaryObject = summary.tree[key];
|
|
113
|
+
let value;
|
|
114
|
+
// Tracks if an entry is unreferenced. Currently, only tree entries can be marked as unreferenced. If the
|
|
115
|
+
// property is not present, the tree entry is considered referenced. If the property is present and is true,
|
|
116
|
+
// the tree entry is considered unreferenced.
|
|
117
|
+
let unreferenced;
|
|
118
|
+
switch (summaryObject.type) {
|
|
119
|
+
case protocol_definitions_1.SummaryType.Tree: {
|
|
120
|
+
value = convertSummaryToSnapshotTreeForCreateNew(summaryObject);
|
|
121
|
+
unreferenced = summaryObject.unreferenced;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
case protocol_definitions_1.SummaryType.Blob: {
|
|
125
|
+
const content = typeof summaryObject.content === "string" ?
|
|
126
|
+
summaryObject.content : (0, common_utils_1.Uint8ArrayToString)(summaryObject.content, "base64");
|
|
127
|
+
const encoding = typeof summaryObject.content === "string" ? "utf-8" : "base64";
|
|
128
|
+
value = {
|
|
129
|
+
type: "blob",
|
|
130
|
+
content,
|
|
131
|
+
encoding,
|
|
132
|
+
};
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case protocol_definitions_1.SummaryType.Handle: {
|
|
136
|
+
throw new Error("No handle should be present for first summary!!");
|
|
137
|
+
}
|
|
138
|
+
default: {
|
|
139
|
+
throw new Error(`Unknown tree type ${summaryObject.type}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const entry = {
|
|
143
|
+
path: encodeURIComponent(key),
|
|
144
|
+
type: (0, protocol_base_1.getGitType)(summaryObject),
|
|
145
|
+
value,
|
|
146
|
+
unreferenced,
|
|
147
|
+
};
|
|
148
|
+
(_a = snapshotTree.entries) === null || _a === void 0 ? void 0 : _a.push(entry);
|
|
149
|
+
}
|
|
150
|
+
return snapshotTree;
|
|
151
|
+
}
|
|
152
|
+
async function createNewFluidContainerCore(args) {
|
|
153
|
+
const { containerSnapshot, getStorageToken, logger, initialUrl, forceAccessTokenViaAuthorizationHeader, epochTracker, telemetryName, fetchType, validateResponseCallback } = args;
|
|
154
|
+
return (0, odspUtils_1.getWithRetryForTokenRefresh)(async (options) => {
|
|
155
|
+
const storageToken = await getStorageToken(options, telemetryName);
|
|
156
|
+
return telemetry_utils_1.PerformanceEvent.timedExecAsync(logger, { eventName: telemetryName }, async (event) => {
|
|
157
|
+
const snapshotBody = JSON.stringify(containerSnapshot);
|
|
158
|
+
let url;
|
|
159
|
+
let headers;
|
|
160
|
+
let addInBody = false;
|
|
161
|
+
const formBoundary = (0, uuid_1.v4)();
|
|
162
|
+
let postBody = `--${formBoundary}\r\n`;
|
|
163
|
+
postBody += `Authorization: Bearer ${storageToken}\r\n`;
|
|
164
|
+
postBody += `X-HTTP-Method-Override: POST\r\n`;
|
|
165
|
+
postBody += `Content-Type: application/json\r\n`;
|
|
166
|
+
postBody += `_post: 1\r\n`;
|
|
167
|
+
postBody += `\r\n${snapshotBody}\r\n`;
|
|
168
|
+
postBody += `\r\n--${formBoundary}--`;
|
|
169
|
+
if (postBody.length <= odspUtils_1.maxUmpPostBodySize) {
|
|
170
|
+
const urlObj = new URL(initialUrl);
|
|
171
|
+
urlObj.searchParams.set("ump", "1");
|
|
172
|
+
url = urlObj.href;
|
|
173
|
+
headers = {
|
|
174
|
+
"Content-Type": `multipart/form-data;boundary=${formBoundary}`,
|
|
175
|
+
};
|
|
176
|
+
addInBody = true;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const parts = (0, getUrlAndHeadersWithAuth_1.getUrlAndHeadersWithAuth)(initialUrl, storageToken, forceAccessTokenViaAuthorizationHeader);
|
|
180
|
+
url = parts.url;
|
|
181
|
+
headers = Object.assign(Object.assign({}, parts.headers), { "Content-Type": "application/json" });
|
|
182
|
+
postBody = snapshotBody;
|
|
183
|
+
}
|
|
184
|
+
const fetchResponse = await (0, retryUtils_1.runWithRetry)(async () => epochTracker.fetchAndParseAsJSON(url, {
|
|
185
|
+
body: postBody,
|
|
186
|
+
headers,
|
|
187
|
+
method: "POST",
|
|
188
|
+
}, fetchType, addInBody), telemetryName, logger);
|
|
189
|
+
validateResponseCallback === null || validateResponseCallback === void 0 ? void 0 : validateResponseCallback(fetchResponse.content);
|
|
190
|
+
event.end(Object.assign({ headers: Object.keys(headers).length !== 0 ? true : undefined, attempts: options.refresh ? 2 : 1 }, fetchResponse.propsToLog));
|
|
191
|
+
return fetchResponse.content;
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
exports.createNewFluidContainerCore = createNewFluidContainerCore;
|
|
66
196
|
//# sourceMappingURL=createNewUtils.js.map
|