-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(asset-bundle): add "add manifest data" logic
- Loading branch information
Showing
12 changed files
with
207 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
type abPath = string; | ||
type abRelativePath = string; | ||
|
||
type abDataArr = array((abPath, Js.Typed_array.ArrayBuffer.t)); | ||
type abDataArr = array((abRelativePath, Js.Typed_array.ArrayBuffer.t)); | ||
|
||
type manifest = { | ||
hashId: string, | ||
dependencyRelation: | ||
WonderCommonlib.ImmutableHashMapService.t(array(abRelativePath)), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
open Js.Promise; | ||
|
||
open WonderBsMost; | ||
|
||
open Js.Typed_array; | ||
|
||
module All = { | ||
let _getHashId = [%bs.raw | ||
arrayBuffer => {| | ||
return crypto.subtle.digest("SHA-256", arrayBuffer) | ||
.then(hash => { | ||
// here hash is an arrayBuffer, so we'll convert it to its hex version | ||
let result = ''; | ||
const view = new DataView(hash); | ||
for (let i = 0; i < hash.byteLength; i += 4) { | ||
result += ('00000000' + view.getUint32(i).toString(16)).slice(-8); | ||
} | ||
return result; | ||
}); | ||
|} | ||
]; | ||
|
||
let buildManifestData = (wholeDependencyRelation, arrayBuffer) => | ||
_getHashId(arrayBuffer) | ||
|> then_(hashId => | ||
( | ||
{hashId, dependencyRelation: wholeDependencyRelation}: AllABType.manifest | ||
) | ||
|> resolve | ||
) | ||
|> Most.fromPromise; | ||
|
||
let _writeBuffer = | ||
(headerAndManifestJsonAlignedByteOffset, buffer, wholeArrayBuffer) => { | ||
let uint8Array = Uint8Array.fromBuffer(wholeArrayBuffer); | ||
|
||
let uint8Array = | ||
BufferUtils.mergeArrayBuffer( | ||
uint8Array, | ||
buffer, | ||
headerAndManifestJsonAlignedByteOffset, | ||
); | ||
|
||
uint8Array |> Uint8Array.buffer; | ||
}; | ||
|
||
let generateAB = | ||
(bufferTotalAlignedByteLength, manifestJsonUint8Array, buffer) => { | ||
let ( | ||
manifestJsonByteLength, | ||
manifestJsonAlignedByteLength, | ||
totalByteLength, | ||
) = | ||
GenerateABUtils.computeByteLength( | ||
bufferTotalAlignedByteLength, | ||
manifestJsonUint8Array, | ||
); | ||
|
||
let ab = ArrayBuffer.make(totalByteLength); | ||
let dataView = DataViewCommon.create(ab); | ||
|
||
let byteOffset = | ||
GenerateABUtils.writeHeader( | ||
manifestJsonByteLength, | ||
bufferTotalAlignedByteLength, | ||
dataView, | ||
); | ||
|
||
let emptyEncodedUint8Data = GenerateABUtils.getEmptyEncodedUint8Data(); | ||
|
||
let (byteOffset, _, dataView) = | ||
GenerateABUtils.writeJson( | ||
byteOffset, | ||
( | ||
emptyEncodedUint8Data, | ||
manifestJsonAlignedByteLength, | ||
manifestJsonUint8Array, | ||
), | ||
dataView, | ||
); | ||
|
||
_writeBuffer(byteOffset, buffer, dataView |> DataView.buffer); | ||
}; | ||
}; | ||
|
||
module SAB = { | ||
let addManifestData = (wholeDependencyRelation, sab) => { | ||
let manifestJsonUint8Array = | ||
All.buildManifestData(wholeDependencyRelation, sab) | ||
|> GenerateABUtils.buildJsonUint8Array; | ||
|
||
All.generateAB( | ||
BufferUtils.alignedLength(sab |> ArrayBuffer.byteLength), | ||
manifestJsonUint8Array, | ||
sab, | ||
); | ||
}; | ||
}; | ||
|
||
module RAB = { | ||
let addManifestData = (wholeDependencyRelation, rab) => { | ||
let manifestJsonUint8Array = | ||
All.buildManifestData(wholeDependencyRelation, rab) | ||
|> GenerateABUtils.buildJsonUint8Array; | ||
|
||
All.generateAB( | ||
BufferUtils.alignedLength(rab |> ArrayBuffer.byteLength), | ||
manifestJsonUint8Array, | ||
rab, | ||
); | ||
}; | ||
}; | ||
|
||
let addManifestData = | ||
( | ||
dependencyRelation: DependencyDataType.dependencyRelation, | ||
(sabArr, rabArr), | ||
) => { | ||
let wholeDependencyRelation = | ||
FindDependencyDataSystem.calcWholeDependencyRelation(dependencyRelation); | ||
|
||
( | ||
sabArr | ||
|> Js.Array.map(sab => RAB.addManifestData(wholeDependencyRelation, sab)), | ||
rabArr | ||
|> Js.Array.map(rab => RAB.addManifestData(wholeDependencyRelation, rab)), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
let getValidKeys = map => | ||
map |> Js.Dict.keys |> Js.Array.filter(value => value |> NullService.isInMap); |