id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
3,300 | cytoscape/cytoscape.js | dist/cytoscape.esm.js | addConnectedEdges | function addConnectedEdges(node) {
var edges = node._private.edges;
for (var i = 0; i < edges.length; i++) {
add(edges[i]);
}
} | javascript | function addConnectedEdges(node) {
var edges = node._private.edges;
for (var i = 0; i < edges.length; i++) {
add(edges[i]);
}
} | [
"function",
"addConnectedEdges",
"(",
"node",
")",
"{",
"var",
"edges",
"=",
"node",
".",
"_private",
".",
"edges",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"edges",
".",
"length",
";",
"i",
"++",
")",
"{",
"add",
"(",
"edges",
"[",
"i",
"]",
")",
";",
"}",
"}"
] | add connected edges | [
"add",
"connected",
"edges"
] | ad2051b65e2243cfd953d8b24a8bf95bfa8559e5 | https://github.com/cytoscape/cytoscape.js/blob/ad2051b65e2243cfd953d8b24a8bf95bfa8559e5/dist/cytoscape.esm.js#L12352-L12358 |
3,301 | cytoscape/cytoscape.js | dist/cytoscape.esm.js | addChildren | function addChildren(node) {
var children = node._private.children;
for (var i = 0; i < children.length; i++) {
add(children[i]);
}
} | javascript | function addChildren(node) {
var children = node._private.children;
for (var i = 0; i < children.length; i++) {
add(children[i]);
}
} | [
"function",
"addChildren",
"(",
"node",
")",
"{",
"var",
"children",
"=",
"node",
".",
"_private",
".",
"children",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"children",
".",
"length",
";",
"i",
"++",
")",
"{",
"add",
"(",
"children",
"[",
"i",
"]",
")",
";",
"}",
"}"
] | add descendant nodes | [
"add",
"descendant",
"nodes"
] | ad2051b65e2243cfd953d8b24a8bf95bfa8559e5 | https://github.com/cytoscape/cytoscape.js/blob/ad2051b65e2243cfd953d8b24a8bf95bfa8559e5/dist/cytoscape.esm.js#L12361-L12367 |
3,302 | cytoscape/cytoscape.js | dist/cytoscape.esm.js | spring | function spring(tension, friction, duration) {
if (duration === 0) {
// can't get a spring w/ duration 0
return easings.linear; // duration 0 => jump to end so impl doesn't matter
}
var spring = generateSpringRK4(tension, friction, duration);
return function (start, end, percent) {
return start + (end - start) * spring(percent);
};
} | javascript | function spring(tension, friction, duration) {
if (duration === 0) {
// can't get a spring w/ duration 0
return easings.linear; // duration 0 => jump to end so impl doesn't matter
}
var spring = generateSpringRK4(tension, friction, duration);
return function (start, end, percent) {
return start + (end - start) * spring(percent);
};
} | [
"function",
"spring",
"(",
"tension",
",",
"friction",
",",
"duration",
")",
"{",
"if",
"(",
"duration",
"===",
"0",
")",
"{",
"// can't get a spring w/ duration 0",
"return",
"easings",
".",
"linear",
";",
"// duration 0 => jump to end so impl doesn't matter",
"}",
"var",
"spring",
"=",
"generateSpringRK4",
"(",
"tension",
",",
"friction",
",",
"duration",
")",
";",
"return",
"function",
"(",
"start",
",",
"end",
",",
"percent",
")",
"{",
"return",
"start",
"+",
"(",
"end",
"-",
"start",
")",
"*",
"spring",
"(",
"percent",
")",
";",
"}",
";",
"}"
] | user param easings... | [
"user",
"param",
"easings",
"..."
] | ad2051b65e2243cfd953d8b24a8bf95bfa8559e5 | https://github.com/cytoscape/cytoscape.js/blob/ad2051b65e2243cfd953d8b24a8bf95bfa8559e5/dist/cytoscape.esm.js#L12947-L12957 |
3,303 | cytoscape/cytoscape.js | dist/cytoscape.esm.js | batchData | function batchData(map) {
var cy = this;
return this.batch(function () {
var ids = Object.keys(map);
for (var i = 0; i < ids.length; i++) {
var id = ids[i];
var data = map[id];
var ele = cy.getElementById(id);
ele.data(data);
}
});
} | javascript | function batchData(map) {
var cy = this;
return this.batch(function () {
var ids = Object.keys(map);
for (var i = 0; i < ids.length; i++) {
var id = ids[i];
var data = map[id];
var ele = cy.getElementById(id);
ele.data(data);
}
});
} | [
"function",
"batchData",
"(",
"map",
")",
"{",
"var",
"cy",
"=",
"this",
";",
"return",
"this",
".",
"batch",
"(",
"function",
"(",
")",
"{",
"var",
"ids",
"=",
"Object",
".",
"keys",
"(",
"map",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"ids",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"id",
"=",
"ids",
"[",
"i",
"]",
";",
"var",
"data",
"=",
"map",
"[",
"id",
"]",
";",
"var",
"ele",
"=",
"cy",
".",
"getElementById",
"(",
"id",
")",
";",
"ele",
".",
"data",
"(",
"data",
")",
";",
"}",
"}",
")",
";",
"}"
] | for backwards compatibility | [
"for",
"backwards",
"compatibility"
] | ad2051b65e2243cfd953d8b24a8bf95bfa8559e5 | https://github.com/cytoscape/cytoscape.js/blob/ad2051b65e2243cfd953d8b24a8bf95bfa8559e5/dist/cytoscape.esm.js#L13604-L13616 |
3,304 | cytoscape/cytoscape.js | dist/cytoscape.esm.js | sortFn | function sortFn(a, b) {
var apct = getWeightedPercent(a);
var bpct = getWeightedPercent(b);
var diff = apct - bpct;
if (diff === 0) {
return ascending(a.id(), b.id()); // make sure sort doesn't have don't-care comparisons
} else {
return diff;
}
} | javascript | function sortFn(a, b) {
var apct = getWeightedPercent(a);
var bpct = getWeightedPercent(b);
var diff = apct - bpct;
if (diff === 0) {
return ascending(a.id(), b.id()); // make sure sort doesn't have don't-care comparisons
} else {
return diff;
}
} | [
"function",
"sortFn",
"(",
"a",
",",
"b",
")",
"{",
"var",
"apct",
"=",
"getWeightedPercent",
"(",
"a",
")",
";",
"var",
"bpct",
"=",
"getWeightedPercent",
"(",
"b",
")",
";",
"var",
"diff",
"=",
"apct",
"-",
"bpct",
";",
"if",
"(",
"diff",
"===",
"0",
")",
"{",
"return",
"ascending",
"(",
"a",
".",
"id",
"(",
")",
",",
"b",
".",
"id",
"(",
")",
")",
";",
"// make sure sort doesn't have don't-care comparisons",
"}",
"else",
"{",
"return",
"diff",
";",
"}",
"}"
] | rearrange the indices in each depth level based on connectivity | [
"rearrange",
"the",
"indices",
"in",
"each",
"depth",
"level",
"based",
"on",
"connectivity"
] | ad2051b65e2243cfd953d8b24a8bf95bfa8559e5 | https://github.com/cytoscape/cytoscape.js/blob/ad2051b65e2243cfd953d8b24a8bf95bfa8559e5/dist/cytoscape.esm.js#L18322-L18332 |
3,305 | cytoscape/cytoscape.js | dist/cytoscape.esm.js | addNodesToDrag | function addNodesToDrag(nodes, opts) {
opts = opts || {};
var hasCompoundNodes = nodes.cy().hasCompoundNodes();
if (opts.inDragLayer) {
nodes.forEach(setInDragLayer);
nodes.neighborhood().stdFilter(function (ele) {
return !hasCompoundNodes || ele.isEdge();
}).forEach(setInDragLayer);
}
if (opts.addToList) {
nodes.forEach(function (ele) {
addToDragList(ele, opts);
});
}
addDescendantsToDrag(nodes, opts); // always add to drag
// also add nodes and edges related to the topmost ancestor
updateAncestorsInDragLayer(nodes, {
inDragLayer: opts.inDragLayer
});
r.updateCachedGrabbedEles();
} | javascript | function addNodesToDrag(nodes, opts) {
opts = opts || {};
var hasCompoundNodes = nodes.cy().hasCompoundNodes();
if (opts.inDragLayer) {
nodes.forEach(setInDragLayer);
nodes.neighborhood().stdFilter(function (ele) {
return !hasCompoundNodes || ele.isEdge();
}).forEach(setInDragLayer);
}
if (opts.addToList) {
nodes.forEach(function (ele) {
addToDragList(ele, opts);
});
}
addDescendantsToDrag(nodes, opts); // always add to drag
// also add nodes and edges related to the topmost ancestor
updateAncestorsInDragLayer(nodes, {
inDragLayer: opts.inDragLayer
});
r.updateCachedGrabbedEles();
} | [
"function",
"addNodesToDrag",
"(",
"nodes",
",",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"var",
"hasCompoundNodes",
"=",
"nodes",
".",
"cy",
"(",
")",
".",
"hasCompoundNodes",
"(",
")",
";",
"if",
"(",
"opts",
".",
"inDragLayer",
")",
"{",
"nodes",
".",
"forEach",
"(",
"setInDragLayer",
")",
";",
"nodes",
".",
"neighborhood",
"(",
")",
".",
"stdFilter",
"(",
"function",
"(",
"ele",
")",
"{",
"return",
"!",
"hasCompoundNodes",
"||",
"ele",
".",
"isEdge",
"(",
")",
";",
"}",
")",
".",
"forEach",
"(",
"setInDragLayer",
")",
";",
"}",
"if",
"(",
"opts",
".",
"addToList",
")",
"{",
"nodes",
".",
"forEach",
"(",
"function",
"(",
"ele",
")",
"{",
"addToDragList",
"(",
"ele",
",",
"opts",
")",
";",
"}",
")",
";",
"}",
"addDescendantsToDrag",
"(",
"nodes",
",",
"opts",
")",
";",
"// always add to drag",
"// also add nodes and edges related to the topmost ancestor",
"updateAncestorsInDragLayer",
"(",
"nodes",
",",
"{",
"inDragLayer",
":",
"opts",
".",
"inDragLayer",
"}",
")",
";",
"r",
".",
"updateCachedGrabbedEles",
"(",
")",
";",
"}"
] | adds the given nodes and its neighbourhood to the drag layer | [
"adds",
"the",
"given",
"nodes",
"and",
"its",
"neighbourhood",
"to",
"the",
"drag",
"layer"
] | ad2051b65e2243cfd953d8b24a8bf95bfa8559e5 | https://github.com/cytoscape/cytoscape.js/blob/ad2051b65e2243cfd953d8b24a8bf95bfa8559e5/dist/cytoscape.esm.js#L23307-L23331 |
3,306 | cytoscape/cytoscape.js | dist/cytoscape.esm.js | setupShapeColor | function setupShapeColor() {
var bgOpy = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : bgOpacity;
r.eleFillStyle(context, node, bgOpy);
} | javascript | function setupShapeColor() {
var bgOpy = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : bgOpacity;
r.eleFillStyle(context, node, bgOpy);
} | [
"function",
"setupShapeColor",
"(",
")",
"{",
"var",
"bgOpy",
"=",
"arguments",
".",
"length",
">",
"0",
"&&",
"arguments",
"[",
"0",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"0",
"]",
":",
"bgOpacity",
";",
"r",
".",
"eleFillStyle",
"(",
"context",
",",
"node",
",",
"bgOpy",
")",
";",
"}"
] | so borders are square with the node shape | [
"so",
"borders",
"are",
"square",
"with",
"the",
"node",
"shape"
] | ad2051b65e2243cfd953d8b24a8bf95bfa8559e5 | https://github.com/cytoscape/cytoscape.js/blob/ad2051b65e2243cfd953d8b24a8bf95bfa8559e5/dist/cytoscape.esm.js#L28500-L28503 |
3,307 | fex-team/webuploader | build/tasks/build.js | convert | function convert( name, _path, contents ) {
var rDefine = /(define\s*\(\s*('|").*?\2\s*,\s*\[)([\s\S]*?)\]/ig,
rDeps = /('|")(.*?)\1/g,
root = _path.substr( 0, _path.length - name.length - 3 ),
dir = path.dirname( _path ),
m, m2, deps, dep, _path2;
contents = contents.replace( rDefine, function( m, m1, m2, m3 ) {
return m1 + m3.replace( rDeps, function( m, m1, m2 ) {
m2 = path.join( dir, m2 );
m2 = path.relative( root, m2 );
m2 = m2.replace(/\\/g, '/');
return m1 + m2 + m1;
}) + ']';
});
return contents;
} | javascript | function convert( name, _path, contents ) {
var rDefine = /(define\s*\(\s*('|").*?\2\s*,\s*\[)([\s\S]*?)\]/ig,
rDeps = /('|")(.*?)\1/g,
root = _path.substr( 0, _path.length - name.length - 3 ),
dir = path.dirname( _path ),
m, m2, deps, dep, _path2;
contents = contents.replace( rDefine, function( m, m1, m2, m3 ) {
return m1 + m3.replace( rDeps, function( m, m1, m2 ) {
m2 = path.join( dir, m2 );
m2 = path.relative( root, m2 );
m2 = m2.replace(/\\/g, '/');
return m1 + m2 + m1;
}) + ']';
});
return contents;
} | [
"function",
"convert",
"(",
"name",
",",
"_path",
",",
"contents",
")",
"{",
"var",
"rDefine",
"=",
"/",
"(define\\s*\\(\\s*('|\").*?\\2\\s*,\\s*\\[)([\\s\\S]*?)\\]",
"/",
"ig",
",",
"rDeps",
"=",
"/",
"('|\")(.*?)\\1",
"/",
"g",
",",
"root",
"=",
"_path",
".",
"substr",
"(",
"0",
",",
"_path",
".",
"length",
"-",
"name",
".",
"length",
"-",
"3",
")",
",",
"dir",
"=",
"path",
".",
"dirname",
"(",
"_path",
")",
",",
"m",
",",
"m2",
",",
"deps",
",",
"dep",
",",
"_path2",
";",
"contents",
"=",
"contents",
".",
"replace",
"(",
"rDefine",
",",
"function",
"(",
"m",
",",
"m1",
",",
"m2",
",",
"m3",
")",
"{",
"return",
"m1",
"+",
"m3",
".",
"replace",
"(",
"rDeps",
",",
"function",
"(",
"m",
",",
"m1",
",",
"m2",
")",
"{",
"m2",
"=",
"path",
".",
"join",
"(",
"dir",
",",
"m2",
")",
";",
"m2",
"=",
"path",
".",
"relative",
"(",
"root",
",",
"m2",
")",
";",
"m2",
"=",
"m2",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'/'",
")",
";",
"return",
"m1",
"+",
"m2",
"+",
"m1",
";",
"}",
")",
"+",
"']'",
";",
"}",
")",
";",
"return",
"contents",
";",
"}"
] | convert relative path to absolute path. | [
"convert",
"relative",
"path",
"to",
"absolute",
"path",
"."
] | 7094e4476c5af3b06993d91dde2d223200b9feb7 | https://github.com/fex-team/webuploader/blob/7094e4476c5af3b06993d91dde2d223200b9feb7/build/tasks/build.js#L12-L30 |
3,308 | fex-team/webuploader | src/runtime/html5/image.js | detectSubsampling | function detectSubsampling( img ) {
var iw = img.naturalWidth,
ih = img.naturalHeight,
canvas, ctx;
// subsampling may happen overmegapixel image
if ( iw * ih > 1024 * 1024 ) {
canvas = document.createElement('canvas');
canvas.width = canvas.height = 1;
ctx = canvas.getContext('2d');
ctx.drawImage( img, -iw + 1, 0 );
// subsampled image becomes half smaller in rendering size.
// check alpha channel value to confirm image is covering
// edge pixel or not. if alpha value is 0
// image is not covering, hence subsampled.
return ctx.getImageData( 0, 0, 1, 1 ).data[ 3 ] === 0;
} else {
return false;
}
} | javascript | function detectSubsampling( img ) {
var iw = img.naturalWidth,
ih = img.naturalHeight,
canvas, ctx;
// subsampling may happen overmegapixel image
if ( iw * ih > 1024 * 1024 ) {
canvas = document.createElement('canvas');
canvas.width = canvas.height = 1;
ctx = canvas.getContext('2d');
ctx.drawImage( img, -iw + 1, 0 );
// subsampled image becomes half smaller in rendering size.
// check alpha channel value to confirm image is covering
// edge pixel or not. if alpha value is 0
// image is not covering, hence subsampled.
return ctx.getImageData( 0, 0, 1, 1 ).data[ 3 ] === 0;
} else {
return false;
}
} | [
"function",
"detectSubsampling",
"(",
"img",
")",
"{",
"var",
"iw",
"=",
"img",
".",
"naturalWidth",
",",
"ih",
"=",
"img",
".",
"naturalHeight",
",",
"canvas",
",",
"ctx",
";",
"// subsampling may happen overmegapixel image",
"if",
"(",
"iw",
"*",
"ih",
">",
"1024",
"*",
"1024",
")",
"{",
"canvas",
"=",
"document",
".",
"createElement",
"(",
"'canvas'",
")",
";",
"canvas",
".",
"width",
"=",
"canvas",
".",
"height",
"=",
"1",
";",
"ctx",
"=",
"canvas",
".",
"getContext",
"(",
"'2d'",
")",
";",
"ctx",
".",
"drawImage",
"(",
"img",
",",
"-",
"iw",
"+",
"1",
",",
"0",
")",
";",
"// subsampled image becomes half smaller in rendering size.",
"// check alpha channel value to confirm image is covering",
"// edge pixel or not. if alpha value is 0",
"// image is not covering, hence subsampled.",
"return",
"ctx",
".",
"getImageData",
"(",
"0",
",",
"0",
",",
"1",
",",
"1",
")",
".",
"data",
"[",
"3",
"]",
"===",
"0",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Detect subsampling in loaded image.
In iOS, larger images than 2M pixels may be
subsampled in rendering. | [
"Detect",
"subsampling",
"in",
"loaded",
"image",
".",
"In",
"iOS",
"larger",
"images",
"than",
"2M",
"pixels",
"may",
"be",
"subsampled",
"in",
"rendering",
"."
] | 7094e4476c5af3b06993d91dde2d223200b9feb7 | https://github.com/fex-team/webuploader/blob/7094e4476c5af3b06993d91dde2d223200b9feb7/src/runtime/html5/image.js#L366-L386 |
3,309 | swimlane/ngx-datatable | release/utils/sort.js | nextSortDir | function nextSortDir(sortType, current) {
if (sortType === types_1.SortType.single) {
if (current === types_1.SortDirection.asc) {
return types_1.SortDirection.desc;
}
else {
return types_1.SortDirection.asc;
}
}
else {
if (!current) {
return types_1.SortDirection.asc;
}
else if (current === types_1.SortDirection.asc) {
return types_1.SortDirection.desc;
}
else if (current === types_1.SortDirection.desc) {
return undefined;
}
// avoid TS7030: Not all code paths return a value.
return undefined;
}
} | javascript | function nextSortDir(sortType, current) {
if (sortType === types_1.SortType.single) {
if (current === types_1.SortDirection.asc) {
return types_1.SortDirection.desc;
}
else {
return types_1.SortDirection.asc;
}
}
else {
if (!current) {
return types_1.SortDirection.asc;
}
else if (current === types_1.SortDirection.asc) {
return types_1.SortDirection.desc;
}
else if (current === types_1.SortDirection.desc) {
return undefined;
}
// avoid TS7030: Not all code paths return a value.
return undefined;
}
} | [
"function",
"nextSortDir",
"(",
"sortType",
",",
"current",
")",
"{",
"if",
"(",
"sortType",
"===",
"types_1",
".",
"SortType",
".",
"single",
")",
"{",
"if",
"(",
"current",
"===",
"types_1",
".",
"SortDirection",
".",
"asc",
")",
"{",
"return",
"types_1",
".",
"SortDirection",
".",
"desc",
";",
"}",
"else",
"{",
"return",
"types_1",
".",
"SortDirection",
".",
"asc",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"current",
")",
"{",
"return",
"types_1",
".",
"SortDirection",
".",
"asc",
";",
"}",
"else",
"if",
"(",
"current",
"===",
"types_1",
".",
"SortDirection",
".",
"asc",
")",
"{",
"return",
"types_1",
".",
"SortDirection",
".",
"desc",
";",
"}",
"else",
"if",
"(",
"current",
"===",
"types_1",
".",
"SortDirection",
".",
"desc",
")",
"{",
"return",
"undefined",
";",
"}",
"// avoid TS7030: Not all code paths return a value.",
"return",
"undefined",
";",
"}",
"}"
] | Gets the next sort direction | [
"Gets",
"the",
"next",
"sort",
"direction"
] | d7df15a070282a169524dba51d9572008b74804c | https://github.com/swimlane/ngx-datatable/blob/d7df15a070282a169524dba51d9572008b74804c/release/utils/sort.js#L8-L30 |
3,310 | swimlane/ngx-datatable | release/utils/sort.js | sortRows | function sortRows(rows, columns, dirs) {
if (!rows)
return [];
if (!dirs || !dirs.length || !columns)
return rows.slice();
/**
* record the row ordering of results from prior sort operations (if applicable)
* this is necessary to guarantee stable sorting behavior
*/
var rowToIndexMap = new Map();
rows.forEach(function (row, index) { return rowToIndexMap.set(row, index); });
var temp = rows.slice();
var cols = columns.reduce(function (obj, col) {
if (col.comparator && typeof col.comparator === 'function') {
obj[col.prop] = col.comparator;
}
return obj;
}, {});
// cache valueGetter and compareFn so that they
// do not need to be looked-up in the sort function body
var cachedDirs = dirs.map(function (dir) {
var prop = dir.prop;
return {
prop: prop,
dir: dir.dir,
valueGetter: column_prop_getters_1.getterForProp(prop),
compareFn: cols[prop] || orderByComparator
};
});
return temp.sort(function (rowA, rowB) {
for (var _i = 0, cachedDirs_1 = cachedDirs; _i < cachedDirs_1.length; _i++) {
var cachedDir = cachedDirs_1[_i];
// Get property and valuegetters for column to be sorted
var prop = cachedDir.prop, valueGetter = cachedDir.valueGetter;
// Get A and B cell values from rows based on properties of the columns
var propA = valueGetter(rowA, prop);
var propB = valueGetter(rowB, prop);
// Compare function gets five parameters:
// Two cell values to be compared as propA and propB
// Two rows corresponding to the cells as rowA and rowB
// Direction of the sort for this column as SortDirection
// Compare can be a standard JS comparison function (a,b) => -1|0|1
// as additional parameters are silently ignored. The whole row and sort
// direction enable more complex sort logic.
var comparison = cachedDir.dir !== types_1.SortDirection.desc ?
cachedDir.compareFn(propA, propB, rowA, rowB, cachedDir.dir) :
-cachedDir.compareFn(propA, propB, rowA, rowB, cachedDir.dir);
// Don't return 0 yet in case of needing to sort by next property
if (comparison !== 0)
return comparison;
}
if (!(rowToIndexMap.has(rowA) && rowToIndexMap.has(rowB)))
return 0;
/**
* all else being equal, preserve original order of the rows (stable sort)
*/
return rowToIndexMap.get(rowA) < rowToIndexMap.get(rowB) ? -1 : 1;
});
} | javascript | function sortRows(rows, columns, dirs) {
if (!rows)
return [];
if (!dirs || !dirs.length || !columns)
return rows.slice();
/**
* record the row ordering of results from prior sort operations (if applicable)
* this is necessary to guarantee stable sorting behavior
*/
var rowToIndexMap = new Map();
rows.forEach(function (row, index) { return rowToIndexMap.set(row, index); });
var temp = rows.slice();
var cols = columns.reduce(function (obj, col) {
if (col.comparator && typeof col.comparator === 'function') {
obj[col.prop] = col.comparator;
}
return obj;
}, {});
// cache valueGetter and compareFn so that they
// do not need to be looked-up in the sort function body
var cachedDirs = dirs.map(function (dir) {
var prop = dir.prop;
return {
prop: prop,
dir: dir.dir,
valueGetter: column_prop_getters_1.getterForProp(prop),
compareFn: cols[prop] || orderByComparator
};
});
return temp.sort(function (rowA, rowB) {
for (var _i = 0, cachedDirs_1 = cachedDirs; _i < cachedDirs_1.length; _i++) {
var cachedDir = cachedDirs_1[_i];
// Get property and valuegetters for column to be sorted
var prop = cachedDir.prop, valueGetter = cachedDir.valueGetter;
// Get A and B cell values from rows based on properties of the columns
var propA = valueGetter(rowA, prop);
var propB = valueGetter(rowB, prop);
// Compare function gets five parameters:
// Two cell values to be compared as propA and propB
// Two rows corresponding to the cells as rowA and rowB
// Direction of the sort for this column as SortDirection
// Compare can be a standard JS comparison function (a,b) => -1|0|1
// as additional parameters are silently ignored. The whole row and sort
// direction enable more complex sort logic.
var comparison = cachedDir.dir !== types_1.SortDirection.desc ?
cachedDir.compareFn(propA, propB, rowA, rowB, cachedDir.dir) :
-cachedDir.compareFn(propA, propB, rowA, rowB, cachedDir.dir);
// Don't return 0 yet in case of needing to sort by next property
if (comparison !== 0)
return comparison;
}
if (!(rowToIndexMap.has(rowA) && rowToIndexMap.has(rowB)))
return 0;
/**
* all else being equal, preserve original order of the rows (stable sort)
*/
return rowToIndexMap.get(rowA) < rowToIndexMap.get(rowB) ? -1 : 1;
});
} | [
"function",
"sortRows",
"(",
"rows",
",",
"columns",
",",
"dirs",
")",
"{",
"if",
"(",
"!",
"rows",
")",
"return",
"[",
"]",
";",
"if",
"(",
"!",
"dirs",
"||",
"!",
"dirs",
".",
"length",
"||",
"!",
"columns",
")",
"return",
"rows",
".",
"slice",
"(",
")",
";",
"/**\n * record the row ordering of results from prior sort operations (if applicable)\n * this is necessary to guarantee stable sorting behavior\n */",
"var",
"rowToIndexMap",
"=",
"new",
"Map",
"(",
")",
";",
"rows",
".",
"forEach",
"(",
"function",
"(",
"row",
",",
"index",
")",
"{",
"return",
"rowToIndexMap",
".",
"set",
"(",
"row",
",",
"index",
")",
";",
"}",
")",
";",
"var",
"temp",
"=",
"rows",
".",
"slice",
"(",
")",
";",
"var",
"cols",
"=",
"columns",
".",
"reduce",
"(",
"function",
"(",
"obj",
",",
"col",
")",
"{",
"if",
"(",
"col",
".",
"comparator",
"&&",
"typeof",
"col",
".",
"comparator",
"===",
"'function'",
")",
"{",
"obj",
"[",
"col",
".",
"prop",
"]",
"=",
"col",
".",
"comparator",
";",
"}",
"return",
"obj",
";",
"}",
",",
"{",
"}",
")",
";",
"// cache valueGetter and compareFn so that they",
"// do not need to be looked-up in the sort function body",
"var",
"cachedDirs",
"=",
"dirs",
".",
"map",
"(",
"function",
"(",
"dir",
")",
"{",
"var",
"prop",
"=",
"dir",
".",
"prop",
";",
"return",
"{",
"prop",
":",
"prop",
",",
"dir",
":",
"dir",
".",
"dir",
",",
"valueGetter",
":",
"column_prop_getters_1",
".",
"getterForProp",
"(",
"prop",
")",
",",
"compareFn",
":",
"cols",
"[",
"prop",
"]",
"||",
"orderByComparator",
"}",
";",
"}",
")",
";",
"return",
"temp",
".",
"sort",
"(",
"function",
"(",
"rowA",
",",
"rowB",
")",
"{",
"for",
"(",
"var",
"_i",
"=",
"0",
",",
"cachedDirs_1",
"=",
"cachedDirs",
";",
"_i",
"<",
"cachedDirs_1",
".",
"length",
";",
"_i",
"++",
")",
"{",
"var",
"cachedDir",
"=",
"cachedDirs_1",
"[",
"_i",
"]",
";",
"// Get property and valuegetters for column to be sorted",
"var",
"prop",
"=",
"cachedDir",
".",
"prop",
",",
"valueGetter",
"=",
"cachedDir",
".",
"valueGetter",
";",
"// Get A and B cell values from rows based on properties of the columns",
"var",
"propA",
"=",
"valueGetter",
"(",
"rowA",
",",
"prop",
")",
";",
"var",
"propB",
"=",
"valueGetter",
"(",
"rowB",
",",
"prop",
")",
";",
"// Compare function gets five parameters:",
"// Two cell values to be compared as propA and propB",
"// Two rows corresponding to the cells as rowA and rowB",
"// Direction of the sort for this column as SortDirection",
"// Compare can be a standard JS comparison function (a,b) => -1|0|1",
"// as additional parameters are silently ignored. The whole row and sort",
"// direction enable more complex sort logic.",
"var",
"comparison",
"=",
"cachedDir",
".",
"dir",
"!==",
"types_1",
".",
"SortDirection",
".",
"desc",
"?",
"cachedDir",
".",
"compareFn",
"(",
"propA",
",",
"propB",
",",
"rowA",
",",
"rowB",
",",
"cachedDir",
".",
"dir",
")",
":",
"-",
"cachedDir",
".",
"compareFn",
"(",
"propA",
",",
"propB",
",",
"rowA",
",",
"rowB",
",",
"cachedDir",
".",
"dir",
")",
";",
"// Don't return 0 yet in case of needing to sort by next property",
"if",
"(",
"comparison",
"!==",
"0",
")",
"return",
"comparison",
";",
"}",
"if",
"(",
"!",
"(",
"rowToIndexMap",
".",
"has",
"(",
"rowA",
")",
"&&",
"rowToIndexMap",
".",
"has",
"(",
"rowB",
")",
")",
")",
"return",
"0",
";",
"/**\n * all else being equal, preserve original order of the rows (stable sort)\n */",
"return",
"rowToIndexMap",
".",
"get",
"(",
"rowA",
")",
"<",
"rowToIndexMap",
".",
"get",
"(",
"rowB",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"}"
] | creates a shallow copy of the `rows` input and returns the sorted copy. this function
does not sort the `rows` argument in place | [
"creates",
"a",
"shallow",
"copy",
"of",
"the",
"rows",
"input",
"and",
"returns",
"the",
"sorted",
"copy",
".",
"this",
"function",
"does",
"not",
"sort",
"the",
"rows",
"argument",
"in",
"place"
] | d7df15a070282a169524dba51d9572008b74804c | https://github.com/swimlane/ngx-datatable/blob/d7df15a070282a169524dba51d9572008b74804c/release/utils/sort.js#L72-L130 |
3,311 | swimlane/ngx-datatable | release/utils/column.js | columnsByPin | function columnsByPin(cols) {
var ret = {
left: [],
center: [],
right: []
};
if (cols) {
for (var _i = 0, cols_1 = cols; _i < cols_1.length; _i++) {
var col = cols_1[_i];
if (col.frozenLeft) {
ret.left.push(col);
}
else if (col.frozenRight) {
ret.right.push(col);
}
else {
ret.center.push(col);
}
}
}
return ret;
} | javascript | function columnsByPin(cols) {
var ret = {
left: [],
center: [],
right: []
};
if (cols) {
for (var _i = 0, cols_1 = cols; _i < cols_1.length; _i++) {
var col = cols_1[_i];
if (col.frozenLeft) {
ret.left.push(col);
}
else if (col.frozenRight) {
ret.right.push(col);
}
else {
ret.center.push(col);
}
}
}
return ret;
} | [
"function",
"columnsByPin",
"(",
"cols",
")",
"{",
"var",
"ret",
"=",
"{",
"left",
":",
"[",
"]",
",",
"center",
":",
"[",
"]",
",",
"right",
":",
"[",
"]",
"}",
";",
"if",
"(",
"cols",
")",
"{",
"for",
"(",
"var",
"_i",
"=",
"0",
",",
"cols_1",
"=",
"cols",
";",
"_i",
"<",
"cols_1",
".",
"length",
";",
"_i",
"++",
")",
"{",
"var",
"col",
"=",
"cols_1",
"[",
"_i",
"]",
";",
"if",
"(",
"col",
".",
"frozenLeft",
")",
"{",
"ret",
".",
"left",
".",
"push",
"(",
"col",
")",
";",
"}",
"else",
"if",
"(",
"col",
".",
"frozenRight",
")",
"{",
"ret",
".",
"right",
".",
"push",
"(",
"col",
")",
";",
"}",
"else",
"{",
"ret",
".",
"center",
".",
"push",
"(",
"col",
")",
";",
"}",
"}",
"}",
"return",
"ret",
";",
"}"
] | Returns the columns by pin. | [
"Returns",
"the",
"columns",
"by",
"pin",
"."
] | d7df15a070282a169524dba51d9572008b74804c | https://github.com/swimlane/ngx-datatable/blob/d7df15a070282a169524dba51d9572008b74804c/release/utils/column.js#L6-L27 |
3,312 | swimlane/ngx-datatable | release/utils/column.js | columnGroupWidths | function columnGroupWidths(groups, all) {
return {
left: columnTotalWidth(groups.left),
center: columnTotalWidth(groups.center),
right: columnTotalWidth(groups.right),
total: Math.floor(columnTotalWidth(all))
};
} | javascript | function columnGroupWidths(groups, all) {
return {
left: columnTotalWidth(groups.left),
center: columnTotalWidth(groups.center),
right: columnTotalWidth(groups.right),
total: Math.floor(columnTotalWidth(all))
};
} | [
"function",
"columnGroupWidths",
"(",
"groups",
",",
"all",
")",
"{",
"return",
"{",
"left",
":",
"columnTotalWidth",
"(",
"groups",
".",
"left",
")",
",",
"center",
":",
"columnTotalWidth",
"(",
"groups",
".",
"center",
")",
",",
"right",
":",
"columnTotalWidth",
"(",
"groups",
".",
"right",
")",
",",
"total",
":",
"Math",
".",
"floor",
"(",
"columnTotalWidth",
"(",
"all",
")",
")",
"}",
";",
"}"
] | Returns the widths of all group sets of a column | [
"Returns",
"the",
"widths",
"of",
"all",
"group",
"sets",
"of",
"a",
"column"
] | d7df15a070282a169524dba51d9572008b74804c | https://github.com/swimlane/ngx-datatable/blob/d7df15a070282a169524dba51d9572008b74804c/release/utils/column.js#L32-L39 |
3,313 | swimlane/ngx-datatable | release/utils/math.js | getTotalFlexGrow | function getTotalFlexGrow(columns) {
var totalFlexGrow = 0;
for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) {
var c = columns_1[_i];
totalFlexGrow += c.flexGrow || 0;
}
return totalFlexGrow;
} | javascript | function getTotalFlexGrow(columns) {
var totalFlexGrow = 0;
for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) {
var c = columns_1[_i];
totalFlexGrow += c.flexGrow || 0;
}
return totalFlexGrow;
} | [
"function",
"getTotalFlexGrow",
"(",
"columns",
")",
"{",
"var",
"totalFlexGrow",
"=",
"0",
";",
"for",
"(",
"var",
"_i",
"=",
"0",
",",
"columns_1",
"=",
"columns",
";",
"_i",
"<",
"columns_1",
".",
"length",
";",
"_i",
"++",
")",
"{",
"var",
"c",
"=",
"columns_1",
"[",
"_i",
"]",
";",
"totalFlexGrow",
"+=",
"c",
".",
"flexGrow",
"||",
"0",
";",
"}",
"return",
"totalFlexGrow",
";",
"}"
] | Calculates the Total Flex Grow | [
"Calculates",
"the",
"Total",
"Flex",
"Grow"
] | d7df15a070282a169524dba51d9572008b74804c | https://github.com/swimlane/ngx-datatable/blob/d7df15a070282a169524dba51d9572008b74804c/release/utils/math.js#L7-L14 |
3,314 | swimlane/ngx-datatable | release/utils/math.js | scaleColumns | function scaleColumns(colsByGroup, maxWidth, totalFlexGrow) {
// calculate total width and flexgrow points for coulumns that can be resized
for (var attr in colsByGroup) {
for (var _i = 0, _a = colsByGroup[attr]; _i < _a.length; _i++) {
var column = _a[_i];
if (!column.canAutoResize) {
maxWidth -= column.width;
totalFlexGrow -= column.flexGrow ? column.flexGrow : 0;
}
else {
column.width = 0;
}
}
}
var hasMinWidth = {};
var remainingWidth = maxWidth;
// resize columns until no width is left to be distributed
do {
var widthPerFlexPoint = remainingWidth / totalFlexGrow;
remainingWidth = 0;
for (var attr in colsByGroup) {
for (var _b = 0, _c = colsByGroup[attr]; _b < _c.length; _b++) {
var column = _c[_b];
// if the column can be resize and it hasn't reached its minimum width yet
if (column.canAutoResize && !hasMinWidth[column.prop]) {
var newWidth = column.width + column.flexGrow * widthPerFlexPoint;
if (column.minWidth !== undefined && newWidth < column.minWidth) {
remainingWidth += newWidth - column.minWidth;
column.width = column.minWidth;
hasMinWidth[column.prop] = true;
}
else {
column.width = newWidth;
}
}
}
}
} while (remainingWidth !== 0);
} | javascript | function scaleColumns(colsByGroup, maxWidth, totalFlexGrow) {
// calculate total width and flexgrow points for coulumns that can be resized
for (var attr in colsByGroup) {
for (var _i = 0, _a = colsByGroup[attr]; _i < _a.length; _i++) {
var column = _a[_i];
if (!column.canAutoResize) {
maxWidth -= column.width;
totalFlexGrow -= column.flexGrow ? column.flexGrow : 0;
}
else {
column.width = 0;
}
}
}
var hasMinWidth = {};
var remainingWidth = maxWidth;
// resize columns until no width is left to be distributed
do {
var widthPerFlexPoint = remainingWidth / totalFlexGrow;
remainingWidth = 0;
for (var attr in colsByGroup) {
for (var _b = 0, _c = colsByGroup[attr]; _b < _c.length; _b++) {
var column = _c[_b];
// if the column can be resize and it hasn't reached its minimum width yet
if (column.canAutoResize && !hasMinWidth[column.prop]) {
var newWidth = column.width + column.flexGrow * widthPerFlexPoint;
if (column.minWidth !== undefined && newWidth < column.minWidth) {
remainingWidth += newWidth - column.minWidth;
column.width = column.minWidth;
hasMinWidth[column.prop] = true;
}
else {
column.width = newWidth;
}
}
}
}
} while (remainingWidth !== 0);
} | [
"function",
"scaleColumns",
"(",
"colsByGroup",
",",
"maxWidth",
",",
"totalFlexGrow",
")",
"{",
"// calculate total width and flexgrow points for coulumns that can be resized",
"for",
"(",
"var",
"attr",
"in",
"colsByGroup",
")",
"{",
"for",
"(",
"var",
"_i",
"=",
"0",
",",
"_a",
"=",
"colsByGroup",
"[",
"attr",
"]",
";",
"_i",
"<",
"_a",
".",
"length",
";",
"_i",
"++",
")",
"{",
"var",
"column",
"=",
"_a",
"[",
"_i",
"]",
";",
"if",
"(",
"!",
"column",
".",
"canAutoResize",
")",
"{",
"maxWidth",
"-=",
"column",
".",
"width",
";",
"totalFlexGrow",
"-=",
"column",
".",
"flexGrow",
"?",
"column",
".",
"flexGrow",
":",
"0",
";",
"}",
"else",
"{",
"column",
".",
"width",
"=",
"0",
";",
"}",
"}",
"}",
"var",
"hasMinWidth",
"=",
"{",
"}",
";",
"var",
"remainingWidth",
"=",
"maxWidth",
";",
"// resize columns until no width is left to be distributed",
"do",
"{",
"var",
"widthPerFlexPoint",
"=",
"remainingWidth",
"/",
"totalFlexGrow",
";",
"remainingWidth",
"=",
"0",
";",
"for",
"(",
"var",
"attr",
"in",
"colsByGroup",
")",
"{",
"for",
"(",
"var",
"_b",
"=",
"0",
",",
"_c",
"=",
"colsByGroup",
"[",
"attr",
"]",
";",
"_b",
"<",
"_c",
".",
"length",
";",
"_b",
"++",
")",
"{",
"var",
"column",
"=",
"_c",
"[",
"_b",
"]",
";",
"// if the column can be resize and it hasn't reached its minimum width yet",
"if",
"(",
"column",
".",
"canAutoResize",
"&&",
"!",
"hasMinWidth",
"[",
"column",
".",
"prop",
"]",
")",
"{",
"var",
"newWidth",
"=",
"column",
".",
"width",
"+",
"column",
".",
"flexGrow",
"*",
"widthPerFlexPoint",
";",
"if",
"(",
"column",
".",
"minWidth",
"!==",
"undefined",
"&&",
"newWidth",
"<",
"column",
".",
"minWidth",
")",
"{",
"remainingWidth",
"+=",
"newWidth",
"-",
"column",
".",
"minWidth",
";",
"column",
".",
"width",
"=",
"column",
".",
"minWidth",
";",
"hasMinWidth",
"[",
"column",
".",
"prop",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"column",
".",
"width",
"=",
"newWidth",
";",
"}",
"}",
"}",
"}",
"}",
"while",
"(",
"remainingWidth",
"!==",
"0",
")",
";",
"}"
] | Resizes columns based on the flexGrow property, while respecting manually set widths | [
"Resizes",
"columns",
"based",
"on",
"the",
"flexGrow",
"property",
"while",
"respecting",
"manually",
"set",
"widths"
] | d7df15a070282a169524dba51d9572008b74804c | https://github.com/swimlane/ngx-datatable/blob/d7df15a070282a169524dba51d9572008b74804c/release/utils/math.js#L32-L70 |
3,315 | swimlane/ngx-datatable | release/utils/math.js | forceFillColumnWidths | function forceFillColumnWidths(allColumns, expectedWidth, startIdx, allowBleed, defaultColWidth) {
if (defaultColWidth === void 0) { defaultColWidth = 300; }
var columnsToResize = allColumns
.slice(startIdx + 1, allColumns.length)
.filter(function (c) {
return c.canAutoResize !== false;
});
for (var _i = 0, columnsToResize_1 = columnsToResize; _i < columnsToResize_1.length; _i++) {
var column = columnsToResize_1[_i];
if (!column.$$oldWidth) {
column.$$oldWidth = column.width;
}
}
var additionWidthPerColumn = 0;
var exceedsWindow = false;
var contentWidth = getContentWidth(allColumns, defaultColWidth);
var remainingWidth = expectedWidth - contentWidth;
var columnsProcessed = [];
// This loop takes care of the
do {
additionWidthPerColumn = remainingWidth / columnsToResize.length;
exceedsWindow = contentWidth >= expectedWidth;
for (var _a = 0, columnsToResize_2 = columnsToResize; _a < columnsToResize_2.length; _a++) {
var column = columnsToResize_2[_a];
if (exceedsWindow && allowBleed) {
column.width = column.$$oldWidth || column.width || defaultColWidth;
}
else {
var newSize = (column.width || defaultColWidth) + additionWidthPerColumn;
if (column.minWidth && newSize < column.minWidth) {
column.width = column.minWidth;
columnsProcessed.push(column);
}
else if (column.maxWidth && newSize > column.maxWidth) {
column.width = column.maxWidth;
columnsProcessed.push(column);
}
else {
column.width = newSize;
}
}
column.width = Math.max(0, column.width);
}
contentWidth = getContentWidth(allColumns);
remainingWidth = expectedWidth - contentWidth;
removeProcessedColumns(columnsToResize, columnsProcessed);
} while (remainingWidth > 0 && columnsToResize.length !== 0);
} | javascript | function forceFillColumnWidths(allColumns, expectedWidth, startIdx, allowBleed, defaultColWidth) {
if (defaultColWidth === void 0) { defaultColWidth = 300; }
var columnsToResize = allColumns
.slice(startIdx + 1, allColumns.length)
.filter(function (c) {
return c.canAutoResize !== false;
});
for (var _i = 0, columnsToResize_1 = columnsToResize; _i < columnsToResize_1.length; _i++) {
var column = columnsToResize_1[_i];
if (!column.$$oldWidth) {
column.$$oldWidth = column.width;
}
}
var additionWidthPerColumn = 0;
var exceedsWindow = false;
var contentWidth = getContentWidth(allColumns, defaultColWidth);
var remainingWidth = expectedWidth - contentWidth;
var columnsProcessed = [];
// This loop takes care of the
do {
additionWidthPerColumn = remainingWidth / columnsToResize.length;
exceedsWindow = contentWidth >= expectedWidth;
for (var _a = 0, columnsToResize_2 = columnsToResize; _a < columnsToResize_2.length; _a++) {
var column = columnsToResize_2[_a];
if (exceedsWindow && allowBleed) {
column.width = column.$$oldWidth || column.width || defaultColWidth;
}
else {
var newSize = (column.width || defaultColWidth) + additionWidthPerColumn;
if (column.minWidth && newSize < column.minWidth) {
column.width = column.minWidth;
columnsProcessed.push(column);
}
else if (column.maxWidth && newSize > column.maxWidth) {
column.width = column.maxWidth;
columnsProcessed.push(column);
}
else {
column.width = newSize;
}
}
column.width = Math.max(0, column.width);
}
contentWidth = getContentWidth(allColumns);
remainingWidth = expectedWidth - contentWidth;
removeProcessedColumns(columnsToResize, columnsProcessed);
} while (remainingWidth > 0 && columnsToResize.length !== 0);
} | [
"function",
"forceFillColumnWidths",
"(",
"allColumns",
",",
"expectedWidth",
",",
"startIdx",
",",
"allowBleed",
",",
"defaultColWidth",
")",
"{",
"if",
"(",
"defaultColWidth",
"===",
"void",
"0",
")",
"{",
"defaultColWidth",
"=",
"300",
";",
"}",
"var",
"columnsToResize",
"=",
"allColumns",
".",
"slice",
"(",
"startIdx",
"+",
"1",
",",
"allColumns",
".",
"length",
")",
".",
"filter",
"(",
"function",
"(",
"c",
")",
"{",
"return",
"c",
".",
"canAutoResize",
"!==",
"false",
";",
"}",
")",
";",
"for",
"(",
"var",
"_i",
"=",
"0",
",",
"columnsToResize_1",
"=",
"columnsToResize",
";",
"_i",
"<",
"columnsToResize_1",
".",
"length",
";",
"_i",
"++",
")",
"{",
"var",
"column",
"=",
"columnsToResize_1",
"[",
"_i",
"]",
";",
"if",
"(",
"!",
"column",
".",
"$$oldWidth",
")",
"{",
"column",
".",
"$$oldWidth",
"=",
"column",
".",
"width",
";",
"}",
"}",
"var",
"additionWidthPerColumn",
"=",
"0",
";",
"var",
"exceedsWindow",
"=",
"false",
";",
"var",
"contentWidth",
"=",
"getContentWidth",
"(",
"allColumns",
",",
"defaultColWidth",
")",
";",
"var",
"remainingWidth",
"=",
"expectedWidth",
"-",
"contentWidth",
";",
"var",
"columnsProcessed",
"=",
"[",
"]",
";",
"// This loop takes care of the",
"do",
"{",
"additionWidthPerColumn",
"=",
"remainingWidth",
"/",
"columnsToResize",
".",
"length",
";",
"exceedsWindow",
"=",
"contentWidth",
">=",
"expectedWidth",
";",
"for",
"(",
"var",
"_a",
"=",
"0",
",",
"columnsToResize_2",
"=",
"columnsToResize",
";",
"_a",
"<",
"columnsToResize_2",
".",
"length",
";",
"_a",
"++",
")",
"{",
"var",
"column",
"=",
"columnsToResize_2",
"[",
"_a",
"]",
";",
"if",
"(",
"exceedsWindow",
"&&",
"allowBleed",
")",
"{",
"column",
".",
"width",
"=",
"column",
".",
"$$oldWidth",
"||",
"column",
".",
"width",
"||",
"defaultColWidth",
";",
"}",
"else",
"{",
"var",
"newSize",
"=",
"(",
"column",
".",
"width",
"||",
"defaultColWidth",
")",
"+",
"additionWidthPerColumn",
";",
"if",
"(",
"column",
".",
"minWidth",
"&&",
"newSize",
"<",
"column",
".",
"minWidth",
")",
"{",
"column",
".",
"width",
"=",
"column",
".",
"minWidth",
";",
"columnsProcessed",
".",
"push",
"(",
"column",
")",
";",
"}",
"else",
"if",
"(",
"column",
".",
"maxWidth",
"&&",
"newSize",
">",
"column",
".",
"maxWidth",
")",
"{",
"column",
".",
"width",
"=",
"column",
".",
"maxWidth",
";",
"columnsProcessed",
".",
"push",
"(",
"column",
")",
";",
"}",
"else",
"{",
"column",
".",
"width",
"=",
"newSize",
";",
"}",
"}",
"column",
".",
"width",
"=",
"Math",
".",
"max",
"(",
"0",
",",
"column",
".",
"width",
")",
";",
"}",
"contentWidth",
"=",
"getContentWidth",
"(",
"allColumns",
")",
";",
"remainingWidth",
"=",
"expectedWidth",
"-",
"contentWidth",
";",
"removeProcessedColumns",
"(",
"columnsToResize",
",",
"columnsProcessed",
")",
";",
"}",
"while",
"(",
"remainingWidth",
">",
"0",
"&&",
"columnsToResize",
".",
"length",
"!==",
"0",
")",
";",
"}"
] | Forces the width of the columns to
distribute equally but overflowing when necessary
Rules:
- If combined withs are less than the total width of the grid,
proportion the widths given the min / max / normal widths to fill the width.
- If the combined widths, exceed the total width of the grid,
use the standard widths.
- If a column is resized, it should always use that width
- The proportional widths should never fall below min size if specified.
- If the grid starts off small but then becomes greater than the size ( + / - )
the width should use the original width; not the newly proportioned widths. | [
"Forces",
"the",
"width",
"of",
"the",
"columns",
"to",
"distribute",
"equally",
"but",
"overflowing",
"when",
"necessary"
] | d7df15a070282a169524dba51d9572008b74804c | https://github.com/swimlane/ngx-datatable/blob/d7df15a070282a169524dba51d9572008b74804c/release/utils/math.js#L90-L137 |
3,316 | swimlane/ngx-datatable | release/utils/math.js | removeProcessedColumns | function removeProcessedColumns(columnsToResize, columnsProcessed) {
for (var _i = 0, columnsProcessed_1 = columnsProcessed; _i < columnsProcessed_1.length; _i++) {
var column = columnsProcessed_1[_i];
var index = columnsToResize.indexOf(column);
columnsToResize.splice(index, 1);
}
} | javascript | function removeProcessedColumns(columnsToResize, columnsProcessed) {
for (var _i = 0, columnsProcessed_1 = columnsProcessed; _i < columnsProcessed_1.length; _i++) {
var column = columnsProcessed_1[_i];
var index = columnsToResize.indexOf(column);
columnsToResize.splice(index, 1);
}
} | [
"function",
"removeProcessedColumns",
"(",
"columnsToResize",
",",
"columnsProcessed",
")",
"{",
"for",
"(",
"var",
"_i",
"=",
"0",
",",
"columnsProcessed_1",
"=",
"columnsProcessed",
";",
"_i",
"<",
"columnsProcessed_1",
".",
"length",
";",
"_i",
"++",
")",
"{",
"var",
"column",
"=",
"columnsProcessed_1",
"[",
"_i",
"]",
";",
"var",
"index",
"=",
"columnsToResize",
".",
"indexOf",
"(",
"column",
")",
";",
"columnsToResize",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"}",
"}"
] | Remove the processed columns from the current active columns. | [
"Remove",
"the",
"processed",
"columns",
"from",
"the",
"current",
"active",
"columns",
"."
] | d7df15a070282a169524dba51d9572008b74804c | https://github.com/swimlane/ngx-datatable/blob/d7df15a070282a169524dba51d9572008b74804c/release/utils/math.js#L142-L148 |
3,317 | swimlane/ngx-datatable | release/utils/math.js | getContentWidth | function getContentWidth(allColumns, defaultColWidth) {
if (defaultColWidth === void 0) { defaultColWidth = 300; }
var contentWidth = 0;
for (var _i = 0, allColumns_1 = allColumns; _i < allColumns_1.length; _i++) {
var column = allColumns_1[_i];
contentWidth += (column.width || defaultColWidth);
}
return contentWidth;
} | javascript | function getContentWidth(allColumns, defaultColWidth) {
if (defaultColWidth === void 0) { defaultColWidth = 300; }
var contentWidth = 0;
for (var _i = 0, allColumns_1 = allColumns; _i < allColumns_1.length; _i++) {
var column = allColumns_1[_i];
contentWidth += (column.width || defaultColWidth);
}
return contentWidth;
} | [
"function",
"getContentWidth",
"(",
"allColumns",
",",
"defaultColWidth",
")",
"{",
"if",
"(",
"defaultColWidth",
"===",
"void",
"0",
")",
"{",
"defaultColWidth",
"=",
"300",
";",
"}",
"var",
"contentWidth",
"=",
"0",
";",
"for",
"(",
"var",
"_i",
"=",
"0",
",",
"allColumns_1",
"=",
"allColumns",
";",
"_i",
"<",
"allColumns_1",
".",
"length",
";",
"_i",
"++",
")",
"{",
"var",
"column",
"=",
"allColumns_1",
"[",
"_i",
"]",
";",
"contentWidth",
"+=",
"(",
"column",
".",
"width",
"||",
"defaultColWidth",
")",
";",
"}",
"return",
"contentWidth",
";",
"}"
] | Gets the width of the columns | [
"Gets",
"the",
"width",
"of",
"the",
"columns"
] | d7df15a070282a169524dba51d9572008b74804c | https://github.com/swimlane/ngx-datatable/blob/d7df15a070282a169524dba51d9572008b74804c/release/utils/math.js#L152-L160 |
3,318 | swimlane/ngx-datatable | release/utils/tree.js | groupRowsByParents | function groupRowsByParents(rows, from, to) {
if (from && to) {
var nodeById = {};
var l = rows.length;
var node = null;
nodeById[0] = new TreeNode(); // that's the root node
var uniqIDs = rows.reduce(function (arr, item) {
var toValue = to(item);
if (arr.indexOf(toValue) === -1) {
arr.push(toValue);
}
return arr;
}, []);
for (var i = 0; i < l; i++) { // make TreeNode objects for each item
nodeById[to(rows[i])] = new TreeNode(rows[i]);
}
for (var i = 0; i < l; i++) { // link all TreeNode objects
node = nodeById[to(rows[i])];
var parent_1 = 0;
var fromValue = from(node.row);
if (!!fromValue && (uniqIDs.indexOf(fromValue) > -1)) {
parent_1 = fromValue;
}
node.parent = nodeById[parent_1];
node.row['level'] = node.parent.row['level'] + 1;
node.parent.children.push(node);
}
var resolvedRows_1 = [];
nodeById[0].flatten(function () {
resolvedRows_1 = resolvedRows_1.concat([this.row]);
}, true);
return resolvedRows_1;
}
else {
return rows;
}
} | javascript | function groupRowsByParents(rows, from, to) {
if (from && to) {
var nodeById = {};
var l = rows.length;
var node = null;
nodeById[0] = new TreeNode(); // that's the root node
var uniqIDs = rows.reduce(function (arr, item) {
var toValue = to(item);
if (arr.indexOf(toValue) === -1) {
arr.push(toValue);
}
return arr;
}, []);
for (var i = 0; i < l; i++) { // make TreeNode objects for each item
nodeById[to(rows[i])] = new TreeNode(rows[i]);
}
for (var i = 0; i < l; i++) { // link all TreeNode objects
node = nodeById[to(rows[i])];
var parent_1 = 0;
var fromValue = from(node.row);
if (!!fromValue && (uniqIDs.indexOf(fromValue) > -1)) {
parent_1 = fromValue;
}
node.parent = nodeById[parent_1];
node.row['level'] = node.parent.row['level'] + 1;
node.parent.children.push(node);
}
var resolvedRows_1 = [];
nodeById[0].flatten(function () {
resolvedRows_1 = resolvedRows_1.concat([this.row]);
}, true);
return resolvedRows_1;
}
else {
return rows;
}
} | [
"function",
"groupRowsByParents",
"(",
"rows",
",",
"from",
",",
"to",
")",
"{",
"if",
"(",
"from",
"&&",
"to",
")",
"{",
"var",
"nodeById",
"=",
"{",
"}",
";",
"var",
"l",
"=",
"rows",
".",
"length",
";",
"var",
"node",
"=",
"null",
";",
"nodeById",
"[",
"0",
"]",
"=",
"new",
"TreeNode",
"(",
")",
";",
"// that's the root node",
"var",
"uniqIDs",
"=",
"rows",
".",
"reduce",
"(",
"function",
"(",
"arr",
",",
"item",
")",
"{",
"var",
"toValue",
"=",
"to",
"(",
"item",
")",
";",
"if",
"(",
"arr",
".",
"indexOf",
"(",
"toValue",
")",
"===",
"-",
"1",
")",
"{",
"arr",
".",
"push",
"(",
"toValue",
")",
";",
"}",
"return",
"arr",
";",
"}",
",",
"[",
"]",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"// make TreeNode objects for each item",
"nodeById",
"[",
"to",
"(",
"rows",
"[",
"i",
"]",
")",
"]",
"=",
"new",
"TreeNode",
"(",
"rows",
"[",
"i",
"]",
")",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"// link all TreeNode objects",
"node",
"=",
"nodeById",
"[",
"to",
"(",
"rows",
"[",
"i",
"]",
")",
"]",
";",
"var",
"parent_1",
"=",
"0",
";",
"var",
"fromValue",
"=",
"from",
"(",
"node",
".",
"row",
")",
";",
"if",
"(",
"!",
"!",
"fromValue",
"&&",
"(",
"uniqIDs",
".",
"indexOf",
"(",
"fromValue",
")",
">",
"-",
"1",
")",
")",
"{",
"parent_1",
"=",
"fromValue",
";",
"}",
"node",
".",
"parent",
"=",
"nodeById",
"[",
"parent_1",
"]",
";",
"node",
".",
"row",
"[",
"'level'",
"]",
"=",
"node",
".",
"parent",
".",
"row",
"[",
"'level'",
"]",
"+",
"1",
";",
"node",
".",
"parent",
".",
"children",
".",
"push",
"(",
"node",
")",
";",
"}",
"var",
"resolvedRows_1",
"=",
"[",
"]",
";",
"nodeById",
"[",
"0",
"]",
".",
"flatten",
"(",
"function",
"(",
")",
"{",
"resolvedRows_1",
"=",
"resolvedRows_1",
".",
"concat",
"(",
"[",
"this",
".",
"row",
"]",
")",
";",
"}",
",",
"true",
")",
";",
"return",
"resolvedRows_1",
";",
"}",
"else",
"{",
"return",
"rows",
";",
"}",
"}"
] | This functions rearrange items by their parents
Also sets the level value to each of the items
Note: Expecting each item has a property called parentId
Note: This algorithm will fail if a list has two or more items with same ID
NOTE: This algorithm will fail if there is a deadlock of relationship
For example,
Input
id -> parent
1 -> 0
2 -> 0
3 -> 1
4 -> 1
5 -> 2
7 -> 8
6 -> 3
Output
id -> level
1 -> 0
--3 -> 1
----6 -> 2
--4 -> 1
2 -> 0
--5 -> 1
7 -> 8
@param rows | [
"This",
"functions",
"rearrange",
"items",
"by",
"their",
"parents",
"Also",
"sets",
"the",
"level",
"value",
"to",
"each",
"of",
"the",
"items"
] | d7df15a070282a169524dba51d9572008b74804c | https://github.com/swimlane/ngx-datatable/blob/d7df15a070282a169524dba51d9572008b74804c/release/utils/tree.js#L44-L80 |
3,319 | swimlane/ngx-datatable | release/utils/column-helper.js | setColumnDefaults | function setColumnDefaults(columns) {
if (!columns)
return;
// Only one column should hold the tree view
// Thus if multiple columns are provided with
// isTreeColumn as true we take only the first one
var treeColumnFound = false;
for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) {
var column = columns_1[_i];
if (!column.$$id) {
column.$$id = id_1.id();
}
// prop can be numeric; zero is valid not a missing prop
// translate name => prop
if (isNullOrUndefined(column.prop) && column.name) {
column.prop = camel_case_1.camelCase(column.name);
}
if (!column.$$valueGetter) {
column.$$valueGetter = column_prop_getters_1.getterForProp(column.prop);
}
// format props if no name passed
if (!isNullOrUndefined(column.prop) && isNullOrUndefined(column.name)) {
column.name = camel_case_1.deCamelCase(String(column.prop));
}
if (isNullOrUndefined(column.prop) && isNullOrUndefined(column.name)) {
column.name = ''; // Fixes IE and Edge displaying `null`
}
if (!column.hasOwnProperty('resizeable')) {
column.resizeable = true;
}
if (!column.hasOwnProperty('sortable')) {
column.sortable = true;
}
if (!column.hasOwnProperty('draggable')) {
column.draggable = true;
}
if (!column.hasOwnProperty('canAutoResize')) {
column.canAutoResize = true;
}
if (!column.hasOwnProperty('width')) {
column.width = 150;
}
if (!column.hasOwnProperty('isTreeColumn')) {
column.isTreeColumn = false;
}
else {
if (column.isTreeColumn && !treeColumnFound) {
// If the first column with isTreeColumn is true found
// we mark that treeCoulmn is found
treeColumnFound = true;
}
else {
// After that isTreeColumn property for any other column
// will be set as false
column.isTreeColumn = false;
}
}
}
} | javascript | function setColumnDefaults(columns) {
if (!columns)
return;
// Only one column should hold the tree view
// Thus if multiple columns are provided with
// isTreeColumn as true we take only the first one
var treeColumnFound = false;
for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) {
var column = columns_1[_i];
if (!column.$$id) {
column.$$id = id_1.id();
}
// prop can be numeric; zero is valid not a missing prop
// translate name => prop
if (isNullOrUndefined(column.prop) && column.name) {
column.prop = camel_case_1.camelCase(column.name);
}
if (!column.$$valueGetter) {
column.$$valueGetter = column_prop_getters_1.getterForProp(column.prop);
}
// format props if no name passed
if (!isNullOrUndefined(column.prop) && isNullOrUndefined(column.name)) {
column.name = camel_case_1.deCamelCase(String(column.prop));
}
if (isNullOrUndefined(column.prop) && isNullOrUndefined(column.name)) {
column.name = ''; // Fixes IE and Edge displaying `null`
}
if (!column.hasOwnProperty('resizeable')) {
column.resizeable = true;
}
if (!column.hasOwnProperty('sortable')) {
column.sortable = true;
}
if (!column.hasOwnProperty('draggable')) {
column.draggable = true;
}
if (!column.hasOwnProperty('canAutoResize')) {
column.canAutoResize = true;
}
if (!column.hasOwnProperty('width')) {
column.width = 150;
}
if (!column.hasOwnProperty('isTreeColumn')) {
column.isTreeColumn = false;
}
else {
if (column.isTreeColumn && !treeColumnFound) {
// If the first column with isTreeColumn is true found
// we mark that treeCoulmn is found
treeColumnFound = true;
}
else {
// After that isTreeColumn property for any other column
// will be set as false
column.isTreeColumn = false;
}
}
}
} | [
"function",
"setColumnDefaults",
"(",
"columns",
")",
"{",
"if",
"(",
"!",
"columns",
")",
"return",
";",
"// Only one column should hold the tree view",
"// Thus if multiple columns are provided with",
"// isTreeColumn as true we take only the first one",
"var",
"treeColumnFound",
"=",
"false",
";",
"for",
"(",
"var",
"_i",
"=",
"0",
",",
"columns_1",
"=",
"columns",
";",
"_i",
"<",
"columns_1",
".",
"length",
";",
"_i",
"++",
")",
"{",
"var",
"column",
"=",
"columns_1",
"[",
"_i",
"]",
";",
"if",
"(",
"!",
"column",
".",
"$$id",
")",
"{",
"column",
".",
"$$id",
"=",
"id_1",
".",
"id",
"(",
")",
";",
"}",
"// prop can be numeric; zero is valid not a missing prop",
"// translate name => prop",
"if",
"(",
"isNullOrUndefined",
"(",
"column",
".",
"prop",
")",
"&&",
"column",
".",
"name",
")",
"{",
"column",
".",
"prop",
"=",
"camel_case_1",
".",
"camelCase",
"(",
"column",
".",
"name",
")",
";",
"}",
"if",
"(",
"!",
"column",
".",
"$$valueGetter",
")",
"{",
"column",
".",
"$$valueGetter",
"=",
"column_prop_getters_1",
".",
"getterForProp",
"(",
"column",
".",
"prop",
")",
";",
"}",
"// format props if no name passed",
"if",
"(",
"!",
"isNullOrUndefined",
"(",
"column",
".",
"prop",
")",
"&&",
"isNullOrUndefined",
"(",
"column",
".",
"name",
")",
")",
"{",
"column",
".",
"name",
"=",
"camel_case_1",
".",
"deCamelCase",
"(",
"String",
"(",
"column",
".",
"prop",
")",
")",
";",
"}",
"if",
"(",
"isNullOrUndefined",
"(",
"column",
".",
"prop",
")",
"&&",
"isNullOrUndefined",
"(",
"column",
".",
"name",
")",
")",
"{",
"column",
".",
"name",
"=",
"''",
";",
"// Fixes IE and Edge displaying `null`",
"}",
"if",
"(",
"!",
"column",
".",
"hasOwnProperty",
"(",
"'resizeable'",
")",
")",
"{",
"column",
".",
"resizeable",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"column",
".",
"hasOwnProperty",
"(",
"'sortable'",
")",
")",
"{",
"column",
".",
"sortable",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"column",
".",
"hasOwnProperty",
"(",
"'draggable'",
")",
")",
"{",
"column",
".",
"draggable",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"column",
".",
"hasOwnProperty",
"(",
"'canAutoResize'",
")",
")",
"{",
"column",
".",
"canAutoResize",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"column",
".",
"hasOwnProperty",
"(",
"'width'",
")",
")",
"{",
"column",
".",
"width",
"=",
"150",
";",
"}",
"if",
"(",
"!",
"column",
".",
"hasOwnProperty",
"(",
"'isTreeColumn'",
")",
")",
"{",
"column",
".",
"isTreeColumn",
"=",
"false",
";",
"}",
"else",
"{",
"if",
"(",
"column",
".",
"isTreeColumn",
"&&",
"!",
"treeColumnFound",
")",
"{",
"// If the first column with isTreeColumn is true found",
"// we mark that treeCoulmn is found",
"treeColumnFound",
"=",
"true",
";",
"}",
"else",
"{",
"// After that isTreeColumn property for any other column",
"// will be set as false",
"column",
".",
"isTreeColumn",
"=",
"false",
";",
"}",
"}",
"}",
"}"
] | Sets the column defaults | [
"Sets",
"the",
"column",
"defaults"
] | d7df15a070282a169524dba51d9572008b74804c | https://github.com/swimlane/ngx-datatable/blob/d7df15a070282a169524dba51d9572008b74804c/release/utils/column-helper.js#L9-L67 |
3,320 | swimlane/ngx-datatable | release/utils/column-helper.js | translateTemplates | function translateTemplates(templates) {
var result = [];
for (var _i = 0, templates_1 = templates; _i < templates_1.length; _i++) {
var temp = templates_1[_i];
var col = {};
var props = Object.getOwnPropertyNames(temp);
for (var _a = 0, props_1 = props; _a < props_1.length; _a++) {
var prop = props_1[_a];
col[prop] = temp[prop];
}
if (temp.headerTemplate) {
col.headerTemplate = temp.headerTemplate;
}
if (temp.cellTemplate) {
col.cellTemplate = temp.cellTemplate;
}
if (temp.summaryFunc) {
col.summaryFunc = temp.summaryFunc;
}
if (temp.summaryTemplate) {
col.summaryTemplate = temp.summaryTemplate;
}
result.push(col);
}
return result;
} | javascript | function translateTemplates(templates) {
var result = [];
for (var _i = 0, templates_1 = templates; _i < templates_1.length; _i++) {
var temp = templates_1[_i];
var col = {};
var props = Object.getOwnPropertyNames(temp);
for (var _a = 0, props_1 = props; _a < props_1.length; _a++) {
var prop = props_1[_a];
col[prop] = temp[prop];
}
if (temp.headerTemplate) {
col.headerTemplate = temp.headerTemplate;
}
if (temp.cellTemplate) {
col.cellTemplate = temp.cellTemplate;
}
if (temp.summaryFunc) {
col.summaryFunc = temp.summaryFunc;
}
if (temp.summaryTemplate) {
col.summaryTemplate = temp.summaryTemplate;
}
result.push(col);
}
return result;
} | [
"function",
"translateTemplates",
"(",
"templates",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"_i",
"=",
"0",
",",
"templates_1",
"=",
"templates",
";",
"_i",
"<",
"templates_1",
".",
"length",
";",
"_i",
"++",
")",
"{",
"var",
"temp",
"=",
"templates_1",
"[",
"_i",
"]",
";",
"var",
"col",
"=",
"{",
"}",
";",
"var",
"props",
"=",
"Object",
".",
"getOwnPropertyNames",
"(",
"temp",
")",
";",
"for",
"(",
"var",
"_a",
"=",
"0",
",",
"props_1",
"=",
"props",
";",
"_a",
"<",
"props_1",
".",
"length",
";",
"_a",
"++",
")",
"{",
"var",
"prop",
"=",
"props_1",
"[",
"_a",
"]",
";",
"col",
"[",
"prop",
"]",
"=",
"temp",
"[",
"prop",
"]",
";",
"}",
"if",
"(",
"temp",
".",
"headerTemplate",
")",
"{",
"col",
".",
"headerTemplate",
"=",
"temp",
".",
"headerTemplate",
";",
"}",
"if",
"(",
"temp",
".",
"cellTemplate",
")",
"{",
"col",
".",
"cellTemplate",
"=",
"temp",
".",
"cellTemplate",
";",
"}",
"if",
"(",
"temp",
".",
"summaryFunc",
")",
"{",
"col",
".",
"summaryFunc",
"=",
"temp",
".",
"summaryFunc",
";",
"}",
"if",
"(",
"temp",
".",
"summaryTemplate",
")",
"{",
"col",
".",
"summaryTemplate",
"=",
"temp",
".",
"summaryTemplate",
";",
"}",
"result",
".",
"push",
"(",
"col",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Translates templates definitions to objects | [
"Translates",
"templates",
"definitions",
"to",
"objects"
] | d7df15a070282a169524dba51d9572008b74804c | https://github.com/swimlane/ngx-datatable/blob/d7df15a070282a169524dba51d9572008b74804c/release/utils/column-helper.js#L76-L101 |
3,321 | swimlane/ngx-datatable | release/utils/column-prop-getters.js | getterForProp | function getterForProp(prop) {
if (prop == null)
return emptyStringGetter;
if (typeof prop === 'number') {
return numericIndexGetter;
}
else {
// deep or simple
if (prop.indexOf('.') !== -1) {
return deepValueGetter;
}
else {
return shallowValueGetter;
}
}
} | javascript | function getterForProp(prop) {
if (prop == null)
return emptyStringGetter;
if (typeof prop === 'number') {
return numericIndexGetter;
}
else {
// deep or simple
if (prop.indexOf('.') !== -1) {
return deepValueGetter;
}
else {
return shallowValueGetter;
}
}
} | [
"function",
"getterForProp",
"(",
"prop",
")",
"{",
"if",
"(",
"prop",
"==",
"null",
")",
"return",
"emptyStringGetter",
";",
"if",
"(",
"typeof",
"prop",
"===",
"'number'",
")",
"{",
"return",
"numericIndexGetter",
";",
"}",
"else",
"{",
"// deep or simple",
"if",
"(",
"prop",
".",
"indexOf",
"(",
"'.'",
")",
"!==",
"-",
"1",
")",
"{",
"return",
"deepValueGetter",
";",
"}",
"else",
"{",
"return",
"shallowValueGetter",
";",
"}",
"}",
"}"
] | Returns the appropriate getter function for this kind of prop.
If prop == null, returns the emptyStringGetter. | [
"Returns",
"the",
"appropriate",
"getter",
"function",
"for",
"this",
"kind",
"of",
"prop",
".",
"If",
"prop",
"==",
"null",
"returns",
"the",
"emptyStringGetter",
"."
] | d7df15a070282a169524dba51d9572008b74804c | https://github.com/swimlane/ngx-datatable/blob/d7df15a070282a169524dba51d9572008b74804c/release/utils/column-prop-getters.js#L16-L31 |
3,322 | swimlane/ngx-datatable | release/utils/column-prop-getters.js | numericIndexGetter | function numericIndexGetter(row, index) {
if (row == null)
return '';
// mimic behavior of deepValueGetter
if (!row || index == null)
return row;
var value = row[index];
if (value == null)
return '';
return value;
} | javascript | function numericIndexGetter(row, index) {
if (row == null)
return '';
// mimic behavior of deepValueGetter
if (!row || index == null)
return row;
var value = row[index];
if (value == null)
return '';
return value;
} | [
"function",
"numericIndexGetter",
"(",
"row",
",",
"index",
")",
"{",
"if",
"(",
"row",
"==",
"null",
")",
"return",
"''",
";",
"// mimic behavior of deepValueGetter",
"if",
"(",
"!",
"row",
"||",
"index",
"==",
"null",
")",
"return",
"row",
";",
"var",
"value",
"=",
"row",
"[",
"index",
"]",
";",
"if",
"(",
"value",
"==",
"null",
")",
"return",
"''",
";",
"return",
"value",
";",
"}"
] | Returns the value at this numeric index.
@param row array of values
@param index numeric index
@returns {any} or '' if invalid index | [
"Returns",
"the",
"value",
"at",
"this",
"numeric",
"index",
"."
] | d7df15a070282a169524dba51d9572008b74804c | https://github.com/swimlane/ngx-datatable/blob/d7df15a070282a169524dba51d9572008b74804c/release/utils/column-prop-getters.js#L39-L49 |
3,323 | aws/aws-sdk-js | lib/credentials/chainable_temporary_credentials.js | ChainableTemporaryCredentials | function ChainableTemporaryCredentials(options) {
AWS.Credentials.call(this);
options = options || {};
this.errorCode = 'ChainableTemporaryCredentialsProviderFailure';
this.expired = true;
this.tokenCodeFn = null;
var params = AWS.util.copy(options.params) || {};
if (params.RoleArn) {
params.RoleSessionName = params.RoleSessionName || 'temporary-credentials';
}
if (params.SerialNumber) {
if (!options.tokenCodeFn || (typeof options.tokenCodeFn !== 'function')) {
throw new AWS.util.error(
new Error('tokenCodeFn must be a function when params.SerialNumber is given'),
{code: this.errorCode}
);
} else {
this.tokenCodeFn = options.tokenCodeFn;
}
}
this.service = new STS({
params: params,
credentials: options.masterCredentials || AWS.config.credentials
});
} | javascript | function ChainableTemporaryCredentials(options) {
AWS.Credentials.call(this);
options = options || {};
this.errorCode = 'ChainableTemporaryCredentialsProviderFailure';
this.expired = true;
this.tokenCodeFn = null;
var params = AWS.util.copy(options.params) || {};
if (params.RoleArn) {
params.RoleSessionName = params.RoleSessionName || 'temporary-credentials';
}
if (params.SerialNumber) {
if (!options.tokenCodeFn || (typeof options.tokenCodeFn !== 'function')) {
throw new AWS.util.error(
new Error('tokenCodeFn must be a function when params.SerialNumber is given'),
{code: this.errorCode}
);
} else {
this.tokenCodeFn = options.tokenCodeFn;
}
}
this.service = new STS({
params: params,
credentials: options.masterCredentials || AWS.config.credentials
});
} | [
"function",
"ChainableTemporaryCredentials",
"(",
"options",
")",
"{",
"AWS",
".",
"Credentials",
".",
"call",
"(",
"this",
")",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"errorCode",
"=",
"'ChainableTemporaryCredentialsProviderFailure'",
";",
"this",
".",
"expired",
"=",
"true",
";",
"this",
".",
"tokenCodeFn",
"=",
"null",
";",
"var",
"params",
"=",
"AWS",
".",
"util",
".",
"copy",
"(",
"options",
".",
"params",
")",
"||",
"{",
"}",
";",
"if",
"(",
"params",
".",
"RoleArn",
")",
"{",
"params",
".",
"RoleSessionName",
"=",
"params",
".",
"RoleSessionName",
"||",
"'temporary-credentials'",
";",
"}",
"if",
"(",
"params",
".",
"SerialNumber",
")",
"{",
"if",
"(",
"!",
"options",
".",
"tokenCodeFn",
"||",
"(",
"typeof",
"options",
".",
"tokenCodeFn",
"!==",
"'function'",
")",
")",
"{",
"throw",
"new",
"AWS",
".",
"util",
".",
"error",
"(",
"new",
"Error",
"(",
"'tokenCodeFn must be a function when params.SerialNumber is given'",
")",
",",
"{",
"code",
":",
"this",
".",
"errorCode",
"}",
")",
";",
"}",
"else",
"{",
"this",
".",
"tokenCodeFn",
"=",
"options",
".",
"tokenCodeFn",
";",
"}",
"}",
"this",
".",
"service",
"=",
"new",
"STS",
"(",
"{",
"params",
":",
"params",
",",
"credentials",
":",
"options",
".",
"masterCredentials",
"||",
"AWS",
".",
"config",
".",
"credentials",
"}",
")",
";",
"}"
] | Creates a new temporary credentials object.
@param options [map] a set of options
@option options params [map] ({}) a map of options that are passed to the
{AWS.STS.assumeRole} or {AWS.STS.getSessionToken} operations.
If a `RoleArn` parameter is passed in, credentials will be based on the
IAM role. If a `SerialNumber` parameter is passed in, {tokenCodeFn} must
also be passed in or an error will be thrown.
@option options masterCredentials [AWS.Credentials] the master credentials
used to get and refresh temporary credentials from AWS STS. By default,
AWS.config.credentials or AWS.config.credentialProvider will be used.
@option options tokenCodeFn [Function] (null) Function to provide
`TokenCode`, if `SerialNumber` is provided for profile in {params}. Function
is called with value of `SerialNumber` and `callback`, and should provide
the `TokenCode` or an error to the callback in the format
`callback(err, token)`.
@example Creating a new credentials object for generic temporary credentials
AWS.config.credentials = new AWS.ChainableTemporaryCredentials();
@example Creating a new credentials object for an IAM role
AWS.config.credentials = new AWS.ChainableTemporaryCredentials({
params: {
RoleArn: 'arn:aws:iam::1234567890:role/TemporaryCredentials'
}
});
@see AWS.STS.assumeRole
@see AWS.STS.getSessionToken | [
"Creates",
"a",
"new",
"temporary",
"credentials",
"object",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/credentials/chainable_temporary_credentials.js#L101-L126 |
3,324 | aws/aws-sdk-js | features/extra/helpers.js | eventually | function eventually(callback, block, options) {
if (!options) options = {};
if (!options.delay) options.delay = 0;
if (!options.backoff) options.backoff = 500;
if (!options.maxTime) options.maxTime = 5;
var delay = options.delay;
var started = this.AWS.util.date.getDate();
var self = this;
var retry = function() { callback(); };
retry.fail = function(err) {
var now = self.AWS.util.date.getDate();
if (now - started < options.maxTime * 1000) {
setTimeout(function () {
delay += options.backoff;
block.call(self, retry);
}, delay);
} else {
callback.fail(err || new Error('Eventually block timed out'));
}
};
block.call(this, retry);
} | javascript | function eventually(callback, block, options) {
if (!options) options = {};
if (!options.delay) options.delay = 0;
if (!options.backoff) options.backoff = 500;
if (!options.maxTime) options.maxTime = 5;
var delay = options.delay;
var started = this.AWS.util.date.getDate();
var self = this;
var retry = function() { callback(); };
retry.fail = function(err) {
var now = self.AWS.util.date.getDate();
if (now - started < options.maxTime * 1000) {
setTimeout(function () {
delay += options.backoff;
block.call(self, retry);
}, delay);
} else {
callback.fail(err || new Error('Eventually block timed out'));
}
};
block.call(this, retry);
} | [
"function",
"eventually",
"(",
"callback",
",",
"block",
",",
"options",
")",
"{",
"if",
"(",
"!",
"options",
")",
"options",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"options",
".",
"delay",
")",
"options",
".",
"delay",
"=",
"0",
";",
"if",
"(",
"!",
"options",
".",
"backoff",
")",
"options",
".",
"backoff",
"=",
"500",
";",
"if",
"(",
"!",
"options",
".",
"maxTime",
")",
"options",
".",
"maxTime",
"=",
"5",
";",
"var",
"delay",
"=",
"options",
".",
"delay",
";",
"var",
"started",
"=",
"this",
".",
"AWS",
".",
"util",
".",
"date",
".",
"getDate",
"(",
")",
";",
"var",
"self",
"=",
"this",
";",
"var",
"retry",
"=",
"function",
"(",
")",
"{",
"callback",
"(",
")",
";",
"}",
";",
"retry",
".",
"fail",
"=",
"function",
"(",
"err",
")",
"{",
"var",
"now",
"=",
"self",
".",
"AWS",
".",
"util",
".",
"date",
".",
"getDate",
"(",
")",
";",
"if",
"(",
"now",
"-",
"started",
"<",
"options",
".",
"maxTime",
"*",
"1000",
")",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"delay",
"+=",
"options",
".",
"backoff",
";",
"block",
".",
"call",
"(",
"self",
",",
"retry",
")",
";",
"}",
",",
"delay",
")",
";",
"}",
"else",
"{",
"callback",
".",
"fail",
"(",
"err",
"||",
"new",
"Error",
"(",
"'Eventually block timed out'",
")",
")",
";",
"}",
"}",
";",
"block",
".",
"call",
"(",
"this",
",",
"retry",
")",
";",
"}"
] | Call this function with a block that will be executed multiple times
to deal with eventually consistent conditions.
this.When(/^I something is eventually consistent$/, function(callback) {
this.eventually(callback, function(next) {
doSomething(function(response) {
if (response != notWhatIExpect) {
next.fail();
} else {
next();
}
});
});
});
You can pass in a few options after the function:
delay: The number of milliseconds to delay before retrying.
backoff: Add this number of milliseconds to the delay between each attempt.
maxTime: Maximum duration of milliseconds to wait for success. | [
"Call",
"this",
"function",
"with",
"a",
"block",
"that",
"will",
"be",
"executed",
"multiple",
"times",
"to",
"deal",
"with",
"eventually",
"consistent",
"conditions",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/features/extra/helpers.js#L33-L59 |
3,325 | aws/aws-sdk-js | features/extra/helpers.js | request | function request(svc, operation, params, next, extra) {
var world = this;
if (!svc) svc = this.service;
if (typeof svc === 'string') svc = this[svc];
svc[operation](params, function(err, data) {
world.response = this;
world.error = err;
world.data = data;
try {
if (typeof next.condition === 'function') {
var condition = next.condition.call(world, world);
if (!condition) {
next.fail(new Error('Request success condition failed'));
return;
}
}
if (extra) {
extra.call(world, world.response);
next.call(world);
}
else if (extra !== false && err) {
world.unexpectedError(world.response, next);
} else {
next.call(world);
}
} catch (err) {
next.fail(err);
}
});
} | javascript | function request(svc, operation, params, next, extra) {
var world = this;
if (!svc) svc = this.service;
if (typeof svc === 'string') svc = this[svc];
svc[operation](params, function(err, data) {
world.response = this;
world.error = err;
world.data = data;
try {
if (typeof next.condition === 'function') {
var condition = next.condition.call(world, world);
if (!condition) {
next.fail(new Error('Request success condition failed'));
return;
}
}
if (extra) {
extra.call(world, world.response);
next.call(world);
}
else if (extra !== false && err) {
world.unexpectedError(world.response, next);
} else {
next.call(world);
}
} catch (err) {
next.fail(err);
}
});
} | [
"function",
"request",
"(",
"svc",
",",
"operation",
",",
"params",
",",
"next",
",",
"extra",
")",
"{",
"var",
"world",
"=",
"this",
";",
"if",
"(",
"!",
"svc",
")",
"svc",
"=",
"this",
".",
"service",
";",
"if",
"(",
"typeof",
"svc",
"===",
"'string'",
")",
"svc",
"=",
"this",
"[",
"svc",
"]",
";",
"svc",
"[",
"operation",
"]",
"(",
"params",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"world",
".",
"response",
"=",
"this",
";",
"world",
".",
"error",
"=",
"err",
";",
"world",
".",
"data",
"=",
"data",
";",
"try",
"{",
"if",
"(",
"typeof",
"next",
".",
"condition",
"===",
"'function'",
")",
"{",
"var",
"condition",
"=",
"next",
".",
"condition",
".",
"call",
"(",
"world",
",",
"world",
")",
";",
"if",
"(",
"!",
"condition",
")",
"{",
"next",
".",
"fail",
"(",
"new",
"Error",
"(",
"'Request success condition failed'",
")",
")",
";",
"return",
";",
"}",
"}",
"if",
"(",
"extra",
")",
"{",
"extra",
".",
"call",
"(",
"world",
",",
"world",
".",
"response",
")",
";",
"next",
".",
"call",
"(",
"world",
")",
";",
"}",
"else",
"if",
"(",
"extra",
"!==",
"false",
"&&",
"err",
")",
"{",
"world",
".",
"unexpectedError",
"(",
"world",
".",
"response",
",",
"next",
")",
";",
"}",
"else",
"{",
"next",
".",
"call",
"(",
"world",
")",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"next",
".",
"fail",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}"
] | A short-cut for calling a service operation and waiting for it to
finish execution before moving onto the next step in the scenario. | [
"A",
"short",
"-",
"cut",
"for",
"calling",
"a",
"service",
"operation",
"and",
"waiting",
"for",
"it",
"to",
"finish",
"execution",
"before",
"moving",
"onto",
"the",
"next",
"step",
"in",
"the",
"scenario",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/features/extra/helpers.js#L65-L98 |
3,326 | aws/aws-sdk-js | features/extra/helpers.js | unexpectedError | function unexpectedError(resp, next) {
var svc = resp.request.service.api.serviceName;
var op = resp.request.operation;
var code = resp.error.code;
var msg = resp.error.message;
var err = 'Received unexpected error from ' + svc + '.' + op + ', ' + code + ': ' + msg;
next.fail(new Error(err));
} | javascript | function unexpectedError(resp, next) {
var svc = resp.request.service.api.serviceName;
var op = resp.request.operation;
var code = resp.error.code;
var msg = resp.error.message;
var err = 'Received unexpected error from ' + svc + '.' + op + ', ' + code + ': ' + msg;
next.fail(new Error(err));
} | [
"function",
"unexpectedError",
"(",
"resp",
",",
"next",
")",
"{",
"var",
"svc",
"=",
"resp",
".",
"request",
".",
"service",
".",
"api",
".",
"serviceName",
";",
"var",
"op",
"=",
"resp",
".",
"request",
".",
"operation",
";",
"var",
"code",
"=",
"resp",
".",
"error",
".",
"code",
";",
"var",
"msg",
"=",
"resp",
".",
"error",
".",
"message",
";",
"var",
"err",
"=",
"'Received unexpected error from '",
"+",
"svc",
"+",
"'.'",
"+",
"op",
"+",
"', '",
"+",
"code",
"+",
"': '",
"+",
"msg",
";",
"next",
".",
"fail",
"(",
"new",
"Error",
"(",
"err",
")",
")",
";",
"}"
] | Given a response that contains an error, this fails the current
step with a formatted error message that indicates which service and
operation failed. | [
"Given",
"a",
"response",
"that",
"contains",
"an",
"error",
"this",
"fails",
"the",
"current",
"step",
"with",
"a",
"formatted",
"error",
"message",
"that",
"indicates",
"which",
"service",
"and",
"operation",
"failed",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/features/extra/helpers.js#L105-L112 |
3,327 | aws/aws-sdk-js | features/extra/helpers.js | function(bucket) {
var fs = require('fs');
var path = require('path');
var filePath = path.resolve('integ.buckets.json');
var cache;
if (fs.existsSync(filePath)) {
try {
cache = JSON.parse(fs.readFileSync(filePath));
cache.buckets.push(bucket);
fs.writeFileSync(filePath, JSON.stringify(cache));
} catch (fileErr) {
throw fileErr;
}
} else {
cache = {};
cache.buckets = [bucket];
fs.writeFileSync(filePath, JSON.stringify(cache));
}
} | javascript | function(bucket) {
var fs = require('fs');
var path = require('path');
var filePath = path.resolve('integ.buckets.json');
var cache;
if (fs.existsSync(filePath)) {
try {
cache = JSON.parse(fs.readFileSync(filePath));
cache.buckets.push(bucket);
fs.writeFileSync(filePath, JSON.stringify(cache));
} catch (fileErr) {
throw fileErr;
}
} else {
cache = {};
cache.buckets = [bucket];
fs.writeFileSync(filePath, JSON.stringify(cache));
}
} | [
"function",
"(",
"bucket",
")",
"{",
"var",
"fs",
"=",
"require",
"(",
"'fs'",
")",
";",
"var",
"path",
"=",
"require",
"(",
"'path'",
")",
";",
"var",
"filePath",
"=",
"path",
".",
"resolve",
"(",
"'integ.buckets.json'",
")",
";",
"var",
"cache",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"filePath",
")",
")",
"{",
"try",
"{",
"cache",
"=",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"filePath",
")",
")",
";",
"cache",
".",
"buckets",
".",
"push",
"(",
"bucket",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"filePath",
",",
"JSON",
".",
"stringify",
"(",
"cache",
")",
")",
";",
"}",
"catch",
"(",
"fileErr",
")",
"{",
"throw",
"fileErr",
";",
"}",
"}",
"else",
"{",
"cache",
"=",
"{",
"}",
";",
"cache",
".",
"buckets",
"=",
"[",
"bucket",
"]",
";",
"fs",
".",
"writeFileSync",
"(",
"filePath",
",",
"JSON",
".",
"stringify",
"(",
"cache",
")",
")",
";",
"}",
"}"
] | Cache bucket names used for cleanup after all features have run. | [
"Cache",
"bucket",
"names",
"used",
"for",
"cleanup",
"after",
"all",
"features",
"have",
"run",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/features/extra/helpers.js#L117-L135 |
|
3,328 | aws/aws-sdk-js | features/extra/helpers.js | function(size, name) {
var fs = require('fs');
var path = require('path');
name = this.uniqueName(name);
// Cannot set this as a world property because the world
// is cleaned up before the AfterFeatures hook is fired.
var fixturePath = path.resolve('./features/extra/fixtures/tmp');
if (!fs.existsSync(fixturePath)) fs.mkdirSync(fixturePath);
var filename = path.join(fixturePath, name);
var body;
if (typeof size === 'string') {
switch (size) {
case 'empty': body = new Buffer(0); break;
case 'small': body = new Buffer(1024 * 1024); break;
case 'large': body = new Buffer(1024 * 1024 * 20); break;
}
} else if (typeof size === 'number') {
body = new Buffer(size);
}
fs.writeFileSync(filename, body);
return filename;
} | javascript | function(size, name) {
var fs = require('fs');
var path = require('path');
name = this.uniqueName(name);
// Cannot set this as a world property because the world
// is cleaned up before the AfterFeatures hook is fired.
var fixturePath = path.resolve('./features/extra/fixtures/tmp');
if (!fs.existsSync(fixturePath)) fs.mkdirSync(fixturePath);
var filename = path.join(fixturePath, name);
var body;
if (typeof size === 'string') {
switch (size) {
case 'empty': body = new Buffer(0); break;
case 'small': body = new Buffer(1024 * 1024); break;
case 'large': body = new Buffer(1024 * 1024 * 20); break;
}
} else if (typeof size === 'number') {
body = new Buffer(size);
}
fs.writeFileSync(filename, body);
return filename;
} | [
"function",
"(",
"size",
",",
"name",
")",
"{",
"var",
"fs",
"=",
"require",
"(",
"'fs'",
")",
";",
"var",
"path",
"=",
"require",
"(",
"'path'",
")",
";",
"name",
"=",
"this",
".",
"uniqueName",
"(",
"name",
")",
";",
"// Cannot set this as a world property because the world",
"// is cleaned up before the AfterFeatures hook is fired.",
"var",
"fixturePath",
"=",
"path",
".",
"resolve",
"(",
"'./features/extra/fixtures/tmp'",
")",
";",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"fixturePath",
")",
")",
"fs",
".",
"mkdirSync",
"(",
"fixturePath",
")",
";",
"var",
"filename",
"=",
"path",
".",
"join",
"(",
"fixturePath",
",",
"name",
")",
";",
"var",
"body",
";",
"if",
"(",
"typeof",
"size",
"===",
"'string'",
")",
"{",
"switch",
"(",
"size",
")",
"{",
"case",
"'empty'",
":",
"body",
"=",
"new",
"Buffer",
"(",
"0",
")",
";",
"break",
";",
"case",
"'small'",
":",
"body",
"=",
"new",
"Buffer",
"(",
"1024",
"*",
"1024",
")",
";",
"break",
";",
"case",
"'large'",
":",
"body",
"=",
"new",
"Buffer",
"(",
"1024",
"*",
"1024",
"*",
"20",
")",
";",
"break",
";",
"}",
"}",
"else",
"if",
"(",
"typeof",
"size",
"===",
"'number'",
")",
"{",
"body",
"=",
"new",
"Buffer",
"(",
"size",
")",
";",
"}",
"fs",
".",
"writeFileSync",
"(",
"filename",
",",
"body",
")",
";",
"return",
"filename",
";",
"}"
] | Creates a fixture file of given size and returns the path. | [
"Creates",
"a",
"fixture",
"file",
"of",
"given",
"size",
"and",
"returns",
"the",
"path",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/features/extra/helpers.js#L140-L162 |
|
3,329 | aws/aws-sdk-js | features/extra/helpers.js | function(size) {
var match;
var buffer;
if (match = size.match(/(\d+)KB/)) {
buffer = new Buffer(parseInt(match[1]) * 1024);
} else if (match = size.match(/(\d+)MB/)) {
buffer = new Buffer(parseInt(match[1]) * 1024 * 1024);
} else {
switch (size) {
case 'empty': buffer = new Buffer(0); break;
case 'small': buffer = new Buffer(1024 * 1024); break;
case 'large': buffer = new Buffer(1024 * 1024 * 20); break;
default: return new Buffer(1024 * 1024);
}
}
buffer.fill('x');
return buffer;
} | javascript | function(size) {
var match;
var buffer;
if (match = size.match(/(\d+)KB/)) {
buffer = new Buffer(parseInt(match[1]) * 1024);
} else if (match = size.match(/(\d+)MB/)) {
buffer = new Buffer(parseInt(match[1]) * 1024 * 1024);
} else {
switch (size) {
case 'empty': buffer = new Buffer(0); break;
case 'small': buffer = new Buffer(1024 * 1024); break;
case 'large': buffer = new Buffer(1024 * 1024 * 20); break;
default: return new Buffer(1024 * 1024);
}
}
buffer.fill('x');
return buffer;
} | [
"function",
"(",
"size",
")",
"{",
"var",
"match",
";",
"var",
"buffer",
";",
"if",
"(",
"match",
"=",
"size",
".",
"match",
"(",
"/",
"(\\d+)KB",
"/",
")",
")",
"{",
"buffer",
"=",
"new",
"Buffer",
"(",
"parseInt",
"(",
"match",
"[",
"1",
"]",
")",
"*",
"1024",
")",
";",
"}",
"else",
"if",
"(",
"match",
"=",
"size",
".",
"match",
"(",
"/",
"(\\d+)MB",
"/",
")",
")",
"{",
"buffer",
"=",
"new",
"Buffer",
"(",
"parseInt",
"(",
"match",
"[",
"1",
"]",
")",
"*",
"1024",
"*",
"1024",
")",
";",
"}",
"else",
"{",
"switch",
"(",
"size",
")",
"{",
"case",
"'empty'",
":",
"buffer",
"=",
"new",
"Buffer",
"(",
"0",
")",
";",
"break",
";",
"case",
"'small'",
":",
"buffer",
"=",
"new",
"Buffer",
"(",
"1024",
"*",
"1024",
")",
";",
"break",
";",
"case",
"'large'",
":",
"buffer",
"=",
"new",
"Buffer",
"(",
"1024",
"*",
"1024",
"*",
"20",
")",
";",
"break",
";",
"default",
":",
"return",
"new",
"Buffer",
"(",
"1024",
"*",
"1024",
")",
";",
"}",
"}",
"buffer",
".",
"fill",
"(",
"'x'",
")",
";",
"return",
"buffer",
";",
"}"
] | Creates and returns a buffer of given size | [
"Creates",
"and",
"returns",
"a",
"buffer",
"of",
"given",
"size"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/features/extra/helpers.js#L167-L184 |
|
3,330 | aws/aws-sdk-js | lib/event-stream/event-message-chunker.js | eventMessageChunker | function eventMessageChunker(buffer) {
/** @type Buffer[] */
var messages = [];
var offset = 0;
while (offset < buffer.length) {
var totalLength = buffer.readInt32BE(offset);
// create new buffer for individual message (shares memory with original)
var message = buffer.slice(offset, totalLength + offset);
// increment offset to it starts at the next message
offset += totalLength;
messages.push(message);
}
return messages;
} | javascript | function eventMessageChunker(buffer) {
/** @type Buffer[] */
var messages = [];
var offset = 0;
while (offset < buffer.length) {
var totalLength = buffer.readInt32BE(offset);
// create new buffer for individual message (shares memory with original)
var message = buffer.slice(offset, totalLength + offset);
// increment offset to it starts at the next message
offset += totalLength;
messages.push(message);
}
return messages;
} | [
"function",
"eventMessageChunker",
"(",
"buffer",
")",
"{",
"/** @type Buffer[] */",
"var",
"messages",
"=",
"[",
"]",
";",
"var",
"offset",
"=",
"0",
";",
"while",
"(",
"offset",
"<",
"buffer",
".",
"length",
")",
"{",
"var",
"totalLength",
"=",
"buffer",
".",
"readInt32BE",
"(",
"offset",
")",
";",
"// create new buffer for individual message (shares memory with original)",
"var",
"message",
"=",
"buffer",
".",
"slice",
"(",
"offset",
",",
"totalLength",
"+",
"offset",
")",
";",
"// increment offset to it starts at the next message",
"offset",
"+=",
"totalLength",
";",
"messages",
".",
"push",
"(",
"message",
")",
";",
"}",
"return",
"messages",
";",
"}"
] | Takes in a buffer of event messages and splits them into individual messages.
@param {Buffer} buffer
@api private | [
"Takes",
"in",
"a",
"buffer",
"of",
"event",
"messages",
"and",
"splits",
"them",
"into",
"individual",
"messages",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/event-stream/event-message-chunker.js#L6-L23 |
3,331 | aws/aws-sdk-js | lib/credentials/shared_ini_file_credentials.js | SharedIniFileCredentials | function SharedIniFileCredentials(options) {
AWS.Credentials.call(this);
options = options || {};
this.filename = options.filename;
this.profile = options.profile || process.env.AWS_PROFILE || AWS.util.defaultProfile;
this.disableAssumeRole = Boolean(options.disableAssumeRole);
this.preferStaticCredentials = Boolean(options.preferStaticCredentials);
this.tokenCodeFn = options.tokenCodeFn || null;
this.httpOptions = options.httpOptions || null;
this.get(options.callback || AWS.util.fn.noop);
} | javascript | function SharedIniFileCredentials(options) {
AWS.Credentials.call(this);
options = options || {};
this.filename = options.filename;
this.profile = options.profile || process.env.AWS_PROFILE || AWS.util.defaultProfile;
this.disableAssumeRole = Boolean(options.disableAssumeRole);
this.preferStaticCredentials = Boolean(options.preferStaticCredentials);
this.tokenCodeFn = options.tokenCodeFn || null;
this.httpOptions = options.httpOptions || null;
this.get(options.callback || AWS.util.fn.noop);
} | [
"function",
"SharedIniFileCredentials",
"(",
"options",
")",
"{",
"AWS",
".",
"Credentials",
".",
"call",
"(",
"this",
")",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"filename",
"=",
"options",
".",
"filename",
";",
"this",
".",
"profile",
"=",
"options",
".",
"profile",
"||",
"process",
".",
"env",
".",
"AWS_PROFILE",
"||",
"AWS",
".",
"util",
".",
"defaultProfile",
";",
"this",
".",
"disableAssumeRole",
"=",
"Boolean",
"(",
"options",
".",
"disableAssumeRole",
")",
";",
"this",
".",
"preferStaticCredentials",
"=",
"Boolean",
"(",
"options",
".",
"preferStaticCredentials",
")",
";",
"this",
".",
"tokenCodeFn",
"=",
"options",
".",
"tokenCodeFn",
"||",
"null",
";",
"this",
".",
"httpOptions",
"=",
"options",
".",
"httpOptions",
"||",
"null",
";",
"this",
".",
"get",
"(",
"options",
".",
"callback",
"||",
"AWS",
".",
"util",
".",
"fn",
".",
"noop",
")",
";",
"}"
] | Creates a new SharedIniFileCredentials object.
@param options [map] a set of options
@option options profile [String] (AWS_PROFILE env var or 'default')
the name of the profile to load.
@option options filename [String] ('~/.aws/credentials' or defined by
AWS_SHARED_CREDENTIALS_FILE process env var)
the filename to use when loading credentials.
@option options disableAssumeRole [Boolean] (false) True to disable
support for profiles that assume an IAM role. If true, and an assume
role profile is selected, an error is raised.
@option options preferStaticCredentials [Boolean] (false) True to
prefer static credentials to role_arn if both are present.
@option options tokenCodeFn [Function] (null) Function to provide
STS Assume Role TokenCode, if mfa_serial is provided for profile in ini
file. Function is called with value of mfa_serial and callback, and
should provide the TokenCode or an error to the callback in the format
callback(err, token)
@option options callback [Function] (err) Credentials are eagerly loaded
by the constructor. When the callback is called with no error, the
credentials have been loaded successfully.
@option options httpOptions [map] A set of options to pass to the low-level
HTTP request. Currently supported options are:
* **proxy** [String] — the URL to proxy requests through
* **agent** [http.Agent, https.Agent] — the Agent object to perform
HTTP requests with. Used for connection pooling. Defaults to the global
agent (`http.globalAgent`) for non-SSL connections. Note that for
SSL connections, a special Agent object is used in order to enable
peer certificate verification. This feature is only available in the
Node.js environment.
* **connectTimeout** [Integer] — Sets the socket to timeout after
failing to establish a connection with the server after
`connectTimeout` milliseconds. This timeout has no effect once a socket
connection has been established.
* **timeout** [Integer] — Sets the socket to timeout after timeout
milliseconds of inactivity on the socket. Defaults to two minutes
(120000). | [
"Creates",
"a",
"new",
"SharedIniFileCredentials",
"object",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/credentials/shared_ini_file_credentials.js#L76-L88 |
3,332 | aws/aws-sdk-js | lib/xml/escape-attribute.js | escapeAttribute | function escapeAttribute(value) {
return value.replace(/&/g, '&').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
} | javascript | function escapeAttribute(value) {
return value.replace(/&/g, '&').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
} | [
"function",
"escapeAttribute",
"(",
"value",
")",
"{",
"return",
"value",
".",
"replace",
"(",
"/",
"&",
"/",
"g",
",",
"'&'",
")",
".",
"replace",
"(",
"/",
"'",
"/",
"g",
",",
"'''",
")",
".",
"replace",
"(",
"/",
"<",
"/",
"g",
",",
"'<'",
")",
".",
"replace",
"(",
"/",
">",
"/",
"g",
",",
"'>'",
")",
".",
"replace",
"(",
"/",
"\"",
"/",
"g",
",",
"'"'",
")",
";",
"}"
] | Escapes characters that can not be in an XML attribute. | [
"Escapes",
"characters",
"that",
"can",
"not",
"be",
"in",
"an",
"XML",
"attribute",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/xml/escape-attribute.js#L4-L6 |
3,333 | aws/aws-sdk-js | lib/credentials/cognito_identity_credentials.js | clearCache | function clearCache() {
this._identityId = null;
delete this.params.IdentityId;
var poolId = this.params.IdentityPoolId;
var loginId = this.params.LoginId || '';
delete this.storage[this.localStorageKey.id + poolId + loginId];
delete this.storage[this.localStorageKey.providers + poolId + loginId];
} | javascript | function clearCache() {
this._identityId = null;
delete this.params.IdentityId;
var poolId = this.params.IdentityPoolId;
var loginId = this.params.LoginId || '';
delete this.storage[this.localStorageKey.id + poolId + loginId];
delete this.storage[this.localStorageKey.providers + poolId + loginId];
} | [
"function",
"clearCache",
"(",
")",
"{",
"this",
".",
"_identityId",
"=",
"null",
";",
"delete",
"this",
".",
"params",
".",
"IdentityId",
";",
"var",
"poolId",
"=",
"this",
".",
"params",
".",
"IdentityPoolId",
";",
"var",
"loginId",
"=",
"this",
".",
"params",
".",
"LoginId",
"||",
"''",
";",
"delete",
"this",
".",
"storage",
"[",
"this",
".",
"localStorageKey",
".",
"id",
"+",
"poolId",
"+",
"loginId",
"]",
";",
"delete",
"this",
".",
"storage",
"[",
"this",
".",
"localStorageKey",
".",
"providers",
"+",
"poolId",
"+",
"loginId",
"]",
";",
"}"
] | Clears the cached Cognito ID associated with the currently configured
identity pool ID. Use this to manually invalidate your cache if
the identity pool ID was deleted. | [
"Clears",
"the",
"cached",
"Cognito",
"ID",
"associated",
"with",
"the",
"currently",
"configured",
"identity",
"pool",
"ID",
".",
"Use",
"this",
"to",
"manually",
"invalidate",
"your",
"cache",
"if",
"the",
"identity",
"pool",
"ID",
"was",
"deleted",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/credentials/cognito_identity_credentials.js#L191-L199 |
3,334 | aws/aws-sdk-js | lib/resource_waiter.js | loadWaiterConfig | function loadWaiterConfig(state) {
if (!this.service.api.waiters[state]) {
throw new AWS.util.error(new Error(), {
code: 'StateNotFoundError',
message: 'State ' + state + ' not found.'
});
}
this.config = AWS.util.copy(this.service.api.waiters[state]);
} | javascript | function loadWaiterConfig(state) {
if (!this.service.api.waiters[state]) {
throw new AWS.util.error(new Error(), {
code: 'StateNotFoundError',
message: 'State ' + state + ' not found.'
});
}
this.config = AWS.util.copy(this.service.api.waiters[state]);
} | [
"function",
"loadWaiterConfig",
"(",
"state",
")",
"{",
"if",
"(",
"!",
"this",
".",
"service",
".",
"api",
".",
"waiters",
"[",
"state",
"]",
")",
"{",
"throw",
"new",
"AWS",
".",
"util",
".",
"error",
"(",
"new",
"Error",
"(",
")",
",",
"{",
"code",
":",
"'StateNotFoundError'",
",",
"message",
":",
"'State '",
"+",
"state",
"+",
"' not found.'",
"}",
")",
";",
"}",
"this",
".",
"config",
"=",
"AWS",
".",
"util",
".",
"copy",
"(",
"this",
".",
"service",
".",
"api",
".",
"waiters",
"[",
"state",
"]",
")",
";",
"}"
] | Loads waiter configuration from API configuration
@api private | [
"Loads",
"waiter",
"configuration",
"from",
"API",
"configuration"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/resource_waiter.js#L194-L203 |
3,335 | aws/aws-sdk-js | lib/xml/xml-node.js | XmlNode | function XmlNode(name, children) {
if (children === void 0) { children = []; }
this.name = name;
this.children = children;
this.attributes = {};
} | javascript | function XmlNode(name, children) {
if (children === void 0) { children = []; }
this.name = name;
this.children = children;
this.attributes = {};
} | [
"function",
"XmlNode",
"(",
"name",
",",
"children",
")",
"{",
"if",
"(",
"children",
"===",
"void",
"0",
")",
"{",
"children",
"=",
"[",
"]",
";",
"}",
"this",
".",
"name",
"=",
"name",
";",
"this",
".",
"children",
"=",
"children",
";",
"this",
".",
"attributes",
"=",
"{",
"}",
";",
"}"
] | Represents an XML node.
@api private | [
"Represents",
"an",
"XML",
"node",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/xml/xml-node.js#L7-L12 |
3,336 | aws/aws-sdk-js | lib/request.js | eachPage | function eachPage(callback) {
// Make all callbacks async-ish
callback = AWS.util.fn.makeAsync(callback, 3);
function wrappedCallback(response) {
callback.call(response, response.error, response.data, function (result) {
if (result === false) return;
if (response.hasNextPage()) {
response.nextPage().on('complete', wrappedCallback).send();
} else {
callback.call(response, null, null, AWS.util.fn.noop);
}
});
}
this.on('complete', wrappedCallback).send();
} | javascript | function eachPage(callback) {
// Make all callbacks async-ish
callback = AWS.util.fn.makeAsync(callback, 3);
function wrappedCallback(response) {
callback.call(response, response.error, response.data, function (result) {
if (result === false) return;
if (response.hasNextPage()) {
response.nextPage().on('complete', wrappedCallback).send();
} else {
callback.call(response, null, null, AWS.util.fn.noop);
}
});
}
this.on('complete', wrappedCallback).send();
} | [
"function",
"eachPage",
"(",
"callback",
")",
"{",
"// Make all callbacks async-ish",
"callback",
"=",
"AWS",
".",
"util",
".",
"fn",
".",
"makeAsync",
"(",
"callback",
",",
"3",
")",
";",
"function",
"wrappedCallback",
"(",
"response",
")",
"{",
"callback",
".",
"call",
"(",
"response",
",",
"response",
".",
"error",
",",
"response",
".",
"data",
",",
"function",
"(",
"result",
")",
"{",
"if",
"(",
"result",
"===",
"false",
")",
"return",
";",
"if",
"(",
"response",
".",
"hasNextPage",
"(",
")",
")",
"{",
"response",
".",
"nextPage",
"(",
")",
".",
"on",
"(",
"'complete'",
",",
"wrappedCallback",
")",
".",
"send",
"(",
")",
";",
"}",
"else",
"{",
"callback",
".",
"call",
"(",
"response",
",",
"null",
",",
"null",
",",
"AWS",
".",
"util",
".",
"fn",
".",
"noop",
")",
";",
"}",
"}",
")",
";",
"}",
"this",
".",
"on",
"(",
"'complete'",
",",
"wrappedCallback",
")",
".",
"send",
"(",
")",
";",
"}"
] | Iterates over each page of results given a pageable request, calling
the provided callback with each page of data. After all pages have been
retrieved, the callback is called with `null` data.
@note This operation can generate multiple requests to a service.
@example Iterating over multiple pages of objects in an S3 bucket
var pages = 1;
s3.listObjects().eachPage(function(err, data) {
if (err) return;
console.log("Page", pages++);
console.log(data);
});
@example Iterating over multiple pages with an asynchronous callback
s3.listObjects(params).eachPage(function(err, data, done) {
doSomethingAsyncAndOrExpensive(function() {
// The next page of results isn't fetched until done is called
done();
});
});
@callback callback function(err, data, [doneCallback])
Called with each page of resulting data from the request. If the
optional `doneCallback` is provided in the function, it must be called
when the callback is complete.
@param err [Error] an error object, if an error occurred.
@param data [Object] a single page of response data. If there is no
more data, this object will be `null`.
@param doneCallback [Function] an optional done callback. If this
argument is defined in the function declaration, it should be called
when the next page is ready to be retrieved. This is useful for
controlling serial pagination across asynchronous operations.
@return [Boolean] if the callback returns `false`, pagination will
stop.
@see AWS.Request.eachItem
@see AWS.Response.nextPage
@since v1.4.0 | [
"Iterates",
"over",
"each",
"page",
"of",
"results",
"given",
"a",
"pageable",
"request",
"calling",
"the",
"provided",
"callback",
"with",
"each",
"page",
"of",
"data",
".",
"After",
"all",
"pages",
"have",
"been",
"retrieved",
"the",
"callback",
"is",
"called",
"with",
"null",
"data",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/request.js#L489-L506 |
3,337 | aws/aws-sdk-js | lib/request.js | eachItem | function eachItem(callback) {
var self = this;
function wrappedCallback(err, data) {
if (err) return callback(err, null);
if (data === null) return callback(null, null);
var config = self.service.paginationConfig(self.operation);
var resultKey = config.resultKey;
if (Array.isArray(resultKey)) resultKey = resultKey[0];
var items = jmespath.search(data, resultKey);
var continueIteration = true;
AWS.util.arrayEach(items, function(item) {
continueIteration = callback(null, item);
if (continueIteration === false) {
return AWS.util.abort;
}
});
return continueIteration;
}
this.eachPage(wrappedCallback);
} | javascript | function eachItem(callback) {
var self = this;
function wrappedCallback(err, data) {
if (err) return callback(err, null);
if (data === null) return callback(null, null);
var config = self.service.paginationConfig(self.operation);
var resultKey = config.resultKey;
if (Array.isArray(resultKey)) resultKey = resultKey[0];
var items = jmespath.search(data, resultKey);
var continueIteration = true;
AWS.util.arrayEach(items, function(item) {
continueIteration = callback(null, item);
if (continueIteration === false) {
return AWS.util.abort;
}
});
return continueIteration;
}
this.eachPage(wrappedCallback);
} | [
"function",
"eachItem",
"(",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
";",
"function",
"wrappedCallback",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"err",
",",
"null",
")",
";",
"if",
"(",
"data",
"===",
"null",
")",
"return",
"callback",
"(",
"null",
",",
"null",
")",
";",
"var",
"config",
"=",
"self",
".",
"service",
".",
"paginationConfig",
"(",
"self",
".",
"operation",
")",
";",
"var",
"resultKey",
"=",
"config",
".",
"resultKey",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"resultKey",
")",
")",
"resultKey",
"=",
"resultKey",
"[",
"0",
"]",
";",
"var",
"items",
"=",
"jmespath",
".",
"search",
"(",
"data",
",",
"resultKey",
")",
";",
"var",
"continueIteration",
"=",
"true",
";",
"AWS",
".",
"util",
".",
"arrayEach",
"(",
"items",
",",
"function",
"(",
"item",
")",
"{",
"continueIteration",
"=",
"callback",
"(",
"null",
",",
"item",
")",
";",
"if",
"(",
"continueIteration",
"===",
"false",
")",
"{",
"return",
"AWS",
".",
"util",
".",
"abort",
";",
"}",
"}",
")",
";",
"return",
"continueIteration",
";",
"}",
"this",
".",
"eachPage",
"(",
"wrappedCallback",
")",
";",
"}"
] | Enumerates over individual items of a request, paging the responses if
necessary.
@api experimental
@since v1.4.0 | [
"Enumerates",
"over",
"individual",
"items",
"of",
"a",
"request",
"paging",
"the",
"responses",
"if",
"necessary",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/request.js#L515-L536 |
3,338 | aws/aws-sdk-js | lib/publisher/index.js | Publisher | function Publisher(options) {
// handle configuration
options = options || {};
this.enabled = options.enabled || false;
this.port = options.port || 31000;
this.clientId = options.clientId || '';
if (this.clientId.length > 255) {
// ClientId has a max length of 255
this.clientId = this.clientId.substr(0, 255);
}
this.messagesInFlight = 0;
this.address = 'localhost';
} | javascript | function Publisher(options) {
// handle configuration
options = options || {};
this.enabled = options.enabled || false;
this.port = options.port || 31000;
this.clientId = options.clientId || '';
if (this.clientId.length > 255) {
// ClientId has a max length of 255
this.clientId = this.clientId.substr(0, 255);
}
this.messagesInFlight = 0;
this.address = 'localhost';
} | [
"function",
"Publisher",
"(",
"options",
")",
"{",
"// handle configuration",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"enabled",
"=",
"options",
".",
"enabled",
"||",
"false",
";",
"this",
".",
"port",
"=",
"options",
".",
"port",
"||",
"31000",
";",
"this",
".",
"clientId",
"=",
"options",
".",
"clientId",
"||",
"''",
";",
"if",
"(",
"this",
".",
"clientId",
".",
"length",
">",
"255",
")",
"{",
"// ClientId has a max length of 255",
"this",
".",
"clientId",
"=",
"this",
".",
"clientId",
".",
"substr",
"(",
"0",
",",
"255",
")",
";",
"}",
"this",
".",
"messagesInFlight",
"=",
"0",
";",
"this",
".",
"address",
"=",
"'localhost'",
";",
"}"
] | 8 KB
Publishes metrics via udp.
@param {object} options Paramters for Publisher constructor
@param {number} [options.port = 31000] Port number
@param {string} [options.clientId = ''] Client Identifier
@param {boolean} [options.enabled = false] enable sending metrics datagram
@api private | [
"8",
"KB",
"Publishes",
"metrics",
"via",
"udp",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/publisher/index.js#L14-L26 |
3,339 | aws/aws-sdk-js | lib/services/s3.js | removeVirtualHostedBucketFromPath | function removeVirtualHostedBucketFromPath(req) {
var httpRequest = req.httpRequest;
var bucket = httpRequest.virtualHostedBucket;
if (bucket && httpRequest.path) {
if (req.params && req.params.Key) {
var encodedS3Key = '/' + AWS.util.uriEscapePath(req.params.Key);
if (httpRequest.path.indexOf(encodedS3Key) === 0 && (httpRequest.path.length === encodedS3Key.length || httpRequest.path[encodedS3Key.length] === '?')) {
//path only contains key or path contains only key and querystring
return;
}
}
httpRequest.path = httpRequest.path.replace(new RegExp('/' + bucket), '');
if (httpRequest.path[0] !== '/') {
httpRequest.path = '/' + httpRequest.path;
}
}
} | javascript | function removeVirtualHostedBucketFromPath(req) {
var httpRequest = req.httpRequest;
var bucket = httpRequest.virtualHostedBucket;
if (bucket && httpRequest.path) {
if (req.params && req.params.Key) {
var encodedS3Key = '/' + AWS.util.uriEscapePath(req.params.Key);
if (httpRequest.path.indexOf(encodedS3Key) === 0 && (httpRequest.path.length === encodedS3Key.length || httpRequest.path[encodedS3Key.length] === '?')) {
//path only contains key or path contains only key and querystring
return;
}
}
httpRequest.path = httpRequest.path.replace(new RegExp('/' + bucket), '');
if (httpRequest.path[0] !== '/') {
httpRequest.path = '/' + httpRequest.path;
}
}
} | [
"function",
"removeVirtualHostedBucketFromPath",
"(",
"req",
")",
"{",
"var",
"httpRequest",
"=",
"req",
".",
"httpRequest",
";",
"var",
"bucket",
"=",
"httpRequest",
".",
"virtualHostedBucket",
";",
"if",
"(",
"bucket",
"&&",
"httpRequest",
".",
"path",
")",
"{",
"if",
"(",
"req",
".",
"params",
"&&",
"req",
".",
"params",
".",
"Key",
")",
"{",
"var",
"encodedS3Key",
"=",
"'/'",
"+",
"AWS",
".",
"util",
".",
"uriEscapePath",
"(",
"req",
".",
"params",
".",
"Key",
")",
";",
"if",
"(",
"httpRequest",
".",
"path",
".",
"indexOf",
"(",
"encodedS3Key",
")",
"===",
"0",
"&&",
"(",
"httpRequest",
".",
"path",
".",
"length",
"===",
"encodedS3Key",
".",
"length",
"||",
"httpRequest",
".",
"path",
"[",
"encodedS3Key",
".",
"length",
"]",
"===",
"'?'",
")",
")",
"{",
"//path only contains key or path contains only key and querystring",
"return",
";",
"}",
"}",
"httpRequest",
".",
"path",
"=",
"httpRequest",
".",
"path",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"'/'",
"+",
"bucket",
")",
",",
"''",
")",
";",
"if",
"(",
"httpRequest",
".",
"path",
"[",
"0",
"]",
"!==",
"'/'",
")",
"{",
"httpRequest",
".",
"path",
"=",
"'/'",
"+",
"httpRequest",
".",
"path",
";",
"}",
"}",
"}"
] | Takes the bucket name out of the path if bucket is virtual-hosted
@api private | [
"Takes",
"the",
"bucket",
"name",
"out",
"of",
"the",
"path",
"if",
"bucket",
"is",
"virtual",
"-",
"hosted"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/services/s3.js#L238-L254 |
3,340 | aws/aws-sdk-js | lib/services/s3.js | addContentType | function addContentType(req) {
var httpRequest = req.httpRequest;
if (httpRequest.method === 'GET' || httpRequest.method === 'HEAD') {
// Content-Type is not set in GET/HEAD requests
delete httpRequest.headers['Content-Type'];
return;
}
if (!httpRequest.headers['Content-Type']) { // always have a Content-Type
httpRequest.headers['Content-Type'] = 'application/octet-stream';
}
var contentType = httpRequest.headers['Content-Type'];
if (AWS.util.isBrowser()) {
if (typeof httpRequest.body === 'string' && !contentType.match(/;\s*charset=/)) {
var charset = '; charset=UTF-8';
httpRequest.headers['Content-Type'] += charset;
} else {
var replaceFn = function(_, prefix, charsetName) {
return prefix + charsetName.toUpperCase();
};
httpRequest.headers['Content-Type'] =
contentType.replace(/(;\s*charset=)(.+)$/, replaceFn);
}
}
} | javascript | function addContentType(req) {
var httpRequest = req.httpRequest;
if (httpRequest.method === 'GET' || httpRequest.method === 'HEAD') {
// Content-Type is not set in GET/HEAD requests
delete httpRequest.headers['Content-Type'];
return;
}
if (!httpRequest.headers['Content-Type']) { // always have a Content-Type
httpRequest.headers['Content-Type'] = 'application/octet-stream';
}
var contentType = httpRequest.headers['Content-Type'];
if (AWS.util.isBrowser()) {
if (typeof httpRequest.body === 'string' && !contentType.match(/;\s*charset=/)) {
var charset = '; charset=UTF-8';
httpRequest.headers['Content-Type'] += charset;
} else {
var replaceFn = function(_, prefix, charsetName) {
return prefix + charsetName.toUpperCase();
};
httpRequest.headers['Content-Type'] =
contentType.replace(/(;\s*charset=)(.+)$/, replaceFn);
}
}
} | [
"function",
"addContentType",
"(",
"req",
")",
"{",
"var",
"httpRequest",
"=",
"req",
".",
"httpRequest",
";",
"if",
"(",
"httpRequest",
".",
"method",
"===",
"'GET'",
"||",
"httpRequest",
".",
"method",
"===",
"'HEAD'",
")",
"{",
"// Content-Type is not set in GET/HEAD requests",
"delete",
"httpRequest",
".",
"headers",
"[",
"'Content-Type'",
"]",
";",
"return",
";",
"}",
"if",
"(",
"!",
"httpRequest",
".",
"headers",
"[",
"'Content-Type'",
"]",
")",
"{",
"// always have a Content-Type",
"httpRequest",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/octet-stream'",
";",
"}",
"var",
"contentType",
"=",
"httpRequest",
".",
"headers",
"[",
"'Content-Type'",
"]",
";",
"if",
"(",
"AWS",
".",
"util",
".",
"isBrowser",
"(",
")",
")",
"{",
"if",
"(",
"typeof",
"httpRequest",
".",
"body",
"===",
"'string'",
"&&",
"!",
"contentType",
".",
"match",
"(",
"/",
";\\s*charset=",
"/",
")",
")",
"{",
"var",
"charset",
"=",
"'; charset=UTF-8'",
";",
"httpRequest",
".",
"headers",
"[",
"'Content-Type'",
"]",
"+=",
"charset",
";",
"}",
"else",
"{",
"var",
"replaceFn",
"=",
"function",
"(",
"_",
",",
"prefix",
",",
"charsetName",
")",
"{",
"return",
"prefix",
"+",
"charsetName",
".",
"toUpperCase",
"(",
")",
";",
"}",
";",
"httpRequest",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"contentType",
".",
"replace",
"(",
"/",
"(;\\s*charset=)(.+)$",
"/",
",",
"replaceFn",
")",
";",
"}",
"}",
"}"
] | Adds a default content type if none is supplied.
@api private | [
"Adds",
"a",
"default",
"content",
"type",
"if",
"none",
"is",
"supplied",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/services/s3.js#L272-L298 |
3,341 | aws/aws-sdk-js | lib/services/s3.js | computeContentMd5 | function computeContentMd5(req) {
if (req.service.willComputeChecksums(req)) {
var md5 = AWS.util.crypto.md5(req.httpRequest.body, 'base64');
req.httpRequest.headers['Content-MD5'] = md5;
}
} | javascript | function computeContentMd5(req) {
if (req.service.willComputeChecksums(req)) {
var md5 = AWS.util.crypto.md5(req.httpRequest.body, 'base64');
req.httpRequest.headers['Content-MD5'] = md5;
}
} | [
"function",
"computeContentMd5",
"(",
"req",
")",
"{",
"if",
"(",
"req",
".",
"service",
".",
"willComputeChecksums",
"(",
"req",
")",
")",
"{",
"var",
"md5",
"=",
"AWS",
".",
"util",
".",
"crypto",
".",
"md5",
"(",
"req",
".",
"httpRequest",
".",
"body",
",",
"'base64'",
")",
";",
"req",
".",
"httpRequest",
".",
"headers",
"[",
"'Content-MD5'",
"]",
"=",
"md5",
";",
"}",
"}"
] | A listener that computes the Content-MD5 and sets it in the header.
@see AWS.S3.willComputeChecksums
@api private | [
"A",
"listener",
"that",
"computes",
"the",
"Content",
"-",
"MD5",
"and",
"sets",
"it",
"in",
"the",
"header",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/services/s3.js#L357-L362 |
3,342 | aws/aws-sdk-js | lib/services/s3.js | dnsCompatibleBucketName | function dnsCompatibleBucketName(bucketName) {
var b = bucketName;
var domain = new RegExp(/^[a-z0-9][a-z0-9\.\-]{1,61}[a-z0-9]$/);
var ipAddress = new RegExp(/(\d+\.){3}\d+/);
var dots = new RegExp(/\.\./);
return (b.match(domain) && !b.match(ipAddress) && !b.match(dots)) ? true : false;
} | javascript | function dnsCompatibleBucketName(bucketName) {
var b = bucketName;
var domain = new RegExp(/^[a-z0-9][a-z0-9\.\-]{1,61}[a-z0-9]$/);
var ipAddress = new RegExp(/(\d+\.){3}\d+/);
var dots = new RegExp(/\.\./);
return (b.match(domain) && !b.match(ipAddress) && !b.match(dots)) ? true : false;
} | [
"function",
"dnsCompatibleBucketName",
"(",
"bucketName",
")",
"{",
"var",
"b",
"=",
"bucketName",
";",
"var",
"domain",
"=",
"new",
"RegExp",
"(",
"/",
"^[a-z0-9][a-z0-9\\.\\-]{1,61}[a-z0-9]$",
"/",
")",
";",
"var",
"ipAddress",
"=",
"new",
"RegExp",
"(",
"/",
"(\\d+\\.){3}\\d+",
"/",
")",
";",
"var",
"dots",
"=",
"new",
"RegExp",
"(",
"/",
"\\.\\.",
"/",
")",
";",
"return",
"(",
"b",
".",
"match",
"(",
"domain",
")",
"&&",
"!",
"b",
".",
"match",
"(",
"ipAddress",
")",
"&&",
"!",
"b",
".",
"match",
"(",
"dots",
")",
")",
"?",
"true",
":",
"false",
";",
"}"
] | Returns true if the bucket name is DNS compatible. Buckets created
outside of the classic region MUST be DNS compatible.
@api private | [
"Returns",
"true",
"if",
"the",
"bucket",
"name",
"is",
"DNS",
"compatible",
".",
"Buckets",
"created",
"outside",
"of",
"the",
"classic",
"region",
"MUST",
"be",
"DNS",
"compatible",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/services/s3.js#L405-L411 |
3,343 | aws/aws-sdk-js | lib/services/s3.js | updateReqBucketRegion | function updateReqBucketRegion(request, region) {
var httpRequest = request.httpRequest;
if (typeof region === 'string' && region.length) {
httpRequest.region = region;
}
if (!httpRequest.endpoint.host.match(/s3(?!-accelerate).*\.amazonaws\.com$/)) {
return;
}
var service = request.service;
var s3Config = service.config;
var s3BucketEndpoint = s3Config.s3BucketEndpoint;
if (s3BucketEndpoint) {
delete s3Config.s3BucketEndpoint;
}
var newConfig = AWS.util.copy(s3Config);
delete newConfig.endpoint;
newConfig.region = httpRequest.region;
httpRequest.endpoint = (new AWS.S3(newConfig)).endpoint;
service.populateURI(request);
s3Config.s3BucketEndpoint = s3BucketEndpoint;
httpRequest.headers.Host = httpRequest.endpoint.host;
if (request._asm.currentState === 'validate') {
request.removeListener('build', service.populateURI);
request.addListener('build', service.removeVirtualHostedBucketFromPath);
}
} | javascript | function updateReqBucketRegion(request, region) {
var httpRequest = request.httpRequest;
if (typeof region === 'string' && region.length) {
httpRequest.region = region;
}
if (!httpRequest.endpoint.host.match(/s3(?!-accelerate).*\.amazonaws\.com$/)) {
return;
}
var service = request.service;
var s3Config = service.config;
var s3BucketEndpoint = s3Config.s3BucketEndpoint;
if (s3BucketEndpoint) {
delete s3Config.s3BucketEndpoint;
}
var newConfig = AWS.util.copy(s3Config);
delete newConfig.endpoint;
newConfig.region = httpRequest.region;
httpRequest.endpoint = (new AWS.S3(newConfig)).endpoint;
service.populateURI(request);
s3Config.s3BucketEndpoint = s3BucketEndpoint;
httpRequest.headers.Host = httpRequest.endpoint.host;
if (request._asm.currentState === 'validate') {
request.removeListener('build', service.populateURI);
request.addListener('build', service.removeVirtualHostedBucketFromPath);
}
} | [
"function",
"updateReqBucketRegion",
"(",
"request",
",",
"region",
")",
"{",
"var",
"httpRequest",
"=",
"request",
".",
"httpRequest",
";",
"if",
"(",
"typeof",
"region",
"===",
"'string'",
"&&",
"region",
".",
"length",
")",
"{",
"httpRequest",
".",
"region",
"=",
"region",
";",
"}",
"if",
"(",
"!",
"httpRequest",
".",
"endpoint",
".",
"host",
".",
"match",
"(",
"/",
"s3(?!-accelerate).*\\.amazonaws\\.com$",
"/",
")",
")",
"{",
"return",
";",
"}",
"var",
"service",
"=",
"request",
".",
"service",
";",
"var",
"s3Config",
"=",
"service",
".",
"config",
";",
"var",
"s3BucketEndpoint",
"=",
"s3Config",
".",
"s3BucketEndpoint",
";",
"if",
"(",
"s3BucketEndpoint",
")",
"{",
"delete",
"s3Config",
".",
"s3BucketEndpoint",
";",
"}",
"var",
"newConfig",
"=",
"AWS",
".",
"util",
".",
"copy",
"(",
"s3Config",
")",
";",
"delete",
"newConfig",
".",
"endpoint",
";",
"newConfig",
".",
"region",
"=",
"httpRequest",
".",
"region",
";",
"httpRequest",
".",
"endpoint",
"=",
"(",
"new",
"AWS",
".",
"S3",
"(",
"newConfig",
")",
")",
".",
"endpoint",
";",
"service",
".",
"populateURI",
"(",
"request",
")",
";",
"s3Config",
".",
"s3BucketEndpoint",
"=",
"s3BucketEndpoint",
";",
"httpRequest",
".",
"headers",
".",
"Host",
"=",
"httpRequest",
".",
"endpoint",
".",
"host",
";",
"if",
"(",
"request",
".",
"_asm",
".",
"currentState",
"===",
"'validate'",
")",
"{",
"request",
".",
"removeListener",
"(",
"'build'",
",",
"service",
".",
"populateURI",
")",
";",
"request",
".",
"addListener",
"(",
"'build'",
",",
"service",
".",
"removeVirtualHostedBucketFromPath",
")",
";",
"}",
"}"
] | Updates httpRequest with region. If region is not provided, then
the httpRequest will be updated based on httpRequest.region
@api private | [
"Updates",
"httpRequest",
"with",
"region",
".",
"If",
"region",
"is",
"not",
"provided",
"then",
"the",
"httpRequest",
"will",
"be",
"updated",
"based",
"on",
"httpRequest",
".",
"region"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/services/s3.js#L461-L488 |
3,344 | aws/aws-sdk-js | lib/services/s3.js | extractError | function extractError(resp) {
var codes = {
304: 'NotModified',
403: 'Forbidden',
400: 'BadRequest',
404: 'NotFound'
};
var req = resp.request;
var code = resp.httpResponse.statusCode;
var body = resp.httpResponse.body || '';
var headers = resp.httpResponse.headers || {};
var region = headers['x-amz-bucket-region'] || null;
var bucket = req.params.Bucket || null;
var bucketRegionCache = req.service.bucketRegionCache;
if (region && bucket && region !== bucketRegionCache[bucket]) {
bucketRegionCache[bucket] = region;
}
var cachedRegion;
if (codes[code] && body.length === 0) {
if (bucket && !region) {
cachedRegion = bucketRegionCache[bucket] || null;
if (cachedRegion !== req.httpRequest.region) {
region = cachedRegion;
}
}
resp.error = AWS.util.error(new Error(), {
code: codes[code],
message: null,
region: region
});
} else {
var data = new AWS.XML.Parser().parse(body.toString());
if (data.Region && !region) {
region = data.Region;
if (bucket && region !== bucketRegionCache[bucket]) {
bucketRegionCache[bucket] = region;
}
} else if (bucket && !region && !data.Region) {
cachedRegion = bucketRegionCache[bucket] || null;
if (cachedRegion !== req.httpRequest.region) {
region = cachedRegion;
}
}
resp.error = AWS.util.error(new Error(), {
code: data.Code || code,
message: data.Message || null,
region: region
});
}
req.service.extractRequestIds(resp);
} | javascript | function extractError(resp) {
var codes = {
304: 'NotModified',
403: 'Forbidden',
400: 'BadRequest',
404: 'NotFound'
};
var req = resp.request;
var code = resp.httpResponse.statusCode;
var body = resp.httpResponse.body || '';
var headers = resp.httpResponse.headers || {};
var region = headers['x-amz-bucket-region'] || null;
var bucket = req.params.Bucket || null;
var bucketRegionCache = req.service.bucketRegionCache;
if (region && bucket && region !== bucketRegionCache[bucket]) {
bucketRegionCache[bucket] = region;
}
var cachedRegion;
if (codes[code] && body.length === 0) {
if (bucket && !region) {
cachedRegion = bucketRegionCache[bucket] || null;
if (cachedRegion !== req.httpRequest.region) {
region = cachedRegion;
}
}
resp.error = AWS.util.error(new Error(), {
code: codes[code],
message: null,
region: region
});
} else {
var data = new AWS.XML.Parser().parse(body.toString());
if (data.Region && !region) {
region = data.Region;
if (bucket && region !== bucketRegionCache[bucket]) {
bucketRegionCache[bucket] = region;
}
} else if (bucket && !region && !data.Region) {
cachedRegion = bucketRegionCache[bucket] || null;
if (cachedRegion !== req.httpRequest.region) {
region = cachedRegion;
}
}
resp.error = AWS.util.error(new Error(), {
code: data.Code || code,
message: data.Message || null,
region: region
});
}
req.service.extractRequestIds(resp);
} | [
"function",
"extractError",
"(",
"resp",
")",
"{",
"var",
"codes",
"=",
"{",
"304",
":",
"'NotModified'",
",",
"403",
":",
"'Forbidden'",
",",
"400",
":",
"'BadRequest'",
",",
"404",
":",
"'NotFound'",
"}",
";",
"var",
"req",
"=",
"resp",
".",
"request",
";",
"var",
"code",
"=",
"resp",
".",
"httpResponse",
".",
"statusCode",
";",
"var",
"body",
"=",
"resp",
".",
"httpResponse",
".",
"body",
"||",
"''",
";",
"var",
"headers",
"=",
"resp",
".",
"httpResponse",
".",
"headers",
"||",
"{",
"}",
";",
"var",
"region",
"=",
"headers",
"[",
"'x-amz-bucket-region'",
"]",
"||",
"null",
";",
"var",
"bucket",
"=",
"req",
".",
"params",
".",
"Bucket",
"||",
"null",
";",
"var",
"bucketRegionCache",
"=",
"req",
".",
"service",
".",
"bucketRegionCache",
";",
"if",
"(",
"region",
"&&",
"bucket",
"&&",
"region",
"!==",
"bucketRegionCache",
"[",
"bucket",
"]",
")",
"{",
"bucketRegionCache",
"[",
"bucket",
"]",
"=",
"region",
";",
"}",
"var",
"cachedRegion",
";",
"if",
"(",
"codes",
"[",
"code",
"]",
"&&",
"body",
".",
"length",
"===",
"0",
")",
"{",
"if",
"(",
"bucket",
"&&",
"!",
"region",
")",
"{",
"cachedRegion",
"=",
"bucketRegionCache",
"[",
"bucket",
"]",
"||",
"null",
";",
"if",
"(",
"cachedRegion",
"!==",
"req",
".",
"httpRequest",
".",
"region",
")",
"{",
"region",
"=",
"cachedRegion",
";",
"}",
"}",
"resp",
".",
"error",
"=",
"AWS",
".",
"util",
".",
"error",
"(",
"new",
"Error",
"(",
")",
",",
"{",
"code",
":",
"codes",
"[",
"code",
"]",
",",
"message",
":",
"null",
",",
"region",
":",
"region",
"}",
")",
";",
"}",
"else",
"{",
"var",
"data",
"=",
"new",
"AWS",
".",
"XML",
".",
"Parser",
"(",
")",
".",
"parse",
"(",
"body",
".",
"toString",
"(",
")",
")",
";",
"if",
"(",
"data",
".",
"Region",
"&&",
"!",
"region",
")",
"{",
"region",
"=",
"data",
".",
"Region",
";",
"if",
"(",
"bucket",
"&&",
"region",
"!==",
"bucketRegionCache",
"[",
"bucket",
"]",
")",
"{",
"bucketRegionCache",
"[",
"bucket",
"]",
"=",
"region",
";",
"}",
"}",
"else",
"if",
"(",
"bucket",
"&&",
"!",
"region",
"&&",
"!",
"data",
".",
"Region",
")",
"{",
"cachedRegion",
"=",
"bucketRegionCache",
"[",
"bucket",
"]",
"||",
"null",
";",
"if",
"(",
"cachedRegion",
"!==",
"req",
".",
"httpRequest",
".",
"region",
")",
"{",
"region",
"=",
"cachedRegion",
";",
"}",
"}",
"resp",
".",
"error",
"=",
"AWS",
".",
"util",
".",
"error",
"(",
"new",
"Error",
"(",
")",
",",
"{",
"code",
":",
"data",
".",
"Code",
"||",
"code",
",",
"message",
":",
"data",
".",
"Message",
"||",
"null",
",",
"region",
":",
"region",
"}",
")",
";",
"}",
"req",
".",
"service",
".",
"extractRequestIds",
"(",
"resp",
")",
";",
"}"
] | Extracts an error object from the http response.
@api private | [
"Extracts",
"an",
"error",
"object",
"from",
"the",
"http",
"response",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/services/s3.js#L537-L592 |
3,345 | aws/aws-sdk-js | lib/services/s3.js | requestBucketRegion | function requestBucketRegion(resp, done) {
var error = resp.error;
var req = resp.request;
var bucket = req.params.Bucket || null;
if (!error || !bucket || error.region || req.operation === 'listObjects' ||
(AWS.util.isNode() && req.operation === 'headBucket') ||
(error.statusCode === 400 && req.operation !== 'headObject') ||
regionRedirectErrorCodes.indexOf(error.code) === -1) {
return done();
}
var reqOperation = AWS.util.isNode() ? 'headBucket' : 'listObjects';
var reqParams = {Bucket: bucket};
if (reqOperation === 'listObjects') reqParams.MaxKeys = 0;
var regionReq = req.service[reqOperation](reqParams);
regionReq._requestRegionForBucket = bucket;
regionReq.send(function() {
var region = req.service.bucketRegionCache[bucket] || null;
error.region = region;
done();
});
} | javascript | function requestBucketRegion(resp, done) {
var error = resp.error;
var req = resp.request;
var bucket = req.params.Bucket || null;
if (!error || !bucket || error.region || req.operation === 'listObjects' ||
(AWS.util.isNode() && req.operation === 'headBucket') ||
(error.statusCode === 400 && req.operation !== 'headObject') ||
regionRedirectErrorCodes.indexOf(error.code) === -1) {
return done();
}
var reqOperation = AWS.util.isNode() ? 'headBucket' : 'listObjects';
var reqParams = {Bucket: bucket};
if (reqOperation === 'listObjects') reqParams.MaxKeys = 0;
var regionReq = req.service[reqOperation](reqParams);
regionReq._requestRegionForBucket = bucket;
regionReq.send(function() {
var region = req.service.bucketRegionCache[bucket] || null;
error.region = region;
done();
});
} | [
"function",
"requestBucketRegion",
"(",
"resp",
",",
"done",
")",
"{",
"var",
"error",
"=",
"resp",
".",
"error",
";",
"var",
"req",
"=",
"resp",
".",
"request",
";",
"var",
"bucket",
"=",
"req",
".",
"params",
".",
"Bucket",
"||",
"null",
";",
"if",
"(",
"!",
"error",
"||",
"!",
"bucket",
"||",
"error",
".",
"region",
"||",
"req",
".",
"operation",
"===",
"'listObjects'",
"||",
"(",
"AWS",
".",
"util",
".",
"isNode",
"(",
")",
"&&",
"req",
".",
"operation",
"===",
"'headBucket'",
")",
"||",
"(",
"error",
".",
"statusCode",
"===",
"400",
"&&",
"req",
".",
"operation",
"!==",
"'headObject'",
")",
"||",
"regionRedirectErrorCodes",
".",
"indexOf",
"(",
"error",
".",
"code",
")",
"===",
"-",
"1",
")",
"{",
"return",
"done",
"(",
")",
";",
"}",
"var",
"reqOperation",
"=",
"AWS",
".",
"util",
".",
"isNode",
"(",
")",
"?",
"'headBucket'",
":",
"'listObjects'",
";",
"var",
"reqParams",
"=",
"{",
"Bucket",
":",
"bucket",
"}",
";",
"if",
"(",
"reqOperation",
"===",
"'listObjects'",
")",
"reqParams",
".",
"MaxKeys",
"=",
"0",
";",
"var",
"regionReq",
"=",
"req",
".",
"service",
"[",
"reqOperation",
"]",
"(",
"reqParams",
")",
";",
"regionReq",
".",
"_requestRegionForBucket",
"=",
"bucket",
";",
"regionReq",
".",
"send",
"(",
"function",
"(",
")",
"{",
"var",
"region",
"=",
"req",
".",
"service",
".",
"bucketRegionCache",
"[",
"bucket",
"]",
"||",
"null",
";",
"error",
".",
"region",
"=",
"region",
";",
"done",
"(",
")",
";",
"}",
")",
";",
"}"
] | If region was not obtained synchronously, then send async request
to get bucket region for errors resulting from wrong region.
@api private | [
"If",
"region",
"was",
"not",
"obtained",
"synchronously",
"then",
"send",
"async",
"request",
"to",
"get",
"bucket",
"region",
"for",
"errors",
"resulting",
"from",
"wrong",
"region",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/services/s3.js#L600-L621 |
3,346 | aws/aws-sdk-js | lib/services/s3.js | reqRegionForNetworkingError | function reqRegionForNetworkingError(resp, done) {
if (!AWS.util.isBrowser()) {
return done();
}
var error = resp.error;
var request = resp.request;
var bucket = request.params.Bucket;
if (!error || error.code !== 'NetworkingError' || !bucket ||
request.httpRequest.region === 'us-east-1') {
return done();
}
var service = request.service;
var bucketRegionCache = service.bucketRegionCache;
var cachedRegion = bucketRegionCache[bucket] || null;
if (cachedRegion && cachedRegion !== request.httpRequest.region) {
service.updateReqBucketRegion(request, cachedRegion);
done();
} else if (!service.dnsCompatibleBucketName(bucket)) {
service.updateReqBucketRegion(request, 'us-east-1');
if (bucketRegionCache[bucket] !== 'us-east-1') {
bucketRegionCache[bucket] = 'us-east-1';
}
done();
} else if (request.httpRequest.virtualHostedBucket) {
var getRegionReq = service.listObjects({Bucket: bucket, MaxKeys: 0});
service.updateReqBucketRegion(getRegionReq, 'us-east-1');
getRegionReq._requestRegionForBucket = bucket;
getRegionReq.send(function() {
var region = service.bucketRegionCache[bucket] || null;
if (region && region !== request.httpRequest.region) {
service.updateReqBucketRegion(request, region);
}
done();
});
} else {
// DNS-compatible path-style
// (s3ForcePathStyle or bucket name with dot over https)
// Cannot obtain region information for this case
done();
}
} | javascript | function reqRegionForNetworkingError(resp, done) {
if (!AWS.util.isBrowser()) {
return done();
}
var error = resp.error;
var request = resp.request;
var bucket = request.params.Bucket;
if (!error || error.code !== 'NetworkingError' || !bucket ||
request.httpRequest.region === 'us-east-1') {
return done();
}
var service = request.service;
var bucketRegionCache = service.bucketRegionCache;
var cachedRegion = bucketRegionCache[bucket] || null;
if (cachedRegion && cachedRegion !== request.httpRequest.region) {
service.updateReqBucketRegion(request, cachedRegion);
done();
} else if (!service.dnsCompatibleBucketName(bucket)) {
service.updateReqBucketRegion(request, 'us-east-1');
if (bucketRegionCache[bucket] !== 'us-east-1') {
bucketRegionCache[bucket] = 'us-east-1';
}
done();
} else if (request.httpRequest.virtualHostedBucket) {
var getRegionReq = service.listObjects({Bucket: bucket, MaxKeys: 0});
service.updateReqBucketRegion(getRegionReq, 'us-east-1');
getRegionReq._requestRegionForBucket = bucket;
getRegionReq.send(function() {
var region = service.bucketRegionCache[bucket] || null;
if (region && region !== request.httpRequest.region) {
service.updateReqBucketRegion(request, region);
}
done();
});
} else {
// DNS-compatible path-style
// (s3ForcePathStyle or bucket name with dot over https)
// Cannot obtain region information for this case
done();
}
} | [
"function",
"reqRegionForNetworkingError",
"(",
"resp",
",",
"done",
")",
"{",
"if",
"(",
"!",
"AWS",
".",
"util",
".",
"isBrowser",
"(",
")",
")",
"{",
"return",
"done",
"(",
")",
";",
"}",
"var",
"error",
"=",
"resp",
".",
"error",
";",
"var",
"request",
"=",
"resp",
".",
"request",
";",
"var",
"bucket",
"=",
"request",
".",
"params",
".",
"Bucket",
";",
"if",
"(",
"!",
"error",
"||",
"error",
".",
"code",
"!==",
"'NetworkingError'",
"||",
"!",
"bucket",
"||",
"request",
".",
"httpRequest",
".",
"region",
"===",
"'us-east-1'",
")",
"{",
"return",
"done",
"(",
")",
";",
"}",
"var",
"service",
"=",
"request",
".",
"service",
";",
"var",
"bucketRegionCache",
"=",
"service",
".",
"bucketRegionCache",
";",
"var",
"cachedRegion",
"=",
"bucketRegionCache",
"[",
"bucket",
"]",
"||",
"null",
";",
"if",
"(",
"cachedRegion",
"&&",
"cachedRegion",
"!==",
"request",
".",
"httpRequest",
".",
"region",
")",
"{",
"service",
".",
"updateReqBucketRegion",
"(",
"request",
",",
"cachedRegion",
")",
";",
"done",
"(",
")",
";",
"}",
"else",
"if",
"(",
"!",
"service",
".",
"dnsCompatibleBucketName",
"(",
"bucket",
")",
")",
"{",
"service",
".",
"updateReqBucketRegion",
"(",
"request",
",",
"'us-east-1'",
")",
";",
"if",
"(",
"bucketRegionCache",
"[",
"bucket",
"]",
"!==",
"'us-east-1'",
")",
"{",
"bucketRegionCache",
"[",
"bucket",
"]",
"=",
"'us-east-1'",
";",
"}",
"done",
"(",
")",
";",
"}",
"else",
"if",
"(",
"request",
".",
"httpRequest",
".",
"virtualHostedBucket",
")",
"{",
"var",
"getRegionReq",
"=",
"service",
".",
"listObjects",
"(",
"{",
"Bucket",
":",
"bucket",
",",
"MaxKeys",
":",
"0",
"}",
")",
";",
"service",
".",
"updateReqBucketRegion",
"(",
"getRegionReq",
",",
"'us-east-1'",
")",
";",
"getRegionReq",
".",
"_requestRegionForBucket",
"=",
"bucket",
";",
"getRegionReq",
".",
"send",
"(",
"function",
"(",
")",
"{",
"var",
"region",
"=",
"service",
".",
"bucketRegionCache",
"[",
"bucket",
"]",
"||",
"null",
";",
"if",
"(",
"region",
"&&",
"region",
"!==",
"request",
".",
"httpRequest",
".",
"region",
")",
"{",
"service",
".",
"updateReqBucketRegion",
"(",
"request",
",",
"region",
")",
";",
"}",
"done",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"// DNS-compatible path-style",
"// (s3ForcePathStyle or bucket name with dot over https)",
"// Cannot obtain region information for this case",
"done",
"(",
")",
";",
"}",
"}"
] | For browser only. If NetworkingError received, will attempt to obtain
the bucket region.
@api private | [
"For",
"browser",
"only",
".",
"If",
"NetworkingError",
"received",
"will",
"attempt",
"to",
"obtain",
"the",
"bucket",
"region",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/services/s3.js#L629-L671 |
3,347 | aws/aws-sdk-js | lib/services/s3.js | function(buckets) {
var bucketRegionCache = this.bucketRegionCache;
if (!buckets) {
buckets = Object.keys(bucketRegionCache);
} else if (typeof buckets === 'string') {
buckets = [buckets];
}
for (var i = 0; i < buckets.length; i++) {
delete bucketRegionCache[buckets[i]];
}
return bucketRegionCache;
} | javascript | function(buckets) {
var bucketRegionCache = this.bucketRegionCache;
if (!buckets) {
buckets = Object.keys(bucketRegionCache);
} else if (typeof buckets === 'string') {
buckets = [buckets];
}
for (var i = 0; i < buckets.length; i++) {
delete bucketRegionCache[buckets[i]];
}
return bucketRegionCache;
} | [
"function",
"(",
"buckets",
")",
"{",
"var",
"bucketRegionCache",
"=",
"this",
".",
"bucketRegionCache",
";",
"if",
"(",
"!",
"buckets",
")",
"{",
"buckets",
"=",
"Object",
".",
"keys",
"(",
"bucketRegionCache",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"buckets",
"===",
"'string'",
")",
"{",
"buckets",
"=",
"[",
"buckets",
"]",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"buckets",
".",
"length",
";",
"i",
"++",
")",
"{",
"delete",
"bucketRegionCache",
"[",
"buckets",
"[",
"i",
"]",
"]",
";",
"}",
"return",
"bucketRegionCache",
";",
"}"
] | Clears bucket region cache.
@api private | [
"Clears",
"bucket",
"region",
"cache",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/services/s3.js#L685-L696 |
|
3,348 | aws/aws-sdk-js | lib/services/s3.js | correctBucketRegionFromCache | function correctBucketRegionFromCache(req) {
var bucket = req.params.Bucket || null;
if (bucket) {
var service = req.service;
var requestRegion = req.httpRequest.region;
var cachedRegion = service.bucketRegionCache[bucket];
if (cachedRegion && cachedRegion !== requestRegion) {
service.updateReqBucketRegion(req, cachedRegion);
}
}
} | javascript | function correctBucketRegionFromCache(req) {
var bucket = req.params.Bucket || null;
if (bucket) {
var service = req.service;
var requestRegion = req.httpRequest.region;
var cachedRegion = service.bucketRegionCache[bucket];
if (cachedRegion && cachedRegion !== requestRegion) {
service.updateReqBucketRegion(req, cachedRegion);
}
}
} | [
"function",
"correctBucketRegionFromCache",
"(",
"req",
")",
"{",
"var",
"bucket",
"=",
"req",
".",
"params",
".",
"Bucket",
"||",
"null",
";",
"if",
"(",
"bucket",
")",
"{",
"var",
"service",
"=",
"req",
".",
"service",
";",
"var",
"requestRegion",
"=",
"req",
".",
"httpRequest",
".",
"region",
";",
"var",
"cachedRegion",
"=",
"service",
".",
"bucketRegionCache",
"[",
"bucket",
"]",
";",
"if",
"(",
"cachedRegion",
"&&",
"cachedRegion",
"!==",
"requestRegion",
")",
"{",
"service",
".",
"updateReqBucketRegion",
"(",
"req",
",",
"cachedRegion",
")",
";",
"}",
"}",
"}"
] | Corrects request region if bucket's cached region is different
@api private | [
"Corrects",
"request",
"region",
"if",
"bucket",
"s",
"cached",
"region",
"is",
"different"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/services/s3.js#L703-L713 |
3,349 | aws/aws-sdk-js | lib/services/s3.js | extractRequestIds | function extractRequestIds(resp) {
var extendedRequestId = resp.httpResponse.headers ? resp.httpResponse.headers['x-amz-id-2'] : null;
var cfId = resp.httpResponse.headers ? resp.httpResponse.headers['x-amz-cf-id'] : null;
resp.extendedRequestId = extendedRequestId;
resp.cfId = cfId;
if (resp.error) {
resp.error.requestId = resp.requestId || null;
resp.error.extendedRequestId = extendedRequestId;
resp.error.cfId = cfId;
}
} | javascript | function extractRequestIds(resp) {
var extendedRequestId = resp.httpResponse.headers ? resp.httpResponse.headers['x-amz-id-2'] : null;
var cfId = resp.httpResponse.headers ? resp.httpResponse.headers['x-amz-cf-id'] : null;
resp.extendedRequestId = extendedRequestId;
resp.cfId = cfId;
if (resp.error) {
resp.error.requestId = resp.requestId || null;
resp.error.extendedRequestId = extendedRequestId;
resp.error.cfId = cfId;
}
} | [
"function",
"extractRequestIds",
"(",
"resp",
")",
"{",
"var",
"extendedRequestId",
"=",
"resp",
".",
"httpResponse",
".",
"headers",
"?",
"resp",
".",
"httpResponse",
".",
"headers",
"[",
"'x-amz-id-2'",
"]",
":",
"null",
";",
"var",
"cfId",
"=",
"resp",
".",
"httpResponse",
".",
"headers",
"?",
"resp",
".",
"httpResponse",
".",
"headers",
"[",
"'x-amz-cf-id'",
"]",
":",
"null",
";",
"resp",
".",
"extendedRequestId",
"=",
"extendedRequestId",
";",
"resp",
".",
"cfId",
"=",
"cfId",
";",
"if",
"(",
"resp",
".",
"error",
")",
"{",
"resp",
".",
"error",
".",
"requestId",
"=",
"resp",
".",
"requestId",
"||",
"null",
";",
"resp",
".",
"error",
".",
"extendedRequestId",
"=",
"extendedRequestId",
";",
"resp",
".",
"error",
".",
"cfId",
"=",
"cfId",
";",
"}",
"}"
] | Extracts S3 specific request ids from the http response.
@api private | [
"Extracts",
"S3",
"specific",
"request",
"ids",
"from",
"the",
"http",
"response",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/services/s3.js#L720-L731 |
3,350 | aws/aws-sdk-js | lib/services/s3.js | getSignedUrl | function getSignedUrl(operation, params, callback) {
params = AWS.util.copy(params || {});
var expires = params.Expires || 900;
delete params.Expires; // we can't validate this
var request = this.makeRequest(operation, params);
if (callback) {
AWS.util.defer(function() {
request.presign(expires, callback);
});
} else {
return request.presign(expires, callback);
}
} | javascript | function getSignedUrl(operation, params, callback) {
params = AWS.util.copy(params || {});
var expires = params.Expires || 900;
delete params.Expires; // we can't validate this
var request = this.makeRequest(operation, params);
if (callback) {
AWS.util.defer(function() {
request.presign(expires, callback);
});
} else {
return request.presign(expires, callback);
}
} | [
"function",
"getSignedUrl",
"(",
"operation",
",",
"params",
",",
"callback",
")",
"{",
"params",
"=",
"AWS",
".",
"util",
".",
"copy",
"(",
"params",
"||",
"{",
"}",
")",
";",
"var",
"expires",
"=",
"params",
".",
"Expires",
"||",
"900",
";",
"delete",
"params",
".",
"Expires",
";",
"// we can't validate this",
"var",
"request",
"=",
"this",
".",
"makeRequest",
"(",
"operation",
",",
"params",
")",
";",
"if",
"(",
"callback",
")",
"{",
"AWS",
".",
"util",
".",
"defer",
"(",
"function",
"(",
")",
"{",
"request",
".",
"presign",
"(",
"expires",
",",
"callback",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"return",
"request",
".",
"presign",
"(",
"expires",
",",
"callback",
")",
";",
"}",
"}"
] | Get a pre-signed URL for a given operation name.
@note You must ensure that you have static or previously resolved
credentials if you call this method synchronously (with no callback),
otherwise it may not properly sign the request. If you cannot guarantee
this (you are using an asynchronous credential provider, i.e., EC2
IAM roles), you should always call this method with an asynchronous
callback.
@note Not all operation parameters are supported when using pre-signed
URLs. Certain parameters, such as `SSECustomerKey`, `ACL`, `Expires`,
`ContentLength`, or `Tagging` must be provided as headers when sending a
request. If you are using pre-signed URLs to upload from a browser and
need to use these fields, see {createPresignedPost}.
@note The default signer allows altering the request by adding corresponding
headers to set some parameters (e.g. Range) and these added parameters
won't be signed. You must use signatureVersion v4 to to include these
parameters in the signed portion of the URL and enforce exact matching
between headers and signed params in the URL.
@note This operation cannot be used with a promise. See note above regarding
asynchronous credentials and use with a callback.
@param operation [String] the name of the operation to call
@param params [map] parameters to pass to the operation. See the given
operation for the expected operation parameters. In addition, you can
also pass the "Expires" parameter to inform S3 how long the URL should
work for.
@option params Expires [Integer] (900) the number of seconds to expire
the pre-signed URL operation in. Defaults to 15 minutes.
@param callback [Function] if a callback is provided, this function will
pass the URL as the second parameter (after the error parameter) to
the callback function.
@return [String] if called synchronously (with no callback), returns the
signed URL.
@return [null] nothing is returned if a callback is provided.
@example Pre-signing a getObject operation (synchronously)
var params = {Bucket: 'bucket', Key: 'key'};
var url = s3.getSignedUrl('getObject', params);
console.log('The URL is', url);
@example Pre-signing a putObject (asynchronously)
var params = {Bucket: 'bucket', Key: 'key'};
s3.getSignedUrl('putObject', params, function (err, url) {
console.log('The URL is', url);
});
@example Pre-signing a putObject operation with a specific payload
var params = {Bucket: 'bucket', Key: 'key', Body: 'body'};
var url = s3.getSignedUrl('putObject', params);
console.log('The URL is', url);
@example Passing in a 1-minute expiry time for a pre-signed URL
var params = {Bucket: 'bucket', Key: 'key', Expires: 60};
var url = s3.getSignedUrl('getObject', params);
console.log('The URL is', url); // expires in 60 seconds | [
"Get",
"a",
"pre",
"-",
"signed",
"URL",
"for",
"a",
"given",
"operation",
"name",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/services/s3.js#L785-L798 |
3,351 | aws/aws-sdk-js | lib/services/s3.js | createPresignedPost | function createPresignedPost(params, callback) {
if (typeof params === 'function' && callback === undefined) {
callback = params;
params = null;
}
params = AWS.util.copy(params || {});
var boundParams = this.config.params || {};
var bucket = params.Bucket || boundParams.Bucket,
self = this,
config = this.config,
endpoint = AWS.util.copy(this.endpoint);
if (!config.s3BucketEndpoint) {
endpoint.pathname = '/' + bucket;
}
function finalizePost() {
return {
url: AWS.util.urlFormat(endpoint),
fields: self.preparePostFields(
config.credentials,
config.region,
bucket,
params.Fields,
params.Conditions,
params.Expires
)
};
}
if (callback) {
config.getCredentials(function (err) {
if (err) {
callback(err);
}
callback(null, finalizePost());
});
} else {
return finalizePost();
}
} | javascript | function createPresignedPost(params, callback) {
if (typeof params === 'function' && callback === undefined) {
callback = params;
params = null;
}
params = AWS.util.copy(params || {});
var boundParams = this.config.params || {};
var bucket = params.Bucket || boundParams.Bucket,
self = this,
config = this.config,
endpoint = AWS.util.copy(this.endpoint);
if (!config.s3BucketEndpoint) {
endpoint.pathname = '/' + bucket;
}
function finalizePost() {
return {
url: AWS.util.urlFormat(endpoint),
fields: self.preparePostFields(
config.credentials,
config.region,
bucket,
params.Fields,
params.Conditions,
params.Expires
)
};
}
if (callback) {
config.getCredentials(function (err) {
if (err) {
callback(err);
}
callback(null, finalizePost());
});
} else {
return finalizePost();
}
} | [
"function",
"createPresignedPost",
"(",
"params",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"params",
"===",
"'function'",
"&&",
"callback",
"===",
"undefined",
")",
"{",
"callback",
"=",
"params",
";",
"params",
"=",
"null",
";",
"}",
"params",
"=",
"AWS",
".",
"util",
".",
"copy",
"(",
"params",
"||",
"{",
"}",
")",
";",
"var",
"boundParams",
"=",
"this",
".",
"config",
".",
"params",
"||",
"{",
"}",
";",
"var",
"bucket",
"=",
"params",
".",
"Bucket",
"||",
"boundParams",
".",
"Bucket",
",",
"self",
"=",
"this",
",",
"config",
"=",
"this",
".",
"config",
",",
"endpoint",
"=",
"AWS",
".",
"util",
".",
"copy",
"(",
"this",
".",
"endpoint",
")",
";",
"if",
"(",
"!",
"config",
".",
"s3BucketEndpoint",
")",
"{",
"endpoint",
".",
"pathname",
"=",
"'/'",
"+",
"bucket",
";",
"}",
"function",
"finalizePost",
"(",
")",
"{",
"return",
"{",
"url",
":",
"AWS",
".",
"util",
".",
"urlFormat",
"(",
"endpoint",
")",
",",
"fields",
":",
"self",
".",
"preparePostFields",
"(",
"config",
".",
"credentials",
",",
"config",
".",
"region",
",",
"bucket",
",",
"params",
".",
"Fields",
",",
"params",
".",
"Conditions",
",",
"params",
".",
"Expires",
")",
"}",
";",
"}",
"if",
"(",
"callback",
")",
"{",
"config",
".",
"getCredentials",
"(",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
"callback",
"(",
"null",
",",
"finalizePost",
"(",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"return",
"finalizePost",
"(",
")",
";",
"}",
"}"
] | Get a pre-signed POST policy to support uploading to S3 directly from an
HTML form.
@param params [map]
@option params Bucket [String] The bucket to which the post should be
uploaded
@option params Expires [Integer] (3600) The number of seconds for which
the presigned policy should be valid.
@option params Conditions [Array] An array of conditions that must be met
for the presigned policy to allow the
upload. This can include required tags,
the accepted range for content lengths,
etc.
@see http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTConstructPolicy.html
@option params Fields [map] Fields to include in the form. All
values passed in as fields will be
signed as exact match conditions.
@param callback [Function]
@note All fields passed in when creating presigned post data will be signed
as exact match conditions. Any fields that will be interpolated by S3
must be added to the fields hash after signing, and an appropriate
condition for such fields must be explicitly added to the Conditions
array passed to this function before signing.
@example Presiging post data with a known key
var params = {
Bucket: 'bucket',
Fields: {
key: 'key'
}
};
s3.createPresignedPost(params, function(err, data) {
if (err) {
console.error('Presigning post data encountered an error', err);
} else {
console.log('The post data is', data);
}
});
@example Presigning post data with an interpolated key
var params = {
Bucket: 'bucket',
Conditions: [
['starts-with', '$key', 'path/to/uploads/']
]
};
s3.createPresignedPost(params, function(err, data) {
if (err) {
console.error('Presigning post data encountered an error', err);
} else {
data.Fields.key = 'path/to/uploads/${filename}';
console.log('The post data is', data);
}
});
@note You must ensure that you have static or previously resolved
credentials if you call this method synchronously (with no callback),
otherwise it may not properly sign the request. If you cannot guarantee
this (you are using an asynchronous credential provider, i.e., EC2
IAM roles), you should always call this method with an asynchronous
callback.
@return [map] If called synchronously (with no callback), returns a hash
with the url to set as the form action and a hash of fields
to include in the form.
@return [null] Nothing is returned if a callback is provided.
@callback callback function (err, data)
@param err [Error] the error object returned from the policy signer
@param data [map] The data necessary to construct an HTML form
@param data.url [String] The URL to use as the action of the form
@param data.fields [map] A hash of fields that must be included in the
form for the upload to succeed. This hash will
include the signed POST policy, your access key
ID and security token (if present), etc. These
may be safely included as input elements of type
'hidden.' | [
"Get",
"a",
"pre",
"-",
"signed",
"POST",
"policy",
"to",
"support",
"uploading",
"to",
"S3",
"directly",
"from",
"an",
"HTML",
"form",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/services/s3.js#L881-L922 |
3,352 | aws/aws-sdk-js | lib/dynamodb/converter.js | convertInput | function convertInput(data, options) {
options = options || {};
var type = typeOf(data);
if (type === 'Object') {
return formatMap(data, options);
} else if (type === 'Array') {
return formatList(data, options);
} else if (type === 'Set') {
return formatSet(data, options);
} else if (type === 'String') {
if (data.length === 0 && options.convertEmptyValues) {
return convertInput(null);
}
return { S: data };
} else if (type === 'Number' || type === 'NumberValue') {
return { N: data.toString() };
} else if (type === 'Binary') {
if (data.length === 0 && options.convertEmptyValues) {
return convertInput(null);
}
return { B: data };
} else if (type === 'Boolean') {
return { BOOL: data };
} else if (type === 'null') {
return { NULL: true };
} else if (type !== 'undefined' && type !== 'Function') {
// this value has a custom constructor
return formatMap(data, options);
}
} | javascript | function convertInput(data, options) {
options = options || {};
var type = typeOf(data);
if (type === 'Object') {
return formatMap(data, options);
} else if (type === 'Array') {
return formatList(data, options);
} else if (type === 'Set') {
return formatSet(data, options);
} else if (type === 'String') {
if (data.length === 0 && options.convertEmptyValues) {
return convertInput(null);
}
return { S: data };
} else if (type === 'Number' || type === 'NumberValue') {
return { N: data.toString() };
} else if (type === 'Binary') {
if (data.length === 0 && options.convertEmptyValues) {
return convertInput(null);
}
return { B: data };
} else if (type === 'Boolean') {
return { BOOL: data };
} else if (type === 'null') {
return { NULL: true };
} else if (type !== 'undefined' && type !== 'Function') {
// this value has a custom constructor
return formatMap(data, options);
}
} | [
"function",
"convertInput",
"(",
"data",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"type",
"=",
"typeOf",
"(",
"data",
")",
";",
"if",
"(",
"type",
"===",
"'Object'",
")",
"{",
"return",
"formatMap",
"(",
"data",
",",
"options",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'Array'",
")",
"{",
"return",
"formatList",
"(",
"data",
",",
"options",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'Set'",
")",
"{",
"return",
"formatSet",
"(",
"data",
",",
"options",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'String'",
")",
"{",
"if",
"(",
"data",
".",
"length",
"===",
"0",
"&&",
"options",
".",
"convertEmptyValues",
")",
"{",
"return",
"convertInput",
"(",
"null",
")",
";",
"}",
"return",
"{",
"S",
":",
"data",
"}",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'Number'",
"||",
"type",
"===",
"'NumberValue'",
")",
"{",
"return",
"{",
"N",
":",
"data",
".",
"toString",
"(",
")",
"}",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'Binary'",
")",
"{",
"if",
"(",
"data",
".",
"length",
"===",
"0",
"&&",
"options",
".",
"convertEmptyValues",
")",
"{",
"return",
"convertInput",
"(",
"null",
")",
";",
"}",
"return",
"{",
"B",
":",
"data",
"}",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'Boolean'",
")",
"{",
"return",
"{",
"BOOL",
":",
"data",
"}",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'null'",
")",
"{",
"return",
"{",
"NULL",
":",
"true",
"}",
";",
"}",
"else",
"if",
"(",
"type",
"!==",
"'undefined'",
"&&",
"type",
"!==",
"'Function'",
")",
"{",
"// this value has a custom constructor",
"return",
"formatMap",
"(",
"data",
",",
"options",
")",
";",
"}",
"}"
] | Convert a JavaScript value to its equivalent DynamoDB AttributeValue type
@param data [any] The data to convert to a DynamoDB AttributeValue
@param options [map]
@option options convertEmptyValues [Boolean] Whether to automatically
convert empty strings, blobs,
and sets to `null`
@option options wrapNumbers [Boolean] Whether to return numbers as a
NumberValue object instead of
converting them to native JavaScript
numbers. This allows for the safe
round-trip transport of numbers of
arbitrary size.
@return [map] An object in the Amazon DynamoDB AttributeValue format
@see AWS.DynamoDB.Converter.marshall AWS.DynamoDB.Converter.marshall to
convert entire records (rather than individual attributes) | [
"Convert",
"a",
"JavaScript",
"value",
"to",
"its",
"equivalent",
"DynamoDB",
"AttributeValue",
"type"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/dynamodb/converter.js#L27-L56 |
3,353 | aws/aws-sdk-js | lib/dynamodb/converter.js | marshallItem | function marshallItem(data, options) {
return AWS.DynamoDB.Converter.input(data, options).M;
} | javascript | function marshallItem(data, options) {
return AWS.DynamoDB.Converter.input(data, options).M;
} | [
"function",
"marshallItem",
"(",
"data",
",",
"options",
")",
"{",
"return",
"AWS",
".",
"DynamoDB",
".",
"Converter",
".",
"input",
"(",
"data",
",",
"options",
")",
".",
"M",
";",
"}"
] | Convert a JavaScript object into a DynamoDB record.
@param data [any] The data to convert to a DynamoDB record
@param options [map]
@option options convertEmptyValues [Boolean] Whether to automatically
convert empty strings, blobs,
and sets to `null`
@option options wrapNumbers [Boolean] Whether to return numbers as a
NumberValue object instead of
converting them to native JavaScript
numbers. This allows for the safe
round-trip transport of numbers of
arbitrary size.
@return [map] An object in the DynamoDB record format.
@example Convert a JavaScript object into a DynamoDB record
var marshalled = AWS.DynamoDB.Converter.marshall({
string: 'foo',
list: ['fizz', 'buzz', 'pop'],
map: {
nestedMap: {
key: 'value',
}
},
number: 123,
nullValue: null,
boolValue: true,
stringSet: new DynamoDBSet(['foo', 'bar', 'baz'])
}); | [
"Convert",
"a",
"JavaScript",
"object",
"into",
"a",
"DynamoDB",
"record",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/dynamodb/converter.js#L90-L92 |
3,354 | aws/aws-sdk-js | lib/dynamodb/converter.js | convertOutput | function convertOutput(data, options) {
options = options || {};
var list, map, i;
for (var type in data) {
var values = data[type];
if (type === 'M') {
map = {};
for (var key in values) {
map[key] = convertOutput(values[key], options);
}
return map;
} else if (type === 'L') {
list = [];
for (i = 0; i < values.length; i++) {
list.push(convertOutput(values[i], options));
}
return list;
} else if (type === 'SS') {
list = [];
for (i = 0; i < values.length; i++) {
list.push(values[i] + '');
}
return new DynamoDBSet(list);
} else if (type === 'NS') {
list = [];
for (i = 0; i < values.length; i++) {
list.push(convertNumber(values[i], options.wrapNumbers));
}
return new DynamoDBSet(list);
} else if (type === 'BS') {
list = [];
for (i = 0; i < values.length; i++) {
list.push(new util.Buffer(values[i]));
}
return new DynamoDBSet(list);
} else if (type === 'S') {
return values + '';
} else if (type === 'N') {
return convertNumber(values, options.wrapNumbers);
} else if (type === 'B') {
return new util.Buffer(values);
} else if (type === 'BOOL') {
return (values === 'true' || values === 'TRUE' || values === true);
} else if (type === 'NULL') {
return null;
}
}
} | javascript | function convertOutput(data, options) {
options = options || {};
var list, map, i;
for (var type in data) {
var values = data[type];
if (type === 'M') {
map = {};
for (var key in values) {
map[key] = convertOutput(values[key], options);
}
return map;
} else if (type === 'L') {
list = [];
for (i = 0; i < values.length; i++) {
list.push(convertOutput(values[i], options));
}
return list;
} else if (type === 'SS') {
list = [];
for (i = 0; i < values.length; i++) {
list.push(values[i] + '');
}
return new DynamoDBSet(list);
} else if (type === 'NS') {
list = [];
for (i = 0; i < values.length; i++) {
list.push(convertNumber(values[i], options.wrapNumbers));
}
return new DynamoDBSet(list);
} else if (type === 'BS') {
list = [];
for (i = 0; i < values.length; i++) {
list.push(new util.Buffer(values[i]));
}
return new DynamoDBSet(list);
} else if (type === 'S') {
return values + '';
} else if (type === 'N') {
return convertNumber(values, options.wrapNumbers);
} else if (type === 'B') {
return new util.Buffer(values);
} else if (type === 'BOOL') {
return (values === 'true' || values === 'TRUE' || values === true);
} else if (type === 'NULL') {
return null;
}
}
} | [
"function",
"convertOutput",
"(",
"data",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"list",
",",
"map",
",",
"i",
";",
"for",
"(",
"var",
"type",
"in",
"data",
")",
"{",
"var",
"values",
"=",
"data",
"[",
"type",
"]",
";",
"if",
"(",
"type",
"===",
"'M'",
")",
"{",
"map",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"key",
"in",
"values",
")",
"{",
"map",
"[",
"key",
"]",
"=",
"convertOutput",
"(",
"values",
"[",
"key",
"]",
",",
"options",
")",
";",
"}",
"return",
"map",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'L'",
")",
"{",
"list",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"values",
".",
"length",
";",
"i",
"++",
")",
"{",
"list",
".",
"push",
"(",
"convertOutput",
"(",
"values",
"[",
"i",
"]",
",",
"options",
")",
")",
";",
"}",
"return",
"list",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'SS'",
")",
"{",
"list",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"values",
".",
"length",
";",
"i",
"++",
")",
"{",
"list",
".",
"push",
"(",
"values",
"[",
"i",
"]",
"+",
"''",
")",
";",
"}",
"return",
"new",
"DynamoDBSet",
"(",
"list",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'NS'",
")",
"{",
"list",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"values",
".",
"length",
";",
"i",
"++",
")",
"{",
"list",
".",
"push",
"(",
"convertNumber",
"(",
"values",
"[",
"i",
"]",
",",
"options",
".",
"wrapNumbers",
")",
")",
";",
"}",
"return",
"new",
"DynamoDBSet",
"(",
"list",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'BS'",
")",
"{",
"list",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"values",
".",
"length",
";",
"i",
"++",
")",
"{",
"list",
".",
"push",
"(",
"new",
"util",
".",
"Buffer",
"(",
"values",
"[",
"i",
"]",
")",
")",
";",
"}",
"return",
"new",
"DynamoDBSet",
"(",
"list",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'S'",
")",
"{",
"return",
"values",
"+",
"''",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'N'",
")",
"{",
"return",
"convertNumber",
"(",
"values",
",",
"options",
".",
"wrapNumbers",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'B'",
")",
"{",
"return",
"new",
"util",
".",
"Buffer",
"(",
"values",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'BOOL'",
")",
"{",
"return",
"(",
"values",
"===",
"'true'",
"||",
"values",
"===",
"'TRUE'",
"||",
"values",
"===",
"true",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'NULL'",
")",
"{",
"return",
"null",
";",
"}",
"}",
"}"
] | Convert a DynamoDB AttributeValue object to its equivalent JavaScript type.
@param data [map] An object in the Amazon DynamoDB AttributeValue format
@param options [map]
@option options convertEmptyValues [Boolean] Whether to automatically
convert empty strings, blobs,
and sets to `null`
@option options wrapNumbers [Boolean] Whether to return numbers as a
NumberValue object instead of
converting them to native JavaScript
numbers. This allows for the safe
round-trip transport of numbers of
arbitrary size.
@return [Object|Array|String|Number|Boolean|null]
@see AWS.DynamoDB.Converter.unmarshall AWS.DynamoDB.Converter.unmarshall to
convert entire records (rather than individual attributes) | [
"Convert",
"a",
"DynamoDB",
"AttributeValue",
"object",
"to",
"its",
"equivalent",
"JavaScript",
"type",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/dynamodb/converter.js#L114-L161 |
3,355 | aws/aws-sdk-js | lib/dynamodb/converter.js | unmarshall | function unmarshall(data, options) {
return AWS.DynamoDB.Converter.output({M: data}, options);
} | javascript | function unmarshall(data, options) {
return AWS.DynamoDB.Converter.output({M: data}, options);
} | [
"function",
"unmarshall",
"(",
"data",
",",
"options",
")",
"{",
"return",
"AWS",
".",
"DynamoDB",
".",
"Converter",
".",
"output",
"(",
"{",
"M",
":",
"data",
"}",
",",
"options",
")",
";",
"}"
] | Convert a DynamoDB record into a JavaScript object.
@param data [any] The DynamoDB record
@param options [map]
@option options convertEmptyValues [Boolean] Whether to automatically
convert empty strings, blobs,
and sets to `null`
@option options wrapNumbers [Boolean] Whether to return numbers as a
NumberValue object instead of
converting them to native JavaScript
numbers. This allows for the safe
round-trip transport of numbers of
arbitrary size.
@return [map] An object whose properties have been converted from
DynamoDB's AttributeValue format into their corresponding native
JavaScript types.
@example Convert a record received from a DynamoDB stream
var unmarshalled = AWS.DynamoDB.Converter.unmarshall({
string: {S: 'foo'},
list: {L: [{S: 'fizz'}, {S: 'buzz'}, {S: 'pop'}]},
map: {
M: {
nestedMap: {
M: {
key: {S: 'value'}
}
}
}
},
number: {N: '123'},
nullValue: {NULL: true},
boolValue: {BOOL: true}
}); | [
"Convert",
"a",
"DynamoDB",
"record",
"into",
"a",
"JavaScript",
"object",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/dynamodb/converter.js#L200-L202 |
3,356 | aws/aws-sdk-js | lib/protocol/helpers.js | populateHostPrefix | function populateHostPrefix(request) {
var enabled = request.service.config.hostPrefixEnabled;
if (!enabled) return request;
var operationModel = request.service.api.operations[request.operation];
//don't marshal host prefix when operation has endpoint discovery traits
if (hasEndpointDiscover(request)) return request;
if (operationModel.endpoint && operationModel.endpoint.hostPrefix) {
var hostPrefixNotation = operationModel.endpoint.hostPrefix;
var hostPrefix = expandHostPrefix(hostPrefixNotation, request.params, operationModel.input);
prependEndpointPrefix(request.httpRequest.endpoint, hostPrefix);
validateHostname(request.httpRequest.endpoint.hostname);
}
return request;
} | javascript | function populateHostPrefix(request) {
var enabled = request.service.config.hostPrefixEnabled;
if (!enabled) return request;
var operationModel = request.service.api.operations[request.operation];
//don't marshal host prefix when operation has endpoint discovery traits
if (hasEndpointDiscover(request)) return request;
if (operationModel.endpoint && operationModel.endpoint.hostPrefix) {
var hostPrefixNotation = operationModel.endpoint.hostPrefix;
var hostPrefix = expandHostPrefix(hostPrefixNotation, request.params, operationModel.input);
prependEndpointPrefix(request.httpRequest.endpoint, hostPrefix);
validateHostname(request.httpRequest.endpoint.hostname);
}
return request;
} | [
"function",
"populateHostPrefix",
"(",
"request",
")",
"{",
"var",
"enabled",
"=",
"request",
".",
"service",
".",
"config",
".",
"hostPrefixEnabled",
";",
"if",
"(",
"!",
"enabled",
")",
"return",
"request",
";",
"var",
"operationModel",
"=",
"request",
".",
"service",
".",
"api",
".",
"operations",
"[",
"request",
".",
"operation",
"]",
";",
"//don't marshal host prefix when operation has endpoint discovery traits",
"if",
"(",
"hasEndpointDiscover",
"(",
"request",
")",
")",
"return",
"request",
";",
"if",
"(",
"operationModel",
".",
"endpoint",
"&&",
"operationModel",
".",
"endpoint",
".",
"hostPrefix",
")",
"{",
"var",
"hostPrefixNotation",
"=",
"operationModel",
".",
"endpoint",
".",
"hostPrefix",
";",
"var",
"hostPrefix",
"=",
"expandHostPrefix",
"(",
"hostPrefixNotation",
",",
"request",
".",
"params",
",",
"operationModel",
".",
"input",
")",
";",
"prependEndpointPrefix",
"(",
"request",
".",
"httpRequest",
".",
"endpoint",
",",
"hostPrefix",
")",
";",
"validateHostname",
"(",
"request",
".",
"httpRequest",
".",
"endpoint",
".",
"hostname",
")",
";",
"}",
"return",
"request",
";",
"}"
] | Prepend prefix defined by API model to endpoint that's already
constructed. This feature does not apply to operations using
endpoint discovery and can be disabled.
@api private | [
"Prepend",
"prefix",
"defined",
"by",
"API",
"model",
"to",
"endpoint",
"that",
"s",
"already",
"constructed",
".",
"This",
"feature",
"does",
"not",
"apply",
"to",
"operations",
"using",
"endpoint",
"discovery",
"and",
"can",
"be",
"disabled",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/protocol/helpers.js#L10-L23 |
3,357 | aws/aws-sdk-js | lib/config.js | loadFromPath | function loadFromPath(path) {
this.clear();
var options = JSON.parse(AWS.util.readFileSync(path));
var fileSystemCreds = new AWS.FileSystemCredentials(path);
var chain = new AWS.CredentialProviderChain();
chain.providers.unshift(fileSystemCreds);
chain.resolve(function (err, creds) {
if (err) throw err;
else options.credentials = creds;
});
this.constructor(options);
return this;
} | javascript | function loadFromPath(path) {
this.clear();
var options = JSON.parse(AWS.util.readFileSync(path));
var fileSystemCreds = new AWS.FileSystemCredentials(path);
var chain = new AWS.CredentialProviderChain();
chain.providers.unshift(fileSystemCreds);
chain.resolve(function (err, creds) {
if (err) throw err;
else options.credentials = creds;
});
this.constructor(options);
return this;
} | [
"function",
"loadFromPath",
"(",
"path",
")",
"{",
"this",
".",
"clear",
"(",
")",
";",
"var",
"options",
"=",
"JSON",
".",
"parse",
"(",
"AWS",
".",
"util",
".",
"readFileSync",
"(",
"path",
")",
")",
";",
"var",
"fileSystemCreds",
"=",
"new",
"AWS",
".",
"FileSystemCredentials",
"(",
"path",
")",
";",
"var",
"chain",
"=",
"new",
"AWS",
".",
"CredentialProviderChain",
"(",
")",
";",
"chain",
".",
"providers",
".",
"unshift",
"(",
"fileSystemCreds",
")",
";",
"chain",
".",
"resolve",
"(",
"function",
"(",
"err",
",",
"creds",
")",
"{",
"if",
"(",
"err",
")",
"throw",
"err",
";",
"else",
"options",
".",
"credentials",
"=",
"creds",
";",
"}",
")",
";",
"this",
".",
"constructor",
"(",
"options",
")",
";",
"return",
"this",
";",
"}"
] | Loads configuration data from a JSON file into this config object.
@note Loading configuration will reset all existing configuration
on the object.
@!macro nobrowser
@param path [String] the path relative to your process's current
working directory to load configuration from.
@return [AWS.Config] the same configuration object | [
"Loads",
"configuration",
"data",
"from",
"a",
"JSON",
"file",
"into",
"this",
"config",
"object",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/config.js#L434-L449 |
3,358 | aws/aws-sdk-js | lib/config.js | extractCredentials | function extractCredentials(options) {
if (options.accessKeyId && options.secretAccessKey) {
options = AWS.util.copy(options);
options.credentials = new AWS.Credentials(options);
}
return options;
} | javascript | function extractCredentials(options) {
if (options.accessKeyId && options.secretAccessKey) {
options = AWS.util.copy(options);
options.credentials = new AWS.Credentials(options);
}
return options;
} | [
"function",
"extractCredentials",
"(",
"options",
")",
"{",
"if",
"(",
"options",
".",
"accessKeyId",
"&&",
"options",
".",
"secretAccessKey",
")",
"{",
"options",
"=",
"AWS",
".",
"util",
".",
"copy",
"(",
"options",
")",
";",
"options",
".",
"credentials",
"=",
"new",
"AWS",
".",
"Credentials",
"(",
"options",
")",
";",
"}",
"return",
"options",
";",
"}"
] | Extracts accessKeyId, secretAccessKey and sessionToken
from a configuration hash.
@api private | [
"Extracts",
"accessKeyId",
"secretAccessKey",
"and",
"sessionToken",
"from",
"a",
"configuration",
"hash",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/config.js#L536-L542 |
3,359 | aws/aws-sdk-js | lib/config.js | setPromisesDependency | function setPromisesDependency(dep) {
PromisesDependency = dep;
// if null was passed in, we should try to use native promises
if (dep === null && typeof Promise === 'function') {
PromisesDependency = Promise;
}
var constructors = [AWS.Request, AWS.Credentials, AWS.CredentialProviderChain];
if (AWS.S3 && AWS.S3.ManagedUpload) constructors.push(AWS.S3.ManagedUpload);
AWS.util.addPromises(constructors, PromisesDependency);
} | javascript | function setPromisesDependency(dep) {
PromisesDependency = dep;
// if null was passed in, we should try to use native promises
if (dep === null && typeof Promise === 'function') {
PromisesDependency = Promise;
}
var constructors = [AWS.Request, AWS.Credentials, AWS.CredentialProviderChain];
if (AWS.S3 && AWS.S3.ManagedUpload) constructors.push(AWS.S3.ManagedUpload);
AWS.util.addPromises(constructors, PromisesDependency);
} | [
"function",
"setPromisesDependency",
"(",
"dep",
")",
"{",
"PromisesDependency",
"=",
"dep",
";",
"// if null was passed in, we should try to use native promises",
"if",
"(",
"dep",
"===",
"null",
"&&",
"typeof",
"Promise",
"===",
"'function'",
")",
"{",
"PromisesDependency",
"=",
"Promise",
";",
"}",
"var",
"constructors",
"=",
"[",
"AWS",
".",
"Request",
",",
"AWS",
".",
"Credentials",
",",
"AWS",
".",
"CredentialProviderChain",
"]",
";",
"if",
"(",
"AWS",
".",
"S3",
"&&",
"AWS",
".",
"S3",
".",
"ManagedUpload",
")",
"constructors",
".",
"push",
"(",
"AWS",
".",
"S3",
".",
"ManagedUpload",
")",
";",
"AWS",
".",
"util",
".",
"addPromises",
"(",
"constructors",
",",
"PromisesDependency",
")",
";",
"}"
] | Sets the promise dependency the SDK will use wherever Promises are returned.
Passing `null` will force the SDK to use native Promises if they are available.
If native Promises are not available, passing `null` will have no effect.
@param [Constructor] dep A reference to a Promise constructor | [
"Sets",
"the",
"promise",
"dependency",
"the",
"SDK",
"will",
"use",
"wherever",
"Promises",
"are",
"returned",
".",
"Passing",
"null",
"will",
"force",
"the",
"SDK",
"to",
"use",
"native",
"Promises",
"if",
"they",
"are",
"available",
".",
"If",
"native",
"Promises",
"are",
"not",
"available",
"passing",
"null",
"will",
"have",
"no",
"effect",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/config.js#L550-L559 |
3,360 | aws/aws-sdk-js | doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/doctools.js | function() {
$('div[id] > :header:first').each(function() {
$('<a class="headerlink">\u00B6</a>').
attr('href', '#' + this.id).
attr('title', _('Permalink to this headline')).
appendTo(this);
});
$('dt[id]').each(function() {
$('<a class="headerlink">\u00B6</a>').
attr('href', '#' + this.id).
attr('title', _('Permalink to this definition')).
appendTo(this);
});
} | javascript | function() {
$('div[id] > :header:first').each(function() {
$('<a class="headerlink">\u00B6</a>').
attr('href', '#' + this.id).
attr('title', _('Permalink to this headline')).
appendTo(this);
});
$('dt[id]').each(function() {
$('<a class="headerlink">\u00B6</a>').
attr('href', '#' + this.id).
attr('title', _('Permalink to this definition')).
appendTo(this);
});
} | [
"function",
"(",
")",
"{",
"$",
"(",
"'div[id] > :header:first'",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"$",
"(",
"'<a class=\"headerlink\">\\u00B6</a>'",
")",
".",
"attr",
"(",
"'href'",
",",
"'#'",
"+",
"this",
".",
"id",
")",
".",
"attr",
"(",
"'title'",
",",
"_",
"(",
"'Permalink to this headline'",
")",
")",
".",
"appendTo",
"(",
"this",
")",
";",
"}",
")",
";",
"$",
"(",
"'dt[id]'",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"$",
"(",
"'<a class=\"headerlink\">\\u00B6</a>'",
")",
".",
"attr",
"(",
"'href'",
",",
"'#'",
"+",
"this",
".",
"id",
")",
".",
"attr",
"(",
"'title'",
",",
"_",
"(",
"'Permalink to this definition'",
")",
")",
".",
"appendTo",
"(",
"this",
")",
";",
"}",
")",
";",
"}"
] | add context elements like header anchor links | [
"add",
"context",
"elements",
"like",
"header",
"anchor",
"links"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/doctools.js#L150-L163 |
|
3,361 | aws/aws-sdk-js | doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/doctools.js | function() {
if (document.location.hash && $.browser.mozilla)
window.setTimeout(function() {
document.location.href += '';
}, 10);
} | javascript | function() {
if (document.location.hash && $.browser.mozilla)
window.setTimeout(function() {
document.location.href += '';
}, 10);
} | [
"function",
"(",
")",
"{",
"if",
"(",
"document",
".",
"location",
".",
"hash",
"&&",
"$",
".",
"browser",
".",
"mozilla",
")",
"window",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"document",
".",
"location",
".",
"href",
"+=",
"''",
";",
"}",
",",
"10",
")",
";",
"}"
] | workaround a firefox stupidity | [
"workaround",
"a",
"firefox",
"stupidity"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/doctools.js#L168-L173 |
|
3,362 | aws/aws-sdk-js | doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/doctools.js | function() {
var togglers = $('img.toggler').click(function() {
var src = $(this).attr('src');
var idnum = $(this).attr('id').substr(7);
$('tr.cg-' + idnum).toggle();
if (src.substr(-9) == 'minus.png')
$(this).attr('src', src.substr(0, src.length-9) + 'plus.png');
else
$(this).attr('src', src.substr(0, src.length-8) + 'minus.png');
}).css('display', '');
if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) {
togglers.click();
}
} | javascript | function() {
var togglers = $('img.toggler').click(function() {
var src = $(this).attr('src');
var idnum = $(this).attr('id').substr(7);
$('tr.cg-' + idnum).toggle();
if (src.substr(-9) == 'minus.png')
$(this).attr('src', src.substr(0, src.length-9) + 'plus.png');
else
$(this).attr('src', src.substr(0, src.length-8) + 'minus.png');
}).css('display', '');
if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) {
togglers.click();
}
} | [
"function",
"(",
")",
"{",
"var",
"togglers",
"=",
"$",
"(",
"'img.toggler'",
")",
".",
"click",
"(",
"function",
"(",
")",
"{",
"var",
"src",
"=",
"$",
"(",
"this",
")",
".",
"attr",
"(",
"'src'",
")",
";",
"var",
"idnum",
"=",
"$",
"(",
"this",
")",
".",
"attr",
"(",
"'id'",
")",
".",
"substr",
"(",
"7",
")",
";",
"$",
"(",
"'tr.cg-'",
"+",
"idnum",
")",
".",
"toggle",
"(",
")",
";",
"if",
"(",
"src",
".",
"substr",
"(",
"-",
"9",
")",
"==",
"'minus.png'",
")",
"$",
"(",
"this",
")",
".",
"attr",
"(",
"'src'",
",",
"src",
".",
"substr",
"(",
"0",
",",
"src",
".",
"length",
"-",
"9",
")",
"+",
"'plus.png'",
")",
";",
"else",
"$",
"(",
"this",
")",
".",
"attr",
"(",
"'src'",
",",
"src",
".",
"substr",
"(",
"0",
",",
"src",
".",
"length",
"-",
"8",
")",
"+",
"'minus.png'",
")",
";",
"}",
")",
".",
"css",
"(",
"'display'",
",",
"''",
")",
";",
"if",
"(",
"DOCUMENTATION_OPTIONS",
".",
"COLLAPSE_INDEX",
")",
"{",
"togglers",
".",
"click",
"(",
")",
";",
"}",
"}"
] | init the domain index toggle buttons | [
"init",
"the",
"domain",
"index",
"toggle",
"buttons"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/doctools.js#L197-L210 |
|
3,363 | aws/aws-sdk-js | doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/doctools.js | function() {
var path = document.location.pathname;
var parts = path.split(/\//);
$.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() {
if (this == '..')
parts.pop();
});
var url = parts.join('/');
return path.substring(url.lastIndexOf('/') + 1, path.length - 1);
} | javascript | function() {
var path = document.location.pathname;
var parts = path.split(/\//);
$.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() {
if (this == '..')
parts.pop();
});
var url = parts.join('/');
return path.substring(url.lastIndexOf('/') + 1, path.length - 1);
} | [
"function",
"(",
")",
"{",
"var",
"path",
"=",
"document",
".",
"location",
".",
"pathname",
";",
"var",
"parts",
"=",
"path",
".",
"split",
"(",
"/",
"\\/",
"/",
")",
";",
"$",
".",
"each",
"(",
"DOCUMENTATION_OPTIONS",
".",
"URL_ROOT",
".",
"split",
"(",
"/",
"\\/",
"/",
")",
",",
"function",
"(",
")",
"{",
"if",
"(",
"this",
"==",
"'..'",
")",
"parts",
".",
"pop",
"(",
")",
";",
"}",
")",
";",
"var",
"url",
"=",
"parts",
".",
"join",
"(",
"'/'",
")",
";",
"return",
"path",
".",
"substring",
"(",
"url",
".",
"lastIndexOf",
"(",
"'/'",
")",
"+",
"1",
",",
"path",
".",
"length",
"-",
"1",
")",
";",
"}"
] | get the current relative url | [
"get",
"the",
"current",
"relative",
"url"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/doctools.js#L230-L239 |
|
3,364 | aws/aws-sdk-js | lib/service.js | Service | function Service(config) {
if (!this.loadServiceClass) {
throw AWS.util.error(new Error(),
'Service must be constructed with `new\' operator');
}
var ServiceClass = this.loadServiceClass(config || {});
if (ServiceClass) {
var originalConfig = AWS.util.copy(config);
var svc = new ServiceClass(config);
Object.defineProperty(svc, '_originalConfig', {
get: function() { return originalConfig; },
enumerable: false,
configurable: true
});
svc._clientId = ++clientCount;
return svc;
}
this.initialize(config);
} | javascript | function Service(config) {
if (!this.loadServiceClass) {
throw AWS.util.error(new Error(),
'Service must be constructed with `new\' operator');
}
var ServiceClass = this.loadServiceClass(config || {});
if (ServiceClass) {
var originalConfig = AWS.util.copy(config);
var svc = new ServiceClass(config);
Object.defineProperty(svc, '_originalConfig', {
get: function() { return originalConfig; },
enumerable: false,
configurable: true
});
svc._clientId = ++clientCount;
return svc;
}
this.initialize(config);
} | [
"function",
"Service",
"(",
"config",
")",
"{",
"if",
"(",
"!",
"this",
".",
"loadServiceClass",
")",
"{",
"throw",
"AWS",
".",
"util",
".",
"error",
"(",
"new",
"Error",
"(",
")",
",",
"'Service must be constructed with `new\\' operator'",
")",
";",
"}",
"var",
"ServiceClass",
"=",
"this",
".",
"loadServiceClass",
"(",
"config",
"||",
"{",
"}",
")",
";",
"if",
"(",
"ServiceClass",
")",
"{",
"var",
"originalConfig",
"=",
"AWS",
".",
"util",
".",
"copy",
"(",
"config",
")",
";",
"var",
"svc",
"=",
"new",
"ServiceClass",
"(",
"config",
")",
";",
"Object",
".",
"defineProperty",
"(",
"svc",
",",
"'_originalConfig'",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"originalConfig",
";",
"}",
",",
"enumerable",
":",
"false",
",",
"configurable",
":",
"true",
"}",
")",
";",
"svc",
".",
"_clientId",
"=",
"++",
"clientCount",
";",
"return",
"svc",
";",
"}",
"this",
".",
"initialize",
"(",
"config",
")",
";",
"}"
] | Create a new service object with a configuration object
@param config [map] a map of configuration options | [
"Create",
"a",
"new",
"service",
"object",
"with",
"a",
"configuration",
"object"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/service.js#L23-L41 |
3,365 | aws/aws-sdk-js | lib/service.js | makeRequest | function makeRequest(operation, params, callback) {
if (typeof params === 'function') {
callback = params;
params = null;
}
params = params || {};
if (this.config.params) { // copy only toplevel bound params
var rules = this.api.operations[operation];
if (rules) {
params = AWS.util.copy(params);
AWS.util.each(this.config.params, function(key, value) {
if (rules.input.members[key]) {
if (params[key] === undefined || params[key] === null) {
params[key] = value;
}
}
});
}
}
var request = new AWS.Request(this, operation, params);
this.addAllRequestListeners(request);
this.attachMonitoringEmitter(request);
if (callback) request.send(callback);
return request;
} | javascript | function makeRequest(operation, params, callback) {
if (typeof params === 'function') {
callback = params;
params = null;
}
params = params || {};
if (this.config.params) { // copy only toplevel bound params
var rules = this.api.operations[operation];
if (rules) {
params = AWS.util.copy(params);
AWS.util.each(this.config.params, function(key, value) {
if (rules.input.members[key]) {
if (params[key] === undefined || params[key] === null) {
params[key] = value;
}
}
});
}
}
var request = new AWS.Request(this, operation, params);
this.addAllRequestListeners(request);
this.attachMonitoringEmitter(request);
if (callback) request.send(callback);
return request;
} | [
"function",
"makeRequest",
"(",
"operation",
",",
"params",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"params",
"===",
"'function'",
")",
"{",
"callback",
"=",
"params",
";",
"params",
"=",
"null",
";",
"}",
"params",
"=",
"params",
"||",
"{",
"}",
";",
"if",
"(",
"this",
".",
"config",
".",
"params",
")",
"{",
"// copy only toplevel bound params",
"var",
"rules",
"=",
"this",
".",
"api",
".",
"operations",
"[",
"operation",
"]",
";",
"if",
"(",
"rules",
")",
"{",
"params",
"=",
"AWS",
".",
"util",
".",
"copy",
"(",
"params",
")",
";",
"AWS",
".",
"util",
".",
"each",
"(",
"this",
".",
"config",
".",
"params",
",",
"function",
"(",
"key",
",",
"value",
")",
"{",
"if",
"(",
"rules",
".",
"input",
".",
"members",
"[",
"key",
"]",
")",
"{",
"if",
"(",
"params",
"[",
"key",
"]",
"===",
"undefined",
"||",
"params",
"[",
"key",
"]",
"===",
"null",
")",
"{",
"params",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"}",
"}",
")",
";",
"}",
"}",
"var",
"request",
"=",
"new",
"AWS",
".",
"Request",
"(",
"this",
",",
"operation",
",",
"params",
")",
";",
"this",
".",
"addAllRequestListeners",
"(",
"request",
")",
";",
"this",
".",
"attachMonitoringEmitter",
"(",
"request",
")",
";",
"if",
"(",
"callback",
")",
"request",
".",
"send",
"(",
"callback",
")",
";",
"return",
"request",
";",
"}"
] | Calls an operation on a service with the given input parameters.
@param operation [String] the name of the operation to call on the service.
@param params [map] a map of input options for the operation
@callback callback function(err, data)
If a callback is supplied, it is called when a response is returned
from the service.
@param err [Error] the error object returned from the request.
Set to `null` if the request is successful.
@param data [Object] the de-serialized data returned from
the request. Set to `null` if a request error occurs. | [
"Calls",
"an",
"operation",
"on",
"a",
"service",
"with",
"the",
"given",
"input",
"parameters",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/service.js#L181-L207 |
3,366 | aws/aws-sdk-js | lib/service.js | makeUnauthenticatedRequest | function makeUnauthenticatedRequest(operation, params, callback) {
if (typeof params === 'function') {
callback = params;
params = {};
}
var request = this.makeRequest(operation, params).toUnauthenticated();
return callback ? request.send(callback) : request;
} | javascript | function makeUnauthenticatedRequest(operation, params, callback) {
if (typeof params === 'function') {
callback = params;
params = {};
}
var request = this.makeRequest(operation, params).toUnauthenticated();
return callback ? request.send(callback) : request;
} | [
"function",
"makeUnauthenticatedRequest",
"(",
"operation",
",",
"params",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"params",
"===",
"'function'",
")",
"{",
"callback",
"=",
"params",
";",
"params",
"=",
"{",
"}",
";",
"}",
"var",
"request",
"=",
"this",
".",
"makeRequest",
"(",
"operation",
",",
"params",
")",
".",
"toUnauthenticated",
"(",
")",
";",
"return",
"callback",
"?",
"request",
".",
"send",
"(",
"callback",
")",
":",
"request",
";",
"}"
] | Calls an operation on a service with the given input parameters, without
any authentication data. This method is useful for "public" API operations.
@param operation [String] the name of the operation to call on the service.
@param params [map] a map of input options for the operation
@callback callback function(err, data)
If a callback is supplied, it is called when a response is returned
from the service.
@param err [Error] the error object returned from the request.
Set to `null` if the request is successful.
@param data [Object] the de-serialized data returned from
the request. Set to `null` if a request error occurs. | [
"Calls",
"an",
"operation",
"on",
"a",
"service",
"with",
"the",
"given",
"input",
"parameters",
"without",
"any",
"authentication",
"data",
".",
"This",
"method",
"is",
"useful",
"for",
"public",
"API",
"operations",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/service.js#L223-L231 |
3,367 | aws/aws-sdk-js | lib/service.js | waitFor | function waitFor(state, params, callback) {
var waiter = new AWS.ResourceWaiter(this, state);
return waiter.wait(params, callback);
} | javascript | function waitFor(state, params, callback) {
var waiter = new AWS.ResourceWaiter(this, state);
return waiter.wait(params, callback);
} | [
"function",
"waitFor",
"(",
"state",
",",
"params",
",",
"callback",
")",
"{",
"var",
"waiter",
"=",
"new",
"AWS",
".",
"ResourceWaiter",
"(",
"this",
",",
"state",
")",
";",
"return",
"waiter",
".",
"wait",
"(",
"params",
",",
"callback",
")",
";",
"}"
] | Waits for a given state
@param state [String] the state on the service to wait for
@param params [map] a map of parameters to pass with each request
@option params $waiter [map] a map of configuration options for the waiter
@option params $waiter.delay [Number] The number of seconds to wait between
requests
@option params $waiter.maxAttempts [Number] The maximum number of requests
to send while waiting
@callback callback function(err, data)
If a callback is supplied, it is called when a response is returned
from the service.
@param err [Error] the error object returned from the request.
Set to `null` if the request is successful.
@param data [Object] the de-serialized data returned from
the request. Set to `null` if a request error occurs. | [
"Waits",
"for",
"a",
"given",
"state"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/service.js#L251-L254 |
3,368 | aws/aws-sdk-js | lib/service.js | apiCallEvent | function apiCallEvent(request) {
var api = request.service.api.operations[request.operation];
var monitoringEvent = {
Type: 'ApiCall',
Api: api ? api.name : request.operation,
Version: 1,
Service: request.service.api.serviceId || request.service.api.endpointPrefix,
Region: request.httpRequest.region,
MaxRetriesExceeded: 0,
UserAgent: request.httpRequest.getUserAgent(),
};
var response = request.response;
if (response.httpResponse.statusCode) {
monitoringEvent.FinalHttpStatusCode = response.httpResponse.statusCode;
}
if (response.error) {
var error = response.error;
var statusCode = response.httpResponse.statusCode;
if (statusCode > 299) {
if (error.code) monitoringEvent.FinalAwsException = error.code;
if (error.message) monitoringEvent.FinalAwsExceptionMessage = error.message;
} else {
if (error.code || error.name) monitoringEvent.FinalSdkException = error.code || error.name;
if (error.message) monitoringEvent.FinalSdkExceptionMessage = error.message;
}
}
return monitoringEvent;
} | javascript | function apiCallEvent(request) {
var api = request.service.api.operations[request.operation];
var monitoringEvent = {
Type: 'ApiCall',
Api: api ? api.name : request.operation,
Version: 1,
Service: request.service.api.serviceId || request.service.api.endpointPrefix,
Region: request.httpRequest.region,
MaxRetriesExceeded: 0,
UserAgent: request.httpRequest.getUserAgent(),
};
var response = request.response;
if (response.httpResponse.statusCode) {
monitoringEvent.FinalHttpStatusCode = response.httpResponse.statusCode;
}
if (response.error) {
var error = response.error;
var statusCode = response.httpResponse.statusCode;
if (statusCode > 299) {
if (error.code) monitoringEvent.FinalAwsException = error.code;
if (error.message) monitoringEvent.FinalAwsExceptionMessage = error.message;
} else {
if (error.code || error.name) monitoringEvent.FinalSdkException = error.code || error.name;
if (error.message) monitoringEvent.FinalSdkExceptionMessage = error.message;
}
}
return monitoringEvent;
} | [
"function",
"apiCallEvent",
"(",
"request",
")",
"{",
"var",
"api",
"=",
"request",
".",
"service",
".",
"api",
".",
"operations",
"[",
"request",
".",
"operation",
"]",
";",
"var",
"monitoringEvent",
"=",
"{",
"Type",
":",
"'ApiCall'",
",",
"Api",
":",
"api",
"?",
"api",
".",
"name",
":",
"request",
".",
"operation",
",",
"Version",
":",
"1",
",",
"Service",
":",
"request",
".",
"service",
".",
"api",
".",
"serviceId",
"||",
"request",
".",
"service",
".",
"api",
".",
"endpointPrefix",
",",
"Region",
":",
"request",
".",
"httpRequest",
".",
"region",
",",
"MaxRetriesExceeded",
":",
"0",
",",
"UserAgent",
":",
"request",
".",
"httpRequest",
".",
"getUserAgent",
"(",
")",
",",
"}",
";",
"var",
"response",
"=",
"request",
".",
"response",
";",
"if",
"(",
"response",
".",
"httpResponse",
".",
"statusCode",
")",
"{",
"monitoringEvent",
".",
"FinalHttpStatusCode",
"=",
"response",
".",
"httpResponse",
".",
"statusCode",
";",
"}",
"if",
"(",
"response",
".",
"error",
")",
"{",
"var",
"error",
"=",
"response",
".",
"error",
";",
"var",
"statusCode",
"=",
"response",
".",
"httpResponse",
".",
"statusCode",
";",
"if",
"(",
"statusCode",
">",
"299",
")",
"{",
"if",
"(",
"error",
".",
"code",
")",
"monitoringEvent",
".",
"FinalAwsException",
"=",
"error",
".",
"code",
";",
"if",
"(",
"error",
".",
"message",
")",
"monitoringEvent",
".",
"FinalAwsExceptionMessage",
"=",
"error",
".",
"message",
";",
"}",
"else",
"{",
"if",
"(",
"error",
".",
"code",
"||",
"error",
".",
"name",
")",
"monitoringEvent",
".",
"FinalSdkException",
"=",
"error",
".",
"code",
"||",
"error",
".",
"name",
";",
"if",
"(",
"error",
".",
"message",
")",
"monitoringEvent",
".",
"FinalSdkExceptionMessage",
"=",
"error",
".",
"message",
";",
"}",
"}",
"return",
"monitoringEvent",
";",
"}"
] | Event recording metrics for a whole API call.
@returns {object} a subset of api call metrics
@api private | [
"Event",
"recording",
"metrics",
"for",
"a",
"whole",
"API",
"call",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/service.js#L292-L319 |
3,369 | aws/aws-sdk-js | lib/service.js | apiAttemptEvent | function apiAttemptEvent(request) {
var api = request.service.api.operations[request.operation];
var monitoringEvent = {
Type: 'ApiCallAttempt',
Api: api ? api.name : request.operation,
Version: 1,
Service: request.service.api.serviceId || request.service.api.endpointPrefix,
Fqdn: request.httpRequest.endpoint.hostname,
UserAgent: request.httpRequest.getUserAgent(),
};
var response = request.response;
if (response.httpResponse.statusCode) {
monitoringEvent.HttpStatusCode = response.httpResponse.statusCode;
}
if (
!request._unAuthenticated &&
request.service.config.credentials &&
request.service.config.credentials.accessKeyId
) {
monitoringEvent.AccessKey = request.service.config.credentials.accessKeyId;
}
if (!response.httpResponse.headers) return monitoringEvent;
if (request.httpRequest.headers['x-amz-security-token']) {
monitoringEvent.SessionToken = request.httpRequest.headers['x-amz-security-token'];
}
if (response.httpResponse.headers['x-amzn-requestid']) {
monitoringEvent.XAmznRequestId = response.httpResponse.headers['x-amzn-requestid'];
}
if (response.httpResponse.headers['x-amz-request-id']) {
monitoringEvent.XAmzRequestId = response.httpResponse.headers['x-amz-request-id'];
}
if (response.httpResponse.headers['x-amz-id-2']) {
monitoringEvent.XAmzId2 = response.httpResponse.headers['x-amz-id-2'];
}
return monitoringEvent;
} | javascript | function apiAttemptEvent(request) {
var api = request.service.api.operations[request.operation];
var monitoringEvent = {
Type: 'ApiCallAttempt',
Api: api ? api.name : request.operation,
Version: 1,
Service: request.service.api.serviceId || request.service.api.endpointPrefix,
Fqdn: request.httpRequest.endpoint.hostname,
UserAgent: request.httpRequest.getUserAgent(),
};
var response = request.response;
if (response.httpResponse.statusCode) {
monitoringEvent.HttpStatusCode = response.httpResponse.statusCode;
}
if (
!request._unAuthenticated &&
request.service.config.credentials &&
request.service.config.credentials.accessKeyId
) {
monitoringEvent.AccessKey = request.service.config.credentials.accessKeyId;
}
if (!response.httpResponse.headers) return monitoringEvent;
if (request.httpRequest.headers['x-amz-security-token']) {
monitoringEvent.SessionToken = request.httpRequest.headers['x-amz-security-token'];
}
if (response.httpResponse.headers['x-amzn-requestid']) {
monitoringEvent.XAmznRequestId = response.httpResponse.headers['x-amzn-requestid'];
}
if (response.httpResponse.headers['x-amz-request-id']) {
monitoringEvent.XAmzRequestId = response.httpResponse.headers['x-amz-request-id'];
}
if (response.httpResponse.headers['x-amz-id-2']) {
monitoringEvent.XAmzId2 = response.httpResponse.headers['x-amz-id-2'];
}
return monitoringEvent;
} | [
"function",
"apiAttemptEvent",
"(",
"request",
")",
"{",
"var",
"api",
"=",
"request",
".",
"service",
".",
"api",
".",
"operations",
"[",
"request",
".",
"operation",
"]",
";",
"var",
"monitoringEvent",
"=",
"{",
"Type",
":",
"'ApiCallAttempt'",
",",
"Api",
":",
"api",
"?",
"api",
".",
"name",
":",
"request",
".",
"operation",
",",
"Version",
":",
"1",
",",
"Service",
":",
"request",
".",
"service",
".",
"api",
".",
"serviceId",
"||",
"request",
".",
"service",
".",
"api",
".",
"endpointPrefix",
",",
"Fqdn",
":",
"request",
".",
"httpRequest",
".",
"endpoint",
".",
"hostname",
",",
"UserAgent",
":",
"request",
".",
"httpRequest",
".",
"getUserAgent",
"(",
")",
",",
"}",
";",
"var",
"response",
"=",
"request",
".",
"response",
";",
"if",
"(",
"response",
".",
"httpResponse",
".",
"statusCode",
")",
"{",
"monitoringEvent",
".",
"HttpStatusCode",
"=",
"response",
".",
"httpResponse",
".",
"statusCode",
";",
"}",
"if",
"(",
"!",
"request",
".",
"_unAuthenticated",
"&&",
"request",
".",
"service",
".",
"config",
".",
"credentials",
"&&",
"request",
".",
"service",
".",
"config",
".",
"credentials",
".",
"accessKeyId",
")",
"{",
"monitoringEvent",
".",
"AccessKey",
"=",
"request",
".",
"service",
".",
"config",
".",
"credentials",
".",
"accessKeyId",
";",
"}",
"if",
"(",
"!",
"response",
".",
"httpResponse",
".",
"headers",
")",
"return",
"monitoringEvent",
";",
"if",
"(",
"request",
".",
"httpRequest",
".",
"headers",
"[",
"'x-amz-security-token'",
"]",
")",
"{",
"monitoringEvent",
".",
"SessionToken",
"=",
"request",
".",
"httpRequest",
".",
"headers",
"[",
"'x-amz-security-token'",
"]",
";",
"}",
"if",
"(",
"response",
".",
"httpResponse",
".",
"headers",
"[",
"'x-amzn-requestid'",
"]",
")",
"{",
"monitoringEvent",
".",
"XAmznRequestId",
"=",
"response",
".",
"httpResponse",
".",
"headers",
"[",
"'x-amzn-requestid'",
"]",
";",
"}",
"if",
"(",
"response",
".",
"httpResponse",
".",
"headers",
"[",
"'x-amz-request-id'",
"]",
")",
"{",
"monitoringEvent",
".",
"XAmzRequestId",
"=",
"response",
".",
"httpResponse",
".",
"headers",
"[",
"'x-amz-request-id'",
"]",
";",
"}",
"if",
"(",
"response",
".",
"httpResponse",
".",
"headers",
"[",
"'x-amz-id-2'",
"]",
")",
"{",
"monitoringEvent",
".",
"XAmzId2",
"=",
"response",
".",
"httpResponse",
".",
"headers",
"[",
"'x-amz-id-2'",
"]",
";",
"}",
"return",
"monitoringEvent",
";",
"}"
] | Event recording metrics for an API call attempt.
@returns {object} a subset of api call attempt metrics
@api private | [
"Event",
"recording",
"metrics",
"for",
"an",
"API",
"call",
"attempt",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/service.js#L326-L361 |
3,370 | aws/aws-sdk-js | lib/service.js | attemptFailEvent | function attemptFailEvent(request) {
var monitoringEvent = this.apiAttemptEvent(request);
var response = request.response;
var error = response.error;
if (response.httpResponse.statusCode > 299 ) {
if (error.code) monitoringEvent.AwsException = error.code;
if (error.message) monitoringEvent.AwsExceptionMessage = error.message;
} else {
if (error.code || error.name) monitoringEvent.SdkException = error.code || error.name;
if (error.message) monitoringEvent.SdkExceptionMessage = error.message;
}
return monitoringEvent;
} | javascript | function attemptFailEvent(request) {
var monitoringEvent = this.apiAttemptEvent(request);
var response = request.response;
var error = response.error;
if (response.httpResponse.statusCode > 299 ) {
if (error.code) monitoringEvent.AwsException = error.code;
if (error.message) monitoringEvent.AwsExceptionMessage = error.message;
} else {
if (error.code || error.name) monitoringEvent.SdkException = error.code || error.name;
if (error.message) monitoringEvent.SdkExceptionMessage = error.message;
}
return monitoringEvent;
} | [
"function",
"attemptFailEvent",
"(",
"request",
")",
"{",
"var",
"monitoringEvent",
"=",
"this",
".",
"apiAttemptEvent",
"(",
"request",
")",
";",
"var",
"response",
"=",
"request",
".",
"response",
";",
"var",
"error",
"=",
"response",
".",
"error",
";",
"if",
"(",
"response",
".",
"httpResponse",
".",
"statusCode",
">",
"299",
")",
"{",
"if",
"(",
"error",
".",
"code",
")",
"monitoringEvent",
".",
"AwsException",
"=",
"error",
".",
"code",
";",
"if",
"(",
"error",
".",
"message",
")",
"monitoringEvent",
".",
"AwsExceptionMessage",
"=",
"error",
".",
"message",
";",
"}",
"else",
"{",
"if",
"(",
"error",
".",
"code",
"||",
"error",
".",
"name",
")",
"monitoringEvent",
".",
"SdkException",
"=",
"error",
".",
"code",
"||",
"error",
".",
"name",
";",
"if",
"(",
"error",
".",
"message",
")",
"monitoringEvent",
".",
"SdkExceptionMessage",
"=",
"error",
".",
"message",
";",
"}",
"return",
"monitoringEvent",
";",
"}"
] | Add metrics of failed request.
@api private | [
"Add",
"metrics",
"of",
"failed",
"request",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/service.js#L367-L379 |
3,371 | aws/aws-sdk-js | lib/service.js | attachMonitoringEmitter | function attachMonitoringEmitter(request) {
var attemptTimestamp; //timestamp marking the beginning of a request attempt
var attemptStartRealTime; //Start time of request attempt. Used to calculating attemptLatency
var attemptLatency; //latency from request sent out to http response reaching SDK
var callStartRealTime; //Start time of API call. Used to calculating API call latency
var attemptCount = 0; //request.retryCount is not reliable here
var region; //region cache region for each attempt since it can be updated in plase (e.g. s3)
var callTimestamp; //timestamp when the request is created
var self = this;
var addToHead = true;
request.on('validate', function () {
callStartRealTime = AWS.util.realClock.now();
callTimestamp = Date.now();
}, addToHead);
request.on('sign', function () {
attemptStartRealTime = AWS.util.realClock.now();
attemptTimestamp = Date.now();
region = request.httpRequest.region;
attemptCount++;
}, addToHead);
request.on('validateResponse', function() {
attemptLatency = Math.round(AWS.util.realClock.now() - attemptStartRealTime);
});
request.addNamedListener('API_CALL_ATTEMPT', 'success', function API_CALL_ATTEMPT() {
var apiAttemptEvent = self.apiAttemptEvent(request);
apiAttemptEvent.Timestamp = attemptTimestamp;
apiAttemptEvent.AttemptLatency = attemptLatency >= 0 ? attemptLatency : 0;
apiAttemptEvent.Region = region;
self.emit('apiCallAttempt', [apiAttemptEvent]);
});
request.addNamedListener('API_CALL_ATTEMPT_RETRY', 'retry', function API_CALL_ATTEMPT_RETRY() {
var apiAttemptEvent = self.attemptFailEvent(request);
apiAttemptEvent.Timestamp = attemptTimestamp;
//attemptLatency may not be available if fail before response
attemptLatency = attemptLatency ||
Math.round(AWS.util.realClock.now() - attemptStartRealTime);
apiAttemptEvent.AttemptLatency = attemptLatency >= 0 ? attemptLatency : 0;
apiAttemptEvent.Region = region;
self.emit('apiCallAttempt', [apiAttemptEvent]);
});
request.addNamedListener('API_CALL', 'complete', function API_CALL() {
var apiCallEvent = self.apiCallEvent(request);
apiCallEvent.AttemptCount = attemptCount;
if (apiCallEvent.AttemptCount <= 0) return;
apiCallEvent.Timestamp = callTimestamp;
var latency = Math.round(AWS.util.realClock.now() - callStartRealTime);
apiCallEvent.Latency = latency >= 0 ? latency : 0;
var response = request.response;
if (
typeof response.retryCount === 'number' &&
typeof response.maxRetries === 'number' &&
(response.retryCount >= response.maxRetries)
) {
apiCallEvent.MaxRetriesExceeded = 1;
}
self.emit('apiCall', [apiCallEvent]);
});
} | javascript | function attachMonitoringEmitter(request) {
var attemptTimestamp; //timestamp marking the beginning of a request attempt
var attemptStartRealTime; //Start time of request attempt. Used to calculating attemptLatency
var attemptLatency; //latency from request sent out to http response reaching SDK
var callStartRealTime; //Start time of API call. Used to calculating API call latency
var attemptCount = 0; //request.retryCount is not reliable here
var region; //region cache region for each attempt since it can be updated in plase (e.g. s3)
var callTimestamp; //timestamp when the request is created
var self = this;
var addToHead = true;
request.on('validate', function () {
callStartRealTime = AWS.util.realClock.now();
callTimestamp = Date.now();
}, addToHead);
request.on('sign', function () {
attemptStartRealTime = AWS.util.realClock.now();
attemptTimestamp = Date.now();
region = request.httpRequest.region;
attemptCount++;
}, addToHead);
request.on('validateResponse', function() {
attemptLatency = Math.round(AWS.util.realClock.now() - attemptStartRealTime);
});
request.addNamedListener('API_CALL_ATTEMPT', 'success', function API_CALL_ATTEMPT() {
var apiAttemptEvent = self.apiAttemptEvent(request);
apiAttemptEvent.Timestamp = attemptTimestamp;
apiAttemptEvent.AttemptLatency = attemptLatency >= 0 ? attemptLatency : 0;
apiAttemptEvent.Region = region;
self.emit('apiCallAttempt', [apiAttemptEvent]);
});
request.addNamedListener('API_CALL_ATTEMPT_RETRY', 'retry', function API_CALL_ATTEMPT_RETRY() {
var apiAttemptEvent = self.attemptFailEvent(request);
apiAttemptEvent.Timestamp = attemptTimestamp;
//attemptLatency may not be available if fail before response
attemptLatency = attemptLatency ||
Math.round(AWS.util.realClock.now() - attemptStartRealTime);
apiAttemptEvent.AttemptLatency = attemptLatency >= 0 ? attemptLatency : 0;
apiAttemptEvent.Region = region;
self.emit('apiCallAttempt', [apiAttemptEvent]);
});
request.addNamedListener('API_CALL', 'complete', function API_CALL() {
var apiCallEvent = self.apiCallEvent(request);
apiCallEvent.AttemptCount = attemptCount;
if (apiCallEvent.AttemptCount <= 0) return;
apiCallEvent.Timestamp = callTimestamp;
var latency = Math.round(AWS.util.realClock.now() - callStartRealTime);
apiCallEvent.Latency = latency >= 0 ? latency : 0;
var response = request.response;
if (
typeof response.retryCount === 'number' &&
typeof response.maxRetries === 'number' &&
(response.retryCount >= response.maxRetries)
) {
apiCallEvent.MaxRetriesExceeded = 1;
}
self.emit('apiCall', [apiCallEvent]);
});
} | [
"function",
"attachMonitoringEmitter",
"(",
"request",
")",
"{",
"var",
"attemptTimestamp",
";",
"//timestamp marking the beginning of a request attempt",
"var",
"attemptStartRealTime",
";",
"//Start time of request attempt. Used to calculating attemptLatency",
"var",
"attemptLatency",
";",
"//latency from request sent out to http response reaching SDK",
"var",
"callStartRealTime",
";",
"//Start time of API call. Used to calculating API call latency",
"var",
"attemptCount",
"=",
"0",
";",
"//request.retryCount is not reliable here",
"var",
"region",
";",
"//region cache region for each attempt since it can be updated in plase (e.g. s3)",
"var",
"callTimestamp",
";",
"//timestamp when the request is created",
"var",
"self",
"=",
"this",
";",
"var",
"addToHead",
"=",
"true",
";",
"request",
".",
"on",
"(",
"'validate'",
",",
"function",
"(",
")",
"{",
"callStartRealTime",
"=",
"AWS",
".",
"util",
".",
"realClock",
".",
"now",
"(",
")",
";",
"callTimestamp",
"=",
"Date",
".",
"now",
"(",
")",
";",
"}",
",",
"addToHead",
")",
";",
"request",
".",
"on",
"(",
"'sign'",
",",
"function",
"(",
")",
"{",
"attemptStartRealTime",
"=",
"AWS",
".",
"util",
".",
"realClock",
".",
"now",
"(",
")",
";",
"attemptTimestamp",
"=",
"Date",
".",
"now",
"(",
")",
";",
"region",
"=",
"request",
".",
"httpRequest",
".",
"region",
";",
"attemptCount",
"++",
";",
"}",
",",
"addToHead",
")",
";",
"request",
".",
"on",
"(",
"'validateResponse'",
",",
"function",
"(",
")",
"{",
"attemptLatency",
"=",
"Math",
".",
"round",
"(",
"AWS",
".",
"util",
".",
"realClock",
".",
"now",
"(",
")",
"-",
"attemptStartRealTime",
")",
";",
"}",
")",
";",
"request",
".",
"addNamedListener",
"(",
"'API_CALL_ATTEMPT'",
",",
"'success'",
",",
"function",
"API_CALL_ATTEMPT",
"(",
")",
"{",
"var",
"apiAttemptEvent",
"=",
"self",
".",
"apiAttemptEvent",
"(",
"request",
")",
";",
"apiAttemptEvent",
".",
"Timestamp",
"=",
"attemptTimestamp",
";",
"apiAttemptEvent",
".",
"AttemptLatency",
"=",
"attemptLatency",
">=",
"0",
"?",
"attemptLatency",
":",
"0",
";",
"apiAttemptEvent",
".",
"Region",
"=",
"region",
";",
"self",
".",
"emit",
"(",
"'apiCallAttempt'",
",",
"[",
"apiAttemptEvent",
"]",
")",
";",
"}",
")",
";",
"request",
".",
"addNamedListener",
"(",
"'API_CALL_ATTEMPT_RETRY'",
",",
"'retry'",
",",
"function",
"API_CALL_ATTEMPT_RETRY",
"(",
")",
"{",
"var",
"apiAttemptEvent",
"=",
"self",
".",
"attemptFailEvent",
"(",
"request",
")",
";",
"apiAttemptEvent",
".",
"Timestamp",
"=",
"attemptTimestamp",
";",
"//attemptLatency may not be available if fail before response",
"attemptLatency",
"=",
"attemptLatency",
"||",
"Math",
".",
"round",
"(",
"AWS",
".",
"util",
".",
"realClock",
".",
"now",
"(",
")",
"-",
"attemptStartRealTime",
")",
";",
"apiAttemptEvent",
".",
"AttemptLatency",
"=",
"attemptLatency",
">=",
"0",
"?",
"attemptLatency",
":",
"0",
";",
"apiAttemptEvent",
".",
"Region",
"=",
"region",
";",
"self",
".",
"emit",
"(",
"'apiCallAttempt'",
",",
"[",
"apiAttemptEvent",
"]",
")",
";",
"}",
")",
";",
"request",
".",
"addNamedListener",
"(",
"'API_CALL'",
",",
"'complete'",
",",
"function",
"API_CALL",
"(",
")",
"{",
"var",
"apiCallEvent",
"=",
"self",
".",
"apiCallEvent",
"(",
"request",
")",
";",
"apiCallEvent",
".",
"AttemptCount",
"=",
"attemptCount",
";",
"if",
"(",
"apiCallEvent",
".",
"AttemptCount",
"<=",
"0",
")",
"return",
";",
"apiCallEvent",
".",
"Timestamp",
"=",
"callTimestamp",
";",
"var",
"latency",
"=",
"Math",
".",
"round",
"(",
"AWS",
".",
"util",
".",
"realClock",
".",
"now",
"(",
")",
"-",
"callStartRealTime",
")",
";",
"apiCallEvent",
".",
"Latency",
"=",
"latency",
">=",
"0",
"?",
"latency",
":",
"0",
";",
"var",
"response",
"=",
"request",
".",
"response",
";",
"if",
"(",
"typeof",
"response",
".",
"retryCount",
"===",
"'number'",
"&&",
"typeof",
"response",
".",
"maxRetries",
"===",
"'number'",
"&&",
"(",
"response",
".",
"retryCount",
">=",
"response",
".",
"maxRetries",
")",
")",
"{",
"apiCallEvent",
".",
"MaxRetriesExceeded",
"=",
"1",
";",
"}",
"self",
".",
"emit",
"(",
"'apiCall'",
",",
"[",
"apiCallEvent",
"]",
")",
";",
"}",
")",
";",
"}"
] | Attach listeners to request object to fetch metrics of each request
and emit data object through \'ApiCall\' and \'ApiCallAttempt\' events.
@api private | [
"Attach",
"listeners",
"to",
"request",
"object",
"to",
"fetch",
"metrics",
"of",
"each",
"request",
"and",
"emit",
"data",
"object",
"through",
"\\",
"ApiCall",
"\\",
"and",
"\\",
"ApiCallAttempt",
"\\",
"events",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/service.js#L386-L444 |
3,372 | aws/aws-sdk-js | lib/service.js | getSignerClass | function getSignerClass(request) {
var version;
// get operation authtype if present
var operation = null;
var authtype = '';
if (request) {
var operations = request.service.api.operations || {};
operation = operations[request.operation] || null;
authtype = operation ? operation.authtype : '';
}
if (this.config.signatureVersion) {
version = this.config.signatureVersion;
} else if (authtype === 'v4' || authtype === 'v4-unsigned-body') {
version = 'v4';
} else {
version = this.api.signatureVersion;
}
return AWS.Signers.RequestSigner.getVersion(version);
} | javascript | function getSignerClass(request) {
var version;
// get operation authtype if present
var operation = null;
var authtype = '';
if (request) {
var operations = request.service.api.operations || {};
operation = operations[request.operation] || null;
authtype = operation ? operation.authtype : '';
}
if (this.config.signatureVersion) {
version = this.config.signatureVersion;
} else if (authtype === 'v4' || authtype === 'v4-unsigned-body') {
version = 'v4';
} else {
version = this.api.signatureVersion;
}
return AWS.Signers.RequestSigner.getVersion(version);
} | [
"function",
"getSignerClass",
"(",
"request",
")",
"{",
"var",
"version",
";",
"// get operation authtype if present",
"var",
"operation",
"=",
"null",
";",
"var",
"authtype",
"=",
"''",
";",
"if",
"(",
"request",
")",
"{",
"var",
"operations",
"=",
"request",
".",
"service",
".",
"api",
".",
"operations",
"||",
"{",
"}",
";",
"operation",
"=",
"operations",
"[",
"request",
".",
"operation",
"]",
"||",
"null",
";",
"authtype",
"=",
"operation",
"?",
"operation",
".",
"authtype",
":",
"''",
";",
"}",
"if",
"(",
"this",
".",
"config",
".",
"signatureVersion",
")",
"{",
"version",
"=",
"this",
".",
"config",
".",
"signatureVersion",
";",
"}",
"else",
"if",
"(",
"authtype",
"===",
"'v4'",
"||",
"authtype",
"===",
"'v4-unsigned-body'",
")",
"{",
"version",
"=",
"'v4'",
";",
"}",
"else",
"{",
"version",
"=",
"this",
".",
"api",
".",
"signatureVersion",
";",
"}",
"return",
"AWS",
".",
"Signers",
".",
"RequestSigner",
".",
"getVersion",
"(",
"version",
")",
";",
"}"
] | Gets the signer class for a given request
@api private | [
"Gets",
"the",
"signer",
"class",
"for",
"a",
"given",
"request"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/service.js#L459-L477 |
3,373 | aws/aws-sdk-js | lib/service.js | defineMethods | function defineMethods(svc) {
AWS.util.each(svc.prototype.api.operations, function iterator(method) {
if (svc.prototype[method]) return;
var operation = svc.prototype.api.operations[method];
if (operation.authtype === 'none') {
svc.prototype[method] = function (params, callback) {
return this.makeUnauthenticatedRequest(method, params, callback);
};
} else {
svc.prototype[method] = function (params, callback) {
return this.makeRequest(method, params, callback);
};
}
});
} | javascript | function defineMethods(svc) {
AWS.util.each(svc.prototype.api.operations, function iterator(method) {
if (svc.prototype[method]) return;
var operation = svc.prototype.api.operations[method];
if (operation.authtype === 'none') {
svc.prototype[method] = function (params, callback) {
return this.makeUnauthenticatedRequest(method, params, callback);
};
} else {
svc.prototype[method] = function (params, callback) {
return this.makeRequest(method, params, callback);
};
}
});
} | [
"function",
"defineMethods",
"(",
"svc",
")",
"{",
"AWS",
".",
"util",
".",
"each",
"(",
"svc",
".",
"prototype",
".",
"api",
".",
"operations",
",",
"function",
"iterator",
"(",
"method",
")",
"{",
"if",
"(",
"svc",
".",
"prototype",
"[",
"method",
"]",
")",
"return",
";",
"var",
"operation",
"=",
"svc",
".",
"prototype",
".",
"api",
".",
"operations",
"[",
"method",
"]",
";",
"if",
"(",
"operation",
".",
"authtype",
"===",
"'none'",
")",
"{",
"svc",
".",
"prototype",
"[",
"method",
"]",
"=",
"function",
"(",
"params",
",",
"callback",
")",
"{",
"return",
"this",
".",
"makeUnauthenticatedRequest",
"(",
"method",
",",
"params",
",",
"callback",
")",
";",
"}",
";",
"}",
"else",
"{",
"svc",
".",
"prototype",
"[",
"method",
"]",
"=",
"function",
"(",
"params",
",",
"callback",
")",
"{",
"return",
"this",
".",
"makeRequest",
"(",
"method",
",",
"params",
",",
"callback",
")",
";",
"}",
";",
"}",
"}",
")",
";",
"}"
] | Adds one method for each operation described in the api configuration
@api private | [
"Adds",
"one",
"method",
"for",
"each",
"operation",
"described",
"in",
"the",
"api",
"configuration"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/service.js#L663-L677 |
3,374 | aws/aws-sdk-js | lib/response.js | nextPage | function nextPage(callback) {
var config;
var service = this.request.service;
var operation = this.request.operation;
try {
config = service.paginationConfig(operation, true);
} catch (e) { this.error = e; }
if (!this.hasNextPage()) {
if (callback) callback(this.error, null);
else if (this.error) throw this.error;
return null;
}
var params = AWS.util.copy(this.request.params);
if (!this.nextPageTokens) {
return callback ? callback(null, null) : null;
} else {
var inputTokens = config.inputToken;
if (typeof inputTokens === 'string') inputTokens = [inputTokens];
for (var i = 0; i < inputTokens.length; i++) {
params[inputTokens[i]] = this.nextPageTokens[i];
}
return service.makeRequest(this.request.operation, params, callback);
}
} | javascript | function nextPage(callback) {
var config;
var service = this.request.service;
var operation = this.request.operation;
try {
config = service.paginationConfig(operation, true);
} catch (e) { this.error = e; }
if (!this.hasNextPage()) {
if (callback) callback(this.error, null);
else if (this.error) throw this.error;
return null;
}
var params = AWS.util.copy(this.request.params);
if (!this.nextPageTokens) {
return callback ? callback(null, null) : null;
} else {
var inputTokens = config.inputToken;
if (typeof inputTokens === 'string') inputTokens = [inputTokens];
for (var i = 0; i < inputTokens.length; i++) {
params[inputTokens[i]] = this.nextPageTokens[i];
}
return service.makeRequest(this.request.operation, params, callback);
}
} | [
"function",
"nextPage",
"(",
"callback",
")",
"{",
"var",
"config",
";",
"var",
"service",
"=",
"this",
".",
"request",
".",
"service",
";",
"var",
"operation",
"=",
"this",
".",
"request",
".",
"operation",
";",
"try",
"{",
"config",
"=",
"service",
".",
"paginationConfig",
"(",
"operation",
",",
"true",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"this",
".",
"error",
"=",
"e",
";",
"}",
"if",
"(",
"!",
"this",
".",
"hasNextPage",
"(",
")",
")",
"{",
"if",
"(",
"callback",
")",
"callback",
"(",
"this",
".",
"error",
",",
"null",
")",
";",
"else",
"if",
"(",
"this",
".",
"error",
")",
"throw",
"this",
".",
"error",
";",
"return",
"null",
";",
"}",
"var",
"params",
"=",
"AWS",
".",
"util",
".",
"copy",
"(",
"this",
".",
"request",
".",
"params",
")",
";",
"if",
"(",
"!",
"this",
".",
"nextPageTokens",
")",
"{",
"return",
"callback",
"?",
"callback",
"(",
"null",
",",
"null",
")",
":",
"null",
";",
"}",
"else",
"{",
"var",
"inputTokens",
"=",
"config",
".",
"inputToken",
";",
"if",
"(",
"typeof",
"inputTokens",
"===",
"'string'",
")",
"inputTokens",
"=",
"[",
"inputTokens",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"inputTokens",
".",
"length",
";",
"i",
"++",
")",
"{",
"params",
"[",
"inputTokens",
"[",
"i",
"]",
"]",
"=",
"this",
".",
"nextPageTokens",
"[",
"i",
"]",
";",
"}",
"return",
"service",
".",
"makeRequest",
"(",
"this",
".",
"request",
".",
"operation",
",",
"params",
",",
"callback",
")",
";",
"}",
"}"
] | Creates a new request for the next page of response data, calling the
callback with the page data if a callback is provided.
@callback callback function(err, data)
Called when a page of data is returned from the next request.
@param err [Error] an error object, if an error occurred in the request
@param data [Object] the next page of data, or null, if there are no
more pages left.
@return [AWS.Request] the request object for the next page of data
@return [null] if no callback is provided and there are no pages left
to retrieve.
@since v1.4.0 | [
"Creates",
"a",
"new",
"request",
"for",
"the",
"next",
"page",
"of",
"response",
"data",
"calling",
"the",
"callback",
"with",
"the",
"page",
"data",
"if",
"a",
"callback",
"is",
"provided",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/response.js#L132-L157 |
3,375 | aws/aws-sdk-js | lib/event-stream/to-buffer.js | toBuffer | function toBuffer(data, encoding) {
return (typeof Buffer.from === 'function' && Buffer.from !== Uint8Array.from) ?
Buffer.from(data, encoding) : new Buffer(data, encoding);
} | javascript | function toBuffer(data, encoding) {
return (typeof Buffer.from === 'function' && Buffer.from !== Uint8Array.from) ?
Buffer.from(data, encoding) : new Buffer(data, encoding);
} | [
"function",
"toBuffer",
"(",
"data",
",",
"encoding",
")",
"{",
"return",
"(",
"typeof",
"Buffer",
".",
"from",
"===",
"'function'",
"&&",
"Buffer",
".",
"from",
"!==",
"Uint8Array",
".",
"from",
")",
"?",
"Buffer",
".",
"from",
"(",
"data",
",",
"encoding",
")",
":",
"new",
"Buffer",
"(",
"data",
",",
"encoding",
")",
";",
"}"
] | Converts data into Buffer.
@param {ArrayBuffer|string|number[]|Buffer} data Data to convert to a Buffer
@param {string} [encoding] String encoding
@returns {Buffer} | [
"Converts",
"data",
"into",
"Buffer",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/event-stream/to-buffer.js#L8-L11 |
3,376 | aws/aws-sdk-js | doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/searchtools.js | function(query) {
// create the required interface elements
this.out = $('#search-results');
this.title = $('<h2>' + _('Searching') + '</h2>').appendTo(this.out);
this.dots = $('<span></span>').appendTo(this.title);
this.status = $('<p style="display: none"></p>').appendTo(this.out);
this.output = $('<ul class="search"/>').appendTo(this.out);
$('#search-progress').text(_('Preparing search...'));
this.startPulse();
// index already loaded, the browser was quick!
if (this.hasIndex())
this.query(query);
else
this.deferQuery(query);
} | javascript | function(query) {
// create the required interface elements
this.out = $('#search-results');
this.title = $('<h2>' + _('Searching') + '</h2>').appendTo(this.out);
this.dots = $('<span></span>').appendTo(this.title);
this.status = $('<p style="display: none"></p>').appendTo(this.out);
this.output = $('<ul class="search"/>').appendTo(this.out);
$('#search-progress').text(_('Preparing search...'));
this.startPulse();
// index already loaded, the browser was quick!
if (this.hasIndex())
this.query(query);
else
this.deferQuery(query);
} | [
"function",
"(",
"query",
")",
"{",
"// create the required interface elements",
"this",
".",
"out",
"=",
"$",
"(",
"'#search-results'",
")",
";",
"this",
".",
"title",
"=",
"$",
"(",
"'<h2>'",
"+",
"_",
"(",
"'Searching'",
")",
"+",
"'</h2>'",
")",
".",
"appendTo",
"(",
"this",
".",
"out",
")",
";",
"this",
".",
"dots",
"=",
"$",
"(",
"'<span></span>'",
")",
".",
"appendTo",
"(",
"this",
".",
"title",
")",
";",
"this",
".",
"status",
"=",
"$",
"(",
"'<p style=\"display: none\"></p>'",
")",
".",
"appendTo",
"(",
"this",
".",
"out",
")",
";",
"this",
".",
"output",
"=",
"$",
"(",
"'<ul class=\"search\"/>'",
")",
".",
"appendTo",
"(",
"this",
".",
"out",
")",
";",
"$",
"(",
"'#search-progress'",
")",
".",
"text",
"(",
"_",
"(",
"'Preparing search...'",
")",
")",
";",
"this",
".",
"startPulse",
"(",
")",
";",
"// index already loaded, the browser was quick!",
"if",
"(",
"this",
".",
"hasIndex",
"(",
")",
")",
"this",
".",
"query",
"(",
"query",
")",
";",
"else",
"this",
".",
"deferQuery",
"(",
"query",
")",
";",
"}"
] | perform a search for something | [
"perform",
"a",
"search",
"for",
"something"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/searchtools.js#L292-L308 |
|
3,377 | aws/aws-sdk-js | lib/publisher/configuration.js | resolveMonitoringConfig | function resolveMonitoringConfig() {
var config = {
port: undefined,
clientId: undefined,
enabled: undefined,
};
if (fromEnvironment(config) || fromConfigFile(config)) return toJSType(config);
return toJSType(config);
} | javascript | function resolveMonitoringConfig() {
var config = {
port: undefined,
clientId: undefined,
enabled: undefined,
};
if (fromEnvironment(config) || fromConfigFile(config)) return toJSType(config);
return toJSType(config);
} | [
"function",
"resolveMonitoringConfig",
"(",
")",
"{",
"var",
"config",
"=",
"{",
"port",
":",
"undefined",
",",
"clientId",
":",
"undefined",
",",
"enabled",
":",
"undefined",
",",
"}",
";",
"if",
"(",
"fromEnvironment",
"(",
"config",
")",
"||",
"fromConfigFile",
"(",
"config",
")",
")",
"return",
"toJSType",
"(",
"config",
")",
";",
"return",
"toJSType",
"(",
"config",
")",
";",
"}"
] | Resolve client-side monitoring configuration from either environmental variables
or shared config file. Configurations from environmental variables have higher priority
than those from shared config file. The resolver will try to read the shared config file
no matter whether the AWS_SDK_LOAD_CONFIG variable is set.
@api private | [
"Resolve",
"client",
"-",
"side",
"monitoring",
"configuration",
"from",
"either",
"environmental",
"variables",
"or",
"shared",
"config",
"file",
".",
"Configurations",
"from",
"environmental",
"variables",
"have",
"higher",
"priority",
"than",
"those",
"from",
"shared",
"config",
"file",
".",
"The",
"resolver",
"will",
"try",
"to",
"read",
"the",
"shared",
"config",
"file",
"no",
"matter",
"whether",
"the",
"AWS_SDK_LOAD_CONFIG",
"variable",
"is",
"set",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/publisher/configuration.js#L10-L18 |
3,378 | aws/aws-sdk-js | lib/publisher/configuration.js | fromEnvironment | function fromEnvironment(config) {
config.port = config.port || process.env.AWS_CSM_PORT;
config.enabled = config.enabled || process.env.AWS_CSM_ENABLED;
config.clientId = config.clientId || process.env.AWS_CSM_CLIENT_ID;
return config.port && config.enabled && config.clientId ||
['false', '0'].indexOf(config.enabled) >= 0; //no need to read shared config file if explicitely disabled
} | javascript | function fromEnvironment(config) {
config.port = config.port || process.env.AWS_CSM_PORT;
config.enabled = config.enabled || process.env.AWS_CSM_ENABLED;
config.clientId = config.clientId || process.env.AWS_CSM_CLIENT_ID;
return config.port && config.enabled && config.clientId ||
['false', '0'].indexOf(config.enabled) >= 0; //no need to read shared config file if explicitely disabled
} | [
"function",
"fromEnvironment",
"(",
"config",
")",
"{",
"config",
".",
"port",
"=",
"config",
".",
"port",
"||",
"process",
".",
"env",
".",
"AWS_CSM_PORT",
";",
"config",
".",
"enabled",
"=",
"config",
".",
"enabled",
"||",
"process",
".",
"env",
".",
"AWS_CSM_ENABLED",
";",
"config",
".",
"clientId",
"=",
"config",
".",
"clientId",
"||",
"process",
".",
"env",
".",
"AWS_CSM_CLIENT_ID",
";",
"return",
"config",
".",
"port",
"&&",
"config",
".",
"enabled",
"&&",
"config",
".",
"clientId",
"||",
"[",
"'false'",
",",
"'0'",
"]",
".",
"indexOf",
"(",
"config",
".",
"enabled",
")",
">=",
"0",
";",
"//no need to read shared config file if explicitely disabled",
"}"
] | Resolve configurations from environmental variables.
@param {object} client side monitoring config object needs to be resolved
@returns {boolean} whether resolving configurations is done
@api private | [
"Resolve",
"configurations",
"from",
"environmental",
"variables",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/publisher/configuration.js#L26-L32 |
3,379 | aws/aws-sdk-js | lib/publisher/configuration.js | fromConfigFile | function fromConfigFile(config) {
var sharedFileConfig;
try {
var configFile = AWS.util.iniLoader.loadFrom({
isConfig: true,
filename: process.env[AWS.util.sharedConfigFileEnv]
});
var sharedFileConfig = configFile[
process.env.AWS_PROFILE || AWS.util.defaultProfile
];
} catch (err) {
return false;
}
if (!sharedFileConfig) return config;
config.port = config.port || sharedFileConfig.csm_port;
config.enabled = config.enabled || sharedFileConfig.csm_enabled;
config.clientId = config.clientId || sharedFileConfig.csm_client_id;
return config.port && config.enabled && config.clientId;
} | javascript | function fromConfigFile(config) {
var sharedFileConfig;
try {
var configFile = AWS.util.iniLoader.loadFrom({
isConfig: true,
filename: process.env[AWS.util.sharedConfigFileEnv]
});
var sharedFileConfig = configFile[
process.env.AWS_PROFILE || AWS.util.defaultProfile
];
} catch (err) {
return false;
}
if (!sharedFileConfig) return config;
config.port = config.port || sharedFileConfig.csm_port;
config.enabled = config.enabled || sharedFileConfig.csm_enabled;
config.clientId = config.clientId || sharedFileConfig.csm_client_id;
return config.port && config.enabled && config.clientId;
} | [
"function",
"fromConfigFile",
"(",
"config",
")",
"{",
"var",
"sharedFileConfig",
";",
"try",
"{",
"var",
"configFile",
"=",
"AWS",
".",
"util",
".",
"iniLoader",
".",
"loadFrom",
"(",
"{",
"isConfig",
":",
"true",
",",
"filename",
":",
"process",
".",
"env",
"[",
"AWS",
".",
"util",
".",
"sharedConfigFileEnv",
"]",
"}",
")",
";",
"var",
"sharedFileConfig",
"=",
"configFile",
"[",
"process",
".",
"env",
".",
"AWS_PROFILE",
"||",
"AWS",
".",
"util",
".",
"defaultProfile",
"]",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"sharedFileConfig",
")",
"return",
"config",
";",
"config",
".",
"port",
"=",
"config",
".",
"port",
"||",
"sharedFileConfig",
".",
"csm_port",
";",
"config",
".",
"enabled",
"=",
"config",
".",
"enabled",
"||",
"sharedFileConfig",
".",
"csm_enabled",
";",
"config",
".",
"clientId",
"=",
"config",
".",
"clientId",
"||",
"sharedFileConfig",
".",
"csm_client_id",
";",
"return",
"config",
".",
"port",
"&&",
"config",
".",
"enabled",
"&&",
"config",
".",
"clientId",
";",
"}"
] | Resolve cofigurations from shared config file with specified role name
@param {object} client side monitoring config object needs to be resolved
@returns {boolean} whether resolving configurations is done
@api private | [
"Resolve",
"cofigurations",
"from",
"shared",
"config",
"file",
"with",
"specified",
"role",
"name"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/publisher/configuration.js#L40-L58 |
3,380 | aws/aws-sdk-js | lib/cloudfront/signer.js | Signer | function Signer(keyPairId, privateKey) {
if (keyPairId === void 0 || privateKey === void 0) {
throw new Error('A key pair ID and private key are required');
}
this.keyPairId = keyPairId;
this.privateKey = privateKey;
} | javascript | function Signer(keyPairId, privateKey) {
if (keyPairId === void 0 || privateKey === void 0) {
throw new Error('A key pair ID and private key are required');
}
this.keyPairId = keyPairId;
this.privateKey = privateKey;
} | [
"function",
"Signer",
"(",
"keyPairId",
",",
"privateKey",
")",
"{",
"if",
"(",
"keyPairId",
"===",
"void",
"0",
"||",
"privateKey",
"===",
"void",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"'A key pair ID and private key are required'",
")",
";",
"}",
"this",
".",
"keyPairId",
"=",
"keyPairId",
";",
"this",
".",
"privateKey",
"=",
"privateKey",
";",
"}"
] | A signer object can be used to generate signed URLs and cookies for granting
access to content on restricted CloudFront distributions.
@see http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html
@param keyPairId [String] (Required) The ID of the CloudFront key pair
being used.
@param privateKey [String] (Required) A private key in RSA format. | [
"A",
"signer",
"object",
"can",
"be",
"used",
"to",
"generate",
"signed",
"URLs",
"and",
"cookies",
"for",
"granting",
"access",
"to",
"content",
"on",
"restricted",
"CloudFront",
"distributions",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/cloudfront/signer.js#L105-L112 |
3,381 | aws/aws-sdk-js | lib/cloudfront/signer.js | function (options, cb) {
var signatureHash = 'policy' in options
? signWithCustomPolicy(options.policy, this.keyPairId, this.privateKey)
: signWithCannedPolicy(options.url, options.expires, this.keyPairId, this.privateKey);
var cookieHash = {};
for (var key in signatureHash) {
if (Object.prototype.hasOwnProperty.call(signatureHash, key)) {
cookieHash['CloudFront-' + key] = signatureHash[key];
}
}
return handleSuccess(cookieHash, cb);
} | javascript | function (options, cb) {
var signatureHash = 'policy' in options
? signWithCustomPolicy(options.policy, this.keyPairId, this.privateKey)
: signWithCannedPolicy(options.url, options.expires, this.keyPairId, this.privateKey);
var cookieHash = {};
for (var key in signatureHash) {
if (Object.prototype.hasOwnProperty.call(signatureHash, key)) {
cookieHash['CloudFront-' + key] = signatureHash[key];
}
}
return handleSuccess(cookieHash, cb);
} | [
"function",
"(",
"options",
",",
"cb",
")",
"{",
"var",
"signatureHash",
"=",
"'policy'",
"in",
"options",
"?",
"signWithCustomPolicy",
"(",
"options",
".",
"policy",
",",
"this",
".",
"keyPairId",
",",
"this",
".",
"privateKey",
")",
":",
"signWithCannedPolicy",
"(",
"options",
".",
"url",
",",
"options",
".",
"expires",
",",
"this",
".",
"keyPairId",
",",
"this",
".",
"privateKey",
")",
";",
"var",
"cookieHash",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"key",
"in",
"signatureHash",
")",
"{",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"signatureHash",
",",
"key",
")",
")",
"{",
"cookieHash",
"[",
"'CloudFront-'",
"+",
"key",
"]",
"=",
"signatureHash",
"[",
"key",
"]",
";",
"}",
"}",
"return",
"handleSuccess",
"(",
"cookieHash",
",",
"cb",
")",
";",
"}"
] | Create a signed Amazon CloudFront Cookie.
@param options [Object] The options to create a signed cookie.
@option options url [String] The URL to which the signature will grant
access. Required unless you pass in a full
policy.
@option options expires [Number] A Unix UTC timestamp indicating when the
signature should expire. Required unless you
pass in a full policy.
@option options policy [String] A CloudFront JSON policy. Required unless
you pass in a url and an expiry time.
@param cb [Function] if a callback is provided, this function will
pass the hash as the second parameter (after the error parameter) to
the callback function.
@return [Object] if called synchronously (with no callback), returns the
signed cookie parameters.
@return [null] nothing is returned if a callback is provided. | [
"Create",
"a",
"signed",
"Amazon",
"CloudFront",
"Cookie",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/cloudfront/signer.js#L135-L148 |
|
3,382 | aws/aws-sdk-js | lib/cloudfront/signer.js | function (options, cb) {
try {
var resource = getResource(options.url);
} catch (err) {
return handleError(err, cb);
}
var parsedUrl = url.parse(options.url, true),
signatureHash = Object.prototype.hasOwnProperty.call(options, 'policy')
? signWithCustomPolicy(options.policy, this.keyPairId, this.privateKey)
: signWithCannedPolicy(resource, options.expires, this.keyPairId, this.privateKey);
parsedUrl.search = null;
for (var key in signatureHash) {
if (Object.prototype.hasOwnProperty.call(signatureHash, key)) {
parsedUrl.query[key] = signatureHash[key];
}
}
try {
var signedUrl = determineScheme(options.url) === 'rtmp'
? getRtmpUrl(url.format(parsedUrl))
: url.format(parsedUrl);
} catch (err) {
return handleError(err, cb);
}
return handleSuccess(signedUrl, cb);
} | javascript | function (options, cb) {
try {
var resource = getResource(options.url);
} catch (err) {
return handleError(err, cb);
}
var parsedUrl = url.parse(options.url, true),
signatureHash = Object.prototype.hasOwnProperty.call(options, 'policy')
? signWithCustomPolicy(options.policy, this.keyPairId, this.privateKey)
: signWithCannedPolicy(resource, options.expires, this.keyPairId, this.privateKey);
parsedUrl.search = null;
for (var key in signatureHash) {
if (Object.prototype.hasOwnProperty.call(signatureHash, key)) {
parsedUrl.query[key] = signatureHash[key];
}
}
try {
var signedUrl = determineScheme(options.url) === 'rtmp'
? getRtmpUrl(url.format(parsedUrl))
: url.format(parsedUrl);
} catch (err) {
return handleError(err, cb);
}
return handleSuccess(signedUrl, cb);
} | [
"function",
"(",
"options",
",",
"cb",
")",
"{",
"try",
"{",
"var",
"resource",
"=",
"getResource",
"(",
"options",
".",
"url",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"handleError",
"(",
"err",
",",
"cb",
")",
";",
"}",
"var",
"parsedUrl",
"=",
"url",
".",
"parse",
"(",
"options",
".",
"url",
",",
"true",
")",
",",
"signatureHash",
"=",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"options",
",",
"'policy'",
")",
"?",
"signWithCustomPolicy",
"(",
"options",
".",
"policy",
",",
"this",
".",
"keyPairId",
",",
"this",
".",
"privateKey",
")",
":",
"signWithCannedPolicy",
"(",
"resource",
",",
"options",
".",
"expires",
",",
"this",
".",
"keyPairId",
",",
"this",
".",
"privateKey",
")",
";",
"parsedUrl",
".",
"search",
"=",
"null",
";",
"for",
"(",
"var",
"key",
"in",
"signatureHash",
")",
"{",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"signatureHash",
",",
"key",
")",
")",
"{",
"parsedUrl",
".",
"query",
"[",
"key",
"]",
"=",
"signatureHash",
"[",
"key",
"]",
";",
"}",
"}",
"try",
"{",
"var",
"signedUrl",
"=",
"determineScheme",
"(",
"options",
".",
"url",
")",
"===",
"'rtmp'",
"?",
"getRtmpUrl",
"(",
"url",
".",
"format",
"(",
"parsedUrl",
")",
")",
":",
"url",
".",
"format",
"(",
"parsedUrl",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"handleError",
"(",
"err",
",",
"cb",
")",
";",
"}",
"return",
"handleSuccess",
"(",
"signedUrl",
",",
"cb",
")",
";",
"}"
] | Create a signed Amazon CloudFront URL.
Keep in mind that URLs meant for use in media/flash players may have
different requirements for URL formats (e.g. some require that the
extension be removed, some require the file name to be prefixed
- mp4:<path>, some require you to add "/cfx/st" into your URL).
@param options [Object] The options to create a signed URL.
@option options url [String] The URL to which the signature will grant
access. Any query params included with
the URL should be encoded. Required.
@option options expires [Number] A Unix UTC timestamp indicating when the
signature should expire. Required unless you
pass in a full policy.
@option options policy [String] A CloudFront JSON policy. Required unless
you pass in a url and an expiry time.
@param cb [Function] if a callback is provided, this function will
pass the URL as the second parameter (after the error parameter) to
the callback function.
@return [String] if called synchronously (with no callback), returns the
signed URL.
@return [null] nothing is returned if a callback is provided. | [
"Create",
"a",
"signed",
"Amazon",
"CloudFront",
"URL",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/cloudfront/signer.js#L176-L204 |
|
3,383 | aws/aws-sdk-js | features/extra/cleanup.js | function(list, iter, callback) {
var item = list.shift();
iter(item, function(err) {
if (err) return callback(err);
else if (list.length) {
eachSeries(list, iter, callback);
} else {
return callback();
}
});
} | javascript | function(list, iter, callback) {
var item = list.shift();
iter(item, function(err) {
if (err) return callback(err);
else if (list.length) {
eachSeries(list, iter, callback);
} else {
return callback();
}
});
} | [
"function",
"(",
"list",
",",
"iter",
",",
"callback",
")",
"{",
"var",
"item",
"=",
"list",
".",
"shift",
"(",
")",
";",
"iter",
"(",
"item",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"err",
")",
";",
"else",
"if",
"(",
"list",
".",
"length",
")",
"{",
"eachSeries",
"(",
"list",
",",
"iter",
",",
"callback",
")",
";",
"}",
"else",
"{",
"return",
"callback",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Run bucket cleanup serially. | [
"Run",
"bucket",
"cleanup",
"serially",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/features/extra/cleanup.js#L48-L58 |
|
3,384 | aws/aws-sdk-js | features/extra/cleanup.js | function(bucket, callback) {
var s3 = new AWS.S3({maxRetries: 100});
var params = {
Bucket: bucket
};
s3.listObjects(params, function (err, data) {
if (err) return callback(err);
if (data.Contents.length > 0) {
params.Delete = { Objects: [] };
data.Contents.forEach(function (item) {
params.Delete.Objects.push({Key: item.Key});
});
s3.deleteObjects(params, callback);
} else {
callback();
}
});
} | javascript | function(bucket, callback) {
var s3 = new AWS.S3({maxRetries: 100});
var params = {
Bucket: bucket
};
s3.listObjects(params, function (err, data) {
if (err) return callback(err);
if (data.Contents.length > 0) {
params.Delete = { Objects: [] };
data.Contents.forEach(function (item) {
params.Delete.Objects.push({Key: item.Key});
});
s3.deleteObjects(params, callback);
} else {
callback();
}
});
} | [
"function",
"(",
"bucket",
",",
"callback",
")",
"{",
"var",
"s3",
"=",
"new",
"AWS",
".",
"S3",
"(",
"{",
"maxRetries",
":",
"100",
"}",
")",
";",
"var",
"params",
"=",
"{",
"Bucket",
":",
"bucket",
"}",
";",
"s3",
".",
"listObjects",
"(",
"params",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"err",
")",
";",
"if",
"(",
"data",
".",
"Contents",
".",
"length",
">",
"0",
")",
"{",
"params",
".",
"Delete",
"=",
"{",
"Objects",
":",
"[",
"]",
"}",
";",
"data",
".",
"Contents",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"params",
".",
"Delete",
".",
"Objects",
".",
"push",
"(",
"{",
"Key",
":",
"item",
".",
"Key",
"}",
")",
";",
"}",
")",
";",
"s3",
".",
"deleteObjects",
"(",
"params",
",",
"callback",
")",
";",
"}",
"else",
"{",
"callback",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Delete objects. | [
"Delete",
"objects",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/features/extra/cleanup.js#L83-L101 |
|
3,385 | aws/aws-sdk-js | lib/credentials/process_credentials.js | ProcessCredentials | function ProcessCredentials(options) {
AWS.Credentials.call(this);
options = options || {};
this.filename = options.filename;
this.profile = options.profile || process.env.AWS_PROFILE || AWS.util.defaultProfile;
this.get(options.callback || AWS.util.fn.noop);
} | javascript | function ProcessCredentials(options) {
AWS.Credentials.call(this);
options = options || {};
this.filename = options.filename;
this.profile = options.profile || process.env.AWS_PROFILE || AWS.util.defaultProfile;
this.get(options.callback || AWS.util.fn.noop);
} | [
"function",
"ProcessCredentials",
"(",
"options",
")",
"{",
"AWS",
".",
"Credentials",
".",
"call",
"(",
"this",
")",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"filename",
"=",
"options",
".",
"filename",
";",
"this",
".",
"profile",
"=",
"options",
".",
"profile",
"||",
"process",
".",
"env",
".",
"AWS_PROFILE",
"||",
"AWS",
".",
"util",
".",
"defaultProfile",
";",
"this",
".",
"get",
"(",
"options",
".",
"callback",
"||",
"AWS",
".",
"util",
".",
"fn",
".",
"noop",
")",
";",
"}"
] | Creates a new ProcessCredentials object.
@param options [map] a set of options
@option options profile [String] (AWS_PROFILE env var or 'default')
the name of the profile to load.
@option options filename [String] ('~/.aws/credentials' or defined by
AWS_SHARED_CREDENTIALS_FILE process env var)
the filename to use when loading credentials.
@option options callback [Function] (err) Credentials are eagerly loaded
by the constructor. When the callback is called with no error, the
credentials have been loaded successfully. | [
"Creates",
"a",
"new",
"ProcessCredentials",
"object",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/credentials/process_credentials.js#L59-L67 |
3,386 | aws/aws-sdk-js | lib/credentials/process_credentials.js | loadViaCredentialProcess | function loadViaCredentialProcess(profile, callback) {
proc.exec(profile['credential_process'], function(err, stdOut, stdErr) {
if (err) {
callback(AWS.util.error(
new Error('credential_process returned error'),
{ code: 'ProcessCredentialsProviderFailure'}
), null);
} else {
try {
var credData = JSON.parse(stdOut);
if (credData.Expiration) {
var currentTime = AWS.util.date.getDate();
var expireTime = new Date(credData.Expiration);
if (expireTime < currentTime) {
throw Error('credential_process returned expired credentials');
}
}
if (credData.Version !== 1) {
throw Error('credential_process does not return Version == 1');
}
callback(null, credData);
} catch (err) {
callback(AWS.util.error(
new Error(err.message),
{ code: 'ProcessCredentialsProviderFailure'}
), null);
}
}
});
} | javascript | function loadViaCredentialProcess(profile, callback) {
proc.exec(profile['credential_process'], function(err, stdOut, stdErr) {
if (err) {
callback(AWS.util.error(
new Error('credential_process returned error'),
{ code: 'ProcessCredentialsProviderFailure'}
), null);
} else {
try {
var credData = JSON.parse(stdOut);
if (credData.Expiration) {
var currentTime = AWS.util.date.getDate();
var expireTime = new Date(credData.Expiration);
if (expireTime < currentTime) {
throw Error('credential_process returned expired credentials');
}
}
if (credData.Version !== 1) {
throw Error('credential_process does not return Version == 1');
}
callback(null, credData);
} catch (err) {
callback(AWS.util.error(
new Error(err.message),
{ code: 'ProcessCredentialsProviderFailure'}
), null);
}
}
});
} | [
"function",
"loadViaCredentialProcess",
"(",
"profile",
",",
"callback",
")",
"{",
"proc",
".",
"exec",
"(",
"profile",
"[",
"'credential_process'",
"]",
",",
"function",
"(",
"err",
",",
"stdOut",
",",
"stdErr",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"AWS",
".",
"util",
".",
"error",
"(",
"new",
"Error",
"(",
"'credential_process returned error'",
")",
",",
"{",
"code",
":",
"'ProcessCredentialsProviderFailure'",
"}",
")",
",",
"null",
")",
";",
"}",
"else",
"{",
"try",
"{",
"var",
"credData",
"=",
"JSON",
".",
"parse",
"(",
"stdOut",
")",
";",
"if",
"(",
"credData",
".",
"Expiration",
")",
"{",
"var",
"currentTime",
"=",
"AWS",
".",
"util",
".",
"date",
".",
"getDate",
"(",
")",
";",
"var",
"expireTime",
"=",
"new",
"Date",
"(",
"credData",
".",
"Expiration",
")",
";",
"if",
"(",
"expireTime",
"<",
"currentTime",
")",
"{",
"throw",
"Error",
"(",
"'credential_process returned expired credentials'",
")",
";",
"}",
"}",
"if",
"(",
"credData",
".",
"Version",
"!==",
"1",
")",
"{",
"throw",
"Error",
"(",
"'credential_process does not return Version == 1'",
")",
";",
"}",
"callback",
"(",
"null",
",",
"credData",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"callback",
"(",
"AWS",
".",
"util",
".",
"error",
"(",
"new",
"Error",
"(",
"err",
".",
"message",
")",
",",
"{",
"code",
":",
"'ProcessCredentialsProviderFailure'",
"}",
")",
",",
"null",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] | Executes the credential_process and retrieves
credentials from the output
@api private
@param profile [map] credentials profile
@throws ProcessCredentialsProviderFailure | [
"Executes",
"the",
"credential_process",
"and",
"retrieves",
"credentials",
"from",
"the",
"output"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/credentials/process_credentials.js#L136-L166 |
3,387 | aws/aws-sdk-js | lib/dynamodb/document_client.js | DocumentClient | function DocumentClient(options) {
var self = this;
self.options = options || {};
self.configure(self.options);
} | javascript | function DocumentClient(options) {
var self = this;
self.options = options || {};
self.configure(self.options);
} | [
"function",
"DocumentClient",
"(",
"options",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"self",
".",
"configure",
"(",
"self",
".",
"options",
")",
";",
"}"
] | Creates a DynamoDB document client with a set of configuration options.
@option options params [map] An optional map of parameters to bind to every
request sent by this service object.
@option options service [AWS.DynamoDB] An optional pre-configured instance
of the AWS.DynamoDB service object to use for requests. The object may
bound parameters used by the document client.
@option options convertEmptyValues [Boolean] set to true if you would like
the document client to convert empty values (0-length strings, binary
buffers, and sets) to be converted to NULL types when persisting to
DynamoDB.
@see AWS.DynamoDB.constructor | [
"Creates",
"a",
"DynamoDB",
"document",
"client",
"with",
"a",
"set",
"of",
"configuration",
"options",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/dynamodb/document_client.js#L58-L62 |
3,388 | aws/aws-sdk-js | lib/event-stream/alloc-buffer.js | allocBuffer | function allocBuffer(size) {
if (typeof size !== 'number') {
throw new Error('size passed to allocBuffer must be a number.');
}
var buffer = typeof Buffer.alloc === 'function' ? Buffer.alloc(size) : new Buffer(size);
buffer.fill(0);
return buffer;
} | javascript | function allocBuffer(size) {
if (typeof size !== 'number') {
throw new Error('size passed to allocBuffer must be a number.');
}
var buffer = typeof Buffer.alloc === 'function' ? Buffer.alloc(size) : new Buffer(size);
buffer.fill(0);
return buffer;
} | [
"function",
"allocBuffer",
"(",
"size",
")",
"{",
"if",
"(",
"typeof",
"size",
"!==",
"'number'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'size passed to allocBuffer must be a number.'",
")",
";",
"}",
"var",
"buffer",
"=",
"typeof",
"Buffer",
".",
"alloc",
"===",
"'function'",
"?",
"Buffer",
".",
"alloc",
"(",
"size",
")",
":",
"new",
"Buffer",
"(",
"size",
")",
";",
"buffer",
".",
"fill",
"(",
"0",
")",
";",
"return",
"buffer",
";",
"}"
] | Allocates a buffer.
@param {number} size Number of bytes to allocate for the buffer.
@returns {Buffer} | [
"Allocates",
"a",
"buffer",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/event-stream/alloc-buffer.js#L7-L14 |
3,389 | aws/aws-sdk-js | scripts/changelog/util.js | addVersionJSONToChangelog | function addVersionJSONToChangelog(version, changes) {
if (!changelog) readChangelog();
var entry = '\n\n## ' + version;
changes.forEach(function(change) {
entry += '\n* ' + change.type + ': ' + change.category + ': ' +
change.description;
});
var logParts = changelog.split(insertMarker);
logParts[0] = logParts[0]
.replace(versionMarkerReg, versionMarker.join(version)) + insertMarker;
changelog = logParts.join(entry);
} | javascript | function addVersionJSONToChangelog(version, changes) {
if (!changelog) readChangelog();
var entry = '\n\n## ' + version;
changes.forEach(function(change) {
entry += '\n* ' + change.type + ': ' + change.category + ': ' +
change.description;
});
var logParts = changelog.split(insertMarker);
logParts[0] = logParts[0]
.replace(versionMarkerReg, versionMarker.join(version)) + insertMarker;
changelog = logParts.join(entry);
} | [
"function",
"addVersionJSONToChangelog",
"(",
"version",
",",
"changes",
")",
"{",
"if",
"(",
"!",
"changelog",
")",
"readChangelog",
"(",
")",
";",
"var",
"entry",
"=",
"'\\n\\n## '",
"+",
"version",
";",
"changes",
".",
"forEach",
"(",
"function",
"(",
"change",
")",
"{",
"entry",
"+=",
"'\\n* '",
"+",
"change",
".",
"type",
"+",
"': '",
"+",
"change",
".",
"category",
"+",
"': '",
"+",
"change",
".",
"description",
";",
"}",
")",
";",
"var",
"logParts",
"=",
"changelog",
".",
"split",
"(",
"insertMarker",
")",
";",
"logParts",
"[",
"0",
"]",
"=",
"logParts",
"[",
"0",
"]",
".",
"replace",
"(",
"versionMarkerReg",
",",
"versionMarker",
".",
"join",
"(",
"version",
")",
")",
"+",
"insertMarker",
";",
"changelog",
"=",
"logParts",
".",
"join",
"(",
"entry",
")",
";",
"}"
] | This will not to write to file writeToChangelog must be called after | [
"This",
"will",
"not",
"to",
"write",
"to",
"file",
"writeToChangelog",
"must",
"be",
"called",
"after"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/scripts/changelog/util.js#L137-L150 |
3,390 | aws/aws-sdk-js | dist-tools/client-creator.js | ClientCreator | function ClientCreator() {
this._metadata = require('../apis/metadata');
this._apisFolderPath = path.join(__dirname, '..', 'apis');
this._clientFolderPath = path.join(__dirname, '..', 'clients');
this._serviceCustomizationsFolderPath = path.join(__dirname, '..', 'lib', 'services');
this._packageJsonPath = path.join(__dirname, '..', 'package.json');
this._apiFileNames = null;
} | javascript | function ClientCreator() {
this._metadata = require('../apis/metadata');
this._apisFolderPath = path.join(__dirname, '..', 'apis');
this._clientFolderPath = path.join(__dirname, '..', 'clients');
this._serviceCustomizationsFolderPath = path.join(__dirname, '..', 'lib', 'services');
this._packageJsonPath = path.join(__dirname, '..', 'package.json');
this._apiFileNames = null;
} | [
"function",
"ClientCreator",
"(",
")",
"{",
"this",
".",
"_metadata",
"=",
"require",
"(",
"'../apis/metadata'",
")",
";",
"this",
".",
"_apisFolderPath",
"=",
"path",
".",
"join",
"(",
"__dirname",
",",
"'..'",
",",
"'apis'",
")",
";",
"this",
".",
"_clientFolderPath",
"=",
"path",
".",
"join",
"(",
"__dirname",
",",
"'..'",
",",
"'clients'",
")",
";",
"this",
".",
"_serviceCustomizationsFolderPath",
"=",
"path",
".",
"join",
"(",
"__dirname",
",",
"'..'",
",",
"'lib'",
",",
"'services'",
")",
";",
"this",
".",
"_packageJsonPath",
"=",
"path",
".",
"join",
"(",
"__dirname",
",",
"'..'",
",",
"'package.json'",
")",
";",
"this",
".",
"_apiFileNames",
"=",
"null",
";",
"}"
] | Generate service clients | [
"Generate",
"service",
"clients"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/dist-tools/client-creator.js#L5-L12 |
3,391 | aws/aws-sdk-js | lib/discover_endpoint.js | marshallCustomIdentifiers | function marshallCustomIdentifiers(request, shape) {
var identifiers = {};
marshallCustomIdentifiersHelper(identifiers, request.params, shape);
return identifiers;
} | javascript | function marshallCustomIdentifiers(request, shape) {
var identifiers = {};
marshallCustomIdentifiersHelper(identifiers, request.params, shape);
return identifiers;
} | [
"function",
"marshallCustomIdentifiers",
"(",
"request",
",",
"shape",
")",
"{",
"var",
"identifiers",
"=",
"{",
"}",
";",
"marshallCustomIdentifiersHelper",
"(",
"identifiers",
",",
"request",
".",
"params",
",",
"shape",
")",
";",
"return",
"identifiers",
";",
"}"
] | Get custom identifiers for cache key.
Identifies custom identifiers by checking each shape's `endpointDiscoveryId` trait.
@param [object] request object
@param [object] input shape of the given operation's api
@api private | [
"Get",
"custom",
"identifiers",
"for",
"cache",
"key",
".",
"Identifies",
"custom",
"identifiers",
"by",
"checking",
"each",
"shape",
"s",
"endpointDiscoveryId",
"trait",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/discover_endpoint.js#L58-L62 |
3,392 | aws/aws-sdk-js | lib/discover_endpoint.js | optionalDiscoverEndpoint | function optionalDiscoverEndpoint(request) {
var service = request.service;
var api = service.api;
var operationModel = api.operations ? api.operations[request.operation] : undefined;
var inputShape = operationModel ? operationModel.input : undefined;
var identifiers = marshallCustomIdentifiers(request, inputShape);
var cacheKey = getCacheKey(request);
if (Object.keys(identifiers).length > 0) {
cacheKey = util.update(cacheKey, identifiers);
if (operationModel) cacheKey.operation = operationModel.name;
}
var endpoints = AWS.endpointCache.get(cacheKey);
if (endpoints && endpoints.length === 1 && endpoints[0].Address === '') {
//endpoint operation is being made but response not yet received
//or endpoint operation just failed in 1 minute
return;
} else if (endpoints && endpoints.length > 0) {
//found endpoint record from cache
request.httpRequest.updateEndpoint(endpoints[0].Address);
} else {
//endpoint record not in cache or outdated. make discovery operation
var endpointRequest = service.makeRequest(api.endpointOperation, {
Operation: operationModel.name,
Identifiers: identifiers,
});
addApiVersionHeader(endpointRequest);
endpointRequest.removeListener('validate', AWS.EventListeners.Core.VALIDATE_PARAMETERS);
endpointRequest.removeListener('retry', AWS.EventListeners.Core.RETRY_CHECK);
//put in a placeholder for endpoints already requested, prevent
//too much in-flight calls
AWS.endpointCache.put(cacheKey, [{
Address: '',
CachePeriodInMinutes: 1
}]);
endpointRequest.send(function(err, data) {
if (data && data.Endpoints) {
AWS.endpointCache.put(cacheKey, data.Endpoints);
} else if (err) {
AWS.endpointCache.put(cacheKey, [{
Address: '',
CachePeriodInMinutes: 1 //not to make more endpoint operation in next 1 minute
}]);
}
});
}
} | javascript | function optionalDiscoverEndpoint(request) {
var service = request.service;
var api = service.api;
var operationModel = api.operations ? api.operations[request.operation] : undefined;
var inputShape = operationModel ? operationModel.input : undefined;
var identifiers = marshallCustomIdentifiers(request, inputShape);
var cacheKey = getCacheKey(request);
if (Object.keys(identifiers).length > 0) {
cacheKey = util.update(cacheKey, identifiers);
if (operationModel) cacheKey.operation = operationModel.name;
}
var endpoints = AWS.endpointCache.get(cacheKey);
if (endpoints && endpoints.length === 1 && endpoints[0].Address === '') {
//endpoint operation is being made but response not yet received
//or endpoint operation just failed in 1 minute
return;
} else if (endpoints && endpoints.length > 0) {
//found endpoint record from cache
request.httpRequest.updateEndpoint(endpoints[0].Address);
} else {
//endpoint record not in cache or outdated. make discovery operation
var endpointRequest = service.makeRequest(api.endpointOperation, {
Operation: operationModel.name,
Identifiers: identifiers,
});
addApiVersionHeader(endpointRequest);
endpointRequest.removeListener('validate', AWS.EventListeners.Core.VALIDATE_PARAMETERS);
endpointRequest.removeListener('retry', AWS.EventListeners.Core.RETRY_CHECK);
//put in a placeholder for endpoints already requested, prevent
//too much in-flight calls
AWS.endpointCache.put(cacheKey, [{
Address: '',
CachePeriodInMinutes: 1
}]);
endpointRequest.send(function(err, data) {
if (data && data.Endpoints) {
AWS.endpointCache.put(cacheKey, data.Endpoints);
} else if (err) {
AWS.endpointCache.put(cacheKey, [{
Address: '',
CachePeriodInMinutes: 1 //not to make more endpoint operation in next 1 minute
}]);
}
});
}
} | [
"function",
"optionalDiscoverEndpoint",
"(",
"request",
")",
"{",
"var",
"service",
"=",
"request",
".",
"service",
";",
"var",
"api",
"=",
"service",
".",
"api",
";",
"var",
"operationModel",
"=",
"api",
".",
"operations",
"?",
"api",
".",
"operations",
"[",
"request",
".",
"operation",
"]",
":",
"undefined",
";",
"var",
"inputShape",
"=",
"operationModel",
"?",
"operationModel",
".",
"input",
":",
"undefined",
";",
"var",
"identifiers",
"=",
"marshallCustomIdentifiers",
"(",
"request",
",",
"inputShape",
")",
";",
"var",
"cacheKey",
"=",
"getCacheKey",
"(",
"request",
")",
";",
"if",
"(",
"Object",
".",
"keys",
"(",
"identifiers",
")",
".",
"length",
">",
"0",
")",
"{",
"cacheKey",
"=",
"util",
".",
"update",
"(",
"cacheKey",
",",
"identifiers",
")",
";",
"if",
"(",
"operationModel",
")",
"cacheKey",
".",
"operation",
"=",
"operationModel",
".",
"name",
";",
"}",
"var",
"endpoints",
"=",
"AWS",
".",
"endpointCache",
".",
"get",
"(",
"cacheKey",
")",
";",
"if",
"(",
"endpoints",
"&&",
"endpoints",
".",
"length",
"===",
"1",
"&&",
"endpoints",
"[",
"0",
"]",
".",
"Address",
"===",
"''",
")",
"{",
"//endpoint operation is being made but response not yet received",
"//or endpoint operation just failed in 1 minute",
"return",
";",
"}",
"else",
"if",
"(",
"endpoints",
"&&",
"endpoints",
".",
"length",
">",
"0",
")",
"{",
"//found endpoint record from cache",
"request",
".",
"httpRequest",
".",
"updateEndpoint",
"(",
"endpoints",
"[",
"0",
"]",
".",
"Address",
")",
";",
"}",
"else",
"{",
"//endpoint record not in cache or outdated. make discovery operation",
"var",
"endpointRequest",
"=",
"service",
".",
"makeRequest",
"(",
"api",
".",
"endpointOperation",
",",
"{",
"Operation",
":",
"operationModel",
".",
"name",
",",
"Identifiers",
":",
"identifiers",
",",
"}",
")",
";",
"addApiVersionHeader",
"(",
"endpointRequest",
")",
";",
"endpointRequest",
".",
"removeListener",
"(",
"'validate'",
",",
"AWS",
".",
"EventListeners",
".",
"Core",
".",
"VALIDATE_PARAMETERS",
")",
";",
"endpointRequest",
".",
"removeListener",
"(",
"'retry'",
",",
"AWS",
".",
"EventListeners",
".",
"Core",
".",
"RETRY_CHECK",
")",
";",
"//put in a placeholder for endpoints already requested, prevent",
"//too much in-flight calls",
"AWS",
".",
"endpointCache",
".",
"put",
"(",
"cacheKey",
",",
"[",
"{",
"Address",
":",
"''",
",",
"CachePeriodInMinutes",
":",
"1",
"}",
"]",
")",
";",
"endpointRequest",
".",
"send",
"(",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"data",
"&&",
"data",
".",
"Endpoints",
")",
"{",
"AWS",
".",
"endpointCache",
".",
"put",
"(",
"cacheKey",
",",
"data",
".",
"Endpoints",
")",
";",
"}",
"else",
"if",
"(",
"err",
")",
"{",
"AWS",
".",
"endpointCache",
".",
"put",
"(",
"cacheKey",
",",
"[",
"{",
"Address",
":",
"''",
",",
"CachePeriodInMinutes",
":",
"1",
"//not to make more endpoint operation in next 1 minute",
"}",
"]",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
] | Call endpoint discovery operation when it's optional.
When endpoint is available in cache then use the cached endpoints. If endpoints
are unavailable then use regional endpoints and call endpoint discovery operation
asynchronously. This is turned off by default.
@param [object] request object
@api private | [
"Call",
"endpoint",
"discovery",
"operation",
"when",
"it",
"s",
"optional",
".",
"When",
"endpoint",
"is",
"available",
"in",
"cache",
"then",
"use",
"the",
"cached",
"endpoints",
".",
"If",
"endpoints",
"are",
"unavailable",
"then",
"use",
"regional",
"endpoints",
"and",
"call",
"endpoint",
"discovery",
"operation",
"asynchronously",
".",
"This",
"is",
"turned",
"off",
"by",
"default",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/discover_endpoint.js#L72-L118 |
3,393 | aws/aws-sdk-js | lib/discover_endpoint.js | addApiVersionHeader | function addApiVersionHeader(endpointRequest) {
var api = endpointRequest.service.api;
var apiVersion = api.apiVersion;
if (apiVersion && !endpointRequest.httpRequest.headers['x-amz-api-version']) {
endpointRequest.httpRequest.headers['x-amz-api-version'] = apiVersion;
}
} | javascript | function addApiVersionHeader(endpointRequest) {
var api = endpointRequest.service.api;
var apiVersion = api.apiVersion;
if (apiVersion && !endpointRequest.httpRequest.headers['x-amz-api-version']) {
endpointRequest.httpRequest.headers['x-amz-api-version'] = apiVersion;
}
} | [
"function",
"addApiVersionHeader",
"(",
"endpointRequest",
")",
"{",
"var",
"api",
"=",
"endpointRequest",
".",
"service",
".",
"api",
";",
"var",
"apiVersion",
"=",
"api",
".",
"apiVersion",
";",
"if",
"(",
"apiVersion",
"&&",
"!",
"endpointRequest",
".",
"httpRequest",
".",
"headers",
"[",
"'x-amz-api-version'",
"]",
")",
"{",
"endpointRequest",
".",
"httpRequest",
".",
"headers",
"[",
"'x-amz-api-version'",
"]",
"=",
"apiVersion",
";",
"}",
"}"
] | add api version header to endpoint operation
@api private | [
"add",
"api",
"version",
"header",
"to",
"endpoint",
"operation"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/discover_endpoint.js#L210-L216 |
3,394 | aws/aws-sdk-js | lib/discover_endpoint.js | invalidateCachedEndpoints | function invalidateCachedEndpoints(response) {
var error = response.error;
var httpResponse = response.httpResponse;
if (error &&
(error.code === 'InvalidEndpointException' || httpResponse.statusCode === 421)
) {
var request = response.request;
var operations = request.service.api.operations || {};
var inputShape = operations[request.operation] ? operations[request.operation].input : undefined;
var identifiers = marshallCustomIdentifiers(request, inputShape);
var cacheKey = getCacheKey(request);
if (Object.keys(identifiers).length > 0) {
cacheKey = util.update(cacheKey, identifiers);
if (operations[request.operation]) cacheKey.operation = operations[request.operation].name;
}
AWS.endpointCache.remove(cacheKey);
}
} | javascript | function invalidateCachedEndpoints(response) {
var error = response.error;
var httpResponse = response.httpResponse;
if (error &&
(error.code === 'InvalidEndpointException' || httpResponse.statusCode === 421)
) {
var request = response.request;
var operations = request.service.api.operations || {};
var inputShape = operations[request.operation] ? operations[request.operation].input : undefined;
var identifiers = marshallCustomIdentifiers(request, inputShape);
var cacheKey = getCacheKey(request);
if (Object.keys(identifiers).length > 0) {
cacheKey = util.update(cacheKey, identifiers);
if (operations[request.operation]) cacheKey.operation = operations[request.operation].name;
}
AWS.endpointCache.remove(cacheKey);
}
} | [
"function",
"invalidateCachedEndpoints",
"(",
"response",
")",
"{",
"var",
"error",
"=",
"response",
".",
"error",
";",
"var",
"httpResponse",
"=",
"response",
".",
"httpResponse",
";",
"if",
"(",
"error",
"&&",
"(",
"error",
".",
"code",
"===",
"'InvalidEndpointException'",
"||",
"httpResponse",
".",
"statusCode",
"===",
"421",
")",
")",
"{",
"var",
"request",
"=",
"response",
".",
"request",
";",
"var",
"operations",
"=",
"request",
".",
"service",
".",
"api",
".",
"operations",
"||",
"{",
"}",
";",
"var",
"inputShape",
"=",
"operations",
"[",
"request",
".",
"operation",
"]",
"?",
"operations",
"[",
"request",
".",
"operation",
"]",
".",
"input",
":",
"undefined",
";",
"var",
"identifiers",
"=",
"marshallCustomIdentifiers",
"(",
"request",
",",
"inputShape",
")",
";",
"var",
"cacheKey",
"=",
"getCacheKey",
"(",
"request",
")",
";",
"if",
"(",
"Object",
".",
"keys",
"(",
"identifiers",
")",
".",
"length",
">",
"0",
")",
"{",
"cacheKey",
"=",
"util",
".",
"update",
"(",
"cacheKey",
",",
"identifiers",
")",
";",
"if",
"(",
"operations",
"[",
"request",
".",
"operation",
"]",
")",
"cacheKey",
".",
"operation",
"=",
"operations",
"[",
"request",
".",
"operation",
"]",
".",
"name",
";",
"}",
"AWS",
".",
"endpointCache",
".",
"remove",
"(",
"cacheKey",
")",
";",
"}",
"}"
] | If api call gets invalid endpoint exception, SDK should attempt to remove the invalid
endpoint from cache.
@api private | [
"If",
"api",
"call",
"gets",
"invalid",
"endpoint",
"exception",
"SDK",
"should",
"attempt",
"to",
"remove",
"the",
"invalid",
"endpoint",
"from",
"cache",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/discover_endpoint.js#L223-L240 |
3,395 | aws/aws-sdk-js | lib/discover_endpoint.js | hasCustomEndpoint | function hasCustomEndpoint(client) {
//if set endpoint is set for specific client, enable endpoint discovery will raise an error.
if (client._originalConfig && client._originalConfig.endpoint && client._originalConfig.endpointDiscoveryEnabled === true) {
throw util.error(new Error(), {
code: 'ConfigurationException',
message: 'Custom endpoint is supplied; endpointDiscoveryEnabled must not be true.'
});
};
var svcConfig = AWS.config[client.serviceIdentifier] || {};
return Boolean(AWS.config.endpoint || svcConfig.endpoint || (client._originalConfig && client._originalConfig.endpoint));
} | javascript | function hasCustomEndpoint(client) {
//if set endpoint is set for specific client, enable endpoint discovery will raise an error.
if (client._originalConfig && client._originalConfig.endpoint && client._originalConfig.endpointDiscoveryEnabled === true) {
throw util.error(new Error(), {
code: 'ConfigurationException',
message: 'Custom endpoint is supplied; endpointDiscoveryEnabled must not be true.'
});
};
var svcConfig = AWS.config[client.serviceIdentifier] || {};
return Boolean(AWS.config.endpoint || svcConfig.endpoint || (client._originalConfig && client._originalConfig.endpoint));
} | [
"function",
"hasCustomEndpoint",
"(",
"client",
")",
"{",
"//if set endpoint is set for specific client, enable endpoint discovery will raise an error.",
"if",
"(",
"client",
".",
"_originalConfig",
"&&",
"client",
".",
"_originalConfig",
".",
"endpoint",
"&&",
"client",
".",
"_originalConfig",
".",
"endpointDiscoveryEnabled",
"===",
"true",
")",
"{",
"throw",
"util",
".",
"error",
"(",
"new",
"Error",
"(",
")",
",",
"{",
"code",
":",
"'ConfigurationException'",
",",
"message",
":",
"'Custom endpoint is supplied; endpointDiscoveryEnabled must not be true.'",
"}",
")",
";",
"}",
";",
"var",
"svcConfig",
"=",
"AWS",
".",
"config",
"[",
"client",
".",
"serviceIdentifier",
"]",
"||",
"{",
"}",
";",
"return",
"Boolean",
"(",
"AWS",
".",
"config",
".",
"endpoint",
"||",
"svcConfig",
".",
"endpoint",
"||",
"(",
"client",
".",
"_originalConfig",
"&&",
"client",
".",
"_originalConfig",
".",
"endpoint",
")",
")",
";",
"}"
] | If endpoint is explicitly configured, SDK should not do endpoint discovery in anytime.
@param [object] client Service client object.
@api private | [
"If",
"endpoint",
"is",
"explicitly",
"configured",
"SDK",
"should",
"not",
"do",
"endpoint",
"discovery",
"in",
"anytime",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/discover_endpoint.js#L247-L257 |
3,396 | aws/aws-sdk-js | lib/discover_endpoint.js | discoverEndpoint | function discoverEndpoint(request, done) {
var service = request.service || {};
if (hasCustomEndpoint(service) || request.isPresigned()) return done();
if (!isEndpointDiscoveryApplicable(request)) return done();
request.httpRequest.appendToUserAgent('endpoint-discovery');
var operations = service.api.operations || {};
var operationModel = operations[request.operation];
var isEndpointDiscoveryRequired = operationModel ? operationModel.endpointDiscoveryRequired : 'NULL';
switch (isEndpointDiscoveryRequired) {
case 'OPTIONAL':
optionalDiscoverEndpoint(request);
request.addNamedListener('INVALIDATE_CACHED_ENDPOINTS', 'extractError', invalidateCachedEndpoints);
done();
break;
case 'REQUIRED':
request.addNamedListener('INVALIDATE_CACHED_ENDPOINTS', 'extractError', invalidateCachedEndpoints);
requiredDiscoverEndpoint(request, done);
break;
case 'NULL':
default:
done();
break;
}
} | javascript | function discoverEndpoint(request, done) {
var service = request.service || {};
if (hasCustomEndpoint(service) || request.isPresigned()) return done();
if (!isEndpointDiscoveryApplicable(request)) return done();
request.httpRequest.appendToUserAgent('endpoint-discovery');
var operations = service.api.operations || {};
var operationModel = operations[request.operation];
var isEndpointDiscoveryRequired = operationModel ? operationModel.endpointDiscoveryRequired : 'NULL';
switch (isEndpointDiscoveryRequired) {
case 'OPTIONAL':
optionalDiscoverEndpoint(request);
request.addNamedListener('INVALIDATE_CACHED_ENDPOINTS', 'extractError', invalidateCachedEndpoints);
done();
break;
case 'REQUIRED':
request.addNamedListener('INVALIDATE_CACHED_ENDPOINTS', 'extractError', invalidateCachedEndpoints);
requiredDiscoverEndpoint(request, done);
break;
case 'NULL':
default:
done();
break;
}
} | [
"function",
"discoverEndpoint",
"(",
"request",
",",
"done",
")",
"{",
"var",
"service",
"=",
"request",
".",
"service",
"||",
"{",
"}",
";",
"if",
"(",
"hasCustomEndpoint",
"(",
"service",
")",
"||",
"request",
".",
"isPresigned",
"(",
")",
")",
"return",
"done",
"(",
")",
";",
"if",
"(",
"!",
"isEndpointDiscoveryApplicable",
"(",
"request",
")",
")",
"return",
"done",
"(",
")",
";",
"request",
".",
"httpRequest",
".",
"appendToUserAgent",
"(",
"'endpoint-discovery'",
")",
";",
"var",
"operations",
"=",
"service",
".",
"api",
".",
"operations",
"||",
"{",
"}",
";",
"var",
"operationModel",
"=",
"operations",
"[",
"request",
".",
"operation",
"]",
";",
"var",
"isEndpointDiscoveryRequired",
"=",
"operationModel",
"?",
"operationModel",
".",
"endpointDiscoveryRequired",
":",
"'NULL'",
";",
"switch",
"(",
"isEndpointDiscoveryRequired",
")",
"{",
"case",
"'OPTIONAL'",
":",
"optionalDiscoverEndpoint",
"(",
"request",
")",
";",
"request",
".",
"addNamedListener",
"(",
"'INVALIDATE_CACHED_ENDPOINTS'",
",",
"'extractError'",
",",
"invalidateCachedEndpoints",
")",
";",
"done",
"(",
")",
";",
"break",
";",
"case",
"'REQUIRED'",
":",
"request",
".",
"addNamedListener",
"(",
"'INVALIDATE_CACHED_ENDPOINTS'",
",",
"'extractError'",
",",
"invalidateCachedEndpoints",
")",
";",
"requiredDiscoverEndpoint",
"(",
"request",
",",
"done",
")",
";",
"break",
";",
"case",
"'NULL'",
":",
"default",
":",
"done",
"(",
")",
";",
"break",
";",
"}",
"}"
] | attach endpoint discovery logic to request object
@param [object] request
@api private | [
"attach",
"endpoint",
"discovery",
"logic",
"to",
"request",
"object"
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/discover_endpoint.js#L324-L350 |
3,397 | aws/aws-sdk-js | lib/s3/managed_upload.js | ManagedUpload | function ManagedUpload(options) {
var self = this;
AWS.SequentialExecutor.call(self);
self.body = null;
self.sliceFn = null;
self.callback = null;
self.parts = {};
self.completeInfo = [];
self.fillQueue = function() {
self.callback(new Error('Unsupported body payload ' + typeof self.body));
};
self.configure(options);
} | javascript | function ManagedUpload(options) {
var self = this;
AWS.SequentialExecutor.call(self);
self.body = null;
self.sliceFn = null;
self.callback = null;
self.parts = {};
self.completeInfo = [];
self.fillQueue = function() {
self.callback(new Error('Unsupported body payload ' + typeof self.body));
};
self.configure(options);
} | [
"function",
"ManagedUpload",
"(",
"options",
")",
"{",
"var",
"self",
"=",
"this",
";",
"AWS",
".",
"SequentialExecutor",
".",
"call",
"(",
"self",
")",
";",
"self",
".",
"body",
"=",
"null",
";",
"self",
".",
"sliceFn",
"=",
"null",
";",
"self",
".",
"callback",
"=",
"null",
";",
"self",
".",
"parts",
"=",
"{",
"}",
";",
"self",
".",
"completeInfo",
"=",
"[",
"]",
";",
"self",
".",
"fillQueue",
"=",
"function",
"(",
")",
"{",
"self",
".",
"callback",
"(",
"new",
"Error",
"(",
"'Unsupported body payload '",
"+",
"typeof",
"self",
".",
"body",
")",
")",
";",
"}",
";",
"self",
".",
"configure",
"(",
"options",
")",
";",
"}"
] | Creates a managed upload object with a set of configuration options.
@note A "Body" parameter is required to be set prior to calling {send}.
@option options params [map] a map of parameters to pass to the upload
requests. The "Body" parameter is required to be specified either on
the service or in the params option.
@note ContentMD5 should not be provided when using the managed upload object.
Instead, setting "computeChecksums" to true will enable automatic ContentMD5 generation
by the managed upload object.
@option options queueSize [Number] (4) the size of the concurrent queue
manager to upload parts in parallel. Set to 1 for synchronous uploading
of parts. Note that the uploader will buffer at most queueSize * partSize
bytes into memory at any given time.
@option options partSize [Number] (5mb) the size in bytes for each
individual part to be uploaded. Adjust the part size to ensure the number
of parts does not exceed {maxTotalParts}. See {minPartSize} for the
minimum allowed part size.
@option options leavePartsOnError [Boolean] (false) whether to abort the
multipart upload if an error occurs. Set to true if you want to handle
failures manually.
@option options service [AWS.S3] an optional S3 service object to use for
requests. This object might have bound parameters used by the uploader.
@option options tags [Array<map>] The tags to apply to the uploaded object.
Each tag should have a `Key` and `Value` keys.
@example Creating a default uploader for a stream object
var upload = new AWS.S3.ManagedUpload({
params: {Bucket: 'bucket', Key: 'key', Body: stream}
});
@example Creating an uploader with concurrency of 1 and partSize of 10mb
var upload = new AWS.S3.ManagedUpload({
partSize: 10 * 1024 * 1024, queueSize: 1,
params: {Bucket: 'bucket', Key: 'key', Body: stream}
});
@example Creating an uploader with tags
var upload = new AWS.S3.ManagedUpload({
params: {Bucket: 'bucket', Key: 'key', Body: stream},
tags: [{Key: 'tag1', Value: 'value1'}, {Key: 'tag2', Value: 'value2'}]
});
@see send | [
"Creates",
"a",
"managed",
"upload",
"object",
"with",
"a",
"set",
"of",
"configuration",
"options",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/s3/managed_upload.js#L81-L94 |
3,398 | aws/aws-sdk-js | lib/s3/managed_upload.js | function(callback) {
var self = this;
self.failed = false;
self.callback = callback || function(err) { if (err) throw err; };
var runFill = true;
if (self.sliceFn) {
self.fillQueue = self.fillBuffer;
} else if (AWS.util.isNode()) {
var Stream = AWS.util.stream.Stream;
if (self.body instanceof Stream) {
runFill = false;
self.fillQueue = self.fillStream;
self.partBuffers = [];
self.body.
on('error', function(err) { self.cleanup(err); }).
on('readable', function() { self.fillQueue(); }).
on('end', function() {
self.isDoneChunking = true;
self.numParts = self.totalPartNumbers;
self.fillQueue.call(self);
if (self.isDoneChunking && self.totalPartNumbers >= 1 && self.doneParts === self.numParts) {
self.finishMultiPart();
}
});
}
}
if (runFill) self.fillQueue.call(self);
} | javascript | function(callback) {
var self = this;
self.failed = false;
self.callback = callback || function(err) { if (err) throw err; };
var runFill = true;
if (self.sliceFn) {
self.fillQueue = self.fillBuffer;
} else if (AWS.util.isNode()) {
var Stream = AWS.util.stream.Stream;
if (self.body instanceof Stream) {
runFill = false;
self.fillQueue = self.fillStream;
self.partBuffers = [];
self.body.
on('error', function(err) { self.cleanup(err); }).
on('readable', function() { self.fillQueue(); }).
on('end', function() {
self.isDoneChunking = true;
self.numParts = self.totalPartNumbers;
self.fillQueue.call(self);
if (self.isDoneChunking && self.totalPartNumbers >= 1 && self.doneParts === self.numParts) {
self.finishMultiPart();
}
});
}
}
if (runFill) self.fillQueue.call(self);
} | [
"function",
"(",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"failed",
"=",
"false",
";",
"self",
".",
"callback",
"=",
"callback",
"||",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"throw",
"err",
";",
"}",
";",
"var",
"runFill",
"=",
"true",
";",
"if",
"(",
"self",
".",
"sliceFn",
")",
"{",
"self",
".",
"fillQueue",
"=",
"self",
".",
"fillBuffer",
";",
"}",
"else",
"if",
"(",
"AWS",
".",
"util",
".",
"isNode",
"(",
")",
")",
"{",
"var",
"Stream",
"=",
"AWS",
".",
"util",
".",
"stream",
".",
"Stream",
";",
"if",
"(",
"self",
".",
"body",
"instanceof",
"Stream",
")",
"{",
"runFill",
"=",
"false",
";",
"self",
".",
"fillQueue",
"=",
"self",
".",
"fillStream",
";",
"self",
".",
"partBuffers",
"=",
"[",
"]",
";",
"self",
".",
"body",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"self",
".",
"cleanup",
"(",
"err",
")",
";",
"}",
")",
".",
"on",
"(",
"'readable'",
",",
"function",
"(",
")",
"{",
"self",
".",
"fillQueue",
"(",
")",
";",
"}",
")",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"self",
".",
"isDoneChunking",
"=",
"true",
";",
"self",
".",
"numParts",
"=",
"self",
".",
"totalPartNumbers",
";",
"self",
".",
"fillQueue",
".",
"call",
"(",
"self",
")",
";",
"if",
"(",
"self",
".",
"isDoneChunking",
"&&",
"self",
".",
"totalPartNumbers",
">=",
"1",
"&&",
"self",
".",
"doneParts",
"===",
"self",
".",
"numParts",
")",
"{",
"self",
".",
"finishMultiPart",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
"if",
"(",
"runFill",
")",
"self",
".",
"fillQueue",
".",
"call",
"(",
"self",
")",
";",
"}"
] | Initiates the managed upload for the payload.
@callback callback function(err, data)
@param err [Error] an error or null if no error occurred.
@param data [map] The response data from the successful upload:
* `Location` (String) the URL of the uploaded object
* `ETag` (String) the ETag of the uploaded object
* `Bucket` (String) the bucket to which the object was uploaded
* `Key` (String) the key to which the object was uploaded
@example Sending a managed upload object
var params = {Bucket: 'bucket', Key: 'key', Body: stream};
var upload = new AWS.S3.ManagedUpload({params: params});
upload.send(function(err, data) {
console.log(err, data);
}); | [
"Initiates",
"the",
"managed",
"upload",
"for",
"the",
"payload",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/s3/managed_upload.js#L170-L200 |
|
3,399 | aws/aws-sdk-js | lib/param_validator.js | ParamValidator | function ParamValidator(validation) {
if (validation === true || validation === undefined) {
validation = {'min': true};
}
this.validation = validation;
} | javascript | function ParamValidator(validation) {
if (validation === true || validation === undefined) {
validation = {'min': true};
}
this.validation = validation;
} | [
"function",
"ParamValidator",
"(",
"validation",
")",
"{",
"if",
"(",
"validation",
"===",
"true",
"||",
"validation",
"===",
"undefined",
")",
"{",
"validation",
"=",
"{",
"'min'",
":",
"true",
"}",
";",
"}",
"this",
".",
"validation",
"=",
"validation",
";",
"}"
] | Create a new validator object.
@param validation [Boolean|map] whether input parameters should be
validated against the operation description before sending the
request. Pass a map to enable any of the following specific
validation features:
* **min** [Boolean] — Validates that a value meets the min
constraint. This is enabled by default when paramValidation is set
to `true`.
* **max** [Boolean] — Validates that a value meets the max
constraint.
* **pattern** [Boolean] — Validates that a string value matches a
regular expression.
* **enum** [Boolean] — Validates that a string value matches one
of the allowable enum values. | [
"Create",
"a",
"new",
"validator",
"object",
"."
] | c23e5f0edd150f8885267e5f7c8a564f8e6e8562 | https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/param_validator.js#L25-L30 |
Subsets and Splits