From 1eb84d482e7059438dec1841536957fabed48150 Mon Sep 17 00:00:00 2001 From: denis Date: Tue, 31 Jul 2018 23:41:23 +0200 Subject: [PATCH 01/25] Activate strictNullChecks And strictFunctionTypes --- types/d3-hierarchy/d3-hierarchy-tests.ts | 94 ++++++++++++++---------- types/d3-hierarchy/index.d.ts | 8 +- types/d3-hierarchy/tsconfig.json | 2 +- 3 files changed, 62 insertions(+), 42 deletions(-) diff --git a/types/d3-hierarchy/d3-hierarchy-tests.ts b/types/d3-hierarchy/d3-hierarchy-tests.ts index b75b9fbbd0..7e4181f822 100644 --- a/types/d3-hierarchy/d3-hierarchy-tests.ts +++ b/types/d3-hierarchy/d3-hierarchy-tests.ts @@ -13,8 +13,10 @@ import * as d3Hierarchy from 'd3-hierarchy'; // ----------------------------------------------------------------------- let num: number; +let numOrUndefined: number | undefined; let size: [number, number]; -let idString: string; +let sizeOrNull: [number, number] | null; +let idString: string | undefined; // ----------------------------------------------------------------------- // Hierarchy @@ -47,16 +49,20 @@ let hierarchyRootDatum: HierarchyDatum = { ] }; -let hierarchyNodeArray: Array>; +let hierarchyNodeArray: Array> = []; +let hierarchyNodeArrayOrUndefined: Array> | undefined; let hierarchyNode: d3Hierarchy.HierarchyNode; -let hierarchyPointNodeArray: Array>; +let hierarchyPointNodeArray: Array> = []; +let hierarchyPointNodeArrayOrUndefined: Array> | undefined; let hierarchyPointNode: d3Hierarchy.HierarchyPointNode; -let hierarchyRectangularNodeArray: Array>; +let hierarchyRectangularNodeArray: Array> = []; +let hierarchyRectangularNodeArrayOrUndefined: Array> | undefined; let hierarchyRectangularNode: d3Hierarchy.HierarchyRectangularNode; -let hierarchyCircularNodeArray: Array>; +let hierarchyCircularNodeArray: Array> = []; +let hierarchyCircularNodeArrayOrUndefined: Array> | undefined; let hierarchyCircularNode: d3Hierarchy.HierarchyCircularNode; // Create Hierarchy Layout Root Node ===================================== @@ -65,6 +71,10 @@ let hierarchyRootNode: d3Hierarchy.HierarchyNode; hierarchyRootNode = d3Hierarchy.hierarchy(hierarchyRootDatum); +hierarchyRootNode = d3Hierarchy.hierarchy(hierarchyRootDatum, (d) => { + return d.children; +}); + hierarchyRootNode = d3Hierarchy.hierarchy(hierarchyRootDatum, (d) => { return d.children || null; }); @@ -79,10 +89,11 @@ num = hierarchyRootNode.height; // children, parent ------------------------------------------------------ -hierarchyNodeArray = hierarchyRootNode.children; +hierarchyNodeArrayOrUndefined = hierarchyRootNode.children; -let parentNode: d3Hierarchy.HierarchyNode; +let parentNode: d3Hierarchy.HierarchyNode | null; parentNode = hierarchyNodeArray.length ? hierarchyNodeArray[0].parent : null; +parentNode = hierarchyNodeArray[0].parent; // id -------------------------------------------------------------------- @@ -119,19 +130,19 @@ hierarchyNode = link.target; hierarchyRootNode = hierarchyRootNode.sum((d) => d.val); -num = hierarchyRootNode.value; +numOrUndefined = hierarchyRootNode.value; // count() and value ---------------------------------------------------------- hierarchyRootNode = hierarchyRootNode.count(); -num = hierarchyRootNode.value; +numOrUndefined = hierarchyRootNode.value; // sort --------------------------------------------------------------------- hierarchyRootNode = hierarchyRootNode.sort((a, b) => { console.log('Raw values in data of a and b:', a.data.val, ' and ', b.data.val); // a and b are of type HierarchyNode - return b.height - a.height || b.value - a.value; + return b.height - a.height || b.value! - a.value!; }); // each(), eachAfter(), eachBefore() ---------------------------------------- @@ -161,12 +172,12 @@ copiedHierarchyNode = hierarchyRootNode.copy(); // ----------------------------------------------------------------------- interface HierarchyDatumWithParentId extends HierarchyDatum { - parentId: string; + parentId: string | null; } interface TabularHierarchyDatum { name: string; - parentId: string; + parentId: string | null; val: number; } @@ -178,7 +189,7 @@ tabularData = [ { name: 'n121', parentId: 'n12', val: 30 } ]; -let idStringAccessor: (d: TabularHierarchyDatum, i?: number, data?: TabularHierarchyDatum[]) => (string | null | '' | undefined); +let idStringAccessor: (d: TabularHierarchyDatum, i: number, data: TabularHierarchyDatum[]) => (string | null | '' | undefined); // Create Stratify Operator --------------------------------------------- @@ -217,7 +228,8 @@ idStringAccessor = stratificatorizer.parentId(); // Use Stratify Operator ------------------------------------------------ -const stratifiedRootNode: d3Hierarchy.HierarchyNode = stratificatorizer(tabularData); +const stratifiedRootNode: d3Hierarchy.HierarchyNode = stratificatorizer(tabularData); +const pId: string | null = stratifiedRootNode.data.parentId; // ----------------------------------------------------------------------- // Cluster @@ -235,12 +247,12 @@ clusterLayout = d3Hierarchy.cluster(); clusterLayout = clusterLayout.size([200, 200]); -size = clusterLayout.size(); +sizeOrNull = clusterLayout.size(); // nodeSize() ------------------------------------------------------------ clusterLayout = clusterLayout.nodeSize([10, 10]); -size = clusterLayout.nodeSize(); +sizeOrNull = clusterLayout.nodeSize(); // separation() ---------------------------------------------------------- @@ -272,10 +284,11 @@ num = clusterRootNode.height; // children, parent ------------------------------------------------------ -hierarchyPointNodeArray = clusterRootNode.children; +hierarchyPointNodeArrayOrUndefined = clusterRootNode.children; -let parentPointNode: d3Hierarchy.HierarchyPointNode; +let parentPointNode: d3Hierarchy.HierarchyPointNode | null; parentPointNode = hierarchyPointNodeArray.length ? hierarchyPointNodeArray[0].parent : null; +parentPointNode = hierarchyPointNodeArray[0].parent; // id -------------------------------------------------------------------- @@ -312,20 +325,20 @@ hierarchyPointNode = pointLink.target; clusterRootNode = clusterRootNode.sum((d) => d.val); -num = clusterRootNode.value; +numOrUndefined = clusterRootNode.value; // count() and value ---------------------------------------------------------- clusterRootNode = clusterRootNode.count(); -num = clusterRootNode.value; +numOrUndefined = clusterRootNode.value; // sort --------------------------------------------------------------------- clusterRootNode = clusterRootNode.sort((a, b) => { console.log('x-coordinates of a:', a.x, ' and b:', b.x); // a and b are of type HierarchyPointNode console.log('Raw values in data of a and b:', a.data.val, ' and ', b.data.val); // a and b are of type HierarchyPointNode - return b.height - a.height || b.value - a.value; + return b.height - a.height || b.value! - a.value!; }); // each(), eachAfter(), eachBefore() ---------------------------------------- @@ -366,12 +379,12 @@ treeLayout = d3Hierarchy.tree(); treeLayout = treeLayout.size([200, 200]); -size = treeLayout.size(); +sizeOrNull = treeLayout.size(); // nodeSize() ------------------------------------------------------------ treeLayout = treeLayout.nodeSize([10, 10]); -size = treeLayout.nodeSize(); +sizeOrNull = treeLayout.nodeSize(); // separation() ---------------------------------------------------------- @@ -547,10 +560,11 @@ num = treemapRootNode.height; // children, parent ------------------------------------------------------ -hierarchyRectangularNodeArray = treemapRootNode.children; +hierarchyRectangularNodeArrayOrUndefined = treemapRootNode.children; -let parentRectangularNode: d3Hierarchy.HierarchyRectangularNode; +let parentRectangularNode: d3Hierarchy.HierarchyRectangularNode | null; parentRectangularNode = hierarchyRectangularNodeArray.length ? hierarchyRectangularNodeArray[0].parent : null; +parentRectangularNode = hierarchyRectangularNodeArray[0].parent; // id -------------------------------------------------------------------- @@ -587,19 +601,19 @@ hierarchyRectangularNode = rectangularLink.target; treemapRootNode = treemapRootNode.sum((d) => d.val); -num = treemapRootNode.value; +numOrUndefined = treemapRootNode.value; // count() and value ---------------------------------------------------------- treemapRootNode = treemapRootNode.count(); -num = treemapRootNode.value; +numOrUndefined = treemapRootNode.value; // sort --------------------------------------------------------------------- treemapRootNode = treemapRootNode.sort((a, b) => { console.log('x0-coordinates of a:', a.x0, ' and b:', b.x0); // a and b are of type HierarchyRectangularNode console.log('Raw values in data of a and b:', a.data.val, ' and ', b.data.val); // a and b are of type HierarchyRectangularNode - return b.height - a.height || b.value - a.value; + return b.height - a.height || b.value! - a.value!; }); // each(), eachAfter(), eachBefore() ---------------------------------------- @@ -664,7 +678,9 @@ partitionRootNode = partitionLayout(stratifiedRootNode); // Pack // ----------------------------------------------------------------------- -let numberCircularNodeAccessor: (node: d3Hierarchy.HierarchyCircularNode) => number; +type CircularAccessor = (node: d3Hierarchy.HierarchyCircularNode) => number; +let numberCircularNodeAccessor: CircularAccessor; +let numberCircularNodeAccessorOrNull: CircularAccessor | null; // Create pack layout generator ======================================= @@ -682,13 +698,15 @@ size = packLayout.size(); // radius() ------------------------------------------------------------ +packLayout = packLayout.radius(null); + packLayout = packLayout.radius((node) => { console.log('Radius property of node before completing accessor: ', node.r); // node is of type HierarchyCircularNode console.log('Parent id of node: ', node.data.parentId); // node is of type HierarchyCircularNode - return node.value; + return node.value!; }); -numberCircularNodeAccessor = packLayout.radius(); +numberCircularNodeAccessorOrNull = packLayout.radius(); // padding() ---------------------------------------------------------------- @@ -697,7 +715,7 @@ packLayout = packLayout.padding(1); packLayout = packLayout.padding((node) => { console.log('Radius property of node: ', node.r); // node is of type HierarchyCircularNode console.log('Parent id of node: ', node.data.parentId); // node is of type HierarchyCircularNode - return node.value > 10 ? 2 : 1; + return node.value! > 10 ? 2 : 1; }); numberCircularNodeAccessor = packLayout.padding(); @@ -724,10 +742,11 @@ num = packRootNode.height; // children, parent ------------------------------------------------------ -hierarchyCircularNodeArray = packRootNode.children; +hierarchyCircularNodeArrayOrUndefined = packRootNode.children; -let parentCircularNode: d3Hierarchy.HierarchyCircularNode; +let parentCircularNode: d3Hierarchy.HierarchyCircularNode | null; parentCircularNode = hierarchyCircularNodeArray.length ? hierarchyCircularNodeArray[0].parent : null; +parentCircularNode = hierarchyCircularNodeArray[0].parent; // id -------------------------------------------------------------------- @@ -764,19 +783,20 @@ hierarchyCircularNode = circularLink.target; packRootNode = packRootNode.sum((d) => d.val); -num = packRootNode.value; +numOrUndefined = packRootNode.value; // count() and value ---------------------------------------------------------- packRootNode = packRootNode.count(); -num = packRootNode.value; +numOrUndefined = packRootNode.value; + // sort --------------------------------------------------------------------- packRootNode = packRootNode.sort((a, b) => { console.log('radius of a:', a.r, ' and b:', b.r); // a and b are of type HierarchyCircularNode console.log('Raw values in data of a and b:', a.data.val, ' and ', b.data.val); // a and b are of type HierarchyCircularNode - return b.height - a.height || b.value - a.value; + return b.height - a.height || b.value! - a.value!; }); // each(), eachAfter(), eachBefore() ---------------------------------------- diff --git a/types/d3-hierarchy/index.d.ts b/types/d3-hierarchy/index.d.ts index bdb7b652d5..31209377b9 100644 --- a/types/d3-hierarchy/index.d.ts +++ b/types/d3-hierarchy/index.d.ts @@ -154,7 +154,7 @@ export interface HierarchyNode { * Must return an array of data representing the children, and return null or undefined if the current datum has no children. * If children is not specified, it defaults to: `(d) => d.children`. */ -export function hierarchy(data: Datum, children?: (d: Datum) => (Datum[] | null)): HierarchyNode; +export function hierarchy(data: Datum, children?: (d: Datum) => (Datum[] | null | undefined)): HierarchyNode; // ----------------------------------------------------------------------- // Stratify @@ -182,7 +182,7 @@ export interface StratifyOperator { * * @param id The id accessor. */ - id(id: (d: Datum, i?: number, data?: Datum[]) => (string | null | '' | undefined)): this; + id(id: (d: Datum, i: number, data: Datum[]) => (string | null | '' | undefined)): this; /** * Returns the current parent id accessor, which defaults to: `(d) => d.parentId`. @@ -197,7 +197,7 @@ export interface StratifyOperator { * * @param parentId The parent id accessor. */ - parentId(parentId: (d: Datum, i?: number, data?: Datum[]) => (string | null | '' | undefined)): this; + parentId(parentId: (d: Datum, i: number, data: Datum[]) => (string | null | '' | undefined)): this; } /** @@ -748,7 +748,7 @@ export interface PackLayout { * * @param radius The specified radius accessor. */ - radius(radius: (node: HierarchyCircularNode) => number): this; + radius(radius: null | ((node: HierarchyCircularNode) => number)): this; /** * Returns the current size, which defaults to [1, 1]. diff --git a/types/d3-hierarchy/tsconfig.json b/types/d3-hierarchy/tsconfig.json index 7fbc1fb5df..da64c5832c 100644 --- a/types/d3-hierarchy/tsconfig.json +++ b/types/d3-hierarchy/tsconfig.json @@ -7,7 +7,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ From 240bc77bf3b535144d6d3b2cf93056b27ab877c0 Mon Sep 17 00:00:00 2001 From: denis Date: Wed, 1 Aug 2018 11:41:54 +0200 Subject: [PATCH 02/25] 75 col dash --- types/d3-hierarchy/d3-hierarchy-tests.ts | 110 +++++++++++------------ types/d3-hierarchy/index.d.ts | 2 +- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/types/d3-hierarchy/d3-hierarchy-tests.ts b/types/d3-hierarchy/d3-hierarchy-tests.ts index 7e4181f822..16b372993d 100644 --- a/types/d3-hierarchy/d3-hierarchy-tests.ts +++ b/types/d3-hierarchy/d3-hierarchy-tests.ts @@ -104,17 +104,17 @@ idString = hierarchyRootNode.id; const ancestors: Array> = hierarchyRootNode.ancestors(); const descendants: Array> = hierarchyRootNode.descendants(); -// leaves() --------------------------------------------------------------- +// leaves() -------------------------------------------------------------- hierarchyNodeArray = hierarchyRootNode.leaves(); -// path() ------------------------------------------------------------------- +// path() ---------------------------------------------------------------- hierarchyNode = descendants[descendants.length - 1]; const path: Array> = hierarchyRootNode.path(hierarchyNode); -// links() and HierarchyLink<...> ------------------------------------------ +// links() and HierarchyLink<...> ---------------------------------------- let links: Array>; @@ -126,26 +126,26 @@ link = links[0]; hierarchyNode = link.source; hierarchyNode = link.target; -// sum() and value ---------------------------------------------------------- +// sum() and value ------------------------------------------------------- hierarchyRootNode = hierarchyRootNode.sum((d) => d.val); numOrUndefined = hierarchyRootNode.value; -// count() and value ---------------------------------------------------------- +// count() and value ----------------------------------------------------- hierarchyRootNode = hierarchyRootNode.count(); numOrUndefined = hierarchyRootNode.value; -// sort --------------------------------------------------------------------- +// sort ------------------------------------------------------------------ hierarchyRootNode = hierarchyRootNode.sort((a, b) => { console.log('Raw values in data of a and b:', a.data.val, ' and ', b.data.val); // a and b are of type HierarchyNode return b.height - a.height || b.value! - a.value!; }); -// each(), eachAfter(), eachBefore() ---------------------------------------- +// each(), eachAfter(), eachBefore() ------------------------------------- hierarchyRootNode = hierarchyRootNode.each((node) => { console.log('Raw value of node:', node.data.val); // node type is HierarchyNode @@ -162,7 +162,7 @@ hierarchyRootNode = hierarchyRootNode.eachBefore((node) => { console.log('Aggregated value of node:', node.value); // node type is HierarchyNode }); -// copy() -------------------------------------------------------------------- +// copy() ---------------------------------------------------------------- let copiedHierarchyNode: d3Hierarchy.HierarchyNode; copiedHierarchyNode = hierarchyRootNode.copy(); @@ -299,17 +299,17 @@ idString = clusterRootNode.id; const pointNodeAncestors: Array> = clusterRootNode.ancestors(); const pointNodeDescendants: Array> = clusterRootNode.descendants(); -// leaves() --------------------------------------------------------------- +// leaves() -------------------------------------------------------------- hierarchyPointNodeArray = clusterRootNode.leaves(); -// path() ------------------------------------------------------------------- +// path() ---------------------------------------------------------------- hierarchyPointNode = pointNodeDescendants[pointNodeDescendants.length - 1]; const clusterPath: Array> = clusterRootNode.path(hierarchyPointNode); -// links() and HierarchyPointLink<...> ------------------------------------------ +// links() and HierarchyPointLink<...> ----------------------------------- let pointLinks: Array>; @@ -321,19 +321,19 @@ pointLink = pointLinks[0]; hierarchyPointNode = pointLink.source; hierarchyPointNode = pointLink.target; -// sum() and value ---------------------------------------------------------- +// sum() and value ------------------------------------------------------- clusterRootNode = clusterRootNode.sum((d) => d.val); numOrUndefined = clusterRootNode.value; -// count() and value ---------------------------------------------------------- +// count() and value ----------------------------------------------------- clusterRootNode = clusterRootNode.count(); numOrUndefined = clusterRootNode.value; -// sort --------------------------------------------------------------------- +// sort ------------------------------------------------------------------ clusterRootNode = clusterRootNode.sort((a, b) => { console.log('x-coordinates of a:', a.x, ' and b:', b.x); // a and b are of type HierarchyPointNode @@ -341,7 +341,7 @@ clusterRootNode = clusterRootNode.sort((a, b) => { return b.height - a.height || b.value! - a.value!; }); -// each(), eachAfter(), eachBefore() ---------------------------------------- +// each(), eachAfter(), eachBefore() ------------------------------------- clusterRootNode = clusterRootNode.each((node) => { console.log('ParentId:', node.data.parentId); // node type is HierarchyPointNode @@ -358,7 +358,7 @@ clusterRootNode = clusterRootNode.eachBefore((node) => { console.log('X-coordinate of node:', node.x); // node type is HierarchyPointNode }); -// copy() -------------------------------------------------------------------- +// copy() ---------------------------------------------------------------- let copiedClusterNode: d3Hierarchy.HierarchyPointNode; copiedClusterNode = clusterRootNode.copy(); @@ -367,13 +367,13 @@ copiedClusterNode = clusterRootNode.copy(); // Tree // ----------------------------------------------------------------------- -// Create tree layout generator ======================================= +// Create tree layout generator ========================================== let treeLayout: d3Hierarchy.TreeLayout; treeLayout = d3Hierarchy.tree(); -// Configure tree layout generator ==================================== +// Configure tree layout generator ======================================= // size() ---------------------------------------------------------------- @@ -437,13 +437,13 @@ treemapLayout = treemapLayout.size([400, 200]); size = treemapLayout.size(); -// round() ------------------------------------------------------------ +// round() --------------------------------------------------------------- treemapLayout = treemapLayout.round(true); let roundFlag: boolean = treemapLayout.round(); -// padding() ---------------------------------------------------------------- +// padding() ------------------------------------------------------------- treemapLayout = treemapLayout.padding(1); treemapLayout = treemapLayout.padding((node) => { @@ -453,7 +453,7 @@ treemapLayout = treemapLayout.padding((node) => { numberRectangularNodeAccessor = treemapLayout.padding(); -// paddingInner() ---------------------------------------------------------------- +// paddingInner() -------------------------------------------------------- treemapLayout = treemapLayout.paddingInner(1); treemapLayout = treemapLayout.paddingInner((node) => { @@ -463,7 +463,7 @@ treemapLayout = treemapLayout.paddingInner((node) => { numberRectangularNodeAccessor = treemapLayout.paddingInner(); -// paddingOuter() ---------------------------------------------------------------- +// paddingOuter() -------------------------------------------------------- treemapLayout = treemapLayout.paddingOuter(1); treemapLayout = treemapLayout.paddingOuter((node) => { @@ -473,7 +473,7 @@ treemapLayout = treemapLayout.paddingOuter((node) => { numberRectangularNodeAccessor = treemapLayout.paddingOuter(); -// paddingTop() ---------------------------------------------------------------- +// paddingTop() ---------------------------------------------------------- treemapLayout = treemapLayout.paddingTop(1); treemapLayout = treemapLayout.paddingTop((node) => { @@ -483,7 +483,7 @@ treemapLayout = treemapLayout.paddingTop((node) => { numberRectangularNodeAccessor = treemapLayout.paddingTop(); -// paddingRight() ---------------------------------------------------------------- +// paddingRight() -------------------------------------------------------- treemapLayout = treemapLayout.paddingRight(1); treemapLayout = treemapLayout.paddingRight((node) => { @@ -493,7 +493,7 @@ treemapLayout = treemapLayout.paddingRight((node) => { numberRectangularNodeAccessor = treemapLayout.paddingRight(); -// paddingBottom() ---------------------------------------------------------------- +// paddingBottom() ------------------------------------------------------- treemapLayout = treemapLayout.paddingBottom(1); treemapLayout = treemapLayout.paddingBottom((node) => { @@ -503,7 +503,7 @@ treemapLayout = treemapLayout.paddingBottom((node) => { numberRectangularNodeAccessor = treemapLayout.paddingBottom(); -// paddingLeft() ---------------------------------------------------------------- +// paddingLeft() --------------------------------------------------------- treemapLayout = treemapLayout.paddingLeft(1); treemapLayout = treemapLayout.paddingLeft((node) => { @@ -543,7 +543,7 @@ tilingFactoryFn = d3Hierarchy.treemapResquarify.ratio(2); treemapLayout.tile(d3Hierarchy.treemapResquarify.ratio(2)); -// Use HierarchyRectangularNode ================================================ +// Use HierarchyRectangularNode ========================================== // x and y coordinates --------------------------------------------------- @@ -575,17 +575,17 @@ idString = treemapRootNode.id; const rectangularNodeAncestors: Array> = treemapRootNode.ancestors(); const rectangularNodeDescendants: Array> = treemapRootNode.descendants(); -// leaves() --------------------------------------------------------------- +// leaves() -------------------------------------------------------------- hierarchyRectangularNodeArray = treemapRootNode.leaves(); -// path() ------------------------------------------------------------------- +// path() ---------------------------------------------------------------- hierarchyRectangularNode = rectangularNodeDescendants[rectangularNodeDescendants.length - 1]; const treemapPath: Array> = treemapRootNode.path(hierarchyRectangularNode); -// links() and HierarchyRectangularLink<...> ------------------------------------------ +// links() and HierarchyRectangularLink<...> ----------------------------- let rectangularLinks: Array>; @@ -597,18 +597,18 @@ rectangularLink = rectangularLinks[0]; hierarchyRectangularNode = rectangularLink.source; hierarchyRectangularNode = rectangularLink.target; -// sum() and value ---------------------------------------------------------- +// sum() and value ------------------------------------------------------- treemapRootNode = treemapRootNode.sum((d) => d.val); numOrUndefined = treemapRootNode.value; -// count() and value ---------------------------------------------------------- +// count() and value ----------------------------------------------------- treemapRootNode = treemapRootNode.count(); numOrUndefined = treemapRootNode.value; -// sort --------------------------------------------------------------------- +// sort ------------------------------------------------------------------ treemapRootNode = treemapRootNode.sort((a, b) => { console.log('x0-coordinates of a:', a.x0, ' and b:', b.x0); // a and b are of type HierarchyRectangularNode @@ -616,7 +616,7 @@ treemapRootNode = treemapRootNode.sort((a, b) => { return b.height - a.height || b.value! - a.value!; }); -// each(), eachAfter(), eachBefore() ---------------------------------------- +// each(), eachAfter(), eachBefore() ------------------------------------- treemapRootNode = treemapRootNode.each((node) => { console.log('ParentId:', node.data.parentId); // node type is HierarchyRectangularNode @@ -633,7 +633,7 @@ treemapRootNode = treemapRootNode.eachBefore((node) => { console.log('X0-coordinate of node:', node.x0); // node type is HierarchyRectangularNode }); -// copy() -------------------------------------------------------------------- +// copy() ---------------------------------------------------------------- let copiedTreemapNode: d3Hierarchy.HierarchyRectangularNode; copiedTreemapNode = treemapRootNode.copy(); @@ -642,13 +642,13 @@ copiedTreemapNode = treemapRootNode.copy(); // Partition // ----------------------------------------------------------------------- -// Create partition layout generator ======================================= +// Create partition layout generator ===================================== let partitionLayout: d3Hierarchy.PartitionLayout; partitionLayout = d3Hierarchy.partition(); -// Configure partition layout generator ==================================== +// Configure partition layout generator ================================== // size() ---------------------------------------------------------------- @@ -656,19 +656,19 @@ partitionLayout = partitionLayout.size([400, 200]); size = partitionLayout.size(); -// round() ------------------------------------------------------------ +// round() --------------------------------------------------------------- partitionLayout = partitionLayout.round(true); roundFlag = partitionLayout.round(); -// padding() ---------------------------------------------------------------- +// padding() ------------------------------------------------------------- partitionLayout = partitionLayout.padding(1); num = partitionLayout.padding(); -// Use partition layout generator ========================================== +// Use partition layout generator ======================================== let partitionRootNode: d3Hierarchy.HierarchyRectangularNode; @@ -682,13 +682,13 @@ type CircularAccessor = (node: d3Hierarchy.HierarchyCircularNode; packLayout = d3Hierarchy.pack(); -// Configure pack layout generator ==================================== +// Configure pack layout generator ======================================= // size() ---------------------------------------------------------------- @@ -696,7 +696,7 @@ packLayout = packLayout.size([400, 400]); size = packLayout.size(); -// radius() ------------------------------------------------------------ +// radius() -------------------------------------------------------------- packLayout = packLayout.radius(null); @@ -708,7 +708,7 @@ packLayout = packLayout.radius((node) => { numberCircularNodeAccessorOrNull = packLayout.radius(); -// padding() ---------------------------------------------------------------- +// padding() ------------------------------------------------------------- packLayout = packLayout.padding(1); @@ -720,15 +720,15 @@ packLayout = packLayout.padding((node) => { numberCircularNodeAccessor = packLayout.padding(); -// Use partition layout generator ========================================== +// Use partition layout generator ======================================== let packRootNode: d3Hierarchy.HierarchyCircularNode; packRootNode = packLayout(stratifiedRootNode); -// Use HierarchyCircularNode ================================================ +// Use HierarchyCircularNode ============================================= -// x and y coordinates and radius r ------------------------------------------ +// x and y coordinates and radius r -------------------------------------- num = packRootNode.x; num = packRootNode.y; @@ -757,17 +757,17 @@ idString = packRootNode.id; const circularNodeAncestors: Array> = packRootNode.ancestors(); const circularNodeDescendants: Array> = packRootNode.descendants(); -// leaves() --------------------------------------------------------------- +// leaves() -------------------------------------------------------------- hierarchyCircularNodeArray = packRootNode.leaves(); -// path() ------------------------------------------------------------------- +// path() ---------------------------------------------------------------- hierarchyCircularNode = circularNodeDescendants[circularNodeDescendants.length - 1]; const packPath: Array> = packRootNode.path(hierarchyCircularNode); -// links() and HierarchyRectangularLink<...> ------------------------------------------ +// links() and HierarchyRectangularLink<...> ----------------------------- let circularLinks: Array>; @@ -779,19 +779,19 @@ circularLink = circularLinks[0]; hierarchyCircularNode = circularLink.source; hierarchyCircularNode = circularLink.target; -// sum() and value ---------------------------------------------------------- +// sum() and value ------------------------------------------------------- packRootNode = packRootNode.sum((d) => d.val); numOrUndefined = packRootNode.value; -// count() and value ---------------------------------------------------------- +// count() and value ----------------------------------------------------- packRootNode = packRootNode.count(); numOrUndefined = packRootNode.value; -// sort --------------------------------------------------------------------- +// sort ------------------------------------------------------------------ packRootNode = packRootNode.sort((a, b) => { console.log('radius of a:', a.r, ' and b:', b.r); // a and b are of type HierarchyCircularNode @@ -799,7 +799,7 @@ packRootNode = packRootNode.sort((a, b) => { return b.height - a.height || b.value! - a.value!; }); -// each(), eachAfter(), eachBefore() ---------------------------------------- +// each(), eachAfter(), eachBefore() ------------------------------------- packRootNode = packRootNode.each((node) => { console.log('ParentId:', node.data.parentId); // node type is HierarchyCircularNode @@ -816,7 +816,7 @@ packRootNode = packRootNode.eachBefore((node) => { console.log('Radius of node:', node.r); // node type is HierarchyCircularNode }); -// copy() -------------------------------------------------------------------- +// copy() ---------------------------------------------------------------- let copiedPackNode: d3Hierarchy.HierarchyCircularNode; copiedPackNode = packRootNode.copy(); diff --git a/types/d3-hierarchy/index.d.ts b/types/d3-hierarchy/index.d.ts index 31209377b9..0ec823cc78 100644 --- a/types/d3-hierarchy/index.d.ts +++ b/types/d3-hierarchy/index.d.ts @@ -576,7 +576,7 @@ export interface TreemapLayout { */ export function treemap(): TreemapLayout; -// Tiling functions ----------------------------------------------------------------------- +// Tiling functions ------------------------------------------------------ /** * Recursively partitions the specified nodes into an approximately-balanced binary tree, From df0a61ff6fd597db2670187a14994e0e44745a9c Mon Sep 17 00:00:00 2001 From: denis Date: Wed, 1 Aug 2018 13:07:39 +0200 Subject: [PATCH 03/25] `document.body` is possibly 'null' in TypeScript@next --- types/d3kit/d3kit-tests.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/types/d3kit/d3kit-tests.ts b/types/d3kit/d3kit-tests.ts index ec3b2de1ce..e8f66c71f2 100644 --- a/types/d3kit/d3kit-tests.ts +++ b/types/d3kit/d3kit-tests.ts @@ -64,7 +64,7 @@ function test_abstract_plate() { let sel: d3.Selection; // create a div, append to body, return Node as type Element - el = document.body.appendChild(document.createElement('div')) as Element; + el = document.body!.appendChild(document.createElement('div')) as Element; // create example of options margins = { top: 20, right: 20, bottom: 20, left: 20}; @@ -193,7 +193,7 @@ function test_abstract_chart() { let plate: d3kit.AbstractPlate; // create a div, append to body, return Node as type Element - el = document.body.appendChild(document.createElement('div')) as Element; + el = document.body!.appendChild(document.createElement('div')) as Element; // create examples of margins, offsets, options, fit options, watch options margins = { top: 20, right: 20, bottom: 20, left: 20}; @@ -285,7 +285,7 @@ function test_svg_chart() { let plate: d3kit.SvgPlate; // create a div, append to body, return Node as type Element - el = document.body.appendChild(document.createElement('div')) as Element; + el = document.body!.appendChild(document.createElement('div')) as Element; // create examples of margins, offsets, options, fit options, watch options margins = { top: 20, right: 20, bottom: 20, left: 20}; @@ -326,7 +326,7 @@ function test_canvas_chart() { let context: CanvasRenderingContext2D; // create a div, append to body, return Node as type Element - el = document.body.appendChild(document.createElement('div')) as Element; + el = document.body!.appendChild(document.createElement('div')) as Element; // create examples of margins, offsets, options, fit options, watch options margins = { top: 20, right: 20, bottom: 20, left: 20}; @@ -362,7 +362,7 @@ function test_hybrid_chart() { let context: CanvasRenderingContext2D; // create a div, append to body, return Node as type Element - el = document.body.appendChild(document.createElement('div')) as Element; + el = document.body!.appendChild(document.createElement('div')) as Element; // create examples of margins, offsets, options, fit options, watch options margins = { top: 20, right: 20, bottom: 20, left: 20}; From b8c03532114c64d9cc397f9ef4c2b8607229101f Mon Sep 17 00:00:00 2001 From: denis Date: Thu, 2 Aug 2018 11:30:02 +0200 Subject: [PATCH 04/25] CanvasPathMethods has been renamed CanvasPath --- types/d3-shape/d3-shape-tests.ts | 2 +- types/d3-shape/index.d.ts | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/types/d3-shape/d3-shape-tests.ts b/types/d3-shape/d3-shape-tests.ts index e668d152f8..8ad3e4809a 100644 --- a/types/d3-shape/d3-shape-tests.ts +++ b/types/d3-shape/d3-shape-tests.ts @@ -1184,7 +1184,7 @@ interface SymbolDatum { let customSymbol: d3Shape.SymbolType; customSymbol = { - draw(context: CanvasPathMethods, size: number): void { + draw(context: d3Shape.CanvasPath_D3Shape, size: number): void { // draw custom symbol using canvas path methods } }; diff --git a/types/d3-shape/index.d.ts b/types/d3-shape/index.d.ts index 47e5c10feb..83222d0ff0 100644 --- a/types/d3-shape/index.d.ts +++ b/types/d3-shape/index.d.ts @@ -7,6 +7,27 @@ import { Path } from 'd3-path'; +// ----------------------------------------------------------------------------------- +// Shared Types and Interfaces +// ----------------------------------------------------------------------------------- + +/** + * @deprecated + * This interface is used to bridge the gap between two incompatible versions of TypeScript (see [#25944](https://github.com/Microsoft/TypeScript/pull/25944)). + * Use `CanvasPathMethods` instead with TS <= 3.0 and `CanvasPath` with TS >= 3.1. + */ +export interface CanvasPath_D3Shape { + arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void; + arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void; + bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void; + closePath(): void; + ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void; + lineTo(x: number, y: number): void; + moveTo(x: number, y: number): void; + quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void; + rect(x: number, y: number, w: number, h: number): void; +} + // ----------------------------------------------------------------------------------- // Arc Generator // ----------------------------------------------------------------------------------- @@ -2264,13 +2285,13 @@ export function linkRadial(): LinkRadial Date: Tue, 7 Aug 2018 10:27:40 +0200 Subject: [PATCH 05/25] `document.body` is not 'null' anymore in TypeScript@next --- types/d3kit/d3kit-tests.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/types/d3kit/d3kit-tests.ts b/types/d3kit/d3kit-tests.ts index e8f66c71f2..ec3b2de1ce 100644 --- a/types/d3kit/d3kit-tests.ts +++ b/types/d3kit/d3kit-tests.ts @@ -64,7 +64,7 @@ function test_abstract_plate() { let sel: d3.Selection; // create a div, append to body, return Node as type Element - el = document.body!.appendChild(document.createElement('div')) as Element; + el = document.body.appendChild(document.createElement('div')) as Element; // create example of options margins = { top: 20, right: 20, bottom: 20, left: 20}; @@ -193,7 +193,7 @@ function test_abstract_chart() { let plate: d3kit.AbstractPlate; // create a div, append to body, return Node as type Element - el = document.body!.appendChild(document.createElement('div')) as Element; + el = document.body.appendChild(document.createElement('div')) as Element; // create examples of margins, offsets, options, fit options, watch options margins = { top: 20, right: 20, bottom: 20, left: 20}; @@ -285,7 +285,7 @@ function test_svg_chart() { let plate: d3kit.SvgPlate; // create a div, append to body, return Node as type Element - el = document.body!.appendChild(document.createElement('div')) as Element; + el = document.body.appendChild(document.createElement('div')) as Element; // create examples of margins, offsets, options, fit options, watch options margins = { top: 20, right: 20, bottom: 20, left: 20}; @@ -326,7 +326,7 @@ function test_canvas_chart() { let context: CanvasRenderingContext2D; // create a div, append to body, return Node as type Element - el = document.body!.appendChild(document.createElement('div')) as Element; + el = document.body.appendChild(document.createElement('div')) as Element; // create examples of margins, offsets, options, fit options, watch options margins = { top: 20, right: 20, bottom: 20, left: 20}; @@ -362,7 +362,7 @@ function test_hybrid_chart() { let context: CanvasRenderingContext2D; // create a div, append to body, return Node as type Element - el = document.body!.appendChild(document.createElement('div')) as Element; + el = document.body.appendChild(document.createElement('div')) as Element; // create examples of margins, offsets, options, fit options, watch options margins = { top: 20, right: 20, bottom: 20, left: 20}; From 06bd28a44f40472d00eebc7d177775f876cd2ca1 Mon Sep 17 00:00:00 2001 From: chenshidong Date: Sun, 12 Aug 2018 00:16:31 +0800 Subject: [PATCH 06/25] feat(better-scroll): add typings --- notNeededPackages.json | 6 - types/better-scroll/better-scroll-tests.ts | 68 ++++++ types/better-scroll/index.d.ts | 238 +++++++++++++++++++++ types/better-scroll/tsconfig.json | 24 +++ types/better-scroll/tslint.json | 1 + 5 files changed, 331 insertions(+), 6 deletions(-) create mode 100644 types/better-scroll/better-scroll-tests.ts create mode 100644 types/better-scroll/index.d.ts create mode 100644 types/better-scroll/tsconfig.json create mode 100644 types/better-scroll/tslint.json diff --git a/notNeededPackages.json b/notNeededPackages.json index f630c4e59e..8cb8b15fe4 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -156,12 +156,6 @@ "sourceRepoURL": "https://github.com/brianloveswords/base64url", "asOfVersion": "2.0.0" }, - { - "libraryName": "better-scroll", - "typingsPackageName": "better-scroll", - "sourceRepoURL": "https://github.com/ustbhuangyi/better-scroll", - "asOfVersion": "1.5.0" - }, { "libraryName": "BigInteger.js", "typingsPackageName": "big-integer", diff --git a/types/better-scroll/better-scroll-tests.ts b/types/better-scroll/better-scroll-tests.ts new file mode 100644 index 0000000000..282e6185ab --- /dev/null +++ b/types/better-scroll/better-scroll-tests.ts @@ -0,0 +1,68 @@ +import BScroll from 'better-scroll'; + +const BScroll1 = new BScroll('#wrapper'); +const BScroll2 = new BScroll('#wrapper', { scrollX: false, scrollY: false }); +const BScroll3 = new BScroll('#wrapper', { + snap: true, + wheel: false, + scrollbar: false, + pullDownRefresh: false, +}); +const BScroll4 = new BScroll('#wrapper', { + wheel: { + selectedIndex: 0, + }, +}); +const BScroll6 = new BScroll('#wrapper', { + snap: { + loop: false, + el: document.querySelector('div-test') as Element, + threshold: 0.1, + stepX: 100, + stepY: 100, + listenFlick: true, + }, +}); +const BScroll7 = new BScroll('#wrapper', { + scrollbar: { + fade: true, + }, +}); + +const BScroll8 = new BScroll('#wrapper', { + pullDownRefresh: { + threshold: 50, + stop: 20, + }, +}); + +BScroll1.refresh(); +BScroll1.scrollTo(0, 100); +BScroll1.scrollTo(0, 100, 200); + +BScroll1.scrollToElement('selectedElement'); +BScroll1.scrollToElement('selectedElement', 250); + +BScroll1.scrollToElement(document.getElementById('selectedElement') as HTMLElement); +BScroll1.scrollToElement(document.getElementById('selectedElement') as HTMLElement, 250); + +BScroll2.on('scrollStart', () => { console.log('scroll started'); }); + +const BScroll9 = new BScroll(document.getElementById('wrapper') as HTMLElement); +const BScroll10 = new BScroll(document.getElementById('wrapper') as HTMLElement, { freeScroll: true }); +const BScroll11 = new BScroll(document.getElementById('wrapper') as HTMLElement, { + preventDefaultException: { + tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/, + }, +}); +const BScroll12 = new BScroll(document.getElementById('wrapper') as HTMLElement, { + preventDefaultException: { + className: /(^|\s)test(\s|$)/, + }, +}); + +const BScroll13 = new BScroll(document.getElementById('wrapper') as HTMLElement, { + swipeBounceTime: 1000, +}); + +const BScroll14 = new BScroll('#wrapper', { disableMouse: true, disableTouch: false }); diff --git a/types/better-scroll/index.d.ts b/types/better-scroll/index.d.ts new file mode 100644 index 0000000000..4ce8b2a4c1 --- /dev/null +++ b/types/better-scroll/index.d.ts @@ -0,0 +1,238 @@ +// Type definitions for better-scroll 1.12 +// Project: https://github.com/ustbhuangyi/better-scroll +// Definitions by: My Self +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// TypeScript Version: 2.2 +export interface WheelOption { + selectedIndex: number; + rotate: number; + adjustTime: number; + wheelWrapperClass: string; + wheelItemClass: string; +} + +export interface PageOption { + x: number; + y: number; + pageX: number; + pageY: number; +} + +export interface SlideOption { + loop: boolean; + el: Element; + threshold: number; + stepX: number; + stepY: number; + speed: number; + listenFlick: boolean; +} + +export interface ScrollBarOption { + fade: boolean; +} + +export interface PullDownOption { + threshold: number; + stop: number; +} + +export interface PullUpOption { + threshold: number; +} + +export interface BounceObjectOption { + top?: boolean; + bottom?: boolean; + left?: boolean; + right?: boolean; +} + +export interface EaseOption { + swipe?: { + style: string; + fn: (t: number) => number; + }; + swipeBounce?: { + style: string; + fn: (t: number) => number; + }; + bounce?: { + style: string; + fn: (t: number) => number; + }; +} + +export interface BsOption { + startX: number; + startY: number; + scrollX: boolean; + scrollY: boolean; + freeScroll: boolean; + directionLockThreshold: number; + eventPassthrough: string | boolean; + click: boolean; + tap: boolean; + bounce: boolean | BounceObjectOption; + bounceTime: number; + momentum: boolean; + momentumLimitTime: number; + momentumLimitDistance: number; + swipeTime: number; + swipeBounceTime: number; + deceleration: number; + flickLimitTime: number; + flickLimitDistance: number; + resizePolling: number; + probeType: number; + preventDefault: boolean; + preventDefaultException: object; + HWCompositing: boolean; + useTransition: boolean; + useTransform: boolean; + bindToWrapper: boolean; + disableMouse: boolean; + disableTouch: boolean; + observeDOM: boolean; + autoBlur: boolean; + stopPropagation: boolean; + /** + * for picker + * wheel: { + * selectedIndex: 0, + * rotate: 25, + * adjustTime: 400 + * } + */ + wheel: Partial | boolean; + /** + * for slide + * snap: { + * loop: boolean, + * el: domEl, + * threshold: 0.1, + * stepX: 100, + * stepY: 100, + * listenFlick: true + * } + */ + snap: Partial | boolean; + /** + * for scrollbar + * scrollbar: { + * fade: true + * } + */ + scrollbar: Partial | boolean; + /** + * for pull down and refresh + * pullDownRefresh: { + * threshold: 50, + * stop: 20 + * } + */ + pullDownRefresh: Partial | boolean; + /** + * for pull up and load + * pullUpLoad: { + * threshold: 50 + * } + */ + pullUpLoad: Partial | boolean; +} + +export interface Position { + x: number; + y: number; +} + +export default class BScroll { + constructor(element: Element | string, options?: Partial); + + x: number; + y: number; + maxScrollX: number; + maxScrollY: number; + movingDirectionX: number; + movingDirectionY: number; + directionX: number; + directionY: number; + enabled: boolean; + isInTransition: boolean; + isAnimating: boolean; + options: BsOption; + + refresh(): void; + + enable(): void; + + disable(): void; + + scrollBy(x: number, y: number, time?: number, easing?: object): void; + + scrollTo(x: number, y: number, time?: number, easing?: object): void; + + scrollToElement(el: HTMLElement | string, time?: number, offsetX?: number | boolean, offsetY?: number | boolean, easing?: object): void; + + stop(): void; + + destroy(): void; + + goToPage(x: number, y: number, time?: number, easing?: object): void; + + next(time?: number, easing?: object): void; + + prev(time?: number, easing?: object): void; + + getCurrentPage(): PageOption; + + wheelTo(index: number): void; + + getSelectedIndex(): number; + + finishPullDown(): void; + + finishPullUp(): void; + + on( + type: + 'beforeScrollStart' | + 'scrollStart' | + 'scrollCancel' | + 'beforeScrollStart' | + 'flick' | + 'refresh' | + 'destroy' | + 'pullingDown' | + 'pullingUp', + fn: () => any + ): void; + + on( + type: + 'scroll' | + 'scrollEnd' | + 'touchEnd', + fn: (pos: Position) => any + ): void; + + off( + type: + 'beforeScrollStart' | + 'scrollStart' | + 'scroll' | + 'scrollCancel' | + 'beforeScrollStart' | + 'scrollEnd' | + 'touchEnd' | + 'flick' | + 'refresh' | + 'destroy' | + 'pullingDown' | + 'pullingUp', + fn: (...args: any[]) => void + ): void; + + trigger(type: string): void; +} diff --git a/types/better-scroll/tsconfig.json b/types/better-scroll/tsconfig.json new file mode 100644 index 0000000000..26f43ee3bd --- /dev/null +++ b/types/better-scroll/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "better-scroll-tests.ts" + ] +} diff --git a/types/better-scroll/tslint.json b/types/better-scroll/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/better-scroll/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 49d55176a9959b92cde2cb6479773e5eb8709378 Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Mon, 13 Aug 2018 15:14:43 +0200 Subject: [PATCH 07/25] Add JSON5 missing type --- types/json5/index.d.ts | 15 ++++++++++++++- types/json5/json5-tests.ts | 20 +++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/types/json5/index.d.ts b/types/json5/index.d.ts index a8fc723b60..8c53949a28 100644 --- a/types/json5/index.d.ts +++ b/types/json5/index.d.ts @@ -40,5 +40,18 @@ Comments Both inline (single-line) and block (multi-line) comments are allowed. */ -declare var json5: JSON; + +type JSONReplacer = (key: string, value: any) => any | (number | string)[] | null; + +interface JSON5 { + // Old JSON methods + parse(text: string, reviver?: (key: any, value: any) => any): any; + stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; + stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; + + // New JSON5 stringify function + stringify(value: any, options?: { space?: number | string, quote?: string, replacer?: JSONReplacer }): string; +} + +declare var json5: JSON5; export = json5; diff --git a/types/json5/json5-tests.ts b/types/json5/json5-tests.ts index f1be5b1038..b92065ccb0 100644 --- a/types/json5/json5-tests.ts +++ b/types/json5/json5-tests.ts @@ -1,7 +1,21 @@ import JSON5 = require('json5'); -var obj = JSON5.parse("{ key:'val', 'key2':[0,1,2,] } //comment "); -var str = JSON5.stringify(obj, null, "\t"); -console.log(str); +const STR = "{ key:'val', 'key2':[0,1,2,] } //comment "; +const OBJ = { key: 'value', key2: [0, 1, 2] }; +function reviverFunction(key: any, value: any): any { + return { [key]: value }; +} + +function replacerFunction(key: string, value: any) { + return { [key]: value }; +} + +const str1: string = JSON5.stringify(OBJ); +const str2: string = JSON5.stringify(OBJ, null, 4); +const str3: string = JSON5.stringify(OBJ, undefined, '2'); +const str4: string = JSON5.stringify(OBJ, replacerFunction, 2); + +JSON.parse(STR); +JSON.parse(STR, reviverFunction); From 8914773fd7787f89c6ca26bdf86bdb0ccfdd5e99 Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Mon, 13 Aug 2018 15:18:40 +0200 Subject: [PATCH 08/25] Add author --- types/json5/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/json5/index.d.ts b/types/json5/index.d.ts index 8c53949a28..87bda70a2e 100644 --- a/types/json5/index.d.ts +++ b/types/json5/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for JSON5 // Project: http://json5.org/ // Definitions by: Jason Swearingen +// Kacper Wiszczuk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped From 925a3c466591c17379a1a8f9ac63d2fe6726905b Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Mon, 13 Aug 2018 15:27:11 +0200 Subject: [PATCH 09/25] Indentation fixes --- types/json5/index.d.ts | 12 ++++++------ types/json5/json5-tests.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/types/json5/index.d.ts b/types/json5/index.d.ts index 87bda70a2e..9c0cb6cde6 100644 --- a/types/json5/index.d.ts +++ b/types/json5/index.d.ts @@ -45,13 +45,13 @@ Both inline (single-line) and block (multi-line) comments are allowed. type JSONReplacer = (key: string, value: any) => any | (number | string)[] | null; interface JSON5 { - // Old JSON methods - parse(text: string, reviver?: (key: any, value: any) => any): any; - stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; - stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; + // Old JSON methods + parse(text: string, reviver?: (key: any, value: any) => any): any; + stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; + stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; - // New JSON5 stringify function - stringify(value: any, options?: { space?: number | string, quote?: string, replacer?: JSONReplacer }): string; + // New JSON5 stringify function + stringify(value: any, options?: { space?: number | string, quote?: string, replacer?: JSONReplacer }): string; } declare var json5: JSON5; diff --git a/types/json5/json5-tests.ts b/types/json5/json5-tests.ts index b92065ccb0..94820866f8 100644 --- a/types/json5/json5-tests.ts +++ b/types/json5/json5-tests.ts @@ -5,11 +5,11 @@ const STR = "{ key:'val', 'key2':[0,1,2,] } //comment "; const OBJ = { key: 'value', key2: [0, 1, 2] }; function reviverFunction(key: any, value: any): any { - return { [key]: value }; + return { [key]: value }; } function replacerFunction(key: string, value: any) { - return { [key]: value }; + return { [key]: value }; } const str1: string = JSON5.stringify(OBJ); From 44137946547fdaf58a7e51b95e768d2eb4229c0c Mon Sep 17 00:00:00 2001 From: Elizabeth Samuel Date: Wed, 15 Aug 2018 14:10:17 -0700 Subject: [PATCH 10/25] office-js: Outlook API in preview --- types/office-js/index.d.ts | 195 +++++++++++++++++++++++++++++++------ 1 file changed, 167 insertions(+), 28 deletions(-) diff --git a/types/office-js/index.d.ts b/types/office-js/index.d.ts index 8d89d895f6..8283752230 100644 --- a/types/office-js/index.d.ts +++ b/types/office-js/index.d.ts @@ -1743,6 +1743,14 @@ declare namespace Office { * */ ActiveViewChanged, + /** + * Triggers when the appointment date or time of the selected series was changed in Outlook. + * + * [Api set: Mailbox Preview] + * + * @beta + */ + AppointmentTimeChanged, /** * Occurs when data within the binding is changed. * To add an event handler for the BindingDataChanged event of a binding, use the addHandlerAsync method of the Binding object. @@ -1830,6 +1838,14 @@ declare namespace Office { * Triggers when a customXmlPart node was replaced. */ NodeReplaced, + /** + * Triggers when the recipient list of the selected series was changed in Outlook. + * + * [Api set: Mailbox Preview] + * + * @beta + */ + RecipientsChanged, /** * Triggers when the recurrence pattern of the selected series was changed in Outlook. * @@ -8691,7 +8707,41 @@ declare namespace Office { } /** - * The subclass of {@link Office.Item} dealing with apppointments. + * Provides a method to get the organizer value of an appointment in an Outlook add-in. + * + * [Api set: Mailbox Preview] + * + * @remarks + * + * + *
{@link https://docs.microsoft.com/outlook/add-ins/understanding-outlook-add-in-permissions | Minimum permission level}ReadItem
{@link https://docs.microsoft.com/outlook/add-ins/#extension-points | Applicable Outlook mode}Compose
+ * + * @beta + */ + export interface Organizer { + /** + * Gets the organizer value of an appointment. + * + * The getAsync method starts an asynchronous call to the Exchange server to get the organizer value of an appointment. + * + * The organizer value of the item is provided as an {@link Office.EmailAddressDetails} in the asyncResult.value property. + * + * [Api set: Mailbox Preview] + * + * @remarks + * + * + *
{@link https://docs.microsoft.com/outlook/add-ins/understanding-outlook-add-in-permissions | Minimum permission level}ReadItem
{@link https://docs.microsoft.com/outlook/add-ins/#extension-points | Applicable Outlook mode}Compose
+ * + * @param options An object literal that contains one or more of the following properties. + * asyncContext: Developers can provide any object they wish to access in the callback method. + * @param callback When the method completes, the function passed in the callback parameter is called with a single parameter, asyncResult, which is an AsyncResult object. + */ + getAsync(options?: Office.AsyncContextOptions, callback?: (result: AsyncResult) => void): void; + } + + /** + * The subclass of {@link Office.Item} dealing with appointments. * * Important: This is an internal Outlook object, not directly exposed through existing interfaces. You should treat this as a mode of Office.context.mailbox.item. Refer to the Object Model pages for more information. */ @@ -8807,6 +8857,22 @@ declare namespace Office { * {@link https://docs.microsoft.com/outlook/add-ins/#extension-points | Applicable Outlook mode}Appointment Organizer */ optionalAttendees: Recipients; + /** + * Gets the email address of the organizer for the specified meeting. + * + * The organizer property returns an Organizer object that provides a method to get the organizer value. + * + * [Api set: Mailbox Preview] + * + * @remarks + * + * + * + *
{@link https://docs.microsoft.com/outlook/add-ins/understanding-outlook-add-in-permissions | Minimum permission level}ReadItem
{@link https://docs.microsoft.com/outlook/add-ins/#extension-points | Applicable Outlook mode}Appointment Organizer
+ * + * @beta + */ + organizer: Office.Organizer; /** * Gets or sets the recurrence pattern of an appointment. * @@ -8919,7 +8985,7 @@ declare namespace Office { * @param attachmentName The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters. * @param options Optional. An object literal that contains one or more of the following properties. * asyncContext: Developers can provide any object they wish to access in the callback method. - * inInline: If true, indicates that the attachment will be shown inline in the message body, and should not be displayed in the attachment list. + * isInline: If true, indicates that the attachment will be shown inline in the message body and should not be displayed in the attachment list. * @param callback When the method completes, the function passed in the callback parameter is called with a single parameter of type asyncResult. On success, the attachment identifier will be provided in the asyncResult.value property. If uploading the attachment fails, the asyncResult object will contain an Error object that provides a description of the error. */ addFileAttachmentAsync(uri: string, attachmentName: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult) => void): void; @@ -8963,7 +9029,7 @@ declare namespace Office { * @param attachmentName The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters. * @param options Optional. An object literal that contains one or more of the following properties. * asyncContext: Developers can provide any object they wish to access in the callback method. - * inInline: If true, indicates that the attachment will be shown inline in the message body, and should not be displayed in the attachment list. + * isInline: If true, indicates that the attachment will be shown inline in the message body and should not be displayed in the attachment list. */ addFileAttachmentAsync(uri: string, attachmentName: string, options: Office.AsyncContextOptions): void; /** @@ -8987,10 +9053,34 @@ declare namespace Office { * @param callback When the method completes, the function passed in the callback parameter is called with a single parameter of type asyncResult. On success, the attachment identifier will be provided in the asyncResult.value property. If uploading the attachment fails, the asyncResult object will contain an Error object that provides a description of the error. */ addFileAttachmentAsync(uri: string, attachmentName: string, callback: (result: AsyncResult) => void): void; + /** + * Adds a file to a message or appointment as an attachment. + * + * The addFileAttachmentFromBase64Async method uploads the file from the base64 encoding and attaches it to the item in the compose form. This method returns the attachment identifier in the AsyncResult.value object. + * + * You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session. + * + * [Api set: Mailbox Preview] + * + * @remarks + * + * + * + * + *
{@link https://docs.microsoft.com/outlook/add-ins/understanding-outlook-add-in-permissions | Minimum permission level}ReadWriteItem
{@link https://docs.microsoft.com/outlook/add-ins/#extension-points | Applicable Outlook mode}Appointment Organizer
ErrorsAttachmentSizeExceeded - The attachment is larger than allowed.
FileTypeNotSupported - The attachment has an extension that is not allowed.
NumberOfAttachmentsExceeded - The message or appointment has too many attachments.
+ * + * @param base64File The base64 encoded content of an image or file to be added to an email or event. + * @param attachmentName The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters. + * @param options Optional. An object literal that contains one or more of the following properties. + * asyncContext: Developers can provide any object they wish to access in the callback method. + * isInline: If true, indicates that the attachment will be shown inline in the message body and should not be displayed in the attachment list. + * @param callback When the method completes, the function passed in the callback parameter is called with a single parameter of type asyncResult. On success, the attachment identifier will be provided in the asyncResult.value property. If uploading the attachment fails, the asyncResult object will contain an Error object that provides a description of the error. + */ + addFileAttachmentFromBase64Async(base64File: string, attachmentName: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult) => void): void; /** * Adds an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -9016,7 +9106,7 @@ declare namespace Office { /** * Adds an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -9331,7 +9421,7 @@ declare namespace Office { /** * Removes an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -9357,7 +9447,7 @@ declare namespace Office { /** * Removes an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -9782,7 +9872,7 @@ declare namespace Office { */ optionalAttendees: EmailAddressDetails[]; /** - * Gets the email address of the meeting organizer for a specified meeting. Read mode only. + * Gets the email address of the meeting organizer for a specified meeting. * * [Api set: Mailbox 1.0] * @@ -9881,7 +9971,7 @@ declare namespace Office { /** * Adds an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -9908,7 +9998,7 @@ declare namespace Office { /** * Adds an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -10218,7 +10308,7 @@ declare namespace Office { /** * Removes an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -10244,7 +10334,7 @@ declare namespace Office { /** * Removes an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -10384,7 +10474,7 @@ declare namespace Office { /** * Adds an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -10411,7 +10501,7 @@ declare namespace Office { /** * Adds an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -10452,7 +10542,7 @@ declare namespace Office { /** * Removes an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -10479,7 +10569,7 @@ declare namespace Office { /** * Removes an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -10547,7 +10637,7 @@ declare namespace Office { * @param attachmentName The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters. * @param options Optional. An object literal that contains one or more of the following properties. * asyncContext: Developers can provide any object they wish to access in the callback method. - * inInline: If true, indicates that the attachment will be shown inline in the message body, and should not be displayed in the attachment list. + * isInline: If true, indicates that the attachment will be shown inline in the message body and should not be displayed in the attachment list. * @param callback When the method completes, the function passed in the callback parameter is called with a single parameter of type asyncResult. On success, the attachment identifier will be provided in the asyncResult.value property. If uploading the attachment fails, the asyncResult object will contain an Error object that provides a description of the error. */ addFileAttachmentAsync(uri: string, attachmentName: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult) => void): void; @@ -10591,7 +10681,7 @@ declare namespace Office { * @param attachmentName The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters. * @param options Optional. An object literal that contains one or more of the following properties. * asyncContext: Developers can provide any object they wish to access in the callback method. - * inInline: If true, indicates that the attachment will be shown inline in the message body, and should not be displayed in the attachment list. + * isInline: If true, indicates that the attachment will be shown inline in the message body and should not be displayed in the attachment list. */ addFileAttachmentAsync(uri: string, attachmentName: string, options: Office.AsyncContextOptions): void; /** @@ -10616,6 +10706,31 @@ declare namespace Office { */ addFileAttachmentAsync(uri: string, attachmentName: string, callback: (result: AsyncResult) => void): void; + /** + * Adds a file to a message or appointment as an attachment. + * + * The addFileAttachmentFromBase64Async method uploads the file from the base64 encoding and attaches it to the item in the compose form. This method returns the attachment identifier in the AsyncResult.value object. + * + * You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session. + * + * [Api set: Mailbox Preview] + * + * @remarks + * + * + * + * + *
{@link https://docs.microsoft.com/outlook/add-ins/understanding-outlook-add-in-permissions | Minimum permission level}ReadWriteItem
{@link https://docs.microsoft.com/outlook/add-ins/#extension-points | Applicable Outlook mode}Appointment Organizer
ErrorsAttachmentSizeExceeded - The attachment is larger than allowed.
FileTypeNotSupported - The attachment has an extension that is not allowed.
NumberOfAttachmentsExceeded - The message or appointment has too many attachments.
+ * + * @param base64File The base64 encoded content of an image or file to be added to an email or event. + * @param attachmentName The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters. + * @param options Optional. An object literal that contains one or more of the following properties. + * asyncContext: Developers can provide any object they wish to access in the callback method. + * isInline: If true, indicates that the attachment will be shown inline in the message body and should not be displayed in the attachment list. + * @param callback When the method completes, the function passed in the callback parameter is called with a single parameter of type asyncResult. On success, the attachment identifier will be provided in the asyncResult.value property. If uploading the attachment fails, the asyncResult object will contain an Error object that provides a description of the error. + */ + addFileAttachmentFromBase64Async(base64File: string, attachmentName: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult) => void): void; + /** * Adds an Exchange item, such as a message, as an attachment to the message or appointment. * @@ -11730,7 +11845,7 @@ declare namespace Office { * @param attachmentName The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters. * @param options Optional. An object literal that contains one or more of the following properties. * asyncContext: Developers can provide any object they wish to access in the callback method. - * inInline: If true, indicates that the attachment will be shown inline in the message body, and should not be displayed in the attachment list. + * isInline: If true, indicates that the attachment will be shown inline in the message body and should not be displayed in the attachment list. * @param callback When the method completes, the function passed in the callback parameter is called with a single parameter of type asyncResult. On success, the attachment identifier will be provided in the asyncResult.value property. If uploading the attachment fails, the asyncResult object will contain an Error object that provides a description of the error. */ addFileAttachmentAsync(uri: string, attachmentName: string, options?: AsyncContextOptions, callback?: (result: AsyncResult) => void): void; @@ -11774,7 +11889,7 @@ declare namespace Office { * @param attachmentName The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters. * @param options Optional. An object literal that contains one or more of the following properties. * asyncContext: Developers can provide any object they wish to access in the callback method. - * inInline: If true, indicates that the attachment will be shown inline in the message body, and should not be displayed in the attachment list. + * isInline: If true, indicates that the attachment will be shown inline in the message body and should not be displayed in the attachment list. */ addFileAttachmentAsync(uri: string, attachmentName: string, options: AsyncContextOptions): void; /** @@ -11798,10 +11913,34 @@ declare namespace Office { * @param callback When the method completes, the function passed in the callback parameter is called with a single parameter of type asyncResult. On success, the attachment identifier will be provided in the asyncResult.value property. If uploading the attachment fails, the asyncResult object will contain an Error object that provides a description of the error. */ addFileAttachmentAsync(uri: string, attachmentName: string, callback: (result: AsyncResult) => void): void; + /** + * Adds a file to a message or appointment as an attachment. + * + * The addFileAttachmentFromBase64Async method uploads the file from the base64 encoding and attaches it to the item in the compose form. This method returns the attachment identifier in the AsyncResult.value object. + * + * You can subsequently use the identifier with the removeAttachmentAsync method to remove the attachment in the same session. + * + * [Api set: Mailbox Preview] + * + * @remarks + * + * + * + * + *
{@link https://docs.microsoft.com/outlook/add-ins/understanding-outlook-add-in-permissions | Minimum permission level}ReadWriteItem
{@link https://docs.microsoft.com/outlook/add-ins/#extension-points | Applicable Outlook mode}Appointment Organizer
ErrorsAttachmentSizeExceeded - The attachment is larger than allowed.
FileTypeNotSupported - The attachment has an extension that is not allowed.
NumberOfAttachmentsExceeded - The message or appointment has too many attachments.
+ * + * @param base64File The base64 encoded content of an image or file to be added to an email or event. + * @param attachmentName The name of the attachment that is shown while the attachment is uploading. The maximum length is 255 characters. + * @param options Optional. An object literal that contains one or more of the following properties. + * asyncContext: Developers can provide any object they wish to access in the callback method. + * isInline: If true, indicates that the attachment will be shown inline in the message body and should not be displayed in the attachment list. + * @param callback When the method completes, the function passed in the callback parameter is called with a single parameter of type asyncResult. On success, the attachment identifier will be provided in the asyncResult.value property. If uploading the attachment fails, the asyncResult object will contain an Error object that provides a description of the error. + */ + addFileAttachmentFromBase64Async(base64File: string, attachmentName: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult) => void): void; /** * Adds an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -11827,7 +11966,7 @@ declare namespace Office { /** * Adds an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -12142,7 +12281,7 @@ declare namespace Office { /** * Removes an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -12168,7 +12307,7 @@ declare namespace Office { /** * Removes an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -12696,7 +12835,7 @@ declare namespace Office { /** * Adds an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -12723,7 +12862,7 @@ declare namespace Office { /** * Adds an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -13033,7 +13172,7 @@ declare namespace Office { /** * Removes an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * @@ -13059,7 +13198,7 @@ declare namespace Office { /** * Removes an event handler for a supported event. * - * Currently the only supported event type is Office.EventType.RecurrencePatternChanged, which is invoked when the user changes the recurrence pattern of a series. + * Currently the supported event types are `Office.EventType.AppointmentTimeChanged`, `Office.EventType.RecipientsChanged`, and `Office.EventType.RecurrencePatternChanged`. * * [Api set: Mailbox Preview] * From e22d3c83bf00d5b3dffc38ce2cbd4bd8403be01b Mon Sep 17 00:00:00 2001 From: Elizabeth Samuel Date: Wed, 15 Aug 2018 14:33:37 -0700 Subject: [PATCH 11/25] update reqt. set for item.getSelectedDataAsync and item.setSelectedDataAsync --- types/office-js/index.d.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/types/office-js/index.d.ts b/types/office-js/index.d.ts index 8283752230..f900beffe8 100644 --- a/types/office-js/index.d.ts +++ b/types/office-js/index.d.ts @@ -8287,7 +8287,7 @@ declare namespace Office { * * When including links in HTML markup, you can disable online link preview by setting the id attribute on the anchor () to "LPNoLP" (please see the Examples section for a sample). * - * [Api set: Mailbox 1.1] + * [Api set: Mailbox 1.2] * * @remarks * @@ -8318,7 +8318,7 @@ declare namespace Office { * * When including links in HTML markup, you can disable online link preview by setting the id attribute on the anchor () to "LPNoLP" (please see the Examples section for a sample). * - * [Api set: Mailbox 1.1] + * [Api set: Mailbox 1.2] * * @remarks *
{@link https://docs.microsoft.com/outlook/add-ins/understanding-outlook-add-in-permissions | Minimum permission level}ReadWriteItem
@@ -8340,7 +8340,7 @@ declare namespace Office { * * When including links in HTML markup, you can disable online link preview by setting the id attribute on the anchor () to "LPNoLP" (please see the Examples section for a sample). * - * [Api set: Mailbox 1.1] + * [Api set: Mailbox 1.2] * * @remarks *
{@link https://docs.microsoft.com/outlook/add-ins/understanding-outlook-add-in-permissions | Minimum permission level}ReadWriteItem
@@ -8360,7 +8360,7 @@ declare namespace Office { * * When including links in HTML markup, you can disable online link preview by setting the id attribute on the anchor () to "LPNoLP" (please see the Examples section for a sample). * - * [Api set: Mailbox 1.1] + * [Api set: Mailbox 1.2] * * @remarks *
{@link https://docs.microsoft.com/outlook/add-ins/understanding-outlook-add-in-permissions | Minimum permission level}ReadWriteItem
@@ -9274,7 +9274,7 @@ declare namespace Office { * * To access the selected data from the callback method, call asyncResult.value.data. To access the source property that the selection comes from, call asyncResult.value.sourceProperty, which will be either body or subject. * - * [Api set: Mailbox 1.0] + * [Api set: Mailbox 1.2] * * @returns * The selected data as a string with format determined by coercionType. @@ -9298,7 +9298,7 @@ declare namespace Office { * * To access the selected data from the callback method, call asyncResult.value.data. To access the source property that the selection comes from, call asyncResult.value.sourceProperty, which will be either body or subject. * - * [Api set: Mailbox 1.0] + * [Api set: Mailbox 1.2] * * @returns * The selected data as a string with format determined by coercionType. @@ -10883,7 +10883,7 @@ declare namespace Office { * * To access the selected data from the callback method, call asyncResult.value.data. To access the source property that the selection comes from, call asyncResult.value.sourceProperty, which will be either body or subject. * - * [Api set: Mailbox 1.0] + * [Api set: Mailbox 1.2] * * @returns * The selected data as a string with format determined by coercionType. @@ -10905,7 +10905,7 @@ declare namespace Office { * * To access the selected data from the callback method, call asyncResult.value.data. To access the source property that the selection comes from, call asyncResult.value.sourceProperty, which will be either body or subject. * - * [Api set: Mailbox 1.0] + * [Api set: Mailbox 1.2] * * @returns * The selected data as a string with format determined by coercionType. @@ -12134,7 +12134,7 @@ declare namespace Office { * * To access the selected data from the callback method, call asyncResult.value.data. To access the source property that the selection comes from, call asyncResult.value.sourceProperty, which will be either body or subject. * - * [Api set: Mailbox 1.0] + * [Api set: Mailbox 1.2] * * @returns * The selected data as a string with format determined by coercionType. @@ -12156,7 +12156,7 @@ declare namespace Office { * * To access the selected data from the callback method, call asyncResult.value.data. To access the source property that the selection comes from, call asyncResult.value.sourceProperty, which will be either body or subject. * - * [Api set: Mailbox 1.0] + * [Api set: Mailbox 1.2] * * @returns * The selected data as a string with format determined by coercionType. From e38054c06caca91cd935ef98d26563f04fd814b0 Mon Sep 17 00:00:00 2001 From: Elizabeth Samuel Date: Thu, 16 Aug 2018 14:16:00 -0700 Subject: [PATCH 12/25] tag getAccessTokenAsync as preview --- types/office-js/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/office-js/index.d.ts b/types/office-js/index.d.ts index 2f8a3ee7bc..f3757bd836 100644 --- a/types/office-js/index.d.ts +++ b/types/office-js/index.d.ts @@ -1084,6 +1084,8 @@ declare namespace Office { * * @param options - Optional. Accepts an AuthOptions object to define sign-on behaviors. * @param callback - Optional. Accepts a callback method to handle the token acquisition attempt. If AsyncResult.status is "succeeded", then AsyncResult.value is the raw AAD v. 2.0-formatted access token. + * + * @beta */ getAccessTokenAsync(options?: AuthOptions, callback?: (result: AsyncResult) => void): void; From 57d984b99a99a83794adfa1fabc799a81227e97f Mon Sep 17 00:00:00 2001 From: Elizabeth Samuel Date: Thu, 16 Aug 2018 14:23:28 -0700 Subject: [PATCH 13/25] update based on feedback --- types/office-js/index.d.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/types/office-js/index.d.ts b/types/office-js/index.d.ts index f3757bd836..fa6513df90 100644 --- a/types/office-js/index.d.ts +++ b/types/office-js/index.d.ts @@ -1846,7 +1846,7 @@ declare namespace Office { */ NodeReplaced, /** - * Triggers when the recipient list of the selected series was changed in Outlook. + * Triggers when the recipient list of the selected item was changed in Outlook. * * [Api set: Mailbox Preview] * @@ -8727,11 +8727,7 @@ declare namespace Office { */ export interface Organizer { /** - * Gets the organizer value of an appointment. - * - * The getAsync method starts an asynchronous call to the Exchange server to get the organizer value of an appointment. - * - * The organizer value of the item is provided as an {@link Office.EmailAddressDetails} in the asyncResult.value property. + * Gets the organizer value of an appointment as an {@link Office.EmailAddressDetails} in the asyncResult.value property. * * [Api set: Mailbox Preview] * From a02804fd8da20d27c48252ed309a331001329acc Mon Sep 17 00:00:00 2001 From: Alexey Morozov Date: Fri, 17 Aug 2018 16:42:07 +0300 Subject: [PATCH 14/25] Update sparqljs to v2.1 (remove parser options, support CLEAR and DROP operations) --- types/sparqljs/index.d.ts | 59 +++++++++++++++++++++++--------- types/sparqljs/sparqljs-tests.ts | 49 ++++++++++++++++++++++++-- 2 files changed, 89 insertions(+), 19 deletions(-) diff --git a/types/sparqljs/index.d.ts b/types/sparqljs/index.d.ts index 4b63cf8a59..dfc04ccfcd 100644 --- a/types/sparqljs/index.d.ts +++ b/types/sparqljs/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for sparqljs 1.5 +// Type definitions for sparqljs 2.1 // Project: https://github.com/RubenVerborgh/SPARQL.js // Definitions by: Alexey Morozov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -8,7 +8,6 @@ export const Parser: { new ( prefixes?: { [prefix: string]: string }, baseIRI?: string, - options?: ParserOptions, ): SparqlParser; }; @@ -16,11 +15,6 @@ export const Generator: { new (options?: GeneratorOptions): SparqlGenerator; }; -export interface ParserOptions { - /** @default true */ - collapseGroups?: boolean; -} - export interface GeneratorOptions { allPrefixes?: boolean; } @@ -94,6 +88,7 @@ export type UpdateOperation = InsertDeleteOperation | ManagementOperation; export interface InsertDeleteOperation { updateType: 'insert' | 'delete' | 'deletewhere' | 'insertdelete'; + graph?: string; insert?: Quads[]; delete?: Quads[]; where?: Pattern[]; @@ -101,17 +96,47 @@ export interface InsertDeleteOperation { export type Quads = BgpPattern | GraphQuads; -export interface ManagementOperation { - type: 'load' | 'copy' | 'move' | 'add'; +export type ManagementOperation = + | CopyMoveAddOperation + | LoadOperation + | CreateOperation + | ClearDropOperation; + +export interface CopyMoveAddOperation { + type: 'copy' | 'move' | 'add'; silent: boolean; - source: string | { - type: 'graph'; - default: boolean; - }; - destination?: string | { - type: 'graph'; - name: string; - }; + source: GraphOrDefault; + destination: GraphOrDefault; +} + +export interface LoadOperation { + type: 'load'; + silent: boolean; + source: string; + destination: string | false; +} + +export interface CreateOperation { + type: 'create'; + silent: boolean; + graph: string; +} + +export interface ClearDropOperation { + type: 'clear' | 'drop'; + silent: boolean; + graph: GraphReference; +} + +export interface GraphOrDefault { + type: 'graph'; + name?: string; + default?: boolean; +} + +export interface GraphReference extends GraphOrDefault { + named?: boolean; + all?: boolean; } /** diff --git a/types/sparqljs/sparqljs-tests.ts b/types/sparqljs/sparqljs-tests.ts index b8c0e36109..2fe29b40c8 100644 --- a/types/sparqljs/sparqljs-tests.ts +++ b/types/sparqljs/sparqljs-tests.ts @@ -26,8 +26,7 @@ function officialExamples() { function advancedOptions() { const parser = new SparqlJs.Parser( {rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'}, - 'http://example.com', - {collapseGroups: true} + 'http://example.com' ); const generator = new SparqlJs.Generator({allPrefixes: false}); } @@ -122,3 +121,49 @@ function basicQueries() { ], }; } + +/** + * Update query structure + */ +function updateQueries() { + const bgp: SparqlJs.BgpPattern = { + type: 'bgp', + triples: [], + }; + + const update: SparqlJs.Update = { + type: 'update', + prefixes: { + rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', + }, + updates: [ + { + updateType: 'insertdelete', + graph: 'http://example.com/foo', + insert: [bgp], + delete: [bgp], + where: [], + }, + { + type: 'copy', + silent: true, + source: { + type: 'graph', + name: 'http://example.com/foo', + }, + destination: { + type: 'graph', + default: true, + }, + }, + { + type: 'clear', + silent: false, + graph: { + type: 'graph', + all: true, + }, + }, + ], + }; +} From cc046b2941d8539d884e2cb65769740393a1a4e1 Mon Sep 17 00:00:00 2001 From: Ole Frank Jensen Date: Fri, 17 Aug 2018 19:25:45 +0200 Subject: [PATCH 15/25] export Focused type to make available externally --- types/react-credit-cards/index.d.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/types/react-credit-cards/index.d.ts b/types/react-credit-cards/index.d.ts index da41f6f05e..4cbf2f9830 100644 --- a/types/react-credit-cards/index.d.ts +++ b/types/react-credit-cards/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for react-credit-cards 0.7 // Project: https://github.com/amarofashion/react-credit-cards -// Definitions by: Vytautas Strimaitis +// Definitions by: Vytautas Strimaitis , Ole Frank // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -8,24 +8,28 @@ import * as React from "react"; export interface CallbackArgument { isValid: boolean; - type: { issuer: string; maxLength: number; }; + type: { issuer: string; maxLength: number }; } +export type Focused = "name" | "number" | "expiry" | "cvc"; + export interface ReactCreditCardProps { acceptedCards?: ReadonlyArray; callback?: (type: CallbackArgument, isValid: boolean) => void; cvc: string | number; expiry: string | number; - focused?: "name" | "number" | "expiry" | "cvc"; + focused?: Focused; issuer?: string; - locale?: { valid: string; }; + locale?: { valid: string }; name: string; number: string | number; - placeholders?: { name: string; }; + placeholders?: { name: string }; preview?: boolean; } -declare class ReactCreditCard extends React.Component { -} +declare class ReactCreditCard extends React.Component< + ReactCreditCardProps, + never +> {} export default ReactCreditCard; From 990cd39cbe1fea7ec082adb81d1786a38d5e4998 Mon Sep 17 00:00:00 2001 From: Ole Frank Jensen Date: Fri, 17 Aug 2018 19:30:55 +0200 Subject: [PATCH 16/25] update version number in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c5b1b03057..09fe064d48 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "definitely-typed", - "version": "0.0.2", + "version": "0.0.3", "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped", "repository": { "type": "git", From 1631657962d068279cef9338d566d842a7d0243d Mon Sep 17 00:00:00 2001 From: Elizabeth Samuel Date: Fri, 17 Aug 2018 14:34:44 -0700 Subject: [PATCH 17/25] update based on feedback --- types/office-js/index.d.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/types/office-js/index.d.ts b/types/office-js/index.d.ts index bde7558531..c840c1b7ea 100644 --- a/types/office-js/index.d.ts +++ b/types/office-js/index.d.ts @@ -8714,7 +8714,8 @@ declare namespace Office { } /** - * Provides a method to get the organizer value of an appointment in an Outlook add-in. + * Represents the appointment organizer, even if an alias or a delegate was used to create the appointment. + * This object provides a method to get the organizer value of an appointment in an Outlook add-in. * * [Api set: Mailbox Preview] * @@ -8861,9 +8862,9 @@ declare namespace Office { */ optionalAttendees: Recipients; /** - * Gets the email address of the organizer for the specified meeting. - * - * The organizer property returns an Organizer object that provides a method to get the organizer value. + * Gets the organizer for the specified meeting. + * + * The organizer property returns an {@link Office.Organizer | Organizer} object that provides a method to get the organizer value. * * [Api set: Mailbox Preview] * From 0d9b247b6ed97a94bb14dbb43535e04b14a8591d Mon Sep 17 00:00:00 2001 From: ChanRay Date: Fri, 17 Aug 2018 19:49:17 +0800 Subject: [PATCH 18/25] [fibjs] add types of fibjs 0.26.0 --- types/fibjs/declare/DgramSocket.d.ts | 2 +- types/fibjs/declare/Digest.d.ts | 16 +---- types/fibjs/declare/EventEmitter.d.ts | 34 ++++----- types/fibjs/declare/EventInfo.d.ts | 2 +- types/fibjs/declare/Handler.d.ts | 2 +- types/fibjs/declare/HandlerEx.d.ts | 2 +- types/fibjs/declare/HeapSnapshot.d.ts | 2 +- types/fibjs/declare/HttpClient.d.ts | 36 ++++++++-- types/fibjs/declare/HttpCollection.d.ts | 4 +- types/fibjs/declare/HttpCookie.d.ts | 4 +- types/fibjs/declare/HttpMessage.d.ts | 4 +- types/fibjs/declare/HttpResponse.d.ts | 4 +- types/fibjs/declare/HttpServer.d.ts | 2 +- types/fibjs/declare/LevelDB.d.ts | 2 +- types/fibjs/declare/LruCache.d.ts | 2 +- types/fibjs/declare/MongoCollection.d.ts | 28 ++++---- types/fibjs/declare/MongoCursor.d.ts | 6 +- types/fibjs/declare/MongoDB.d.ts | 4 +- types/fibjs/declare/PKey.d.ts | 6 +- types/fibjs/declare/Redis.d.ts | 12 ++-- types/fibjs/declare/RedisHash.d.ts | 2 +- types/fibjs/declare/RedisSortedSet.d.ts | 2 +- types/fibjs/declare/Routing.d.ts | 20 +++--- types/fibjs/declare/SandBox.d.ts | 90 ++++++++++++++++++++++-- types/fibjs/declare/Service.d.ts | 2 +- types/fibjs/declare/UrlObject.d.ts | 4 +- types/fibjs/declare/Worker.d.ts | 2 +- types/fibjs/declare/X509Req.d.ts | 2 +- types/fibjs/declare/bson.d.ts | 4 +- types/fibjs/declare/console.d.ts | 2 +- types/fibjs/declare/dgram.d.ts | 4 +- types/fibjs/declare/fs.d.ts | 21 ++++++ types/fibjs/declare/global.d.ts | 2 +- types/fibjs/declare/gui.d.ts | 2 +- types/fibjs/declare/http.d.ts | 40 ++++++++--- types/fibjs/declare/index.d.ts | 68 +++++++++--------- types/fibjs/declare/net.d.ts | 2 +- types/fibjs/declare/os.d.ts | 6 +- types/fibjs/declare/path.d.ts | 13 ++++ types/fibjs/declare/path_posix.d.ts | 13 ++++ types/fibjs/declare/path_win32.d.ts | 13 ++++ types/fibjs/declare/process.d.ts | 14 ++-- types/fibjs/declare/profiler.d.ts | 2 +- types/fibjs/declare/querystring.d.ts | 4 +- types/fibjs/declare/ssl.d.ts | 2 +- types/fibjs/declare/timers.d.ts | 15 +++- types/fibjs/declare/url.d.ts | 2 +- types/fibjs/declare/util.d.ts | 40 +++++++---- types/fibjs/declare/zlib.d.ts | 36 ++++++---- types/fibjs/index.d.ts | 2 +- 50 files changed, 410 insertions(+), 195 deletions(-) diff --git a/types/fibjs/declare/DgramSocket.d.ts b/types/fibjs/declare/DgramSocket.d.ts index 6618ae9c1c..22486d5832 100644 --- a/types/fibjs/declare/DgramSocket.d.ts +++ b/types/fibjs/declare/DgramSocket.d.ts @@ -45,7 +45,7 @@ declare class Class_DgramSocket extends Class_EventEmitter { * * @async */ - bind(opts: Object): void; + bind(opts: object): void; /** * diff --git a/types/fibjs/declare/Digest.d.ts b/types/fibjs/declare/Digest.d.ts index d440f31486..71c62f0386 100644 --- a/types/fibjs/declare/Digest.d.ts +++ b/types/fibjs/declare/Digest.d.ts @@ -52,23 +52,13 @@ declare class Class_Digest extends Class__object { /** * * @brief 计算并返回摘要 - * @param data 二进制数据块,此数据块将在计算前更新进摘要 - * @return 返回摘要的二进制数据 + * @param codec 指定编码格式,允许值为:"buffer", "hex", "base64", "utf8", 或者系统支持的字符集 + * @return 返回指定编码的摘要表示 * * * */ - digest(data: Class_Buffer): Class_Buffer; - - /** - * - * @brief 计算并返回摘要 - * @return 返回摘要的二进制数据 - * - * - * - */ - digest(): Class_Buffer; + digest(codec?: string/** = "buffer"*/): any; } /** endof class */ diff --git a/types/fibjs/declare/EventEmitter.d.ts b/types/fibjs/declare/EventEmitter.d.ts index 608b6f2edb..0008b2faa3 100644 --- a/types/fibjs/declare/EventEmitter.d.ts +++ b/types/fibjs/declare/EventEmitter.d.ts @@ -56,7 +56,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - on(ev: string, func: Function): Object; + on(ev: string, func: Function): object; /** * @@ -67,7 +67,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - on(map: Object): Object; + on(map: object): object; /** * @@ -79,7 +79,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - addListener(ev: string, func: Function): Object; + addListener(ev: string, func: Function): object; /** * @@ -90,7 +90,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - addListener(map: Object): Object; + addListener(map: object): object; /** * @@ -102,7 +102,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - prependListener(ev: string, func: Function): Object; + prependListener(ev: string, func: Function): object; /** * @@ -113,7 +113,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - prependListener(map: Object): Object; + prependListener(map: object): object; /** * @@ -125,7 +125,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - once(ev: string, func: Function): Object; + once(ev: string, func: Function): object; /** * @@ -136,7 +136,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - once(map: Object): Object; + once(map: object): object; /** * @@ -148,7 +148,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - prependOnceListener(ev: string, func: Function): Object; + prependOnceListener(ev: string, func: Function): object; /** * @@ -159,7 +159,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - prependOnceListener(map: Object): Object; + prependOnceListener(map: object): object; /** * @@ -171,7 +171,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - off(ev: string, func: Function): Object; + off(ev: string, func: Function): object; /** * @@ -182,7 +182,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - off(ev: string): Object; + off(ev: string): object; /** * @@ -193,7 +193,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - off(map: Object): Object; + off(map: object): object; /** * @@ -205,7 +205,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - removeListener(ev: string, func: Function): Object; + removeListener(ev: string, func: Function): object; /** * @@ -216,7 +216,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - removeListener(ev: string): Object; + removeListener(ev: string): object; /** * @@ -227,7 +227,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - removeListener(map: Object): Object; + removeListener(map: object): object; /** * @@ -238,7 +238,7 @@ declare class Class_EventEmitter extends Class__object { * * */ - removeAllListeners(evs?: any[]/** = v8::Array::New(isolate)*/): Object; + removeAllListeners(evs?: any[]/** = v8::Array::New(isolate)*/): object; /** * diff --git a/types/fibjs/declare/EventInfo.d.ts b/types/fibjs/declare/EventInfo.d.ts index a7c43a70a7..f60190d315 100644 --- a/types/fibjs/declare/EventInfo.d.ts +++ b/types/fibjs/declare/EventInfo.d.ts @@ -70,7 +70,7 @@ declare class Class_EventInfo extends Class__object { * @type Object */ - target: Object + target: object diff --git a/types/fibjs/declare/Handler.d.ts b/types/fibjs/declare/Handler.d.ts index ae7af823a2..df2ef6463f 100644 --- a/types/fibjs/declare/Handler.d.ts +++ b/types/fibjs/declare/Handler.d.ts @@ -44,7 +44,7 @@ declare class Class_Handler extends Class__object { * * */ - constructor(map: Object); + constructor(map: object); /** * diff --git a/types/fibjs/declare/HandlerEx.d.ts b/types/fibjs/declare/HandlerEx.d.ts index 504ab42c1a..22bca1ce76 100644 --- a/types/fibjs/declare/HandlerEx.d.ts +++ b/types/fibjs/declare/HandlerEx.d.ts @@ -81,7 +81,7 @@ declare class Class_HandlerEx extends Class_Handler { * * */ - onerror(hdlrs: Object): void; + onerror(hdlrs: object): void; } /** endof class */ diff --git a/types/fibjs/declare/HeapSnapshot.d.ts b/types/fibjs/declare/HeapSnapshot.d.ts index c65282165c..0a10a6b68f 100644 --- a/types/fibjs/declare/HeapSnapshot.d.ts +++ b/types/fibjs/declare/HeapSnapshot.d.ts @@ -71,7 +71,7 @@ declare class Class_HeapSnapshot extends Class__object { * * */ - diff(before: Class_HeapSnapshot): Object; + diff(before: Class_HeapSnapshot): object; /** * diff --git a/types/fibjs/declare/HttpClient.d.ts b/types/fibjs/declare/HttpClient.d.ts index 580e90c70c..7c9f6c073f 100644 --- a/types/fibjs/declare/HttpClient.d.ts +++ b/types/fibjs/declare/HttpClient.d.ts @@ -96,6 +96,30 @@ declare class Class_HttpClient extends Class__object { userAgent: string + /** + * class prop + * + * + * @brief 查询和设置 keep-alive 最大缓存连接数,缺省 128 + * + * + * @type Integer + */ + + poolSize: number + + /** + * class prop + * + * + * @brief 查询和设置 keep-alive 缓存连接超时时间,缺省 10000 ms + * + * + * @type Integer + */ + + poolTimeout: number + /** @@ -139,7 +163,7 @@ declare class Class_HttpClient extends Class__object { * * @async */ - request(method: string, url: string, opts?: Object/** = v8::Object::New(isolate)*/): Class_HttpResponse; + request(method: string, url: string, opts?: object/** = v8::Object::New(isolate)*/): Class_HttpResponse; /** * @@ -161,7 +185,7 @@ declare class Class_HttpClient extends Class__object { * * @async */ - get(url: string, opts?: Object/** = v8::Object::New(isolate)*/): Class_HttpResponse; + get(url: string, opts?: object/** = v8::Object::New(isolate)*/): Class_HttpResponse; /** * @@ -183,7 +207,7 @@ declare class Class_HttpClient extends Class__object { * * @async */ - post(url: string, opts?: Object/** = v8::Object::New(isolate)*/): Class_HttpResponse; + post(url: string, opts?: object/** = v8::Object::New(isolate)*/): Class_HttpResponse; /** * @@ -205,7 +229,7 @@ declare class Class_HttpClient extends Class__object { * * @async */ - del(url: string, opts?: Object/** = v8::Object::New(isolate)*/): Class_HttpResponse; + del(url: string, opts?: object/** = v8::Object::New(isolate)*/): Class_HttpResponse; /** * @@ -227,7 +251,7 @@ declare class Class_HttpClient extends Class__object { * * @async */ - put(url: string, opts?: Object/** = v8::Object::New(isolate)*/): Class_HttpResponse; + put(url: string, opts?: object/** = v8::Object::New(isolate)*/): Class_HttpResponse; /** * @@ -249,7 +273,7 @@ declare class Class_HttpClient extends Class__object { * * @async */ - patch(url: string, opts?: Object/** = v8::Object::New(isolate)*/): Class_HttpResponse; + patch(url: string, opts?: object/** = v8::Object::New(isolate)*/): Class_HttpResponse; } /** endof class */ diff --git a/types/fibjs/declare/HttpCollection.d.ts b/types/fibjs/declare/HttpCollection.d.ts index 5aa34c40bb..1936011e1d 100644 --- a/types/fibjs/declare/HttpCollection.d.ts +++ b/types/fibjs/declare/HttpCollection.d.ts @@ -75,7 +75,7 @@ declare class Class_HttpCollection extends Class__object { * * */ - add(map: Object): void; + add(map: object): void; /** * @@ -96,7 +96,7 @@ declare class Class_HttpCollection extends Class__object { * * */ - set(map: Object): void; + set(map: object): void; /** * diff --git a/types/fibjs/declare/HttpCookie.d.ts b/types/fibjs/declare/HttpCookie.d.ts index 5be7604293..b7c3980150 100644 --- a/types/fibjs/declare/HttpCookie.d.ts +++ b/types/fibjs/declare/HttpCookie.d.ts @@ -118,7 +118,7 @@ declare class Class_HttpCookie extends Class__object { * * */ - constructor(opts?: Object/** = v8::Object::New(isolate)*/); + constructor(opts?: object/** = v8::Object::New(isolate)*/); /** * @@ -130,7 +130,7 @@ declare class Class_HttpCookie extends Class__object { * * */ - constructor(name: string, value: string, opts?: Object/** = v8::Object::New(isolate)*/); + constructor(name: string, value: string, opts?: object/** = v8::Object::New(isolate)*/); /** * diff --git a/types/fibjs/declare/HttpMessage.d.ts b/types/fibjs/declare/HttpMessage.d.ts index 89ef9c96c6..1d64ba5c5f 100644 --- a/types/fibjs/declare/HttpMessage.d.ts +++ b/types/fibjs/declare/HttpMessage.d.ts @@ -151,7 +151,7 @@ declare class Class_HttpMessage extends Class_Message { * * */ - addHeader(map: Object): void; + addHeader(map: object): void; /** * @@ -172,7 +172,7 @@ declare class Class_HttpMessage extends Class_Message { * * */ - setHeader(map: Object): void; + setHeader(map: object): void; /** * diff --git a/types/fibjs/declare/HttpResponse.d.ts b/types/fibjs/declare/HttpResponse.d.ts index 4ecf06866d..7f69b8509a 100644 --- a/types/fibjs/declare/HttpResponse.d.ts +++ b/types/fibjs/declare/HttpResponse.d.ts @@ -80,7 +80,7 @@ declare class Class_HttpResponse extends Class_HttpMessage { * * */ - writeHead(statusCode: number, statusMessage: string, headers?: Object/** = v8::Object::New(isolate)*/): void; + writeHead(statusCode: number, statusMessage: string, headers?: object/** = v8::Object::New(isolate)*/): void; /** * @@ -91,7 +91,7 @@ declare class Class_HttpResponse extends Class_HttpMessage { * * */ - writeHead(statusCode: number, headers?: Object/** = v8::Object::New(isolate)*/): void; + writeHead(statusCode: number, headers?: object/** = v8::Object::New(isolate)*/): void; /** * diff --git a/types/fibjs/declare/HttpServer.d.ts b/types/fibjs/declare/HttpServer.d.ts index 157c951ea8..75ba24c290 100644 --- a/types/fibjs/declare/HttpServer.d.ts +++ b/types/fibjs/declare/HttpServer.d.ts @@ -143,7 +143,7 @@ declare class Class_HttpServer extends Class_TcpServer { * * */ - onerror(hdlrs: Object): void; + onerror(hdlrs: object): void; /** * diff --git a/types/fibjs/declare/LevelDB.d.ts b/types/fibjs/declare/LevelDB.d.ts index feb6ce2b6b..c9721bf337 100644 --- a/types/fibjs/declare/LevelDB.d.ts +++ b/types/fibjs/declare/LevelDB.d.ts @@ -78,7 +78,7 @@ declare class Class_LevelDB extends Class__object { * * */ - mset(map: Object): void; + mset(map: object): void; /** * diff --git a/types/fibjs/declare/LruCache.d.ts b/types/fibjs/declare/LruCache.d.ts index 884bb65d26..f68ac413cd 100644 --- a/types/fibjs/declare/LruCache.d.ts +++ b/types/fibjs/declare/LruCache.d.ts @@ -134,7 +134,7 @@ declare class Class_LruCache extends Class_EventEmitter { * * */ - set(map: Object): void; + set(map: object): void; /** * diff --git a/types/fibjs/declare/MongoCollection.d.ts b/types/fibjs/declare/MongoCollection.d.ts index 4b1f07478b..e721feabcd 100644 --- a/types/fibjs/declare/MongoCollection.d.ts +++ b/types/fibjs/declare/MongoCollection.d.ts @@ -36,7 +36,7 @@ declare class Class_MongoCollection extends Class__object { * * */ - find(query?: Object/** = v8::Object::New(isolate)*/, projection?: Object/** = v8::Object::New(isolate)*/): Class_MongoCursor; + find(query?: object/** = v8::Object::New(isolate)*/, projection?: object/** = v8::Object::New(isolate)*/): Class_MongoCursor; /** * @@ -48,7 +48,7 @@ declare class Class_MongoCollection extends Class__object { * * */ - findOne(query?: Object/** = v8::Object::New(isolate)*/, projection?: Object/** = v8::Object::New(isolate)*/): Object; + findOne(query?: object/** = v8::Object::New(isolate)*/, projection?: object/** = v8::Object::New(isolate)*/): object; /** * @@ -59,7 +59,7 @@ declare class Class_MongoCollection extends Class__object { * * */ - findAndModify(query: Object): Object; + findAndModify(query: object): object; /** * @@ -79,7 +79,7 @@ declare class Class_MongoCollection extends Class__object { * * */ - insert(document: Object): void; + insert(document: object): void; /** * @@ -89,7 +89,7 @@ declare class Class_MongoCollection extends Class__object { * * */ - save(document: Object): void; + save(document: object): void; /** * @@ -102,7 +102,7 @@ declare class Class_MongoCollection extends Class__object { * * */ - update(query: Object, document: Object, upsert?: boolean/** = false*/, multi?: boolean/** = false*/): void; + update(query: object, document: object, upsert?: boolean/** = false*/, multi?: boolean/** = false*/): void; /** * @@ -114,7 +114,7 @@ declare class Class_MongoCollection extends Class__object { * * */ - update(query: Object, document: Object, options: Object): void; + update(query: object, document: object, options: object): void; /** * @@ -124,7 +124,7 @@ declare class Class_MongoCollection extends Class__object { * * */ - remove(query: Object): void; + remove(query: object): void; /** * @@ -135,7 +135,7 @@ declare class Class_MongoCollection extends Class__object { * * */ - runCommand(cmd: Object): Object; + runCommand(cmd: object): object; /** * @@ -147,7 +147,7 @@ declare class Class_MongoCollection extends Class__object { * * */ - runCommand(cmd: string, arg?: Object/** = v8::Object::New(isolate)*/): Object; + runCommand(cmd: string, arg?: object/** = v8::Object::New(isolate)*/): object; /** * @@ -166,7 +166,7 @@ declare class Class_MongoCollection extends Class__object { * * */ - ensureIndex(keys: Object, options?: Object/** = v8::Object::New(isolate)*/): void; + ensureIndex(keys: object, options?: object/** = v8::Object::New(isolate)*/): void; /** * @@ -176,7 +176,7 @@ declare class Class_MongoCollection extends Class__object { * * */ - reIndex(): Object; + reIndex(): object; /** * @@ -187,7 +187,7 @@ declare class Class_MongoCollection extends Class__object { * * */ - dropIndex(name: string): Object; + dropIndex(name: string): object; /** * @@ -197,7 +197,7 @@ declare class Class_MongoCollection extends Class__object { * * */ - dropIndexes(): Object; + dropIndexes(): object; /** * diff --git a/types/fibjs/declare/MongoCursor.d.ts b/types/fibjs/declare/MongoCursor.d.ts index d9e26b833f..2dc99b5e96 100644 --- a/types/fibjs/declare/MongoCursor.d.ts +++ b/types/fibjs/declare/MongoCursor.d.ts @@ -57,7 +57,7 @@ declare class Class_MongoCursor extends Class__object { * * */ - sort(opts: Object): Class_MongoCursor; + sort(opts: object): Class_MongoCursor; /** * @@ -77,7 +77,7 @@ declare class Class_MongoCursor extends Class__object { * * */ - next(): Object; + next(): object; /** * @@ -140,7 +140,7 @@ declare class Class_MongoCursor extends Class__object { * * */ - hint(opts: Object): Class_MongoCursor; + hint(opts: object): Class_MongoCursor; } /** endof class */ diff --git a/types/fibjs/declare/MongoDB.d.ts b/types/fibjs/declare/MongoDB.d.ts index c0bf5432bd..11bcf1456d 100644 --- a/types/fibjs/declare/MongoDB.d.ts +++ b/types/fibjs/declare/MongoDB.d.ts @@ -46,7 +46,7 @@ declare class Class_MongoDB extends Class__object { * * */ - runCommand(cmd: Object): Object; + runCommand(cmd: object): object; /** * @@ -58,7 +58,7 @@ declare class Class_MongoDB extends Class__object { * * */ - runCommand(cmd: string, arg: any): Object; + runCommand(cmd: string, arg: any): object; /** * diff --git a/types/fibjs/declare/PKey.d.ts b/types/fibjs/declare/PKey.d.ts index 0c3f939e3e..297cfb2a13 100644 --- a/types/fibjs/declare/PKey.d.ts +++ b/types/fibjs/declare/PKey.d.ts @@ -144,7 +144,7 @@ declare class Class_PKey extends Class__object { * * */ - constructor(jsonKey: Object); + constructor(jsonKey: object); /** * @@ -258,7 +258,7 @@ declare class Class_PKey extends Class__object { * * */ - importKey(jsonKey: Object): void; + importKey(jsonKey: object): void; /** * @@ -299,7 +299,7 @@ declare class Class_PKey extends Class__object { * * */ - exportJson(): Object; + exportJson(): object; /** * diff --git a/types/fibjs/declare/Redis.d.ts b/types/fibjs/declare/Redis.d.ts index 4c5201d62c..384e0e4d80 100644 --- a/types/fibjs/declare/Redis.d.ts +++ b/types/fibjs/declare/Redis.d.ts @@ -90,7 +90,7 @@ declare class Class_Redis extends Class__object { * * */ - mset(kvs: Object): void; + mset(kvs: object): void; /** * @@ -108,7 +108,7 @@ declare class Class_Redis extends Class__object { * * */ - msetNX(kvs: Object): void; + msetNX(kvs: object): void; /** * @@ -383,7 +383,7 @@ declare class Class_Redis extends Class__object { * * */ - sub(map: Object): void; + sub(map: object): void; /** * @@ -424,7 +424,7 @@ declare class Class_Redis extends Class__object { * * */ - unsub(map: Object): void; + unsub(map: object): void; /** * @@ -445,7 +445,7 @@ declare class Class_Redis extends Class__object { * * */ - psub(map: Object): void; + psub(map: object): void; /** * @@ -486,7 +486,7 @@ declare class Class_Redis extends Class__object { * * */ - unpsub(map: Object): void; + unpsub(map: object): void; /** * diff --git a/types/fibjs/declare/RedisHash.d.ts b/types/fibjs/declare/RedisHash.d.ts index 0c8c9ea362..0c16eef47d 100644 --- a/types/fibjs/declare/RedisHash.d.ts +++ b/types/fibjs/declare/RedisHash.d.ts @@ -53,7 +53,7 @@ declare class Class_RedisHash extends Class__object { * * */ - mset(kvs: Object): void; + mset(kvs: object): void; /** * diff --git a/types/fibjs/declare/RedisSortedSet.d.ts b/types/fibjs/declare/RedisSortedSet.d.ts index ed2bcfaf5c..1769fb0a79 100644 --- a/types/fibjs/declare/RedisSortedSet.d.ts +++ b/types/fibjs/declare/RedisSortedSet.d.ts @@ -34,7 +34,7 @@ declare class Class_RedisSortedSet extends Class__object { * * */ - add(sms: Object): number; + add(sms: object): number; /** * diff --git a/types/fibjs/declare/Routing.d.ts b/types/fibjs/declare/Routing.d.ts index c06bc4e887..aef820feae 100644 --- a/types/fibjs/declare/Routing.d.ts +++ b/types/fibjs/declare/Routing.d.ts @@ -34,7 +34,7 @@ declare class Class_Routing extends Class_Handler { * * */ - constructor(map?: Object/** = v8::Object::New(isolate)*/); + constructor(map?: object/** = v8::Object::New(isolate)*/); /** * @@ -45,7 +45,7 @@ declare class Class_Routing extends Class_Handler { * * */ - constructor(method: string, map: Object); + constructor(method: string, map: object); /** * @@ -67,7 +67,7 @@ declare class Class_Routing extends Class_Handler { * * */ - append(map: Object): Class_Routing; + append(map: object): Class_Routing; /** * @@ -103,7 +103,7 @@ declare class Class_Routing extends Class_Handler { * * */ - all(map: Object): Class_Routing; + all(map: object): Class_Routing; /** * @@ -126,7 +126,7 @@ declare class Class_Routing extends Class_Handler { * * */ - get(map: Object): Class_Routing; + get(map: object): Class_Routing; /** * @@ -149,7 +149,7 @@ declare class Class_Routing extends Class_Handler { * * */ - post(map: Object): Class_Routing; + post(map: object): Class_Routing; /** * @@ -172,7 +172,7 @@ declare class Class_Routing extends Class_Handler { * * */ - del(map: Object): Class_Routing; + del(map: object): Class_Routing; /** * @@ -195,7 +195,7 @@ declare class Class_Routing extends Class_Handler { * * */ - put(map: Object): Class_Routing; + put(map: object): Class_Routing; /** * @@ -218,7 +218,7 @@ declare class Class_Routing extends Class_Handler { * * */ - patch(map: Object): Class_Routing; + patch(map: object): Class_Routing; /** * @@ -241,7 +241,7 @@ declare class Class_Routing extends Class_Handler { * * */ - find(map: Object): Class_Routing; + find(map: object): Class_Routing; /** * diff --git a/types/fibjs/declare/SandBox.d.ts b/types/fibjs/declare/SandBox.d.ts index 31f9dc53ce..fc3152b232 100644 --- a/types/fibjs/declare/SandBox.d.ts +++ b/types/fibjs/declare/SandBox.d.ts @@ -34,7 +34,20 @@ declare class Class_SandBox extends Class__object { * @type Object */ - global: Object + global: object + + /** + * class prop + * + * + * @brief 查询沙箱中现存的所有模块的字典对象 + * + * + * @readonly + * @type Object + */ + + modules: object @@ -46,7 +59,7 @@ declare class Class_SandBox extends Class__object { * * */ - constructor(mods: Object); + constructor(mods: object); /** * @@ -57,7 +70,7 @@ declare class Class_SandBox extends Class__object { * * */ - constructor(mods: Object, require: Function); + constructor(mods: object, require: Function); /** * @@ -68,7 +81,7 @@ declare class Class_SandBox extends Class__object { * * */ - constructor(mods: Object, global: Object); + constructor(mods: object, global: object); /** * @@ -80,7 +93,7 @@ declare class Class_SandBox extends Class__object { * * */ - constructor(mods: Object, require: Function, global: Object); + constructor(mods: object, require: Function, global: object); /** * @@ -101,7 +114,7 @@ declare class Class_SandBox extends Class__object { * * */ - add(mods: Object): void; + add(mods: object): void; /** * @@ -125,6 +138,17 @@ declare class Class_SandBox extends Class__object { */ remove(id: string): void; + /** + * + * @brief 从沙箱中检测基础模块是否存在 + * @param id 指定要检测的模块名称,此路径与当前运行脚本无关,必须为绝对路径或者模块名 + * @return 是否存在 + * + * + * + */ + has(id: string): boolean; + /** * * @brief 复制当前沙箱,新沙箱包含当前沙箱的模块,以及相同的名称和 require 函数 @@ -135,6 +159,22 @@ declare class Class_SandBox extends Class__object { */ clone(): Class_SandBox; + /** + * + * @brief 冻结当前沙箱,冻结后的沙箱,对 global 所做的修改将被忽略 + * + * + */ + freeze(): void; + + /** + * + * @brief 重新加载沙箱内的模块,此操作只会重新初始化模块,复位模块内的变量,不更新模块代码 + * + * + */ + refresh(): void; + /** * * @brief 运行一个脚本 @@ -170,6 +210,44 @@ declare class Class_SandBox extends Class__object { */ require(id: string, base: string): any; + /** + * + * @brief 对指定的 extname 添加 compiler, extname 不可为系统内置扩展名 (包括 {'.js', '.json', '.jsc', '.wasm'}), compiler 需返回有效的 javascript 脚本. + * + * ```JavaScript + * var vm = require('vm'); + * var sbox = new vm.SandBox({ + * }); + * + * // 编译 typescript 脚本为 js 并加载 + * sbox.setModuleCompiler('.ts', tsCompiler); + * var mod_ts = sbox.require('./a.ts'); + * + * // 编译 coffee 脚本为 js 并加载 + * sbox.setModuleCompiler('.coffee', cafeCompiler); + * var mod_coffee = sbox.require('./a.coffee'); + * + * // 编译 jsx 脚本为 js 并加载 + * sbox.setModuleCompiler('.jsx', reactCompiler); + * var mod_react = sbox.require('./a.jsx'); + * + * // 编译 yml 脚本为自定义的内容(如 API 集合) 并加载 + * sbox.setModuleCompiler('.yml', yaml2Rest) + * sbox.setModuleCompiler('.yaml', yaml2Rest) + * + * // 编译 markdown 为自定义的内容(如 html 字符串或 XmlDocument 对象) 并加载 + * sbox.setModuleCompiler('.md', mdCompiler) + * sbox.setModuleCompiler('.markdown', mdCompiler) + * ``` + * + * @param extname 指定的 extname, 必须以 '.' 开头, 且为非系统内置扩展名 + * @param compiler 编译回调函数, 所有带 extname 的文件仅会 require 一次. 该回调函数格式为 `compiler(buf, requireInfo)`, buf 为读取到的文件 Buffer, requireInfo 结构为 `{filename: string}`. + * + * + * + */ + setModuleCompiler(extname: string, compiler: Function): void; + } /** endof class */ /** endof `module Or Internal Object` */ diff --git a/types/fibjs/declare/Service.d.ts b/types/fibjs/declare/Service.d.ts index 6ca8feab53..7816e2d8bc 100644 --- a/types/fibjs/declare/Service.d.ts +++ b/types/fibjs/declare/Service.d.ts @@ -84,7 +84,7 @@ declare class Class_Service extends Class_EventEmitter { * * */ - constructor(name: string, worker: Function, event?: Object/** = v8::Object::New(isolate)*/); + constructor(name: string, worker: Function, event?: object/** = v8::Object::New(isolate)*/); /** * diff --git a/types/fibjs/declare/UrlObject.d.ts b/types/fibjs/declare/UrlObject.d.ts index 578d3b5079..5baa5b2d7d 100644 --- a/types/fibjs/declare/UrlObject.d.ts +++ b/types/fibjs/declare/UrlObject.d.ts @@ -216,7 +216,7 @@ declare class Class_UrlObject extends Class__object { * * */ - constructor(args: Object); + constructor(args: object); /** * @@ -250,7 +250,7 @@ declare class Class_UrlObject extends Class__object { * * */ - format(args: Object): void; + format(args: object): void; /** * diff --git a/types/fibjs/declare/Worker.d.ts b/types/fibjs/declare/Worker.d.ts index 1bbc793b85..c427f6f41c 100644 --- a/types/fibjs/declare/Worker.d.ts +++ b/types/fibjs/declare/Worker.d.ts @@ -47,7 +47,7 @@ declare class Class_Worker extends Class_EventEmitter { * * */ - constructor(path: string, opts?: Object/** = v8::Object::New(isolate)*/); + constructor(path: string, opts?: object/** = v8::Object::New(isolate)*/); /** * diff --git a/types/fibjs/declare/X509Req.d.ts b/types/fibjs/declare/X509Req.d.ts index 6317e9afa1..502c078402 100644 --- a/types/fibjs/declare/X509Req.d.ts +++ b/types/fibjs/declare/X509Req.d.ts @@ -146,7 +146,7 @@ declare class Class_X509Req extends Class__object { * * @async */ - sign(issuer: string, key: Class_PKey, opts?: Object/** = v8::Object::New(isolate)*/): Class_X509Cert; + sign(issuer: string, key: Class_PKey, opts?: object/** = v8::Object::New(isolate)*/): Class_X509Cert; } /** endof class */ diff --git a/types/fibjs/declare/bson.d.ts b/types/fibjs/declare/bson.d.ts index 920a1ace79..f9eeab19cb 100644 --- a/types/fibjs/declare/bson.d.ts +++ b/types/fibjs/declare/bson.d.ts @@ -217,7 +217,7 @@ declare module "bson" { * * */ - export function encode(data: Object): Class_Buffer; + export function encode(data: object): Class_Buffer; /** * @@ -228,7 +228,7 @@ declare module "bson" { * * */ - export function decode(data: Class_Buffer): Object; + export function decode(data: Class_Buffer): object; } /** end of `module bson` */ export = bson diff --git a/types/fibjs/declare/console.d.ts b/types/fibjs/declare/console.d.ts index 7a657ecd93..43f8603c2e 100644 --- a/types/fibjs/declare/console.d.ts +++ b/types/fibjs/declare/console.d.ts @@ -391,7 +391,7 @@ declare module "console" { * * */ - export function add(cfg: Object): void; + export function add(cfg: object): void; /** * diff --git a/types/fibjs/declare/dgram.d.ts b/types/fibjs/declare/dgram.d.ts index e925eac7af..0d3ccd20a9 100644 --- a/types/fibjs/declare/dgram.d.ts +++ b/types/fibjs/declare/dgram.d.ts @@ -238,7 +238,7 @@ declare module "dgram" { * * */ - export function createSocket(opts: Object): Class_DgramSocket; + export function createSocket(opts: object): Class_DgramSocket; /** * @@ -260,7 +260,7 @@ declare module "dgram" { * * */ - export function createSocket(opts: Object, callback: Function): Class_DgramSocket; + export function createSocket(opts: object, callback: Function): Class_DgramSocket; /** * diff --git a/types/fibjs/declare/fs.d.ts b/types/fibjs/declare/fs.d.ts index ec22c54c3d..b0971e3ee5 100644 --- a/types/fibjs/declare/fs.d.ts +++ b/types/fibjs/declare/fs.d.ts @@ -647,6 +647,27 @@ declare module "fs" { */ export function appendFile(fname: string, data: Class_Buffer): void; + /** + * + * @brief 设置 zip 虚拟文件映射 + * @param fname 指定映射路径 + * @param data 指定映射的 zip 文件数据 + * + * + * + */ + export function setZipFS(fname: string, data: Class_Buffer): void; + + /** + * + * @brief 清除 zip 虚拟文件映射 + * @param fname 指定映射路径,缺省清除全部缓存 + * + * + * + */ + export function clearZipFS(fname?: string/** = ""*/): void; + } /** end of `module fs` */ export = fs } diff --git a/types/fibjs/declare/global.d.ts b/types/fibjs/declare/global.d.ts index 3c58e8289c..19d539d932 100644 --- a/types/fibjs/declare/global.d.ts +++ b/types/fibjs/declare/global.d.ts @@ -379,7 +379,7 @@ declare module "global" { * * */ - export function setTimeout(callback: Function, timeout: number, ...args: any[]): Class_Timer; + export function setTimeout(callback: Function, timeout?: number/** = 1*/, ...args: any[]): Class_Timer; /** * diff --git a/types/fibjs/declare/gui.d.ts b/types/fibjs/declare/gui.d.ts index e2522b8331..60768a9d93 100644 --- a/types/fibjs/declare/gui.d.ts +++ b/types/fibjs/declare/gui.d.ts @@ -293,7 +293,7 @@ declare module "gui" { * * */ - export function open(url: string, opt?: Object/** = v8::Object::New(isolate)*/): Class_WebView; + export function open(url: string, opt?: object/** = v8::Object::New(isolate)*/): Class_WebView; } /** end of `module gui` */ export = gui diff --git a/types/fibjs/declare/http.d.ts b/types/fibjs/declare/http.d.ts index 2712b08370..000f4a6b79 100644 --- a/types/fibjs/declare/http.d.ts +++ b/types/fibjs/declare/http.d.ts @@ -196,7 +196,7 @@ /** module Or Internal Object */ /** - * @brief 超文本传输协议模块,用以支持 http 协议处理 + * @brief 超文本传输协议模块,用以支持 http 协议处理,模块别名:https * @detail */ declare module "http" { @@ -205,6 +205,14 @@ declare module "http" { module http { + /** + * + * @brief 返回标准的 HTTP 响应状态码的集合,以及各自的简短描述。 + * + * + */ + export const STATUS_CODES: any[]; + /** * * @brief 返回http客户端的 HttpCookie 对象列表 @@ -253,6 +261,22 @@ declare module "http" { */ export const userAgent: string; + /** + * + * @brief 查询和设置 keep-alive 最大缓存连接数,缺省 128 + * + * + */ + export const poolSize: number; + + /** + * + * @brief 查询和设置 keep-alive 缓存连接超时时间,缺省 10000 ms + * + * + */ + export const poolTimeout: number; + /** * @@ -333,7 +357,7 @@ declare module "http" { * * */ - export function fileHandler(root: string, mimes?: Object/** = v8::Object::New(isolate)*/, autoIndex?: boolean/** = false*/): Class_Handler; + export function fileHandler(root: string, mimes?: object/** = v8::Object::New(isolate)*/, autoIndex?: boolean/** = false*/): Class_Handler; /** * @@ -368,7 +392,7 @@ declare module "http" { * * @async */ - export function request(method: string, url: string, opts?: Object/** = v8::Object::New(isolate)*/): Class_HttpResponse; + export function request(method: string, url: string, opts?: object/** = v8::Object::New(isolate)*/): Class_HttpResponse; /** * @@ -390,7 +414,7 @@ declare module "http" { * * @async */ - export function get(url: string, opts?: Object/** = v8::Object::New(isolate)*/): Class_HttpResponse; + export function get(url: string, opts?: object/** = v8::Object::New(isolate)*/): Class_HttpResponse; /** * @@ -412,7 +436,7 @@ declare module "http" { * * @async */ - export function post(url: string, opts?: Object/** = v8::Object::New(isolate)*/): Class_HttpResponse; + export function post(url: string, opts?: object/** = v8::Object::New(isolate)*/): Class_HttpResponse; /** * @@ -434,7 +458,7 @@ declare module "http" { * * @async */ - export function del(url: string, opts?: Object/** = v8::Object::New(isolate)*/): Class_HttpResponse; + export function del(url: string, opts?: object/** = v8::Object::New(isolate)*/): Class_HttpResponse; /** * @@ -456,7 +480,7 @@ declare module "http" { * * @async */ - export function put(url: string, opts?: Object/** = v8::Object::New(isolate)*/): Class_HttpResponse; + export function put(url: string, opts?: object/** = v8::Object::New(isolate)*/): Class_HttpResponse; /** * @@ -478,7 +502,7 @@ declare module "http" { * * @async */ - export function patch(url: string, opts?: Object/** = v8::Object::New(isolate)*/): Class_HttpResponse; + export function patch(url: string, opts?: object/** = v8::Object::New(isolate)*/): Class_HttpResponse; } /** end of `module http` */ export = http diff --git a/types/fibjs/declare/index.d.ts b/types/fibjs/declare/index.d.ts index 53be0766e3..df0e02e683 100644 --- a/types/fibjs/declare/index.d.ts +++ b/types/fibjs/declare/index.d.ts @@ -14,54 +14,54 @@ -/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// /// /// /// /// -/// -/// -/// -/// -/// -/// -/// /// -/// -/// -/// -/// -/// /// -/// /// -/// /// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// /// +/// +/// +/// +/// +/// +/// /// -/// -/// -/// +/// +/// /// /// /// -/// /// -/// -/// -/// +/// import _Global from 'global'; import _Process from 'process'; diff --git a/types/fibjs/declare/net.d.ts b/types/fibjs/declare/net.d.ts index 831b958124..8c2bf58055 100644 --- a/types/fibjs/declare/net.d.ts +++ b/types/fibjs/declare/net.d.ts @@ -284,7 +284,7 @@ declare module "net" { * * */ - export function info(): Object; + export function info(): object; /** * diff --git a/types/fibjs/declare/os.d.ts b/types/fibjs/declare/os.d.ts index d98d2b58d5..977fc4c6ce 100644 --- a/types/fibjs/declare/os.d.ts +++ b/types/fibjs/declare/os.d.ts @@ -380,7 +380,7 @@ declare module "os" { * * */ - export function userInfo(options?: Object/** = v8::Object::New(isolate)*/): Object; + export function userInfo(options?: object/** = v8::Object::New(isolate)*/): object; /** * @@ -390,7 +390,7 @@ declare module "os" { * * */ - export function networkInterfaces(): Object; + export function networkInterfaces(): object; /** * @@ -470,7 +470,7 @@ declare module "os" { * * */ - export function memoryUsage(): Object; + export function memoryUsage(): object; } /** end of `module os` */ export = os diff --git a/types/fibjs/declare/path.d.ts b/types/fibjs/declare/path.d.ts index 2764664778..9b6ae9cfec 100644 --- a/types/fibjs/declare/path.d.ts +++ b/types/fibjs/declare/path.d.ts @@ -341,6 +341,19 @@ declare module "path" { */ export function resolve(...ps: any[]): string; + /** + * + * @brief 求 _from 到 to 的相对路径 + * + * @param _from 源路径 + * @param to 目标路径 + * @return 返回得到的相对路径 + * + * + * + */ + export function relative(_from: string, to: string): string; + /** * * @brief 转换成 namespace-prefixed 路径。只在 windows 有效,其他系统直接返回。 diff --git a/types/fibjs/declare/path_posix.d.ts b/types/fibjs/declare/path_posix.d.ts index e28fbfee0a..bfeea21068 100644 --- a/types/fibjs/declare/path_posix.d.ts +++ b/types/fibjs/declare/path_posix.d.ts @@ -341,6 +341,19 @@ declare module "path_posix" { */ export function resolve(...ps: any[]): string; + /** + * + * @brief 求 _from 到 to 的相对路径 + * + * @param _from 源路径 + * @param to 目标路径 + * @return 返回得到的相对路径 + * + * + * + */ + export function relative(_from: string, to: string): string; + /** * * @brief 转换成 namespace-prefixed 路径。只在 windows 有效,其他系统直接返回。 diff --git a/types/fibjs/declare/path_win32.d.ts b/types/fibjs/declare/path_win32.d.ts index 80f236ba50..25ce64db09 100644 --- a/types/fibjs/declare/path_win32.d.ts +++ b/types/fibjs/declare/path_win32.d.ts @@ -341,6 +341,19 @@ declare module "path_win32" { */ export function resolve(...ps: any[]): string; + /** + * + * @brief 求 _from 到 to 的相对路径 + * + * @param _from 源路径 + * @param to 目标路径 + * @return 返回得到的相对路径 + * + * + * + */ + export function relative(_from: string, to: string): string; + /** * * @brief 转换成 namespace-prefixed 路径。只在 windows 有效,其他系统直接返回。 diff --git a/types/fibjs/declare/process.d.ts b/types/fibjs/declare/process.d.ts index 669eff12d2..1e6e1c8739 100644 --- a/types/fibjs/declare/process.d.ts +++ b/types/fibjs/declare/process.d.ts @@ -416,7 +416,7 @@ declare module "process" { * * */ - export function memoryUsage(): Object; + export function memoryUsage(): object; /** * @@ -448,7 +448,7 @@ declare module "process" { * * */ - export function open(command: string, args: any[], opts?: Object/** = v8::Object::New(isolate)*/): Class_SubProcess; + export function open(command: string, args: any[], opts?: object/** = v8::Object::New(isolate)*/): Class_SubProcess; /** * @@ -468,7 +468,7 @@ declare module "process" { * * */ - export function open(command: string, opts?: Object/** = v8::Object::New(isolate)*/): Class_SubProcess; + export function open(command: string, opts?: object/** = v8::Object::New(isolate)*/): Class_SubProcess; /** * @@ -489,7 +489,7 @@ declare module "process" { * * */ - export function start(command: string, args: any[], opts?: Object/** = v8::Object::New(isolate)*/): Class_SubProcess; + export function start(command: string, args: any[], opts?: object/** = v8::Object::New(isolate)*/): Class_SubProcess; /** * @@ -509,7 +509,7 @@ declare module "process" { * * */ - export function start(command: string, opts?: Object/** = v8::Object::New(isolate)*/): Class_SubProcess; + export function start(command: string, opts?: object/** = v8::Object::New(isolate)*/): Class_SubProcess; /** * @@ -530,7 +530,7 @@ declare module "process" { * * */ - export function run(command: string, args: any[], opts?: Object/** = v8::Object::New(isolate)*/): number; + export function run(command: string, args: any[], opts?: object/** = v8::Object::New(isolate)*/): number; /** * @@ -550,7 +550,7 @@ declare module "process" { * * */ - export function run(command: string, opts?: Object/** = v8::Object::New(isolate)*/): number; + export function run(command: string, opts?: object/** = v8::Object::New(isolate)*/): number; } /** end of `module process` */ export = process diff --git a/types/fibjs/declare/profiler.d.ts b/types/fibjs/declare/profiler.d.ts index 36a89b2644..5d3459ddbb 100644 --- a/types/fibjs/declare/profiler.d.ts +++ b/types/fibjs/declare/profiler.d.ts @@ -416,7 +416,7 @@ declare module "profiler" { * * */ - export function diff(test: Function): Object; + export function diff(test: Function): object; /** * diff --git a/types/fibjs/declare/querystring.d.ts b/types/fibjs/declare/querystring.d.ts index 9010d119e5..bd939a0621 100644 --- a/types/fibjs/declare/querystring.d.ts +++ b/types/fibjs/declare/querystring.d.ts @@ -242,7 +242,7 @@ declare module "querystring" { * * */ - export function parse(str: string, sep?: string/** = "&"*/, eq?: string/** = "="*/, opt?: Object/** = v8::Object::New(isolate)*/): Class_HttpCollection; + export function parse(str: string, sep?: string/** = "&"*/, eq?: string/** = "="*/, opt?: object/** = v8::Object::New(isolate)*/): Class_HttpCollection; /** * @@ -256,7 +256,7 @@ declare module "querystring" { * * */ - export function stringify(obj: Object, sep?: string/** = "&"*/, eq?: string/** = "="*/, opt?: Object/** = v8::Object::New(isolate)*/): string; + export function stringify(obj: object, sep?: string/** = "&"*/, eq?: string/** = "="*/, opt?: object/** = v8::Object::New(isolate)*/): string; } /** end of `module querystring` */ export = querystring diff --git a/types/fibjs/declare/ssl.d.ts b/types/fibjs/declare/ssl.d.ts index 2799f59be3..e331eeb691 100644 --- a/types/fibjs/declare/ssl.d.ts +++ b/types/fibjs/declare/ssl.d.ts @@ -196,7 +196,7 @@ /** module Or Internal Object */ /** - * @brief ssl/tls 模块 + * @brief ssl/tls 模块,模块别名:tls * @detail */ declare module "ssl" { diff --git a/types/fibjs/declare/timers.d.ts b/types/fibjs/declare/timers.d.ts index 7469a7ea68..8de6e72812 100644 --- a/types/fibjs/declare/timers.d.ts +++ b/types/fibjs/declare/timers.d.ts @@ -219,7 +219,7 @@ declare module "timers" { * * */ - export function setTimeout(callback: Function, timeout: number, ...args: any[]): Class_Timer; + export function setTimeout(callback: Function, timeout?: number/** = 1*/, ...args: any[]): Class_Timer; /** * @@ -313,6 +313,19 @@ declare module "timers" { */ export function clearImmediate(t: any): void; + /** + * + * @brief 调用给定的函数,并在超时时间到期时中断函数运行 + * @param func 指定要运行的函数 + * @param timeout 指定超时时间 + * @param args 额外的参数,传入到指定的 callback 内,可选。 + * @return 返回 func 的运行结果 + * + * + * + */ + export function call(func: Function, timeout: number, ...args: any[]): any; + } /** end of `module timers` */ export = timers } diff --git a/types/fibjs/declare/url.d.ts b/types/fibjs/declare/url.d.ts index 7728d433a2..545b516cd2 100644 --- a/types/fibjs/declare/url.d.ts +++ b/types/fibjs/declare/url.d.ts @@ -217,7 +217,7 @@ declare module "url" { * * */ - export function format(args: Object): string; + export function format(args: object): string; /** * diff --git a/types/fibjs/declare/util.d.ts b/types/fibjs/declare/util.d.ts index 6998b4aab1..1b38c49399 100644 --- a/types/fibjs/declare/util.d.ts +++ b/types/fibjs/declare/util.d.ts @@ -274,7 +274,7 @@ declare module "util" { * * */ - export function inspect(obj: Object, options?: Object/** = v8::Object::New(isolate)*/): string; + export function inspect(obj: object, options?: object/** = v8::Object::New(isolate)*/): string; /** * @@ -637,6 +637,17 @@ declare module "util" { */ export function clone(v: any): any; + /** + * + * @brief 深度冻结一个对象,被冻结后的对象及其包含的对象都将不允许修改 + * + * @param v 指定要冻结的对象 + * + * + * + */ + export function deepFreeze(v: any): void; + /** * * @brief 将一个或者多个对象的键值扩展到指定对象 @@ -674,7 +685,7 @@ declare module "util" { * * */ - export function pick(v: any, ...objs: any[]): Object; + export function pick(v: any, ...objs: any[]): object; /** * @@ -687,7 +698,7 @@ declare module "util" { * * */ - export function omit(v: any, ...keys: any[]): Object; + export function omit(v: any, ...keys: any[]): object; /** * @@ -937,22 +948,25 @@ declare module "util" { * * ```JavaScript * { - * "fibjs": "0.1.0", - * "svn": 1753, - * "build": "Dec 10 2013 21:44:17", + * "fibjs": "0.25.0", + * "clang": "9.1", + * "date": "Jun 12 2018 07:22:40", * "vender": { - * "ev": "4.11", - * "exif": "0.6.21", - * "gd": "2.1.0-alpha", + * "ev": "4.24", + * "expat": "2.2.5", + * "gd": "2.2.4", * "jpeg": "8.3", - * "log4cpp": "1.0", + * "leveldb": "1.17", * "mongo": "0.7", * "pcre": "8.21", * "png": "1.5.4", - * "sqlite": "3.8.1", + * "mbedtls": "2.6.1", + * "snappy": "1.1.2", + * "sqlite": "3.23.0", * "tiff": "3.9.5", * "uuid": "1.6.2", - * "v8": "3.23.17 (candidate)", + * "v8": "6.7.288.20", + * "v8-snapshot": true, * "zlib": "1.2.7", * "zmq": "3.1" * } @@ -963,7 +977,7 @@ declare module "util" { * * */ - export function buildInfo(): Object; + export function buildInfo(): object; } /** end of `module util` */ export = util diff --git a/types/fibjs/declare/zlib.d.ts b/types/fibjs/declare/zlib.d.ts index 049d70f365..693dcf81bf 100644 --- a/types/fibjs/declare/zlib.d.ts +++ b/types/fibjs/declare/zlib.d.ts @@ -264,11 +264,12 @@ declare module "zlib" { * * @brief 创建一个 gunzip 流对象 * @param to 用于存储处理结果的流 + * @param maxSize 指定解压缩尺寸限制,缺省为 -1,不限制 * @return 返回封装过的流对象 * * */ - export function createGunzip(to: Class_Stream): Class_Stream; + export function createGunzip(to: Class_Stream, maxSize?: number/** = -1*/): Class_Stream; /** * @@ -284,21 +285,23 @@ declare module "zlib" { * * @brief 创建一个 inflate 流对象 * @param to 用于存储处理结果的流 + * @param maxSize 指定解压缩尺寸限制,缺省为 -1,不限制 * @return 返回封装过的流对象 * * */ - export function createInflate(to: Class_Stream): Class_Stream; + export function createInflate(to: Class_Stream, maxSize?: number/** = -1*/): Class_Stream; /** * * @brief 创建一个 inflateRaw 流对象 * @param to 用于存储处理结果的流 + * @param maxSize 指定解压缩尺寸限制,缺省为 -1,不限制 * @return 返回封装过的流对象 * * */ - export function createInflateRaw(to: Class_Stream): Class_Stream; + export function createInflateRaw(to: Class_Stream, maxSize?: number/** = -1*/): Class_Stream; /** * @@ -340,34 +343,37 @@ declare module "zlib" { * * @brief 解压缩 deflate 算法压缩的数据(zlib格式) * @param data 给定压缩后的数据 + * @param maxSize 指定解压缩尺寸限制,缺省为 -1,不限制 * @return 返回解压缩后的二进制数据 * * * @async */ - export function inflate(data: Class_Buffer): Class_Buffer; + export function inflate(data: Class_Buffer, maxSize?: number/** = -1*/): Class_Buffer; /** * * @brief 解压缩 deflate 算法压缩的数据到流对象中(zlib格式) * @param data 给定要解压缩的数据 * @param stm 指定存储解压缩数据的流 + * @param maxSize 指定解压缩尺寸限制,缺省为 -1,不限制 * * * @async */ - export function inflateTo(data: Class_Buffer, stm: Class_Stream): void; + export function inflateTo(data: Class_Buffer, stm: Class_Stream, maxSize?: number/** = -1*/): void; /** * * @brief 解压缩源流中 deflate 算法压缩的数据到流对象中(zlib格式) * @param src 给定要解压缩的数据所在的流 * @param stm 指定存储解压缩数据的流 + * @param maxSize 指定解压缩尺寸限制,缺省为 -1,不限制 * * * @async */ - export function inflateTo(src: Class_Stream, stm: Class_Stream): void; + export function inflateTo(src: Class_Stream, stm: Class_Stream, maxSize?: number/** = -1*/): void; /** * @@ -406,34 +412,37 @@ declare module "zlib" { * * @brief 解压缩 gzip 算法压缩的数据 * @param data 给定压缩后的数据 + * @param maxSize 指定解压缩尺寸限制,缺省为 -1,不限制 * @return 返回解压缩后的二进制数据 * * * @async */ - export function gunzip(data: Class_Buffer): Class_Buffer; + export function gunzip(data: Class_Buffer, maxSize?: number/** = -1*/): Class_Buffer; /** * * @brief 解压缩 gzip 算法压缩的数据到流对象中 * @param data 给定要解压缩的数据 * @param stm 指定存储解压缩数据的流 + * @param maxSize 指定解压缩尺寸限制,缺省为 -1,不限制 * * * @async */ - export function gunzipTo(data: Class_Buffer, stm: Class_Stream): void; + export function gunzipTo(data: Class_Buffer, stm: Class_Stream, maxSize?: number/** = -1*/): void; /** * * @brief 解压缩源流中 gzip 算法压缩的数据到流对象中 * @param src 给定要解压缩的数据所在的流 * @param stm 指定存储解压缩数据的流 + * @param maxSize 指定解压缩尺寸限制,缺省为 -1,不限制 * * * @async */ - export function gunzipTo(src: Class_Stream, stm: Class_Stream): void; + export function gunzipTo(src: Class_Stream, stm: Class_Stream, maxSize?: number/** = -1*/): void; /** * @@ -475,34 +484,37 @@ declare module "zlib" { * * @brief 解压缩 deflate 算法压缩的数据(inflateRaw) * @param data 给定压缩后的数据 + * @param maxSize 指定解压缩尺寸限制,缺省为 -1,不限制 * @return 返回解压缩后的二进制数据 * * * @async */ - export function inflateRaw(data: Class_Buffer): Class_Buffer; + export function inflateRaw(data: Class_Buffer, maxSize?: number/** = -1*/): Class_Buffer; /** * * @brief 解压缩 deflate 算法压缩的数据到流对象中(inflateRaw) * @param data 给定要解压缩的数据 * @param stm 指定存储解压缩数据的流 + * @param maxSize 指定解压缩尺寸限制,缺省为 -1,不限制 * * * @async */ - export function inflateRawTo(data: Class_Buffer, stm: Class_Stream): void; + export function inflateRawTo(data: Class_Buffer, stm: Class_Stream, maxSize?: number/** = -1*/): void; /** * * @brief 解压缩源流中 deflate 算法压缩的数据到流对象中(inflateRaw) * @param src 给定要解压缩的数据所在的流 * @param stm 指定存储解压缩数据的流 + * @param maxSize 指定解压缩尺寸限制,缺省为 -1,不限制 * * * @async */ - export function inflateRawTo(src: Class_Stream, stm: Class_Stream): void; + export function inflateRawTo(src: Class_Stream, stm: Class_Stream, maxSize?: number/** = -1*/): void; } /** end of `module zlib` */ export = zlib diff --git a/types/fibjs/index.d.ts b/types/fibjs/index.d.ts index 0b4ef29975..02201fd904 100644 --- a/types/fibjs/index.d.ts +++ b/types/fibjs/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for fibjs 0.25 +// Type definitions for fibjs 0.26 // Project: https://github.com/fibjs/fibjs // Definitions by: richardo2016 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped From 987e3bbf7f9c9f668c3012ddc1d750887b8d3b55 Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Sat, 18 Aug 2018 14:03:09 +0200 Subject: [PATCH 19/25] Add types for websequencediagrams --- types/websequencediagrams/index.d.ts | 17 ++++++++++++++ types/websequencediagrams/tsconfig.json | 23 +++++++++++++++++++ types/websequencediagrams/tslint.json | 1 + .../websequencediagrams-tests.ts | 18 +++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 types/websequencediagrams/index.d.ts create mode 100644 types/websequencediagrams/tsconfig.json create mode 100644 types/websequencediagrams/tslint.json create mode 100644 types/websequencediagrams/websequencediagrams-tests.ts diff --git a/types/websequencediagrams/index.d.ts b/types/websequencediagrams/index.d.ts new file mode 100644 index 0000000000..59dc8cebb6 --- /dev/null +++ b/types/websequencediagrams/index.d.ts @@ -0,0 +1,17 @@ +// Type definitions for websequencediagrams 0.1 +// Project: https://github.com/hildjj/node-websequencediagrams +// Definitions by: Florian Keller +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +export type OutputType = 'png' | 'svg' | 'pdf'; +export type Style = 'default' | 'earth' | 'modern-blue' | 'mscgen' | 'omegapple' | 'qsd' | 'rose' | 'roundgreen' | 'napkin' | 'magazine' | 'vs2010' | 'patent'; +export type diagramCallback = (error: Error | null, buffer?: Buffer, mimeType?: string) => void; +export type diagramUrlCallback = (error: Error | null, url?: string) => void; + +export const root: string; +export const styles: Style[]; + +export function diagram(description: string | Buffer, style: Style | null, format: OutputType | null, callback: diagramCallback): void; +export function diagram_url(description: string | Buffer, style: Style | null, format: OutputType | null, callback: diagramUrlCallback): void; diff --git a/types/websequencediagrams/tsconfig.json b/types/websequencediagrams/tsconfig.json new file mode 100644 index 0000000000..d5a406dfe7 --- /dev/null +++ b/types/websequencediagrams/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "websequencediagrams-tests.ts" + ] +} diff --git a/types/websequencediagrams/tslint.json b/types/websequencediagrams/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/websequencediagrams/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/websequencediagrams/websequencediagrams-tests.ts b/types/websequencediagrams/websequencediagrams-tests.ts new file mode 100644 index 0000000000..34caa4dc19 --- /dev/null +++ b/types/websequencediagrams/websequencediagrams-tests.ts @@ -0,0 +1,18 @@ +import * as wsd from 'websequencediagrams'; + +wsd.diagram('Alice->Bob: message', 'modern-blue', 'png', (error, buffer, mimeType) => { + if (error) { + console.error(error); + } else { + console.log('Received MIME type:', mimeType); + console.log('Received Buffer:', buffer); + } +}); + +wsd.diagram_url('Alice->Bob: message', 'modern-blue', 'png', (error, url) => { + if (error) { + console.error(error); + } else { + console.log('Received URL:', url); + } +}); From 40c53ba44256d4b07c9ea0c200d62bfbaef8b162 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Sat, 18 Aug 2018 10:52:40 -0700 Subject: [PATCH 20/25] dav: Fix line endings --- types/dav/dav-tests.ts | 500 ++++++------ types/dav/index.d.ts | 1608 +++++++++++++++++++-------------------- types/dav/tsconfig.json | 44 +- 3 files changed, 1076 insertions(+), 1076 deletions(-) diff --git a/types/dav/dav-tests.ts b/types/dav/dav-tests.ts index 6a31df698d..b4218494cd 100644 --- a/types/dav/dav-tests.ts +++ b/types/dav/dav-tests.ts @@ -1,250 +1,250 @@ -import * as dav from "dav"; - -(() => { - const xhr = new dav.transport.Basic( - new dav.Credentials({ - username: 'xxx', - password: 'xxx' - }) - ); - - dav.createAccount({ server: 'http://dav.example.com', xhr }) - .then((account) => { - account.calendars.forEach(() => { - }); - }); - const client = new dav.Client(xhr); - - client.createAccount({ - server: 'http://dav.example.com', - accountType: 'carddav' - }).then((account) => { - account.addressBooks.forEach(() => { - }); - }); -})(); - -(() => { - const client = new dav.Client( - new dav.transport.Basic( - new dav.Credentials({ - username: 'xxx', - password: 'xxx' - }) - ), - { - baseUrl: 'https://mail.mozilla.com' - } - ); - - const req = dav.request.basic({ - method: 'PUT', - data: 'BEGIN:VCALENDAR\nEND:VCALENDAR', - etag: '12345' - }); - - client.send(req, '/calendars/123.ics') - .then(() => { }); -})(); - -(() => { - const xhr = new dav.transport.Basic( - new dav.Credentials({ - username: 'xxx', - password: 'xxx' - }) - ); - - const req = dav.request.basic({ - method: 'PUT', - data: 'BEGIN:VCALENDAR\nEND:VCALENDAR', - etag: '12345' - }); - - xhr.send(req, 'https://mail.mozilla.com/calendars/123.ics') - .then(() => { - }); -})(); - -dav.debug.enabled = true; - -(() => { - const xhr = new dav.transport.Basic( - new dav.Credentials({ - username: 'Killer BOB', - password: 'blacklodge' - }) - ); - - const client = new dav.Client(xhr, { baseUrl: 'https://mail.mozilla.com' }); - - const url = 'https://mail.mozilla.com/'; - const req = dav.request.basic({ - method: 'PUT', - data: 'BEGIN:VCALENDAR\nEND:VCALENDAR', - etag: 'abc123' - }); - - const sandbox = dav.createSandbox(); - client.send(req, url, { sandbox }); - xhr.send(req, url, { sandbox }); - - client.createAccount({ sandbox: {}, server: 'http://dav.example.com' }); - dav.createAccount({ - sandbox: {}, - server: 'http://dav.example.com', - xhr - }); - - let calendar = new dav.Calendar(); - client.createCalendarObject(calendar, { - data: 'BEGIN:VCALENDAR\nEND:VCALENDAR', - filename: 'test.ics' - }); - dav.createCalendarObject( - calendar, - { - data: 'BEGIN:VCALENDAR\nEND:VCALENDAR', - filename: 'test.ics', - xhr - }); - - let object = new dav.CalendarObject(); - client.updateCalendarObject(object); - dav.updateCalendarObject( - object, - { - xhr - } - ); - - object = new dav.CalendarObject(); - client.deleteCalendarObject(object); - dav.deleteCalendarObject( - object, - { - xhr - } - ); - - calendar = new dav.Calendar(); - client.syncCalendar(calendar, { syncMethod: 'webdav' }); - dav.syncCalendar( - calendar, - { - syncMethod: 'webdav', - xhr - } - ); - - let account = new dav.Account(); - client.syncCaldavAccount(account, { syncMethod: 'webdav' }); - dav.syncCaldavAccount( - account, - { - syncMethod: 'webdav', - xhr - } - ); - - let addressBook = new dav.AddressBook(); - client.createCard(addressBook, { - data: 'BEGIN:VCARD\nEND:VCARD', - filename: 'test.vcf' - }); - dav.createCard(addressBook, - { - data: 'BEGIN:VCARD\nEND:VCARD', - filename: 'test.vcf', - xhr - }); - - let vcard = new dav.VCard(); - client.updateCard(vcard); - dav.updateCard( - vcard, - { - xhr - } - ); - vcard = new dav.VCard(); - client.deleteCard(vcard); - dav.deleteCard( - vcard, - { - xhr - }); - - addressBook = new dav.AddressBook(); - client.syncAddressBook(addressBook, { - syncMethod: 'basic' - }); - - dav.syncAddressBook( - addressBook, - { - syncMethod: 'basic', - xhr - }); - - account = new dav.Account(); - client.syncCarddavAccount(account, { syncMethod: 'basic' }); - - dav.syncCarddavAccount( - account, - { - syncMethod: 'basic', - xhr - }); -})(); - -(() => { - const xhr = new dav.transport.Basic( - new dav.Credentials({ username: 'admin', password: 'admin' }) - ); - - const req: dav.Request = { - method: 'GET', - transformRequest: (xhr: any) => xhr - }; - - const sandbox = dav.createSandbox(); - xhr.send(req, 'http://127.0.0.1:1337', { sandbox }); - sandbox.requestList; - - xhr.send(req, 'http://127.0.0.1:1337'); -})(); - -(() => { - const credentials = new dav.Credentials({ - clientId: '605300196874-1ki833poa7uqabmh3hq' + - '6u1onlqlsi54h.apps.googleusercontent.com', - clientSecret: 'jQTKlOhF-RclGaGJot3HIcVf', - redirectUrl: 'https://oauth.gaiamobile.org/authenticated', - tokenUrl: 'https://accounts.google.com/o/oauth2/token', - authorizationCode: 'gareth' - }); - - const xhr = new dav.transport.OAuth2(credentials); - - const req = { method: 'GET' }; - - credentials.accessToken = 'EXPIRED'; - credentials.refreshToken = '1/oPHTPFgECWFPrs7KgHdis24u6Xl4E4EnRrkkiwLfzdk'; - credentials.expiration = Date.now() - 1; - - xhr.send(req, 'http://127.0.0.1:1337', { - retry: false - }); - - credentials.accessToken = 'Little Bear'; - credentials.refreshToken = 'spicy tamales'; - const expiration = credentials.expiration = Date.now() + 60 * 60 * 1000; - - credentials.accessToken = 'EXPIRED'; - credentials.refreshToken = 'raspberry pie'; - credentials.expiration = Date.now() + 60 * 60 * 1000; - - credentials.accessToken = 'EXPIRED'; - credentials.refreshToken = 'soda'; -})(); +import * as dav from "dav"; + +(() => { + const xhr = new dav.transport.Basic( + new dav.Credentials({ + username: 'xxx', + password: 'xxx' + }) + ); + + dav.createAccount({ server: 'http://dav.example.com', xhr }) + .then((account) => { + account.calendars.forEach(() => { + }); + }); + const client = new dav.Client(xhr); + + client.createAccount({ + server: 'http://dav.example.com', + accountType: 'carddav' + }).then((account) => { + account.addressBooks.forEach(() => { + }); + }); +})(); + +(() => { + const client = new dav.Client( + new dav.transport.Basic( + new dav.Credentials({ + username: 'xxx', + password: 'xxx' + }) + ), + { + baseUrl: 'https://mail.mozilla.com' + } + ); + + const req = dav.request.basic({ + method: 'PUT', + data: 'BEGIN:VCALENDAR\nEND:VCALENDAR', + etag: '12345' + }); + + client.send(req, '/calendars/123.ics') + .then(() => { }); +})(); + +(() => { + const xhr = new dav.transport.Basic( + new dav.Credentials({ + username: 'xxx', + password: 'xxx' + }) + ); + + const req = dav.request.basic({ + method: 'PUT', + data: 'BEGIN:VCALENDAR\nEND:VCALENDAR', + etag: '12345' + }); + + xhr.send(req, 'https://mail.mozilla.com/calendars/123.ics') + .then(() => { + }); +})(); + +dav.debug.enabled = true; + +(() => { + const xhr = new dav.transport.Basic( + new dav.Credentials({ + username: 'Killer BOB', + password: 'blacklodge' + }) + ); + + const client = new dav.Client(xhr, { baseUrl: 'https://mail.mozilla.com' }); + + const url = 'https://mail.mozilla.com/'; + const req = dav.request.basic({ + method: 'PUT', + data: 'BEGIN:VCALENDAR\nEND:VCALENDAR', + etag: 'abc123' + }); + + const sandbox = dav.createSandbox(); + client.send(req, url, { sandbox }); + xhr.send(req, url, { sandbox }); + + client.createAccount({ sandbox: {}, server: 'http://dav.example.com' }); + dav.createAccount({ + sandbox: {}, + server: 'http://dav.example.com', + xhr + }); + + let calendar = new dav.Calendar(); + client.createCalendarObject(calendar, { + data: 'BEGIN:VCALENDAR\nEND:VCALENDAR', + filename: 'test.ics' + }); + dav.createCalendarObject( + calendar, + { + data: 'BEGIN:VCALENDAR\nEND:VCALENDAR', + filename: 'test.ics', + xhr + }); + + let object = new dav.CalendarObject(); + client.updateCalendarObject(object); + dav.updateCalendarObject( + object, + { + xhr + } + ); + + object = new dav.CalendarObject(); + client.deleteCalendarObject(object); + dav.deleteCalendarObject( + object, + { + xhr + } + ); + + calendar = new dav.Calendar(); + client.syncCalendar(calendar, { syncMethod: 'webdav' }); + dav.syncCalendar( + calendar, + { + syncMethod: 'webdav', + xhr + } + ); + + let account = new dav.Account(); + client.syncCaldavAccount(account, { syncMethod: 'webdav' }); + dav.syncCaldavAccount( + account, + { + syncMethod: 'webdav', + xhr + } + ); + + let addressBook = new dav.AddressBook(); + client.createCard(addressBook, { + data: 'BEGIN:VCARD\nEND:VCARD', + filename: 'test.vcf' + }); + dav.createCard(addressBook, + { + data: 'BEGIN:VCARD\nEND:VCARD', + filename: 'test.vcf', + xhr + }); + + let vcard = new dav.VCard(); + client.updateCard(vcard); + dav.updateCard( + vcard, + { + xhr + } + ); + vcard = new dav.VCard(); + client.deleteCard(vcard); + dav.deleteCard( + vcard, + { + xhr + }); + + addressBook = new dav.AddressBook(); + client.syncAddressBook(addressBook, { + syncMethod: 'basic' + }); + + dav.syncAddressBook( + addressBook, + { + syncMethod: 'basic', + xhr + }); + + account = new dav.Account(); + client.syncCarddavAccount(account, { syncMethod: 'basic' }); + + dav.syncCarddavAccount( + account, + { + syncMethod: 'basic', + xhr + }); +})(); + +(() => { + const xhr = new dav.transport.Basic( + new dav.Credentials({ username: 'admin', password: 'admin' }) + ); + + const req: dav.Request = { + method: 'GET', + transformRequest: (xhr: any) => xhr + }; + + const sandbox = dav.createSandbox(); + xhr.send(req, 'http://127.0.0.1:1337', { sandbox }); + sandbox.requestList; + + xhr.send(req, 'http://127.0.0.1:1337'); +})(); + +(() => { + const credentials = new dav.Credentials({ + clientId: '605300196874-1ki833poa7uqabmh3hq' + + '6u1onlqlsi54h.apps.googleusercontent.com', + clientSecret: 'jQTKlOhF-RclGaGJot3HIcVf', + redirectUrl: 'https://oauth.gaiamobile.org/authenticated', + tokenUrl: 'https://accounts.google.com/o/oauth2/token', + authorizationCode: 'gareth' + }); + + const xhr = new dav.transport.OAuth2(credentials); + + const req = { method: 'GET' }; + + credentials.accessToken = 'EXPIRED'; + credentials.refreshToken = '1/oPHTPFgECWFPrs7KgHdis24u6Xl4E4EnRrkkiwLfzdk'; + credentials.expiration = Date.now() - 1; + + xhr.send(req, 'http://127.0.0.1:1337', { + retry: false + }); + + credentials.accessToken = 'Little Bear'; + credentials.refreshToken = 'spicy tamales'; + const expiration = credentials.expiration = Date.now() + 60 * 60 * 1000; + + credentials.accessToken = 'EXPIRED'; + credentials.refreshToken = 'raspberry pie'; + credentials.expiration = Date.now() + 60 * 60 * 1000; + + credentials.accessToken = 'EXPIRED'; + credentials.refreshToken = 'soda'; +})(); diff --git a/types/dav/index.d.ts b/types/dav/index.d.ts index 6b1b09e326..063cc38e60 100644 --- a/types/dav/index.d.ts +++ b/types/dav/index.d.ts @@ -1,804 +1,804 @@ -// Type definitions for dav 1.7 -// Project: https://github.com/lambdabaa/dav/ -// Definitions by: ToastHawaii -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.2 - -export let version: string; - -/** - * Perform an initial download of a caldav or carddav account's data. - * @param options - * @returns a Promise which will be fulfilled with a dav.Account object. - */ -export function createAccount(options: CreateAccountOptions): Promise; - -export interface CreateAccountOptions { - /** - * one of 'caldav' or 'carddav'. Defaults to 'caldav'. - */ - accountType?: "caldav" | "carddav"; - - /** - * list of caldav filters to send with request. - */ - filters?: object[]; - - /** - * whether or not to load dav collections. - */ - loadCollections?: boolean; - - /** - * whether or not to load dav objects. - */ - loadObjects?: boolean; - - /** - * request sandox. - */ - sandbox?: Sandbox | {}; - - /** - * some url for server (needn't be base url). - */ - server: string; - - /** - * VTIMEZONE calendar object. - */ - timezone?: string; - - /** - * request sender. - */ - - xhr?: transport.Transport; -} - -/** - * Create a calendar object on the parameter calendar. - * @param calendar the calendar to put the object on. - * @param options - * @returns a Promise which will be fulfilled when the calendar has been created. - */ -export function createCalendarObject(calendar: Calendar, options: CreateCalendarObjectOptions): Promise; - -export interface CreateCalendarObjectOptions { - /** - * rfc 5545 VCALENDAR object. - */ - data: string; - - /** - * name for the calendar ics file. - */ - filename: string; - - /** - * request sandbox. - */ - sandbox?: Sandbox; - - /** - * request sender. - */ - xhr?: transport.Transport; -} - -/** - * Persist updates to the parameter calendar object to the server. - * @param calendarObject updated calendar object. - * @param options - * @returns a Promise which will be fulfilled when the calendar has been updated. - */ -export function updateCalendarObject(calendarObject: CalendarObject, options: UpdateCalendarObjectOptions): Promise; - -export interface UpdateCalendarObjectOptions { - /** - * request sandbox. - */ - sandbox?: Sandbox; - - /** - * request sender. - */ - xhr?: transport.Transport; -} - -/** - * Delete the parameter calendar object on the server. - * @param calendarObject target calendar object. - * @param options - * @returns a Promise which will be fulfilled when the calendar has been deleted. - */ -export function deleteCalendarObject(calendarObject: CalendarObject, options: DeleteCalendarObjectOptions): Promise; - -export interface DeleteCalendarObjectOptions { - /** - * request sandbox. - */ - sandbox?: Sandbox; - - /** - * request sender. - */ - xhr?: transport.Transport; -} - -/** - * Fetch changes from the remote server to the parameter calendar. - * @param calendar the calendar to fetch changes for. - * @param options - * @returns a Promise which will be fulfilled with an updated dav.Calendar object once sync is complete. - */ -export function syncCalendar(calendar: Calendar, options: SyncCalendarOptions): Promise; - -export interface SyncCalendarOptions { - /** - * list of caldav filters to send with request. - */ - filters?: object[]; - - /** - * request sandbox. - */ - sandbox?: Sandbox; - - /** - * either 'basic' or 'webdav'. If unspecified, will try to do webdav sync - * and failover to basic sync if rfc 6578 is not supported by the server. - */ - syncMethod?: "basic" | "webdav"; - - /** - * VTIMEZONE calendar object. - */ - timezone?: string; - - /** - * request sender. - */ - xhr?: transport.Transport; -} - -/** - * Fetch changes from the remote server to the account's calendars. - * @param account the calendar account to sync. - * @param options - * @returns a Promise which will be fulfilled with an updated dav.Account object once sync is complete. - */ -export function syncCaldavAccount(account: Account, options: SyncCaldavAccountOptions): Promise; - -export interface SyncCaldavAccountOptions { - /** - * list of caldav filters to send with request. - */ - filters?: object[]; - - /** - * request sandbox. - */ - sandbox?: Sandbox; - - /** - * either 'basic' or 'webdav'. If unspecified, will try to do webdav sync - * and failover to basic sync if rfc 6578 is not supported by the server. - */ - syncMethod?: "basic" | "webdav"; - - /** - * VTIMEZONE calendar object. - */ - timezone?: string; - - /** - * request sender. - */ - xhr?: transport.Transport; -} - -/** - * Create a vcard object on the parameter address book. - * @param addressBook the address book to put the object on. - * @param options - * @returns a Promise which will be fulfilled when the vcard has been created. - */ -export function createCard(addressBook: AddressBook, options: CreateCardOptions): Promise; - -export interface CreateCardOptions { - /** - * VCARD object. - */ - data: string; - /** - * name for the vcard vcf file. - */ - filename: string; - - /** - * request sandbox. - */ - sandbox?: Sandbox; - /** - * request sender. - */ - xhr?: transport.Transport; -} - -/** - * Persist updates to the parameter vcard object to the server. - * @param card updated vcard object. - * @param options - * @returns a Promise which will be fulfilled when the vcard has been updated. - */ -export function updateCard(card: VCard, options: UpdateCardOptions): Promise; - -export interface UpdateCardOptions { - /** - * request sandbox. - */ - sandbox?: Sandbox; - /** - * request sender. - */ - xhr?: transport.Transport; -} - -/** - * Delete the parameter vcard object on the server. - * @param card target vcard object. - * @param options - * @returns a Promise which will be fulfilled when the vcard has been deleted. - */ -export function deleteCard(card: VCard, options: DeleteCardOptions): Promise; - -export interface DeleteCardOptions { - /** - * request sandbox. - */ - sandbox?: Sandbox; - /** - * request sender. - */ - xhr?: transport.Transport; -} - -/** - * Fetch changes from the remote server to the parameter address books. - * @param addressBook the address book to fetch changes for. - * @param options - * @returns a Promise which will be fulfilled with an updated AddressBook object once sync is complete. - */ -export function syncAddressBook(addressBook: AddressBook, options: SyncAddressBookOptions): Promise; - -export interface SyncAddressBookOptions { - /** - * request sandbox. - */ - sandbox?: Sandbox; - /** - * either 'basic' or 'webdav'.If unspecified, will try to do webdav sync - * and failover to basic sync if rfc 6578 is not supported by the server. - */ - syncMethod?: "basic" | "webdav"; - - /** - * request sender. - */ - xhr?: transport.Transport; -} - -/** - * Fetch changes from the remote server to the account's address books. - * @param account the address book account to sync. - * @param options - * @returns a Promise which will be fulfilled with an updated Account object once sync is complete. - */ -export function syncCarddavAccount(account: Account, options: SyncCarddavAccountOptions): Promise; - -export interface SyncCarddavAccountOptions { - /** - * list of caldav filters to send with request. - */ - filters?: object[]; - - /** - * request sandbox. - */ - sandbox?: Sandbox; - - /** - * either 'basic' or 'webdav'. If unspecified, will try to do webdav sync - * and failover to basic sync if rfc 6578 is not supported by the server. - */ - syncMethod?: "basic" | "webdav"; - - /** - * VTIMEZONE calendar object. - */ - timezone?: string; - - /** - * request sender. - */ - xhr?: transport.Transport; -} - -/** - * Create a request sandbox. - */ -export class Sandbox { - constructor(); - - requestList: any[]; - - add(request: any): void; - - /** - * abort sandboxed requests as a group. - */ - abort(): void; -} - -/** - * @deprecated - */ -export function createSandbox(): Sandbox; - -export namespace transport { - class Transport { - /** - * @param credentials user authorization. - */ - constructor(credentials: Credentials); - - send(request: Request, url: string, options?: TransportOptions): Promise; - } - - interface TransportOptions { - /** - * request sandbox. - */ - sandbox?: Sandbox; - - retry?: boolean; - } - - class Basic extends Transport { - /** - * Create a new Basic object. This sends dav requests using http basic authentication. - * @param credentials user authorization. - */ - constructor(credentials: Credentials); - - /** - * - * @param request object with request info. - * @param url - * @param options - * @return a promise that will be resolved with an xhr request after - * its readyState is 4 or the result of applying an optional request - * `transformResponse` function to the xhr object after its readyState - * is 4. - */ - send(request: Request, url: string, options?: TransportOptions): Promise; - } - - /** - * Create a new OAuth2 object.This sends dav requests authorized via rfc 6749 oauth2. - * @param credentials user authorization. - */ - class OAuth2 extends Transport { - constructor(credentials: Credentials); - - /** - * - * @param request object with request info. - * @param url - * @param options - * @return a promise that will be resolved with an xhr request after - * its readyState is 4 or the result of applying an optional request - * `transformResponse` function to the xhr object after its readyState - * is 4. - */ - send(request: Request, url: string, options?: TransportOptions): Promise; - } -} - -export namespace request { - /** - * - * @param options - * @returns - */ - function addressBookQuery(options: AddressBookQueryOptions): string; - - interface AddressBookQueryOptions { - /** - * value for Depth header. - */ - depth?: string; - - /** - * list of props to request. - */ - props: object[]; - } - - /** - * - * @param options - * @returns - */ - function basic(options: BasicOptions): Request; - - interface BasicOptions { - /** - * put request body. - */ - data: string; - - /** - * http method. - */ - method: string; - - /** - * cached calendar object etag. - */ - etag: string; - } - - /** - * - * @param options - * @returns - */ - function calendarQuery(options: CalendarQueryOptions): string; - - interface CalendarQueryOptions { - /** - * value for Depth header. - */ - depth?: string; - - /** - * list of filters to send with request. - */ - filters: object[]; - - /** - * list of props to request. - */ - props: object[]; - - /** - * VTIMEZONE calendar object. - */ - timezone: string; - } - - /** - * - * @param options - * @returns - */ - function propfind(options: PropfindOptions): string; - - interface PropfindOptions { - /** - * value for Depth header. - */ - depth?: string; - - /** - * list of props to request. - */ - props: object[]; - } - - /** - * - * @param options - * @returns - */ - function syncCollection(options: SyncCollectionOptions): string; - - interface SyncCollectionOptions { - /** - * option value for Depth header. - */ - depth?: string; - - /** - * list of props to request. - */ - props: object[]; - - /** - * indicates scope of the sync report request. - */ - syncLevel: number; - - /** - * synchronization token provided by the server. - */ - syncToken: string; - } -} - -export class Client { - /** - * Create a new Client object. The client interface allows consumers to set - * their credentials and transport once and then make authorized requests - * without passing them to each request. Each of the other, public API - * methods should be available on Client objects. - * @param xhr request sender. - * @param options - */ - constructor(xhr: transport.Transport, options?: ClientOptions); - - /** - * Send a request using this client's transport (and perhaps baseUrl). - * @param req dav request. - * @param options - * @return a promise that will be resolved with an xhr request after - * its readyState is 4 or the result of applying an optional request - * `transformResponse` function to the xhr object after its readyState - * is 4. - */ - send(req: Request, uri: string, options?: ClientSendOptions): Promise; - - /** - * Perform an initial download of a caldav or carddav account's data. - * @param options - * @returns a Promise which will be fulfilled with a dav.Account object. - */ - createAccount(options?: CreateAccountOptions): Promise; - - /** - * Create a calendar object on the parameter calendar. - * @param calendar the calendar to put the object on. - * @param options - * @returns a Promise which will be fulfilled when the calendar has been created. - */ - createCalendarObject(calendar: Calendar, options?: CreateCalendarObjectOptions): Promise; - - /** - * Persist updates to the parameter calendar object to the server. - * @param calendarObject updated calendar object. - * @param options - * @returns a Promise which will be fulfilled when the calendar has been updated. - */ - updateCalendarObject(calendarObject: CalendarObject, options?: UpdateCalendarObjectOptions): Promise; - - /** - * Delete the parameter calendar object on the server. - * @param calendarObject target calendar object. - * @param options - * @returns a Promise which will be fulfilled when the calendar has been deleted. - */ - deleteCalendarObject(calendarObject: CalendarObject, options?: DeleteCalendarObjectOptions): Promise; - - /** - * Fetch changes from the remote server to the parameter calendar. - * @param calendar the calendar to fetch changes for. - * @param options - * @returns a Promise which will be fulfilled with an updated dav.Calendar object once sync is complete. - */ - syncCalendar(calendar: Calendar, options?: SyncCalendarOptions): Promise; - - /** - * Fetch changes from the remote server to the account's calendars. - * @param account the calendar account to sync. - * @param options - * @returns a Promise which will be fulfilled with an updated dav.Account object once sync is complete. - */ - syncCaldavAccount(account: Account, options?: SyncCaldavAccountOptions): Promise; - - /** - * Create a vcard object on the parameter address book. - * @param addressBook the address book to put the object on. - * @param options - * @returns a Promise which will be fulfilled when the vcard has been created. - */ - createCard(addressBook: AddressBook, options?: CreateCardOptions): Promise; - - /** - * Persist updates to the parameter vcard object to the server. - * @param card updated vcard object. - * @param options - * @returns a Promise which will be fulfilled when the vcard has been updated. - */ - updateCard(card: VCard, options?: UpdateCardOptions): Promise; - - /** - * - * Delete the parameter vcard object on the server. - * @param card target vcard object. - * @param options - * @returns a Promise which will be fulfilled when the vcard has been deleted. - */ - deleteCard(card: VCard, options?: DeleteCardOptions): Promise; - - /** - * Fetch changes from the remote server to the parameter address books. - * @param addressBook the address book to fetch changes for. - * @param options - * @returns a Promise which will be fulfilled with an updated AddressBook object once sync is complete. - */ - syncAddressBook(addressBook: AddressBook, options?: SyncAddressBookOptions): Promise; - - /** - * Fetch changes from the remote server to the account's address books. - * @param account the address book account to sync. - * @param options - * @returns a Promise which will be fulfilled with an updated Account object once sync is complete. - */ - syncCarddavAccount(account: Account, options?: SyncCarddavAccountOptions): Promise; -} - -export interface ClientOptions { - /** - * root url to resolve relative request urls with. - */ - baseUrl: string; -} - -export interface ClientSendOptions { - /** - * request sandbox. - */ - sandbox?: Sandbox; - /** - * relative url for request. - */ - url?: string; -} - -export type Partial = { - [P in keyof T]?: T[P]; -}; - -export class Account { - constructor(options?: AccountOptions); - server: string; - credentials: Credentials; - rootUrl: string; - principalUrl: string; - homeUrl: string; - calendars: Calendar[]; - addressBooks: AddressBook[]; -} - -export type AccountOptions = Partial; - -export class Credentials { - constructor(options?: CredentialsOptions); - - /** - * username (perhaps email) for calendar user. - */ - username: string; - - /** - * plaintext password for calendar user. - */ - password: string; - - /** - * oauth client id. - */ - clientId: string; - - /** - * oauth client secret. - */ - clientSecret: string; - - /** - * oauth code. - */ - authorizationCode: string; - - /** - * oauth redirect url. - */ - redirectUrl: string; - - /** - * oauth token url. - */ - tokenUrl: string; - - /** - * oauth access token. - */ - accessToken: string; - - /** - * oauth refresh token. - */ - refreshToken: string; - - /** - * unix time for access token expiration. - */ - expiration: number; -} -export type CredentialsOptions = Partial; - -export class DAVCollection { - constructor(options: DAVCollectionOptions); - data: string; - objects: T[]; - account: Account; - ctag: string; - description: string; - displayName: string; - reports: string[]; - resourcetype: string; - syncToken: string; - url: string; -} -export type DAVCollectionOptions = Partial>; - -export class AddressBook extends DAVCollection { - constructor(options?: AddressBookOptions); -} -export type AddressBookOptions = Partial; - -export class Calendar extends DAVCollection { - constructor(options?: CalendarOptions); - - components: string[]; - timezone: string; -} -export type CalendarOptions = Partial; - -export class DAVObject { - constructor(options: DAVObjectOptions); - data: string; - etag: string; - url: string; -} -export type DAVObjectOptions = Partial; - -export class CalendarObject extends DAVObject { - constructor(options?: CalendarObjectOptions); - calendar: Calendar; - calendarData: string; -} -export type CalendarObjectOptions = Partial; - -export class VCard extends DAVObject { - constructor(options?: VCardOptions); - addressBook: AddressBook; - addressData: string; -} - -export type VCardOptions = Partial; - -export class Request { - constructor(options?: RequestOptions); - method: string; - requestData?: string; - transformRequest?: (xhr: any) => any; - transformResponse?: (xhr: any) => any; - onerror?: (error: Error) => any; -} - -export type RequestOptions = Partial; - -export namespace debug { - let enabled: boolean; -} - -export namespace ns { - const CALENDAR_SERVER = 'http://calendarserver.org/ns/'; - const CALDAV_APPLE = 'http://apple.com/ns/ical/'; - const CALDAV = 'urn:ietf:params:xml:ns:caldav'; - const CARDDAV = 'urn:ietf:params:xml:ns:carddav'; - const DAV = 'DAV:'; -} +// Type definitions for dav 1.7 +// Project: https://github.com/lambdabaa/dav/ +// Definitions by: ToastHawaii +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +export let version: string; + +/** + * Perform an initial download of a caldav or carddav account's data. + * @param options + * @returns a Promise which will be fulfilled with a dav.Account object. + */ +export function createAccount(options: CreateAccountOptions): Promise; + +export interface CreateAccountOptions { + /** + * one of 'caldav' or 'carddav'. Defaults to 'caldav'. + */ + accountType?: "caldav" | "carddav"; + + /** + * list of caldav filters to send with request. + */ + filters?: object[]; + + /** + * whether or not to load dav collections. + */ + loadCollections?: boolean; + + /** + * whether or not to load dav objects. + */ + loadObjects?: boolean; + + /** + * request sandox. + */ + sandbox?: Sandbox | {}; + + /** + * some url for server (needn't be base url). + */ + server: string; + + /** + * VTIMEZONE calendar object. + */ + timezone?: string; + + /** + * request sender. + */ + + xhr?: transport.Transport; +} + +/** + * Create a calendar object on the parameter calendar. + * @param calendar the calendar to put the object on. + * @param options + * @returns a Promise which will be fulfilled when the calendar has been created. + */ +export function createCalendarObject(calendar: Calendar, options: CreateCalendarObjectOptions): Promise; + +export interface CreateCalendarObjectOptions { + /** + * rfc 5545 VCALENDAR object. + */ + data: string; + + /** + * name for the calendar ics file. + */ + filename: string; + + /** + * request sandbox. + */ + sandbox?: Sandbox; + + /** + * request sender. + */ + xhr?: transport.Transport; +} + +/** + * Persist updates to the parameter calendar object to the server. + * @param calendarObject updated calendar object. + * @param options + * @returns a Promise which will be fulfilled when the calendar has been updated. + */ +export function updateCalendarObject(calendarObject: CalendarObject, options: UpdateCalendarObjectOptions): Promise; + +export interface UpdateCalendarObjectOptions { + /** + * request sandbox. + */ + sandbox?: Sandbox; + + /** + * request sender. + */ + xhr?: transport.Transport; +} + +/** + * Delete the parameter calendar object on the server. + * @param calendarObject target calendar object. + * @param options + * @returns a Promise which will be fulfilled when the calendar has been deleted. + */ +export function deleteCalendarObject(calendarObject: CalendarObject, options: DeleteCalendarObjectOptions): Promise; + +export interface DeleteCalendarObjectOptions { + /** + * request sandbox. + */ + sandbox?: Sandbox; + + /** + * request sender. + */ + xhr?: transport.Transport; +} + +/** + * Fetch changes from the remote server to the parameter calendar. + * @param calendar the calendar to fetch changes for. + * @param options + * @returns a Promise which will be fulfilled with an updated dav.Calendar object once sync is complete. + */ +export function syncCalendar(calendar: Calendar, options: SyncCalendarOptions): Promise; + +export interface SyncCalendarOptions { + /** + * list of caldav filters to send with request. + */ + filters?: object[]; + + /** + * request sandbox. + */ + sandbox?: Sandbox; + + /** + * either 'basic' or 'webdav'. If unspecified, will try to do webdav sync + * and failover to basic sync if rfc 6578 is not supported by the server. + */ + syncMethod?: "basic" | "webdav"; + + /** + * VTIMEZONE calendar object. + */ + timezone?: string; + + /** + * request sender. + */ + xhr?: transport.Transport; +} + +/** + * Fetch changes from the remote server to the account's calendars. + * @param account the calendar account to sync. + * @param options + * @returns a Promise which will be fulfilled with an updated dav.Account object once sync is complete. + */ +export function syncCaldavAccount(account: Account, options: SyncCaldavAccountOptions): Promise; + +export interface SyncCaldavAccountOptions { + /** + * list of caldav filters to send with request. + */ + filters?: object[]; + + /** + * request sandbox. + */ + sandbox?: Sandbox; + + /** + * either 'basic' or 'webdav'. If unspecified, will try to do webdav sync + * and failover to basic sync if rfc 6578 is not supported by the server. + */ + syncMethod?: "basic" | "webdav"; + + /** + * VTIMEZONE calendar object. + */ + timezone?: string; + + /** + * request sender. + */ + xhr?: transport.Transport; +} + +/** + * Create a vcard object on the parameter address book. + * @param addressBook the address book to put the object on. + * @param options + * @returns a Promise which will be fulfilled when the vcard has been created. + */ +export function createCard(addressBook: AddressBook, options: CreateCardOptions): Promise; + +export interface CreateCardOptions { + /** + * VCARD object. + */ + data: string; + /** + * name for the vcard vcf file. + */ + filename: string; + + /** + * request sandbox. + */ + sandbox?: Sandbox; + /** + * request sender. + */ + xhr?: transport.Transport; +} + +/** + * Persist updates to the parameter vcard object to the server. + * @param card updated vcard object. + * @param options + * @returns a Promise which will be fulfilled when the vcard has been updated. + */ +export function updateCard(card: VCard, options: UpdateCardOptions): Promise; + +export interface UpdateCardOptions { + /** + * request sandbox. + */ + sandbox?: Sandbox; + /** + * request sender. + */ + xhr?: transport.Transport; +} + +/** + * Delete the parameter vcard object on the server. + * @param card target vcard object. + * @param options + * @returns a Promise which will be fulfilled when the vcard has been deleted. + */ +export function deleteCard(card: VCard, options: DeleteCardOptions): Promise; + +export interface DeleteCardOptions { + /** + * request sandbox. + */ + sandbox?: Sandbox; + /** + * request sender. + */ + xhr?: transport.Transport; +} + +/** + * Fetch changes from the remote server to the parameter address books. + * @param addressBook the address book to fetch changes for. + * @param options + * @returns a Promise which will be fulfilled with an updated AddressBook object once sync is complete. + */ +export function syncAddressBook(addressBook: AddressBook, options: SyncAddressBookOptions): Promise; + +export interface SyncAddressBookOptions { + /** + * request sandbox. + */ + sandbox?: Sandbox; + /** + * either 'basic' or 'webdav'.If unspecified, will try to do webdav sync + * and failover to basic sync if rfc 6578 is not supported by the server. + */ + syncMethod?: "basic" | "webdav"; + + /** + * request sender. + */ + xhr?: transport.Transport; +} + +/** + * Fetch changes from the remote server to the account's address books. + * @param account the address book account to sync. + * @param options + * @returns a Promise which will be fulfilled with an updated Account object once sync is complete. + */ +export function syncCarddavAccount(account: Account, options: SyncCarddavAccountOptions): Promise; + +export interface SyncCarddavAccountOptions { + /** + * list of caldav filters to send with request. + */ + filters?: object[]; + + /** + * request sandbox. + */ + sandbox?: Sandbox; + + /** + * either 'basic' or 'webdav'. If unspecified, will try to do webdav sync + * and failover to basic sync if rfc 6578 is not supported by the server. + */ + syncMethod?: "basic" | "webdav"; + + /** + * VTIMEZONE calendar object. + */ + timezone?: string; + + /** + * request sender. + */ + xhr?: transport.Transport; +} + +/** + * Create a request sandbox. + */ +export class Sandbox { + constructor(); + + requestList: any[]; + + add(request: any): void; + + /** + * abort sandboxed requests as a group. + */ + abort(): void; +} + +/** + * @deprecated + */ +export function createSandbox(): Sandbox; + +export namespace transport { + class Transport { + /** + * @param credentials user authorization. + */ + constructor(credentials: Credentials); + + send(request: Request, url: string, options?: TransportOptions): Promise; + } + + interface TransportOptions { + /** + * request sandbox. + */ + sandbox?: Sandbox; + + retry?: boolean; + } + + class Basic extends Transport { + /** + * Create a new Basic object. This sends dav requests using http basic authentication. + * @param credentials user authorization. + */ + constructor(credentials: Credentials); + + /** + * + * @param request object with request info. + * @param url + * @param options + * @return a promise that will be resolved with an xhr request after + * its readyState is 4 or the result of applying an optional request + * `transformResponse` function to the xhr object after its readyState + * is 4. + */ + send(request: Request, url: string, options?: TransportOptions): Promise; + } + + /** + * Create a new OAuth2 object.This sends dav requests authorized via rfc 6749 oauth2. + * @param credentials user authorization. + */ + class OAuth2 extends Transport { + constructor(credentials: Credentials); + + /** + * + * @param request object with request info. + * @param url + * @param options + * @return a promise that will be resolved with an xhr request after + * its readyState is 4 or the result of applying an optional request + * `transformResponse` function to the xhr object after its readyState + * is 4. + */ + send(request: Request, url: string, options?: TransportOptions): Promise; + } +} + +export namespace request { + /** + * + * @param options + * @returns + */ + function addressBookQuery(options: AddressBookQueryOptions): string; + + interface AddressBookQueryOptions { + /** + * value for Depth header. + */ + depth?: string; + + /** + * list of props to request. + */ + props: object[]; + } + + /** + * + * @param options + * @returns + */ + function basic(options: BasicOptions): Request; + + interface BasicOptions { + /** + * put request body. + */ + data: string; + + /** + * http method. + */ + method: string; + + /** + * cached calendar object etag. + */ + etag: string; + } + + /** + * + * @param options + * @returns + */ + function calendarQuery(options: CalendarQueryOptions): string; + + interface CalendarQueryOptions { + /** + * value for Depth header. + */ + depth?: string; + + /** + * list of filters to send with request. + */ + filters: object[]; + + /** + * list of props to request. + */ + props: object[]; + + /** + * VTIMEZONE calendar object. + */ + timezone: string; + } + + /** + * + * @param options + * @returns + */ + function propfind(options: PropfindOptions): string; + + interface PropfindOptions { + /** + * value for Depth header. + */ + depth?: string; + + /** + * list of props to request. + */ + props: object[]; + } + + /** + * + * @param options + * @returns + */ + function syncCollection(options: SyncCollectionOptions): string; + + interface SyncCollectionOptions { + /** + * option value for Depth header. + */ + depth?: string; + + /** + * list of props to request. + */ + props: object[]; + + /** + * indicates scope of the sync report request. + */ + syncLevel: number; + + /** + * synchronization token provided by the server. + */ + syncToken: string; + } +} + +export class Client { + /** + * Create a new Client object. The client interface allows consumers to set + * their credentials and transport once and then make authorized requests + * without passing them to each request. Each of the other, public API + * methods should be available on Client objects. + * @param xhr request sender. + * @param options + */ + constructor(xhr: transport.Transport, options?: ClientOptions); + + /** + * Send a request using this client's transport (and perhaps baseUrl). + * @param req dav request. + * @param options + * @return a promise that will be resolved with an xhr request after + * its readyState is 4 or the result of applying an optional request + * `transformResponse` function to the xhr object after its readyState + * is 4. + */ + send(req: Request, uri: string, options?: ClientSendOptions): Promise; + + /** + * Perform an initial download of a caldav or carddav account's data. + * @param options + * @returns a Promise which will be fulfilled with a dav.Account object. + */ + createAccount(options?: CreateAccountOptions): Promise; + + /** + * Create a calendar object on the parameter calendar. + * @param calendar the calendar to put the object on. + * @param options + * @returns a Promise which will be fulfilled when the calendar has been created. + */ + createCalendarObject(calendar: Calendar, options?: CreateCalendarObjectOptions): Promise; + + /** + * Persist updates to the parameter calendar object to the server. + * @param calendarObject updated calendar object. + * @param options + * @returns a Promise which will be fulfilled when the calendar has been updated. + */ + updateCalendarObject(calendarObject: CalendarObject, options?: UpdateCalendarObjectOptions): Promise; + + /** + * Delete the parameter calendar object on the server. + * @param calendarObject target calendar object. + * @param options + * @returns a Promise which will be fulfilled when the calendar has been deleted. + */ + deleteCalendarObject(calendarObject: CalendarObject, options?: DeleteCalendarObjectOptions): Promise; + + /** + * Fetch changes from the remote server to the parameter calendar. + * @param calendar the calendar to fetch changes for. + * @param options + * @returns a Promise which will be fulfilled with an updated dav.Calendar object once sync is complete. + */ + syncCalendar(calendar: Calendar, options?: SyncCalendarOptions): Promise; + + /** + * Fetch changes from the remote server to the account's calendars. + * @param account the calendar account to sync. + * @param options + * @returns a Promise which will be fulfilled with an updated dav.Account object once sync is complete. + */ + syncCaldavAccount(account: Account, options?: SyncCaldavAccountOptions): Promise; + + /** + * Create a vcard object on the parameter address book. + * @param addressBook the address book to put the object on. + * @param options + * @returns a Promise which will be fulfilled when the vcard has been created. + */ + createCard(addressBook: AddressBook, options?: CreateCardOptions): Promise; + + /** + * Persist updates to the parameter vcard object to the server. + * @param card updated vcard object. + * @param options + * @returns a Promise which will be fulfilled when the vcard has been updated. + */ + updateCard(card: VCard, options?: UpdateCardOptions): Promise; + + /** + * + * Delete the parameter vcard object on the server. + * @param card target vcard object. + * @param options + * @returns a Promise which will be fulfilled when the vcard has been deleted. + */ + deleteCard(card: VCard, options?: DeleteCardOptions): Promise; + + /** + * Fetch changes from the remote server to the parameter address books. + * @param addressBook the address book to fetch changes for. + * @param options + * @returns a Promise which will be fulfilled with an updated AddressBook object once sync is complete. + */ + syncAddressBook(addressBook: AddressBook, options?: SyncAddressBookOptions): Promise; + + /** + * Fetch changes from the remote server to the account's address books. + * @param account the address book account to sync. + * @param options + * @returns a Promise which will be fulfilled with an updated Account object once sync is complete. + */ + syncCarddavAccount(account: Account, options?: SyncCarddavAccountOptions): Promise; +} + +export interface ClientOptions { + /** + * root url to resolve relative request urls with. + */ + baseUrl: string; +} + +export interface ClientSendOptions { + /** + * request sandbox. + */ + sandbox?: Sandbox; + /** + * relative url for request. + */ + url?: string; +} + +export type Partial = { + [P in keyof T]?: T[P]; +}; + +export class Account { + constructor(options?: AccountOptions); + server: string; + credentials: Credentials; + rootUrl: string; + principalUrl: string; + homeUrl: string; + calendars: Calendar[]; + addressBooks: AddressBook[]; +} + +export type AccountOptions = Partial; + +export class Credentials { + constructor(options?: CredentialsOptions); + + /** + * username (perhaps email) for calendar user. + */ + username: string; + + /** + * plaintext password for calendar user. + */ + password: string; + + /** + * oauth client id. + */ + clientId: string; + + /** + * oauth client secret. + */ + clientSecret: string; + + /** + * oauth code. + */ + authorizationCode: string; + + /** + * oauth redirect url. + */ + redirectUrl: string; + + /** + * oauth token url. + */ + tokenUrl: string; + + /** + * oauth access token. + */ + accessToken: string; + + /** + * oauth refresh token. + */ + refreshToken: string; + + /** + * unix time for access token expiration. + */ + expiration: number; +} +export type CredentialsOptions = Partial; + +export class DAVCollection { + constructor(options: DAVCollectionOptions); + data: string; + objects: T[]; + account: Account; + ctag: string; + description: string; + displayName: string; + reports: string[]; + resourcetype: string; + syncToken: string; + url: string; +} +export type DAVCollectionOptions = Partial>; + +export class AddressBook extends DAVCollection { + constructor(options?: AddressBookOptions); +} +export type AddressBookOptions = Partial; + +export class Calendar extends DAVCollection { + constructor(options?: CalendarOptions); + + components: string[]; + timezone: string; +} +export type CalendarOptions = Partial; + +export class DAVObject { + constructor(options: DAVObjectOptions); + data: string; + etag: string; + url: string; +} +export type DAVObjectOptions = Partial; + +export class CalendarObject extends DAVObject { + constructor(options?: CalendarObjectOptions); + calendar: Calendar; + calendarData: string; +} +export type CalendarObjectOptions = Partial; + +export class VCard extends DAVObject { + constructor(options?: VCardOptions); + addressBook: AddressBook; + addressData: string; +} + +export type VCardOptions = Partial; + +export class Request { + constructor(options?: RequestOptions); + method: string; + requestData?: string; + transformRequest?: (xhr: any) => any; + transformResponse?: (xhr: any) => any; + onerror?: (error: Error) => any; +} + +export type RequestOptions = Partial; + +export namespace debug { + let enabled: boolean; +} + +export namespace ns { + const CALENDAR_SERVER = 'http://calendarserver.org/ns/'; + const CALDAV_APPLE = 'http://apple.com/ns/ical/'; + const CALDAV = 'urn:ietf:params:xml:ns:caldav'; + const CARDDAV = 'urn:ietf:params:xml:ns:carddav'; + const DAV = 'DAV:'; +} diff --git a/types/dav/tsconfig.json b/types/dav/tsconfig.json index 5de3437644..344edfe56a 100644 --- a/types/dav/tsconfig.json +++ b/types/dav/tsconfig.json @@ -1,23 +1,23 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "dav-tests.ts" - ] +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "dav-tests.ts" + ] } \ No newline at end of file From 6b32afc1d68134b76db1c229bfa1da89a9b23240 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Sat, 18 Aug 2018 11:02:08 -0700 Subject: [PATCH 21/25] ora/v0: Fix lint --- types/ora/v0/index.d.ts | 4 +- types/ora/v0/tslint.json | 80 +--------------------------------------- 2 files changed, 3 insertions(+), 81 deletions(-) diff --git a/types/ora/v0/index.d.ts b/types/ora/v0/index.d.ts index 536d858bd7..771f6beef6 100644 --- a/types/ora/v0/index.d.ts +++ b/types/ora/v0/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for ora v0.3.0 +// Type definitions for ora 0.3 // Project: https://github.com/sindresorhus/ora -// Definitions by: Basarat Ali Syed , Christian Rackerseder +// Definitions by: Basarat Ali Syed , Christian Rackerseder // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// diff --git a/types/ora/v0/tslint.json b/types/ora/v0/tslint.json index a41bf5d19a..3db14f85ea 100644 --- a/types/ora/v0/tslint.json +++ b/types/ora/v0/tslint.json @@ -1,79 +1 @@ -{ - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } -} +{ "extends": "dtslint/dt.json" } From ee84ef5f4f658a8010ce5d5f14bf9448d9bafeb2 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Sat, 18 Aug 2018 13:33:03 -0700 Subject: [PATCH 22/25] joi: lint more --- types/joi/index.d.ts | 32 +- types/joi/joi-tests.ts | 65 +- types/joi/tslint.json | 70 +- types/joi/v10/index.d.ts | 25 +- types/joi/v10/joi-tests.ts | 113 ++- types/joi/v10/tslint.json | 71 +- types/joi/v6/index.d.ts | 1507 ++++++++++++++++++------------------ types/joi/v6/joi-tests.ts | 95 ++- types/joi/v6/tslint.json | 71 +- 9 files changed, 907 insertions(+), 1142 deletions(-) diff --git a/types/joi/index.d.ts b/types/joi/index.d.ts index 0453ef7d20..256e35a8c7 100644 --- a/types/joi/index.d.ts +++ b/types/joi/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for joi v13.4.0 +// Type definitions for joi 13.4 // Project: https://github.com/hapijs/joi // Definitions by: Bart van der Schoor // Laurence Dougal Myers @@ -125,7 +125,7 @@ export interface IpOptions { cidr?: string; } -export type GuidVersions = 'uuidv1' | 'uuidv2' | 'uuidv3' | 'uuidv4' | 'uuidv5' +export type GuidVersions = 'uuidv1' | 'uuidv2' | 'uuidv3' | 'uuidv4' | 'uuidv5'; export interface GuidOptions { version: GuidVersions[] | GuidVersions; @@ -181,8 +181,8 @@ export interface ReferenceOptions { } export interface IPOptions { - version?: Array; - cidr?: string + version?: string[]; + cidr?: string; } export interface StringRegexOptions { @@ -236,7 +236,6 @@ export type Schema = AnySchema | LazySchema; export interface AnySchema extends JoiObject { - schemaType?: Types | string; /** @@ -441,7 +440,6 @@ export interface State { } export interface BooleanSchema extends AnySchema { - /** * Allows for additional values to be considered valid booleans by converting them to true during validation. * Accepts a value or an array of values. String comparisons are by default case insensitive, @@ -695,7 +693,9 @@ export interface ArraySchema extends AnySchema { /** * Lists the types in sequence order for the array values where: * @param type - a joi schema object to validate against each array item in sequence order. type can be an array of values, or multiple values can be passed as individual arguments. - * If a given type is .required() then there must be a matching item with the same index position in the array. Errors will contain the number of items that didn't match. Any unmatched item having a label will be mentioned explicitly. + * If a given type is .required() then there must be a matching item with the same index position in the array. + * Errors will contain the number of items that didn't match. + * Any unmatched item having a label will be mentioned explicitly. */ ordered(...types: SchemaLike[]): this; ordered(types: SchemaLike[]): this; @@ -726,7 +726,6 @@ export interface ArraySchema extends AnySchema { } export interface ObjectSchema extends AnySchema { - /** * Sets or extends the allowed object keys. */ @@ -754,9 +753,9 @@ export interface ObjectSchema extends AnySchema { /** * Specify validation rules for unknown keys matching a pattern. - * - * @param pattern - a pattern that can be either a regular expression or a joi schema that will be tested against the unknown key names - * @param schema - the schema object matching keys must validate against + * + * @param pattern - a pattern that can be either a regular expression or a joi schema that will be tested against the unknown key names + * @param schema - the schema object matching keys must validate against */ pattern(pattern: RegExp | SchemaLike, schema: SchemaLike): this; @@ -884,7 +883,6 @@ export interface BinarySchema extends AnySchema { } export interface DateSchema extends AnySchema { - /** * Specifies the oldest date allowed. * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date, @@ -927,7 +925,6 @@ export interface DateSchema extends AnySchema { } export interface FunctionSchema extends AnySchema { - /** * Specifies the arity of the function where: * @param n - the arity expected. @@ -961,7 +958,6 @@ export interface AlternativesSchema extends AnySchema { } export interface LazySchema extends AnySchema { - } export interface Reference extends JoiObject { @@ -982,7 +978,7 @@ export type ExtensionBoundSchema = Schema & { * @param options - should the context passed into the `validate` function in a custom rule */ createError(type: string, context: Context, state: State, options: ValidationOptions): Err; -} +}; export interface Rules

{ name: string; @@ -1134,7 +1130,7 @@ export function reach(schema: ObjectSchema, path: string[]): T /** * Creates a new Joi instance customized with the extension(s) you provide included. */ -export function extend(extension: Extension|Extension[], ...extensions: (Extension|Extension[])[]): any; +export function extend(extension: Extension|Extension[], ...extensions: Array): any; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- @@ -1160,8 +1156,8 @@ export function defaults(fn: DefaultsFunction): Root; export function describe(schema: Schema): Description; /** -* Whitelists a value -*/ + * Whitelists a value + */ export function allow(value: any, ...values: any[]): Schema; export function allow(values: any[]): Schema; diff --git a/types/joi/joi-tests.ts b/types/joi/joi-tests.ts index 49ff810263..5defe20cc1 100644 --- a/types/joi/joi-tests.ts +++ b/types/joi/joi-tests.ts @@ -3,29 +3,24 @@ import Joi = require('joi'); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- let x: any = null; -let value: any = null; -let num: number = 0; -let str: string = ''; -let bool: boolean = false; -let exp: RegExp = null; -let obj: object = null; -let date: Date = null; -let err: Error = null; -let func: Function = null; +declare const value: any; +let num = 0; +let str = ''; +declare const bool: boolean; +declare const exp: RegExp; +declare const obj: object; +declare const date: Date; +declare const err: Error; +declare const func: Function; -let anyArr: any[] = []; -let numArr: number[] = []; -let strArr: string[] = []; -let boolArr: boolean[] = []; -let expArr: RegExp[] = []; -let objArr: object[] = []; -let errArr: Error[] = []; -let funcArr: Function[] = []; +declare const numArr: number[]; +declare const strArr: string[]; +declare const expArr: RegExp[]; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- let schema: Joi.Schema = null; -let schemaLike: Joi.SchemaLike = null; +declare const schemaLike: Joi.SchemaLike; let anySchema: Joi.AnySchema = null; let numSchema: Joi.NumberSchema = null; @@ -38,7 +33,7 @@ let funcSchema: Joi.FunctionSchema = null; let objSchema: Joi.ObjectSchema = null; let altSchema: Joi.AlternativesSchema = null; -let schemaArr: Joi.Schema[] = []; +declare const schemaArr: Joi.Schema[]; let ref: Joi.Reference = null; let description: Joi.Description = null; @@ -156,7 +151,7 @@ stringRegexOpts = { invert: bool }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -let validErr: Joi.ValidationError = null; +declare const validErr: Joi.ValidationError; let validErrItem: Joi.ValidationErrorItem; let validErrFunc: Joi.ValidationErrorFunction; @@ -235,13 +230,13 @@ schemaMap = { { c1: true }, { c2: null } ] -} +}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- anySchema = Joi.any(); -namespace common { +{ // common anySchema = anySchema.allow(x); anySchema = anySchema.allow(x, x); anySchema = anySchema.allow([x, x, x]); @@ -323,7 +318,6 @@ arrSchema = arrSchema.unique(); arrSchema = arrSchema.unique((a, b) => a.test === b.test); arrSchema = arrSchema.unique('customer.id'); - arrSchema = arrSchema.items(numSchema); arrSchema = arrSchema.items(numSchema, strSchema, schemaLike); arrSchema = arrSchema.items([numSchema, strSchema, schemaLike]); @@ -333,7 +327,7 @@ arrSchema = arrSchema.items([schemaMap, schemaMap, schemaLike]); // - - - - - - - - -namespace common_copy_paste { +{ // common copy paste // use search & replace from any arrSchema = arrSchema.allow(x); arrSchema = arrSchema.allow(x, x); @@ -387,7 +381,7 @@ namespace common_copy_paste { boolSchema = Joi.bool(); boolSchema = Joi.boolean(); -namespace common_copy_paste { +{ // common copy paste boolSchema = boolSchema.allow(x); boolSchema = boolSchema.allow(x, x); boolSchema = boolSchema.allow([x, x, x]); @@ -462,7 +456,7 @@ binSchema = binSchema.min(num); binSchema = binSchema.max(num); binSchema = binSchema.length(num); -namespace common { +{ // common binSchema = binSchema.allow(x); binSchema = binSchema.allow(x, x); binSchema = binSchema.allow([x, x, x]); @@ -535,7 +529,7 @@ dateSchema = dateSchema.timestamp(); dateSchema = dateSchema.timestamp('javascript'); dateSchema = dateSchema.timestamp('unix'); -namespace common { +{ // common dateSchema = dateSchema.allow(x); dateSchema = dateSchema.allow(x, x); dateSchema = dateSchema.allow([x, x, x]); @@ -611,7 +605,7 @@ numSchema = numSchema.positive(); numSchema = numSchema.negative(); numSchema = numSchema.port(); -namespace common { +{ // common numSchema = numSchema.allow(x); numSchema = numSchema.allow(x, x); numSchema = numSchema.allow([x, x, x]); @@ -729,7 +723,7 @@ objSchema = objSchema.forbiddenKeys(str); objSchema = objSchema.forbiddenKeys(str, str); objSchema = objSchema.forbiddenKeys(strArr); -namespace common { +{ // common objSchema = objSchema.allow(x); objSchema = objSchema.allow(x, x); objSchema = objSchema.allow([x, x, x]); @@ -809,7 +803,7 @@ strSchema = strSchema.ip(ipOpts); strSchema = strSchema.uri(); strSchema = strSchema.uri(uriOpts); strSchema = strSchema.guid(); -strSchema = strSchema.guid({ version: ['uuidv1', 'uuidv2', 'uuidv3', 'uuidv4', 'uuidv5'] } as Joi.GuidOptions); +strSchema = strSchema.guid({ version: ['uuidv1', 'uuidv2', 'uuidv3', 'uuidv4', 'uuidv5'] }); strSchema = strSchema.guid({ version: 'uuidv4' }); strSchema = strSchema.hex(); strSchema = strSchema.hex(hexOpts); @@ -825,7 +819,7 @@ strSchema = strSchema.normalize('NFKC'); strSchema = strSchema.base64(); strSchema = strSchema.base64(base64Opts); -namespace common { +{ // common strSchema = strSchema.allow(x); strSchema = strSchema.allow(x, x); strSchema = strSchema.allow([x, x, x]); @@ -891,11 +885,11 @@ schema = Joi.alt(schema, anySchema, boolSchema); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -schema = Joi.lazy(() => schema) +schema = Joi.lazy(() => schema); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -namespace validate_tests { +{ // validate tests { Joi.validate(value, obj); Joi.validate(value, schema); @@ -925,7 +919,7 @@ namespace validate_tests { { let value = { username: 'example', password: 'example' }; - let schema = Joi.object().keys({ + const schema = Joi.object().keys({ username: Joi.string().max(255).required(), password: Joi.string().regex(/^[a-zA-Z0-9]{3,255}$/).required(), }); @@ -951,12 +945,11 @@ namespace validate_tests { returnValue .then(val => JSON.stringify(val, null, 2)) - .then(val => { throw 'one error'; }) + .then(val => { throw new Error('one error'); }) .catch(e => {}); } } - // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- schema = Joi.compile(obj); diff --git a/types/joi/tslint.json b/types/joi/tslint.json index a41bf5d19a..87b70df769 100644 --- a/types/joi/tslint.json +++ b/types/joi/tslint.json @@ -1,79 +1,13 @@ { "extends": "dtslint/dt.json", "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, + // All are TODOs "ban-types": false, "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false + "unified-signatures": false } } diff --git a/types/joi/v10/index.d.ts b/types/joi/v10/index.d.ts index e8202d77dd..8e0026a5fe 100644 --- a/types/joi/v10/index.d.ts +++ b/types/joi/v10/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for joi v10.6.0 +// Type definitions for joi 10.6 // Project: https://github.com/hapijs/joi // Definitions by: Bart van der Schoor // Laurence Dougal Myers @@ -114,7 +114,7 @@ export interface IpOptions { cidr?: string; } -export type GuidVersions = 'uuidv1' | 'uuidv2' | 'uuidv3' | 'uuidv4' | 'uuidv5' +export type GuidVersions = 'uuidv1' | 'uuidv2' | 'uuidv3' | 'uuidv4' | 'uuidv5'; export interface GuidOptions { version: GuidVersions[] | GuidVersions; @@ -160,8 +160,8 @@ export interface ReferenceOptions { } export interface IPOptions { - version?: Array; - cidr?: string + version?: string[]; + cidr?: string; } export interface JoiObject { @@ -210,7 +210,6 @@ export type Schema = AnySchema | LazySchema; export interface AnySchema extends JoiObject { - /** * Validates a value using the schema and options. */ @@ -411,7 +410,6 @@ export interface State { } export interface BooleanSchema extends AnySchema { - /** * Allows for additional values to be considered valid booleans by converting them to true during validation. * Accepts a value or an array of values. String comparisons are by default case insensitive, @@ -514,7 +512,6 @@ export interface StringSchema extends AnySchema { max(limit: number, encoding?: string): this; max(limit: Reference, encoding?: string): this; - /** * Specifies whether the string.max() limit should be used as a truncation. * @param enabled - optional parameter defaulting to true which allows you to reset the behavior of truncate by providing a falsy value. @@ -651,7 +648,9 @@ export interface ArraySchema extends AnySchema { /** * Lists the types in sequence order for the array values where: * @param type - a joi schema object to validate against each array item in sequence order. type can be an array of values, or multiple values can be passed as individual arguments. - * If a given type is .required() then there must be a matching item with the same index position in the array. Errors will contain the number of items that didn't match. Any unmatched item having a label will be mentioned explicitly. + * If a given type is .required() then there must be a matching item with the same index position in the array. + * Errors will contain the number of items that didn't match. + * Any unmatched item having a label will be mentioned explicitly. */ ordered(...types: SchemaLike[]): this; ordered(types: SchemaLike[]): this; @@ -682,7 +681,6 @@ export interface ArraySchema extends AnySchema { } export interface ObjectSchema extends AnySchema { - /** * Sets the allowed object keys. */ @@ -819,7 +817,6 @@ export interface BinarySchema extends AnySchema { } export interface DateSchema extends AnySchema { - /** * Specifies the oldest date allowed. * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date, @@ -862,7 +859,6 @@ export interface DateSchema extends AnySchema { } export interface FunctionSchema extends AnySchema { - /** * Specifies the arity of the function where: * @param n - the arity expected. @@ -896,7 +892,6 @@ export interface AlternativesSchema extends AnySchema { } export interface LazySchema extends AnySchema { - } export interface Reference extends JoiObject { @@ -917,7 +912,7 @@ export type ExtensionBoundSchema = Schema & { * @param options - should the context passed into the `validate` function in a custom rule */ createError(type: string, context: Context, state: State, options: ValidationOptions): Err; -} +}; export interface Rules

{ name: string; @@ -1078,8 +1073,8 @@ export function extend(extention: Extension): any; export function describe(schema: Schema): Description; /** -* Whitelists a value -*/ + * Whitelists a value + */ export function allow(value: any, ...values: any[]): Schema; export function allow(values: any[]): Schema; diff --git a/types/joi/v10/joi-tests.ts b/types/joi/v10/joi-tests.ts index e1194f5b76..8782a46dfa 100644 --- a/types/joi/v10/joi-tests.ts +++ b/types/joi/v10/joi-tests.ts @@ -2,50 +2,45 @@ import Joi = require('joi'); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var x: any = null; -var value: any = null; -var num: number = 0; -var str: string = ''; -var bool: boolean = false; -var exp: RegExp = null; -var obj: object = null; -var date: Date = null; -var err: Error = null; -var func: Function = null; +let x: any = null; +declare const value: any; +let num = 0; +let str = ''; +declare const bool: boolean; +declare const exp: RegExp; +declare const obj: object; +declare const date: Date; +declare const err: Error; +declare const func: Function; -var anyArr: any[] = []; -var numArr: number[] = []; -var strArr: string[] = []; -var boolArr: boolean[] = []; -var expArr: RegExp[] = []; -var objArr: object[] = []; -var errArr: Error[] = []; -var funcArr: Function[] = []; +declare const numArr: number[]; +declare const strArr: string[]; +declare const expArr: RegExp[]; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var schema: Joi.Schema = null; -var schemaLike: Joi.SchemaLike = null; +let schema: Joi.Schema = null; +declare const schemaLike: Joi.SchemaLike; -var anySchema: Joi.AnySchema = null; -var numSchema: Joi.NumberSchema = null; -var strSchema: Joi.StringSchema = null; -var arrSchema: Joi.ArraySchema = null; -var boolSchema: Joi.BooleanSchema = null; -var binSchema: Joi.BinarySchema = null; -var dateSchema: Joi.DateSchema = null; -var funcSchema: Joi.FunctionSchema = null; -var objSchema: Joi.ObjectSchema = null; -var altSchema: Joi.AlternativesSchema = null; +let anySchema: Joi.AnySchema = null; +let numSchema: Joi.NumberSchema = null; +let strSchema: Joi.StringSchema = null; +let arrSchema: Joi.ArraySchema = null; +let boolSchema: Joi.BooleanSchema = null; +let binSchema: Joi.BinarySchema = null; +let dateSchema: Joi.DateSchema = null; +let funcSchema: Joi.FunctionSchema = null; +let objSchema: Joi.ObjectSchema = null; +let altSchema: Joi.AlternativesSchema = null; -var schemaArr: Joi.Schema[] = []; +declare const schemaArr: Joi.Schema[]; -var ref: Joi.Reference = null; -var description: Joi.Description = null; +let ref: Joi.Reference = null; +let description: Joi.Description = null; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var validOpts: Joi.ValidationOptions = null; +let validOpts: Joi.ValidationOptions = null; validOpts = { abortEarly: bool }; validOpts = { convert: bool }; @@ -77,7 +72,7 @@ validOpts = { // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var renOpts: Joi.RenameOptions = null; +let renOpts: Joi.RenameOptions; renOpts = { alias: bool }; renOpts = { multiple: bool }; @@ -86,7 +81,7 @@ renOpts = { ignoreUndefined: bool }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var emailOpts: Joi.EmailOptions = null; +let emailOpts: Joi.EmailOptions; emailOpts = { errorLevel: num }; emailOpts = { errorLevel: bool }; @@ -96,7 +91,7 @@ emailOpts = { minDomainAtoms: num }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var ipOpts: Joi.IpOptions = null; +let ipOpts: Joi.IpOptions; ipOpts = { version: str }; ipOpts = { version: strArr }; @@ -104,7 +99,7 @@ ipOpts = { cidr: str }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var uriOpts: Joi.UriOptions = null; +let uriOpts: Joi.UriOptions; uriOpts = { scheme: str }; uriOpts = { scheme: exp }; @@ -113,7 +108,7 @@ uriOpts = { scheme: expArr }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var whenOpts: Joi.WhenOptions = null; +let whenOpts: Joi.WhenOptions; whenOpts = { is: x }; whenOpts = { is: schema, then: schema }; @@ -122,7 +117,7 @@ whenOpts = { is: schemaLike, then: schemaLike, otherwise: schemaLike }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var whenSchemaOpts: Joi.WhenSchemaOptions = null; +let whenSchemaOpts: Joi.WhenSchemaOptions; whenSchemaOpts = { then: schema }; whenSchemaOpts = { otherwise: schema }; @@ -130,16 +125,16 @@ whenSchemaOpts = { then: schemaLike, otherwise: schemaLike }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var refOpts: Joi.ReferenceOptions = null; +let refOpts: Joi.ReferenceOptions; refOpts = { separator: str }; refOpts = { contextPrefix: str }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var validErr: Joi.ValidationError = null; -var validErrItem: Joi.ValidationErrorItem; -var validErrFunc: Joi.ValidationErrorFunction; +declare const validErr: Joi.ValidationError; +let validErrItem: Joi.ValidationErrorItem; +let validErrFunc: Joi.ValidationErrorFunction; validErrItem = { message: str, @@ -184,7 +179,7 @@ anySchema = objSchema; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var schemaMap: Joi.SchemaMap = null; +let schemaMap: Joi.SchemaMap; schemaMap = { a: numSchema, @@ -216,13 +211,13 @@ schemaMap = { { c1: true }, { c2: null } ] -} +}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- anySchema = Joi.any(); -namespace common { +{ // common anySchema = anySchema.allow(x); anySchema = anySchema.allow(x, x); anySchema = anySchema.allow([x, x, x]); @@ -304,7 +299,6 @@ arrSchema = arrSchema.unique(); arrSchema = arrSchema.unique((a, b) => a.test === b.test); arrSchema = arrSchema.unique('customer.id'); - arrSchema = arrSchema.items(numSchema); arrSchema = arrSchema.items(numSchema, strSchema, schemaLike); arrSchema = arrSchema.items([numSchema, strSchema, schemaLike]); @@ -314,7 +308,7 @@ arrSchema = arrSchema.items([schemaMap, schemaMap, schemaLike]); // - - - - - - - - -namespace common_copy_paste { +{ // common copy paste // use search & replace from any arrSchema = arrSchema.allow(x); arrSchema = arrSchema.allow(x, x); @@ -368,7 +362,7 @@ namespace common_copy_paste { boolSchema = Joi.bool(); boolSchema = Joi.boolean(); -namespace common_copy_paste { +{ // common copy paste boolSchema = boolSchema.allow(x); boolSchema = boolSchema.allow(x, x); boolSchema = boolSchema.allow([x, x, x]); @@ -443,7 +437,7 @@ binSchema = binSchema.min(num); binSchema = binSchema.max(num); binSchema = binSchema.length(num); -namespace common { +{ // common binSchema = binSchema.allow(x); binSchema = binSchema.allow(x, x); binSchema = binSchema.allow([x, x, x]); @@ -516,7 +510,7 @@ dateSchema = dateSchema.timestamp(); dateSchema = dateSchema.timestamp('javascript'); dateSchema = dateSchema.timestamp('unix'); -namespace common { +{ // common dateSchema = dateSchema.allow(x); dateSchema = dateSchema.allow(x, x); dateSchema = dateSchema.allow([x, x, x]); @@ -591,7 +585,7 @@ numSchema = numSchema.multiple(num); numSchema = numSchema.positive(); numSchema = numSchema.negative(); -namespace common { +{ // common numSchema = numSchema.allow(x); numSchema = numSchema.allow(x, x); numSchema = numSchema.allow([x, x, x]); @@ -702,7 +696,7 @@ objSchema = objSchema.optionalKeys(str); objSchema = objSchema.optionalKeys(str, str); objSchema = objSchema.optionalKeys(strArr); -namespace common { +{ // common objSchema = objSchema.allow(x); objSchema = objSchema.allow(x, x); objSchema = objSchema.allow([x, x, x]); @@ -781,7 +775,7 @@ strSchema = strSchema.ip(ipOpts); strSchema = strSchema.uri(); strSchema = strSchema.uri(uriOpts); strSchema = strSchema.guid(); -strSchema = strSchema.guid({ version: ['uuidv1', 'uuidv2', 'uuidv3', 'uuidv4', 'uuidv5'] } as Joi.GuidOptions); +strSchema = strSchema.guid({ version: ['uuidv1', 'uuidv2', 'uuidv3', 'uuidv4', 'uuidv5'] }); strSchema = strSchema.guid({ version: 'uuidv4' }); strSchema = strSchema.hex(); strSchema = strSchema.hostname(); @@ -794,7 +788,7 @@ strSchema = strSchema.truncate(false); strSchema = strSchema.normalize(); strSchema = strSchema.normalize('NFKC'); -namespace common { +{ // common strSchema = strSchema.allow(x); strSchema = strSchema.allow(x, x); strSchema = strSchema.allow([x, x, x]); @@ -860,11 +854,11 @@ schema = Joi.alt(schema, anySchema, boolSchema); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -schema = Joi.lazy(() => schema) +schema = Joi.lazy(() => schema); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -namespace validate_tests { +{ // validate tests { Joi.validate(value, obj); Joi.validate(value, schema); @@ -894,7 +888,7 @@ namespace validate_tests { { let value = { username: 'example', password: 'example' }; - let schema = Joi.object().keys({ + const schema = Joi.object().keys({ username: Joi.string().max(255).required(), password: Joi.string().regex(/^[a-zA-Z0-9]{3,255}$/).required(), }); @@ -920,7 +914,6 @@ namespace validate_tests { } } - // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- schema = Joi.compile(obj); diff --git a/types/joi/v10/tslint.json b/types/joi/v10/tslint.json index a41bf5d19a..0b8095b5e1 100644 --- a/types/joi/v10/tslint.json +++ b/types/joi/v10/tslint.json @@ -1,79 +1,12 @@ { "extends": "dtslint/dt.json", "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, + // All are TODOs "ban-types": false, "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false + "unified-signatures": false } } diff --git a/types/joi/v6/index.d.ts b/types/joi/v6/index.d.ts index d9ee7c20d1..5f5fb5625d 100644 --- a/types/joi/v6/index.d.ts +++ b/types/joi/v6/index.d.ts @@ -1,778 +1,773 @@ -// Type definitions for joi v6.5.0 +// Type definitions for joi 6.5 // Project: https://github.com/spumko/joi -// Definitions by: Bart van der Schoor , Laurence Dougal Myers , Christopher Glantschnig , David Broder-Rodgers +// Definitions by: Bart van der Schoor +// Laurence Dougal Myers +// Christopher Glantschnig +// David Broder-Rodgers // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TODO express type of Schema in a type-parameter (.default, .valid, .example etc) -declare module 'joi' { - - export interface ValidationOptions { - /** - * when true, stops validation on the first error, otherwise returns all the errors found. Defaults to true. - */ - abortEarly?: boolean; - /** - * when true, attempts to cast values to the required types (e.g. a string to a number). Defaults to true. - */ - convert?: boolean; - /** - * when true, allows object to contain unknown keys which are ignored. Defaults to false. - */ - allowUnknown?: boolean; - /** - * when true, ignores unknown keys with a function value. Defaults to false. - */ - skipFunctions?: boolean; - /** - * when true, unknown keys are deleted (only when value is an object). Defaults to false. - */ - stripUnknown?: boolean; - /** - * overrides individual error messages. Defaults to no override ({}). - */ - language?: Object; - /** - * sets the default presence requirements. Supported modes: 'optional', 'required', and 'forbidden'. Defaults to 'optional'. - */ - presence?: string; - /** - * provides an external data set to be used in references - */ - context?: Object; - } - - export interface RenameOptions { - /** - * if true, does not delete the old key name, keeping both the new and old keys in place. Defaults to false. - */ - alias?: boolean; - /** - * if true, allows renaming multiple keys to the same destination where the last rename wins. Defaults to false. - */ - multiple?: boolean; - /** - * if true, allows renaming a key over an existing key. Defaults to false. - */ - override?: boolean; - /** - * if true, skip renaming of a key if it's undefined. Defaults to false. - */ - ignoreUndefined?: boolean; - } - - export interface EmailOptions { - /** - * Numerical threshold at which an email address is considered invalid - */ - errorLevel?: number | boolean; - /** - * Specifies a list of acceptable TLDs. - */ - tldWhitelist?: string[] | Object; - /** - * Number of atoms required for the domain. Be careful since some domains, such as io, directly allow email. - */ - minDomainAtoms?: number; - } - - export interface IpOptions { - /** - * One or more IP address versions to validate against. Valid values: ipv4, ipv6, ipvfuture - */ - version ?: string | string[]; - /** - * Used to determine if a CIDR is allowed or not. Valid values: optional, required, forbidden - */ - cidr?: string; - } - - export interface UriOptions { - /** - * Specifies one or more acceptable Schemes, should only include the scheme name. - * Can be an Array or String (strings are automatically escaped for use in a Regular Expression). - */ - scheme ?: string | RegExp | Array; - } - - export interface WhenOptions { - /** - * the required condition joi type. - */ - is: T; - /** - * the alternative schema type if the condition is true. Required if otherwise is missing. - */ - then?: Schema; - /** - * the alternative schema type if the condition is false. Required if then is missing - */ - otherwise?: Schema; - } - - export interface ReferenceOptions { - separator?: string; - contextPrefix?: string; - } - - export interface IPOptions { - version?: Array; - cidr?: string - } - - export interface ValidationError extends Error { - message: string; - details: ValidationErrorItem[]; - simple(): string; - annotated(): string; - } - - export interface ValidationErrorItem { - message: string; - type: string; - path: string; - options?: ValidationOptions; - } - - export interface ValidationResult { - error: ValidationError; - value: T; - } - - export interface SchemaMap { - [key: string]: Schema; - } - - export interface Schema extends AnySchema { - - } - - export interface Reference extends Schema { - - } - - export interface AnySchema> { - /** - * Whitelists a value - */ - allow(value: any, ...values: any[]): T; - allow(values: any[]): T; - - /** - * Adds the provided values into the allowed whitelist and marks them as the only valid values allowed. - */ - valid(value: any, ...values: any[]): T; - valid(values: any[]): T; - only(value: any, ...values : any[]): T; - only(values: any[]): T; - equal(value: any, ...values : any[]): T; - equal(values: any[]): T; - - /** - * Blacklists a value - */ - invalid(value: any, ...values: any[]): T; - invalid(values: any[]): T; - disallow(value: any, ...values : any[]): T; - disallow(values: any[]): T; - not(value: any, ...values : any[]): T; - not(values: any[]): T; - - /** - * Marks a key as required which will not allow undefined as value. All keys are optional by default. - */ - required(): T; - - /** - * Marks a key as optional which will allow undefined as values. Used to annotate the schema for readability as all keys are optional by default. - */ - optional(): T; - - /** - * Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys. - */ - forbidden(): T; - - /** - * Marks a key to be removed from a resulting object or array after validation. Used to sanitize output. - */ - strip(): T; - - /** - * Annotates the key - */ - description(desc: string): T; - - /** - * Annotates the key - */ - notes(notes: string): T; - notes(notes: string[]): T; - - /** - * Annotates the key - */ - tags(notes: string): T; - tags(notes: string[]): T; - - /** - * Attaches metadata to the key. - */ - meta(meta: Object): T; - - /** - * Annotates the key with an example value, must be valid. - */ - example(value: any): T; - - /** - * Annotates the key with an unit name. - */ - unit(name: string): T; - - /** - * Overrides the global validate() options for the current key and any sub-key. - */ - options(options: ValidationOptions): T; - - /** - * Sets the options.convert options to false which prevent type casting for the current key and any child keys. - */ - strict(isStrict?: boolean): T; - - /** - * Sets a default value if the original value is undefined. - * @param value - the value. - * value supports references. - * value may also be a function which returns the default value. - * If value is specified as a function that accepts a single parameter, that parameter will be a context - * object that can be used to derive the resulting value. This clones the object however, which incurs some - * overhead so if you don't need access to the context define your method so that it does not accept any - * parameters. - * Without any value, default has no effect, except for object that will then create nested defaults - * (applying inner defaults of that object). - * - * Note that if value is an object, any changes to the object after default() is called will change the - * reference and any future assignment. - * - * Additionally, when specifying a method you must either have a description property on your method or the - * second parameter is required. - */ - default(value: any, description?: string): T; - default(): T; - - /** - * Returns a new type that is the result of adding the rules of one type to another. - */ - concat(schema: T): T; - - /** - * Converts the type into an alternatives type where the conditions are merged into the type definition where: - */ - when(ref: string, options: WhenOptions): AlternativesSchema; - when(ref: Reference, options: WhenOptions): AlternativesSchema; - - /** - * Overrides the key name in error messages. - */ - label(name: string): T; - - /** - * Outputs the original untouched value instead of the casted value. - */ - raw(isRaw?: boolean): T; - - /** - * Considers anything that matches the schema to be empty (undefined). - * @param schema - any object or joi schema to match. An undefined schema unsets that rule. - */ - empty(schema?: any) : T; - } - - export interface BooleanSchema extends AnySchema { - - } - - export interface NumberSchema extends AnySchema { - /** - * Specifies the minimum value. - * It can also be a reference to another field. - */ - min(limit: number): NumberSchema; - min(limit: Reference): NumberSchema; - - /** - * Specifies the maximum value. - * It can also be a reference to another field. - */ - max(limit: number): NumberSchema; - max(limit: Reference): NumberSchema; - - /** - * Specifies that the value must be greater than limit. - * It can also be a reference to another field. - */ - greater(limit: number): NumberSchema; - greater(limit: Reference): NumberSchema; - - /** - * Specifies that the value must be less than limit. - * It can also be a reference to another field. - */ - less(limit: number): NumberSchema; - less(limit: Reference): NumberSchema; - - /** - * Requires the number to be an integer (no floating point). - */ - integer(): NumberSchema; - - /** - * Specifies the maximum number of decimal places where: - * limit - the maximum number of decimal places allowed. - */ - precision(limit: number): NumberSchema; - - /** - * Specifies that the value must be a multiple of base. - */ - multiple(base: number): NumberSchema; - - /** - * Requires the number to be positive. - */ - positive(): NumberSchema; - - /** - * Requires the number to be negative. - */ - negative(): NumberSchema; - } - - export interface StringSchema extends AnySchema { - /** - * Allows the value to match any whitelist of blacklist item in a case insensitive comparison. - */ - insensitive(): StringSchema; - - /** - * Specifies the minimum number string characters. - * @param limit - the minimum number of string characters required. It can also be a reference to another field. - * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. - */ - min(limit: number, encoding?: string): StringSchema; - min(limit: Reference, encoding?: string): StringSchema; - - /** - * Specifies the maximum number of string characters. - * @param limit - the maximum number of string characters allowed. It can also be a reference to another field. - * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. - */ - max(limit: number, encoding?: string): StringSchema; - max(limit: Reference, encoding?: string): StringSchema; - - /** - * Requires the number to be a credit card number (Using Lunh Algorithm). - */ - creditCard(): StringSchema; - - /** - * Specifies the exact string length required - * @param limit - the required string length. It can also be a reference to another field. - * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. - */ - length(limit: number, encoding?: string): StringSchema; - length(limit: Reference, encoding?: string): StringSchema; - - /** - * Defines a regular expression rule. - * @param pattern - a regular expression object the string value must match against. - * @param name - optional name for patterns (useful with multiple patterns). Defaults to 'required'. - */ - regex(pattern: RegExp, name?: string): StringSchema; - - /** - * Replace characters matching the given pattern with the specified replacement string where: - * @param pattern - a regular expression object to match against, or a string of which all occurrences will be replaced. - * @param replacement - the string that will replace the pattern. - */ - replace(pattern: RegExp, replacement: string): StringSchema; - replace(pattern: string, replacement: string): StringSchema; - - /** - * Requires the string value to only contain a-z, A-Z, and 0-9. - */ - alphanum(): StringSchema; - - /** - * Requires the string value to only contain a-z, A-Z, 0-9, and underscore _. - */ - token(): StringSchema; - - /** - * Requires the string value to be a valid email address. - */ - email(options?: EmailOptions): StringSchema; - - /** - * Requires the string value to be a valid ip address. - */ - ip(options?: IpOptions): StringSchema; - - /** - * Requires the string value to be a valid RFC 3986 URI. - */ - uri(options?: UriOptions): StringSchema; - - /** - * Requires the string value to be a valid GUID. - */ - guid(): StringSchema; - - /** - * Requires the string value to be a valid hexadecimal string. - */ - hex(): StringSchema; - - /** - * Requires the string value to be a valid hostname as per RFC1123. - */ - hostname(): StringSchema; - - /** - * Requires the string value to be in valid ISO 8601 date format. - */ - isoDate(): StringSchema; - - /** - * Requires the string value to be all lowercase. If the validation convert option is on (enabled by default), the string will be forced to lowercase. - */ - lowercase(): StringSchema; - - /** - * Requires the string value to be all uppercase. If the validation convert option is on (enabled by default), the string will be forced to uppercase. - */ - uppercase(): StringSchema; - - /** - * Requires the string value to contain no whitespace before or after. If the validation convert option is on (enabled by default), the string will be trimmed. - */ - trim(): StringSchema; - } - - export interface ArraySchema extends AnySchema { - /** - * Allow this array to be sparse. - * enabled can be used with a falsy value to go back to the default behavior. - */ - sparse(enabled?: any): ArraySchema; - - /** - * Allow single values to be checked against rules as if it were provided as an array. - * enabled can be used with a falsy value to go back to the default behavior. - */ - single(enabled?: any): ArraySchema; - - /** - * List the types allowed for the array values. - * type can be an array of values, or multiple values can be passed as individual arguments. - * If a given type is .required() then there must be a matching item in the array. - * If a type is .forbidden() then it cannot appear in the array. - * Required items can be added multiple times to signify that multiple items must be found. - * Errors will contain the number of items that didn't match. - * Any unmatched item having a label will be mentioned explicitly. - * - * @param type - a joi schema object to validate each array item against. - */ - items(type: Schema, ...types: Schema[]): ArraySchema; - items(types: Schema[]): ArraySchema; - - /** - * Specifies the minimum number of items in the array. - */ - min(limit: number): ArraySchema; - - /** - * Specifies the maximum number of items in the array. - */ - max(limit: number): ArraySchema; - - /** - * Specifies the exact number of items in the array. - */ - length(limit: number): ArraySchema; - - /** - * Requires the array values to be unique. - * Be aware that a deep equality is performed on elements of the array having a type of object, - * a performance penalty is to be expected for this kind of operation. - */ - unique(): ArraySchema; - } - - export interface ObjectSchema extends AnySchema { - /** - * Sets the allowed object keys. - */ - keys(schema?: SchemaMap): ObjectSchema; - - /** - * Specifies the minimum number of keys in the object. - */ - min(limit: number): ObjectSchema; - - /** - * Specifies the maximum number of keys in the object. - */ - max(limit: number): ObjectSchema; - - /** - * Specifies the exact number of keys in the object. - */ - length(limit: number): ObjectSchema; - - /** - * Specify validation rules for unknown keys matching a pattern. - */ - pattern(regex: RegExp, schema: Schema): ObjectSchema; - - /** - * Defines an all-or-nothing relationship between keys where if one of the peers is present, all of them are required as well. - * @param peers - the key names of which if one present, all are required. peers can be a single string value, - * an array of string values, or each peer provided as an argument. - */ - and(peer1: string, ...peers: string[]): ObjectSchema; - and(peers: string[]): ObjectSchema; - - /** - * Defines a relationship between keys where not all peers can be present at the same time. - * @param peers - the key names of which if one present, the others may not all be present. - * peers can be a single string value, an array of string values, or each peer provided as an argument. - */ - nand(peer1: string, ...peers: string[]): ObjectSchema; - nand(peers: string[]): ObjectSchema; - - /** - * Defines a relationship between keys where one of the peers is required (and more than one is allowed). - */ - or(peer1: string, ...peers: string[]): ObjectSchema; - or(peers: string[]): ObjectSchema; - - /** - * Defines an exclusive relationship between a set of keys. one of them is required but not at the same time where: - */ - xor(peer1: string, ...peers: string[]): ObjectSchema; - xor(peers: string[]): ObjectSchema; - - /** - * Requires the presence of other keys whenever the specified key is present. - */ - with(key: string, peers: string): ObjectSchema; - with(key: string, peers: string[]): ObjectSchema; - - /** - * Forbids the presence of other keys whenever the specified is present. - */ - without(key: string, peers: string): ObjectSchema; - without(key: string, peers: string[]): ObjectSchema; - - /** - * Renames a key to another name (deletes the renamed key). - */ - rename(from: string, to: string, options?: RenameOptions): ObjectSchema; - - /** - * Verifies an assertion where. - */ - assert(ref: string, schema: Schema, message?: string): ObjectSchema; - assert(ref: Reference, schema: Schema, message?: string): ObjectSchema; - - /** - * Overrides the handling of unknown keys for the scope of the current object only (does not apply to children). - */ - unknown(allow?: boolean): ObjectSchema; - - /** - * Requires the object to be an instance of a given constructor. - * - * @param constructor - the constructor function that the object must be an instance of. - * @param name - an alternate name to use in validation errors. This is useful when the constructor function does not have a name. - */ - type(constructor: Function, name?: string): ObjectSchema; - - /** - * Sets the specified children to required. - * - * @param children - can be a single string value, an array of string values, or each child provided as an argument. - * - * var schema = Joi.object().keys({ a: { b: Joi.number() }, c: { d: Joi.string() } }); - * var requiredSchema = schema.requiredKeys('', 'a.b', 'c', 'c.d'); - * - * Note that in this example '' means the current object, a is not required but b is, as well as c and d. - */ - requiredKeys(children: string): ObjectSchema; - requiredKeys(children: string[]): ObjectSchema; - requiredKeys(child:string, ...children: string[]): ObjectSchema; - - /** - * Sets the specified children to optional. - * - * @param children - can be a single string value, an array of string values, or each child provided as an argument. - * - * The behavior is exactly the same as requiredKeys. - */ - optionalKeys(children: string): ObjectSchema; - optionalKeys(children: string[]): ObjectSchema; - optionalKeys(child:string, ...children: string[]): ObjectSchema; - } - - export interface BinarySchema extends AnySchema { - /** - * Sets the string encoding format if a string input is converted to a buffer. - */ - encoding(encoding: string): BinarySchema; - - /** - * Specifies the minimum length of the buffer. - */ - min(limit: number): BinarySchema; - - /** - * Specifies the maximum length of the buffer. - */ - max(limit: number): BinarySchema; - - /** - * Specifies the exact length of the buffer: - */ - length(limit: number): BinarySchema; - } - - export interface DateSchema extends AnySchema { - - /** - * Specifies the oldest date allowed. - * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date, - * allowing to explicitly ensure a date is either in the past or in the future. - * It can also be a reference to another field. - */ - min(date: Date): DateSchema; - min(date: number): DateSchema; - min(date: string): DateSchema; - min(date: Reference): DateSchema; - - /** - * Specifies the latest date allowed. - * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date, - * allowing to explicitly ensure a date is either in the past or in the future. - * It can also be a reference to another field. - */ - max(date: Date): DateSchema; - max(date: number): DateSchema; - max(date: string): DateSchema; - max(date: Reference): DateSchema; - - /** - * Specifies the allowed date format: - * @param format - string or array of strings that follow the moment.js format. - */ - format(format: string): DateSchema; - format(format: string[]): DateSchema; - - /** - * Requires the string value to be in valid ISO 8601 date format. - */ - iso(): DateSchema; - } - - export interface FunctionSchema extends AnySchema { - - } - - export interface AlternativesSchema extends AnySchema { - try(schemas: Schema[]): AlternativesSchema; - when(ref: string, options: WhenOptions): AlternativesSchema; - when(ref: Reference, options: WhenOptions): AlternativesSchema; - } - - // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- - +export interface ValidationOptions { /** - * Generates a schema object that matches any data type. + * when true, stops validation on the first error, otherwise returns all the errors found. Defaults to true. */ - export function any(): Schema; - + abortEarly?: boolean; /** - * Generates a schema object that matches an array data type. + * when true, attempts to cast values to the required types (e.g. a string to a number). Defaults to true. */ - export function array(): ArraySchema; - + convert?: boolean; /** - * Generates a schema object that matches a boolean data type (as well as the strings 'true', 'false', 'yes', and 'no'). Can also be called via bool(). + * when true, allows object to contain unknown keys which are ignored. Defaults to false. */ - export function bool(): BooleanSchema; - - export function boolean(): BooleanSchema; - + allowUnknown?: boolean; /** - * Generates a schema object that matches a Buffer data type (as well as the strings which will be converted to Buffers). + * when true, ignores unknown keys with a function value. Defaults to false. */ - export function binary(): BinarySchema; - + skipFunctions?: boolean; /** - * Generates a schema object that matches a date type (as well as a JavaScript date string or number of milliseconds). + * when true, unknown keys are deleted (only when value is an object). Defaults to false. */ - export function date(): DateSchema; - + stripUnknown?: boolean; /** - * Generates a schema object that matches a function type. + * overrides individual error messages. Defaults to no override ({}). */ - export function func(): FunctionSchema; - + language?: Object; /** - * Generates a schema object that matches a number data type (as well as strings that can be converted to numbers). + * sets the default presence requirements. Supported modes: 'optional', 'required', and 'forbidden'. Defaults to 'optional'. */ - export function number(): NumberSchema; - + presence?: string; /** - * Generates a schema object that matches an object data type (as well as JSON strings that parsed into objects). + * provides an external data set to be used in references */ - export function object(schema?: SchemaMap): ObjectSchema; - - /** - * Generates a schema object that matches a string data type. Note that empty strings are not allowed by default and must be enabled with allow(''). - */ - export function string(): StringSchema; - - /** - * Generates a type that will match one of the provided alternative schemas - */ - export function alternatives(types: Schema[]): Schema; - export function alternatives(type1: Schema, type2: Schema, ...types: Schema[]): Schema; - - /** - * Validates a value using the given schema and options. - */ - export function validate(value: T, schema: Schema, callback: (err: ValidationError, value: T) => void): void; - export function validate(value: T, schema: Object, callback: (err: ValidationError, value: T) => void): void; - export function validate(value: T, schema: Object, options?: ValidationOptions, callback?: (err: ValidationError, value: T) => void): ValidationResult; - - /** - * Converts literal schema definition to joi schema object (or returns the same back if already a joi schema object). - */ - export function compile(schema: Object): Schema; - - /** - * Validates a value against a schema and throws if validation fails. - * - * @param value - the value to validate. - * @param schema - the schema object. - * @param message - optional message string prefix added in front of the error message. may also be an Error object. - */ - export function assert(value: any, schema: Schema, message?: string | Error): void; - - /** - * Generates a reference to the value of the named key. - */ - export function ref(key: string, options?: ReferenceOptions): Reference; + context?: Object; } + +export interface RenameOptions { + /** + * if true, does not delete the old key name, keeping both the new and old keys in place. Defaults to false. + */ + alias?: boolean; + /** + * if true, allows renaming multiple keys to the same destination where the last rename wins. Defaults to false. + */ + multiple?: boolean; + /** + * if true, allows renaming a key over an existing key. Defaults to false. + */ + override?: boolean; + /** + * if true, skip renaming of a key if it's undefined. Defaults to false. + */ + ignoreUndefined?: boolean; +} + +export interface EmailOptions { + /** + * Numerical threshold at which an email address is considered invalid + */ + errorLevel?: number | boolean; + /** + * Specifies a list of acceptable TLDs. + */ + tldWhitelist?: string[] | Object; + /** + * Number of atoms required for the domain. Be careful since some domains, such as io, directly allow email. + */ + minDomainAtoms?: number; +} + +export interface IpOptions { + /** + * One or more IP address versions to validate against. Valid values: ipv4, ipv6, ipvfuture + */ + version ?: string | string[]; + /** + * Used to determine if a CIDR is allowed or not. Valid values: optional, required, forbidden + */ + cidr?: string; +} + +export interface UriOptions { + /** + * Specifies one or more acceptable Schemes, should only include the scheme name. + * Can be an Array or String (strings are automatically escaped for use in a Regular Expression). + */ + scheme ?: string | RegExp | Array; +} + +export interface WhenOptions { + /** + * the required condition joi type. + */ + is: T; + /** + * the alternative schema type if the condition is true. Required if otherwise is missing. + */ + then?: Schema; + /** + * the alternative schema type if the condition is false. Required if then is missing + */ + otherwise?: Schema; +} + +export interface ReferenceOptions { + separator?: string; + contextPrefix?: string; +} + +export interface IPOptions { + version?: string[]; + cidr?: string; +} + +export interface ValidationError extends Error { + message: string; + details: ValidationErrorItem[]; + simple(): string; + annotated(): string; +} + +export interface ValidationErrorItem { + message: string; + type: string; + path: string; + options?: ValidationOptions; +} + +export interface ValidationResult { + error: ValidationError; + value: T; +} + +export interface SchemaMap { + [key: string]: Schema; +} + +export interface Schema extends AnySchema { +} + +export interface Reference extends Schema { +} + +export interface AnySchema> { + /** + * Whitelists a value + */ + allow(value: any, ...values: any[]): T; + allow(values: any[]): T; + + /** + * Adds the provided values into the allowed whitelist and marks them as the only valid values allowed. + */ + valid(value: any, ...values: any[]): T; + valid(values: any[]): T; + only(value: any, ...values: any[]): T; + only(values: any[]): T; + equal(value: any, ...values: any[]): T; + equal(values: any[]): T; + + /** + * Blacklists a value + */ + invalid(value: any, ...values: any[]): T; + invalid(values: any[]): T; + disallow(value: any, ...values: any[]): T; + disallow(values: any[]): T; + not(value: any, ...values: any[]): T; + not(values: any[]): T; + + /** + * Marks a key as required which will not allow undefined as value. All keys are optional by default. + */ + required(): T; + + /** + * Marks a key as optional which will allow undefined as values. Used to annotate the schema for readability as all keys are optional by default. + */ + optional(): T; + + /** + * Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys. + */ + forbidden(): T; + + /** + * Marks a key to be removed from a resulting object or array after validation. Used to sanitize output. + */ + strip(): T; + + /** + * Annotates the key + */ + description(desc: string): T; + + /** + * Annotates the key + */ + notes(notes: string): T; + notes(notes: string[]): T; + + /** + * Annotates the key + */ + tags(notes: string): T; + tags(notes: string[]): T; + + /** + * Attaches metadata to the key. + */ + meta(meta: Object): T; + + /** + * Annotates the key with an example value, must be valid. + */ + example(value: any): T; + + /** + * Annotates the key with an unit name. + */ + unit(name: string): T; + + /** + * Overrides the global validate() options for the current key and any sub-key. + */ + options(options: ValidationOptions): T; + + /** + * Sets the options.convert options to false which prevent type casting for the current key and any child keys. + */ + strict(isStrict?: boolean): T; + + /** + * Sets a default value if the original value is undefined. + * @param value - the value. + * value supports references. + * value may also be a function which returns the default value. + * If value is specified as a function that accepts a single parameter, that parameter will be a context + * object that can be used to derive the resulting value. This clones the object however, which incurs some + * overhead so if you don't need access to the context define your method so that it does not accept any + * parameters. + * Without any value, default has no effect, except for object that will then create nested defaults + * (applying inner defaults of that object). + * + * Note that if value is an object, any changes to the object after default() is called will change the + * reference and any future assignment. + * + * Additionally, when specifying a method you must either have a description property on your method or the + * second parameter is required. + */ + default(value: any, description?: string): T; + default(): T; + + /** + * Returns a new type that is the result of adding the rules of one type to another. + */ + concat(schema: T): T; + + /** + * Converts the type into an alternatives type where the conditions are merged into the type definition where: + */ + when(ref: string, options: WhenOptions): AlternativesSchema; + when(ref: Reference, options: WhenOptions): AlternativesSchema; + + /** + * Overrides the key name in error messages. + */ + label(name: string): T; + + /** + * Outputs the original untouched value instead of the casted value. + */ + raw(isRaw?: boolean): T; + + /** + * Considers anything that matches the schema to be empty (undefined). + * @param schema - any object or joi schema to match. An undefined schema unsets that rule. + */ + empty(schema?: any): T; +} + +export interface BooleanSchema extends AnySchema { +} + +export interface NumberSchema extends AnySchema { + /** + * Specifies the minimum value. + * It can also be a reference to another field. + */ + min(limit: number): NumberSchema; + min(limit: Reference): NumberSchema; + + /** + * Specifies the maximum value. + * It can also be a reference to another field. + */ + max(limit: number): NumberSchema; + max(limit: Reference): NumberSchema; + + /** + * Specifies that the value must be greater than limit. + * It can also be a reference to another field. + */ + greater(limit: number): NumberSchema; + greater(limit: Reference): NumberSchema; + + /** + * Specifies that the value must be less than limit. + * It can also be a reference to another field. + */ + less(limit: number): NumberSchema; + less(limit: Reference): NumberSchema; + + /** + * Requires the number to be an integer (no floating point). + */ + integer(): NumberSchema; + + /** + * Specifies the maximum number of decimal places where: + * limit - the maximum number of decimal places allowed. + */ + precision(limit: number): NumberSchema; + + /** + * Specifies that the value must be a multiple of base. + */ + multiple(base: number): NumberSchema; + + /** + * Requires the number to be positive. + */ + positive(): NumberSchema; + + /** + * Requires the number to be negative. + */ + negative(): NumberSchema; +} + +export interface StringSchema extends AnySchema { + /** + * Allows the value to match any whitelist of blacklist item in a case insensitive comparison. + */ + insensitive(): StringSchema; + + /** + * Specifies the minimum number string characters. + * @param limit - the minimum number of string characters required. It can also be a reference to another field. + * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. + */ + min(limit: number, encoding?: string): StringSchema; + min(limit: Reference, encoding?: string): StringSchema; + + /** + * Specifies the maximum number of string characters. + * @param limit - the maximum number of string characters allowed. It can also be a reference to another field. + * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. + */ + max(limit: number, encoding?: string): StringSchema; + max(limit: Reference, encoding?: string): StringSchema; + + /** + * Requires the number to be a credit card number (Using Lunh Algorithm). + */ + creditCard(): StringSchema; + + /** + * Specifies the exact string length required + * @param limit - the required string length. It can also be a reference to another field. + * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. + */ + length(limit: number, encoding?: string): StringSchema; + length(limit: Reference, encoding?: string): StringSchema; + + /** + * Defines a regular expression rule. + * @param pattern - a regular expression object the string value must match against. + * @param name - optional name for patterns (useful with multiple patterns). Defaults to 'required'. + */ + regex(pattern: RegExp, name?: string): StringSchema; + + /** + * Replace characters matching the given pattern with the specified replacement string where: + * @param pattern - a regular expression object to match against, or a string of which all occurrences will be replaced. + * @param replacement - the string that will replace the pattern. + */ + replace(pattern: RegExp, replacement: string): StringSchema; + replace(pattern: string, replacement: string): StringSchema; + + /** + * Requires the string value to only contain a-z, A-Z, and 0-9. + */ + alphanum(): StringSchema; + + /** + * Requires the string value to only contain a-z, A-Z, 0-9, and underscore _. + */ + token(): StringSchema; + + /** + * Requires the string value to be a valid email address. + */ + email(options?: EmailOptions): StringSchema; + + /** + * Requires the string value to be a valid ip address. + */ + ip(options?: IpOptions): StringSchema; + + /** + * Requires the string value to be a valid RFC 3986 URI. + */ + uri(options?: UriOptions): StringSchema; + + /** + * Requires the string value to be a valid GUID. + */ + guid(): StringSchema; + + /** + * Requires the string value to be a valid hexadecimal string. + */ + hex(): StringSchema; + + /** + * Requires the string value to be a valid hostname as per RFC1123. + */ + hostname(): StringSchema; + + /** + * Requires the string value to be in valid ISO 8601 date format. + */ + isoDate(): StringSchema; + + /** + * Requires the string value to be all lowercase. If the validation convert option is on (enabled by default), the string will be forced to lowercase. + */ + lowercase(): StringSchema; + + /** + * Requires the string value to be all uppercase. If the validation convert option is on (enabled by default), the string will be forced to uppercase. + */ + uppercase(): StringSchema; + + /** + * Requires the string value to contain no whitespace before or after. If the validation convert option is on (enabled by default), the string will be trimmed. + */ + trim(): StringSchema; +} + +export interface ArraySchema extends AnySchema { + /** + * Allow this array to be sparse. + * enabled can be used with a falsy value to go back to the default behavior. + */ + sparse(enabled?: any): ArraySchema; + + /** + * Allow single values to be checked against rules as if it were provided as an array. + * enabled can be used with a falsy value to go back to the default behavior. + */ + single(enabled?: any): ArraySchema; + + /** + * List the types allowed for the array values. + * type can be an array of values, or multiple values can be passed as individual arguments. + * If a given type is .required() then there must be a matching item in the array. + * If a type is .forbidden() then it cannot appear in the array. + * Required items can be added multiple times to signify that multiple items must be found. + * Errors will contain the number of items that didn't match. + * Any unmatched item having a label will be mentioned explicitly. + * + * @param type - a joi schema object to validate each array item against. + */ + items(type: Schema, ...types: Schema[]): ArraySchema; + items(types: Schema[]): ArraySchema; + + /** + * Specifies the minimum number of items in the array. + */ + min(limit: number): ArraySchema; + + /** + * Specifies the maximum number of items in the array. + */ + max(limit: number): ArraySchema; + + /** + * Specifies the exact number of items in the array. + */ + length(limit: number): ArraySchema; + + /** + * Requires the array values to be unique. + * Be aware that a deep equality is performed on elements of the array having a type of object, + * a performance penalty is to be expected for this kind of operation. + */ + unique(): ArraySchema; +} + +export interface ObjectSchema extends AnySchema { + /** + * Sets the allowed object keys. + */ + keys(schema?: SchemaMap): ObjectSchema; + + /** + * Specifies the minimum number of keys in the object. + */ + min(limit: number): ObjectSchema; + + /** + * Specifies the maximum number of keys in the object. + */ + max(limit: number): ObjectSchema; + + /** + * Specifies the exact number of keys in the object. + */ + length(limit: number): ObjectSchema; + + /** + * Specify validation rules for unknown keys matching a pattern. + */ + pattern(regex: RegExp, schema: Schema): ObjectSchema; + + /** + * Defines an all-or-nothing relationship between keys where if one of the peers is present, all of them are required as well. + * @param peers - the key names of which if one present, all are required. peers can be a single string value, + * an array of string values, or each peer provided as an argument. + */ + and(peer1: string, ...peers: string[]): ObjectSchema; + and(peers: string[]): ObjectSchema; + + /** + * Defines a relationship between keys where not all peers can be present at the same time. + * @param peers - the key names of which if one present, the others may not all be present. + * peers can be a single string value, an array of string values, or each peer provided as an argument. + */ + nand(peer1: string, ...peers: string[]): ObjectSchema; + nand(peers: string[]): ObjectSchema; + + /** + * Defines a relationship between keys where one of the peers is required (and more than one is allowed). + */ + or(peer1: string, ...peers: string[]): ObjectSchema; + or(peers: string[]): ObjectSchema; + + /** + * Defines an exclusive relationship between a set of keys. one of them is required but not at the same time where: + */ + xor(peer1: string, ...peers: string[]): ObjectSchema; + xor(peers: string[]): ObjectSchema; + + /** + * Requires the presence of other keys whenever the specified key is present. + */ + with(key: string, peers: string): ObjectSchema; + with(key: string, peers: string[]): ObjectSchema; + + /** + * Forbids the presence of other keys whenever the specified is present. + */ + without(key: string, peers: string): ObjectSchema; + without(key: string, peers: string[]): ObjectSchema; + + /** + * Renames a key to another name (deletes the renamed key). + */ + rename(from: string, to: string, options?: RenameOptions): ObjectSchema; + + /** + * Verifies an assertion where. + */ + assert(ref: string, schema: Schema, message?: string): ObjectSchema; + assert(ref: Reference, schema: Schema, message?: string): ObjectSchema; + + /** + * Overrides the handling of unknown keys for the scope of the current object only (does not apply to children). + */ + unknown(allow?: boolean): ObjectSchema; + + /** + * Requires the object to be an instance of a given constructor. + * + * @param constructor - the constructor function that the object must be an instance of. + * @param name - an alternate name to use in validation errors. This is useful when the constructor function does not have a name. + */ + type(constructor: Function, name?: string): ObjectSchema; + + /** + * Sets the specified children to required. + * + * @param children - can be a single string value, an array of string values, or each child provided as an argument. + * + * var schema = Joi.object().keys({ a: { b: Joi.number() }, c: { d: Joi.string() } }); + * var requiredSchema = schema.requiredKeys('', 'a.b', 'c', 'c.d'); + * + * Note that in this example '' means the current object, a is not required but b is, as well as c and d. + */ + requiredKeys(children: string): ObjectSchema; + requiredKeys(children: string[]): ObjectSchema; + requiredKeys(child: string, ...children: string[]): ObjectSchema; + + /** + * Sets the specified children to optional. + * + * @param children - can be a single string value, an array of string values, or each child provided as an argument. + * + * The behavior is exactly the same as requiredKeys. + */ + optionalKeys(children: string): ObjectSchema; + optionalKeys(children: string[]): ObjectSchema; + optionalKeys(child: string, ...children: string[]): ObjectSchema; +} + +export interface BinarySchema extends AnySchema { + /** + * Sets the string encoding format if a string input is converted to a buffer. + */ + encoding(encoding: string): BinarySchema; + + /** + * Specifies the minimum length of the buffer. + */ + min(limit: number): BinarySchema; + + /** + * Specifies the maximum length of the buffer. + */ + max(limit: number): BinarySchema; + + /** + * Specifies the exact length of the buffer: + */ + length(limit: number): BinarySchema; +} + +export interface DateSchema extends AnySchema { + /** + * Specifies the oldest date allowed. + * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date, + * allowing to explicitly ensure a date is either in the past or in the future. + * It can also be a reference to another field. + */ + min(date: Date): DateSchema; + min(date: number): DateSchema; + min(date: string): DateSchema; + min(date: Reference): DateSchema; + + /** + * Specifies the latest date allowed. + * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date, + * allowing to explicitly ensure a date is either in the past or in the future. + * It can also be a reference to another field. + */ + max(date: Date): DateSchema; + max(date: number): DateSchema; + max(date: string): DateSchema; + max(date: Reference): DateSchema; + + /** + * Specifies the allowed date format: + * @param format - string or array of strings that follow the moment.js format. + */ + format(format: string): DateSchema; + format(format: string[]): DateSchema; + + /** + * Requires the string value to be in valid ISO 8601 date format. + */ + iso(): DateSchema; +} + +export interface FunctionSchema extends AnySchema { +} + +export interface AlternativesSchema extends AnySchema { + try(schemas: Schema[]): AlternativesSchema; + when(ref: string, options: WhenOptions): AlternativesSchema; + when(ref: Reference, options: WhenOptions): AlternativesSchema; +} + +// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- + +/** + * Generates a schema object that matches any data type. + */ +export function any(): Schema; + +/** + * Generates a schema object that matches an array data type. + */ +export function array(): ArraySchema; + +/** + * Generates a schema object that matches a boolean data type (as well as the strings 'true', 'false', 'yes', and 'no'). Can also be called via bool(). + */ +export function bool(): BooleanSchema; + +export function boolean(): BooleanSchema; + +/** + * Generates a schema object that matches a Buffer data type (as well as the strings which will be converted to Buffers). + */ +export function binary(): BinarySchema; + +/** + * Generates a schema object that matches a date type (as well as a JavaScript date string or number of milliseconds). + */ +export function date(): DateSchema; + +/** + * Generates a schema object that matches a function type. + */ +export function func(): FunctionSchema; + +/** + * Generates a schema object that matches a number data type (as well as strings that can be converted to numbers). + */ +export function number(): NumberSchema; + +/** + * Generates a schema object that matches an object data type (as well as JSON strings that parsed into objects). + */ +export function object(schema?: SchemaMap): ObjectSchema; + +/** + * Generates a schema object that matches a string data type. Note that empty strings are not allowed by default and must be enabled with allow(''). + */ +export function string(): StringSchema; + +/** + * Generates a type that will match one of the provided alternative schemas + */ +export function alternatives(types: Schema[]): Schema; +export function alternatives(type1: Schema, type2: Schema, ...types: Schema[]): Schema; + +/** + * Validates a value using the given schema and options. + */ +export function validate(value: T, schema: Schema, callback: (err: ValidationError, value: T) => void): void; +export function validate(value: T, schema: Object, callback: (err: ValidationError, value: T) => void): void; +export function validate(value: T, schema: Object, options?: ValidationOptions, callback?: (err: ValidationError, value: T) => void): ValidationResult; + +/** + * Converts literal schema definition to joi schema object (or returns the same back if already a joi schema object). + */ +export function compile(schema: Object): Schema; + +/** + * Validates a value against a schema and throws if validation fails. + * + * @param value - the value to validate. + * @param schema - the schema object. + * @param message - optional message string prefix added in front of the error message. may also be an Error object. + */ +export function assert(value: any, schema: Schema, message?: string | Error): void; + +/** + * Generates a reference to the value of the named key. + */ +export function ref(key: string, options?: ReferenceOptions): Reference; diff --git a/types/joi/v6/joi-tests.ts b/types/joi/v6/joi-tests.ts index 33923b500a..d8c5a99ae2 100644 --- a/types/joi/v6/joi-tests.ts +++ b/types/joi/v6/joi-tests.ts @@ -2,48 +2,42 @@ import Joi = require('joi'); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var x: any = null; -var value: any = null; -var num: number = 0; -var str: string = ''; -var bool: boolean = false; -var exp: RegExp = null; -var obj: Object = null; -var date: Date = null; -var err: Error = null; -var func: Function = null; +let x: any = null; +declare const value: any; +let num = 0; +let str = ''; +declare const bool: boolean; +declare const exp: RegExp; +declare const obj: Object; +declare const date: Date; +declare const err: Error; +declare const func: Function; -var anyArr: any[] = []; -var numArr: number[] = []; -var strArr: string[] = []; -var boolArr: boolean[] = []; -var expArr: RegExp[] = []; -var objArr: Object[] = []; -var errArr: Error[] = []; -var funcArr: Function[] = []; +declare const strArr: string[]; +declare const expArr: RegExp[]; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var schema: Joi.Schema = null; +let schema: Joi.Schema = null; -var anySchema: Joi.AnySchema = null; -var numSchema: Joi.NumberSchema = null; -var strSchema: Joi.StringSchema = null; -var arrSchema: Joi.ArraySchema = null; -var boolSchema: Joi.BooleanSchema = null; -var binSchema: Joi.BinarySchema = null; -var dateSchema: Joi.DateSchema = null; -var funcSchema: Joi.FunctionSchema = null; -var objSchema: Joi.ObjectSchema = null; -var altSchema: Joi.AlternativesSchema = null; +let anySchema: Joi.AnySchema = null; +let numSchema: Joi.NumberSchema = null; +let strSchema: Joi.StringSchema = null; +let arrSchema: Joi.ArraySchema = null; +let boolSchema: Joi.BooleanSchema = null; +let binSchema: Joi.BinarySchema = null; +let dateSchema: Joi.DateSchema = null; +let funcSchema: Joi.FunctionSchema = null; +let objSchema: Joi.ObjectSchema = null; +let altSchema: Joi.AlternativesSchema = null; -var schemaArr: Joi.Schema[] = []; +declare const schemaArr: Joi.Schema[]; -var ref: Joi.Reference = null; +let ref: Joi.Reference = null; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var validOpts: Joi.ValidationOptions = null; +let validOpts: Joi.ValidationOptions = null; validOpts = {abortEarly: bool}; validOpts = {convert: bool}; @@ -56,7 +50,7 @@ validOpts = {context: obj}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var renOpts: Joi.RenameOptions = null; +let renOpts: Joi.RenameOptions = null; renOpts = {alias: bool}; renOpts = {multiple: bool}; @@ -65,7 +59,7 @@ renOpts = {ignoreUndefined: bool}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var emailOpts: Joi.EmailOptions = null; +let emailOpts: Joi.EmailOptions = null; emailOpts = {errorLevel: num}; emailOpts = {errorLevel: bool}; @@ -75,7 +69,7 @@ emailOpts = {minDomainAtoms: num}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var ipOpts: Joi.IpOptions = null; +let ipOpts: Joi.IpOptions = null; ipOpts = {version: str}; ipOpts = {version: strArr}; @@ -83,7 +77,7 @@ ipOpts = {cidr: str}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var uriOpts: Joi.UriOptions = null; +let uriOpts: Joi.UriOptions = null; uriOpts = {scheme: str}; uriOpts = {scheme: exp}; @@ -92,7 +86,7 @@ uriOpts = {scheme: expArr}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var whenOpts: Joi.WhenOptions = null; +let whenOpts: Joi.WhenOptions = null; whenOpts = {is: x}; whenOpts = {is: schema, then: schema}; @@ -100,17 +94,17 @@ whenOpts = {is: schema, otherwise: schema}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var refOpts: Joi.ReferenceOptions = null; +let refOpts: Joi.ReferenceOptions = null; refOpts = {separator: str}; refOpts = {contextPrefix: str}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var validErr: Joi.ValidationError = null; -var validErrItem: Joi.ValidationErrorItem; +declare const validErr: Joi.ValidationError; +let validErrItem: Joi.ValidationErrorItem; -validErrItem= { +validErrItem = { message: str, type: str, path: str @@ -149,7 +143,7 @@ anySchema = objSchema; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var schemaMap: Joi.SchemaMap = null; +let schemaMap: Joi.SchemaMap = null; schemaMap = { a: numSchema, @@ -160,7 +154,7 @@ schemaMap = { anySchema = Joi.any(); -namespace common { +{ // common anySchema = anySchema.allow(x); anySchema = anySchema.allow(x, x); anySchema = anySchema.allow([x, x, x]); @@ -235,10 +229,9 @@ arrSchema = arrSchema.items(numSchema); arrSchema = arrSchema.items(numSchema, strSchema); arrSchema = arrSchema.items([numSchema, strSchema]); - // - - - - - - - - -namespace common_copy_paste { +{ // common copy paste // use search & replace from any arrSchema = arrSchema.allow(x); arrSchema = arrSchema.allow(x, x); @@ -291,7 +284,7 @@ namespace common_copy_paste { boolSchema = Joi.bool(); boolSchema = Joi.boolean(); -namespace common_copy_paste { +{ // common copy paste boolSchema = boolSchema.allow(x); boolSchema = boolSchema.allow(x, x); boolSchema = boolSchema.allow([x, x, x]); @@ -347,7 +340,7 @@ binSchema = binSchema.min(num); binSchema = binSchema.max(num); binSchema = binSchema.length(num); -namespace common { +{ // common binSchema = binSchema.allow(x); binSchema = binSchema.allow(x, x); binSchema = binSchema.allow([x, x, x]); @@ -415,7 +408,7 @@ dateSchema = dateSchema.format(strArr); dateSchema = dateSchema.iso(); -namespace common { +{ // common dateSchema = dateSchema.allow(x); dateSchema = dateSchema.allow(x, x); dateSchema = dateSchema.allow([x, x, x]); @@ -484,7 +477,7 @@ numSchema = numSchema.multiple(num); numSchema = numSchema.positive(); numSchema = numSchema.negative(); -namespace common { +{ // common numSchema = numSchema.allow(x); numSchema = numSchema.allow(x, x); numSchema = numSchema.allow([x, x, x]); @@ -593,7 +586,7 @@ objSchema = objSchema.optionalKeys(str); objSchema = objSchema.optionalKeys(str, str); objSchema = objSchema.optionalKeys(strArr); -namespace common { +{ // common objSchema = objSchema.allow(x); objSchema = objSchema.allow(x, x); objSchema = objSchema.allow([x, x, x]); @@ -678,7 +671,7 @@ strSchema = strSchema.lowercase(); strSchema = strSchema.uppercase(); strSchema = strSchema.trim(); -namespace common { +{ // common strSchema = strSchema.allow(x); strSchema = strSchema.allow(x, x); strSchema = strSchema.allow([x, x, x]); diff --git a/types/joi/v6/tslint.json b/types/joi/v6/tslint.json index a41bf5d19a..0b8095b5e1 100644 --- a/types/joi/v6/tslint.json +++ b/types/joi/v6/tslint.json @@ -1,79 +1,12 @@ { "extends": "dtslint/dt.json", "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, + // All are TODOs "ban-types": false, "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false + "unified-signatures": false } } From 7be86467250ff04c917b47e18d1b44e29a6d8212 Mon Sep 17 00:00:00 2001 From: Bruno Lemos Date: Sat, 18 Aug 2018 20:31:57 -0300 Subject: [PATCH 23/25] [react-native] Disable Style Props --- types/react-native/index.d.ts | 12 ++---------- types/react-native/test/index.tsx | 25 ------------------------- 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 184fc39724..d664018786 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -1919,7 +1919,7 @@ type AccessibilityTrait = * @see https://facebook.github.io/react-native/docs/view.html#props */ export interface ViewProps - extends ViewPropsAndroid, ViewPropsIOS, GestureResponderHandlers, Touchable, AccessibilityProps, ViewStyle { + extends ViewPropsAndroid, ViewPropsIOS, GestureResponderHandlers, Touchable, AccessibilityProps { /** * This defines how far a touch event can start away from the view. * Typical interface guidelines recommend touch targets that are at least @@ -3605,7 +3605,7 @@ export interface ImageResolvedAssetSource { /** * @see https://facebook.github.io/react-native/docs/image.html */ -export interface ImagePropsBase extends ImagePropsIOS, ImagePropsAndroid, AccessibilityProps, ImageStyle { +export interface ImagePropsBase extends ImagePropsIOS, ImagePropsAndroid, AccessibilityProps { /** * onLayout function * @@ -3720,14 +3720,6 @@ export interface ImagePropsBase extends ImagePropsIOS, ImagePropsAndroid, Access * A static image to display while downloading the final image off the network. */ defaultSource?: ImageURISource | number; - - /** - * Currently broken - * @see https://github.com/facebook/react-native/pull/19281 - */ - width?: never; - height?: never; - tintColor?: never; } export interface ImageProps extends ImagePropsBase { diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 60c4d89302..4e21cb5c72 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -686,31 +686,6 @@ export class ImageBackgroundProps extends React.Component { } } -class StylePropsTest extends React.PureComponent { - render() { - const uri = 'https://seeklogo.com/images/T/typescript-logo-B29A3F462D-seeklogo.com.png' - - return ( - - - - - Text - - - ); - } -} - const listViewDataSourceTest = new ListView.DataSource({rowHasChanged: () => true}) class AccessibilityTest extends React.Component { From 9c8fba0b121786bc5698c6e1ac11ce791c47da1b Mon Sep 17 00:00:00 2001 From: chenshidong Date: Sun, 19 Aug 2018 08:14:45 +0800 Subject: [PATCH 24/25] fix: add author --- types/better-scroll/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/better-scroll/index.d.ts b/types/better-scroll/index.d.ts index 4ce8b2a4c1..326dd2c3a0 100644 --- a/types/better-scroll/index.d.ts +++ b/types/better-scroll/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for better-scroll 1.12 // Project: https://github.com/ustbhuangyi/better-scroll -// Definitions by: My Self +// Definitions by: cloudstone // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 From 0c12ca65cc17f297cfb0979b49b3a568ca5e5288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Thu, 16 Aug 2018 23:00:12 +0200 Subject: [PATCH 25/25] [dd-trace] Update for 0.5.x --- types/dd-trace/dd-trace-tests.ts | 18 ++- types/dd-trace/index.d.ts | 43 ++++++- types/dd-trace/src/opentracing/span.d.ts | 121 ------------------ .../src/opentracing/span_context.d.ts | 40 ------ types/dd-trace/src/opentracing/tracer.d.ts | 11 -- 5 files changed, 53 insertions(+), 180 deletions(-) delete mode 100644 types/dd-trace/src/opentracing/span.d.ts delete mode 100644 types/dd-trace/src/opentracing/span_context.d.ts delete mode 100644 types/dd-trace/src/opentracing/tracer.d.ts diff --git a/types/dd-trace/dd-trace-tests.ts b/types/dd-trace/dd-trace-tests.ts index 18f5daae10..bfde3536f4 100644 --- a/types/dd-trace/dd-trace-tests.ts +++ b/types/dd-trace/dd-trace-tests.ts @@ -1,7 +1,7 @@ -import * as ddTrace from 'dd-trace'; -import SpanContext = require('dd-trace/src/opentracing/span_context'); +import * as tracer from 'dd-trace'; +import { SpanContext } from 'opentracing'; -const tracer = ddTrace.init({ +tracer.init({ service: 'MyLovelyService', hostname: 'localhost', port: 8126, @@ -14,7 +14,7 @@ const tracer = ddTrace.init({ tracer .trace('web.request', { service: 'my_service', - childOf: new SpanContext({ traceId: 1337, spanId: 42 }), + childOf: new SpanContext(), tags: { env: 'dev' } @@ -23,3 +23,13 @@ tracer span.setTag('my_tag', 'my_value'); span.finish(); }); + +const parentScope = tracer.scopeManager().active(); +const span = tracer.startSpan('memcached', { + childOf: parentScope && parentScope.span(), + tags: { + 'service.name': 'my-memcached', + 'resource.name': 'get', + 'span.type': 'memcached', + }, +}); diff --git a/types/dd-trace/index.d.ts b/types/dd-trace/index.d.ts index 11bcdb42f2..d7130f3f5b 100644 --- a/types/dd-trace/index.d.ts +++ b/types/dd-trace/index.d.ts @@ -1,11 +1,10 @@ -// Type definitions for dd-trace-js 0.2 +// Type definitions for dd-trace-js 0.5 // Project: https://github.com/DataDog/dd-trace-js // Definitions by: Colin Bradley +// Eloy Durán // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -import Tracer = require('./src/opentracing/tracer'); -import Span = require('./src/opentracing/span'); -import SpanContext = require('./src/opentracing/span_context'); +import { Tracer, Span, SpanContext } from "opentracing"; declare var trace: TraceProxy; export = trace; @@ -42,6 +41,11 @@ declare class TraceProxy extends Tracer { * @returns The current span or null if outside a trace context. */ currentSpan(): Span | null; + + /** + * Get the scope manager to manager context propagation for the tracer. + */ + scopeManager(): ScopeManager; } interface TracerOptions { @@ -147,3 +151,34 @@ interface TraceOptions { */ tags?: { [key: string]: any } | string; } + +declare class ScopeManager { + /** + * Get the current active scope or null if there is none. + * + * @todo The dd-trace source returns null, but opentracing's childOf span + * option is typed as taking undefined or a scope, so using undefined + * here instead. + */ + active(): Scope | undefined; + + /** + * Activate a new scope wrapping the provided span. + * + * @param span The span for which to activate the new scope. + * @param finishSpanOnClose Whether to automatically finish the span when the scope is closed. + */ + activate(span: Span, finishSpanOnClose?: boolean): Scope; +} + +declare class Scope { + /** + * Get the span wrapped by this scope. + */ + span(): Span; + + /** + * Close the scope, and finish the span if the scope was created with `finishSpanOnClose` set to true. + */ + close(): void; +} diff --git a/types/dd-trace/src/opentracing/span.d.ts b/types/dd-trace/src/opentracing/span.d.ts deleted file mode 100644 index cf9286210b..0000000000 --- a/types/dd-trace/src/opentracing/span.d.ts +++ /dev/null @@ -1,121 +0,0 @@ -import Tracer = require('./tracer'); -import SpanContext = require('./span_context'); -import { Span } from 'opentracing'; - -declare class DatadogSpan extends Span { - /** - * Returns the SpanContext object associated with this Span. - */ - context(): SpanContext; - - /** - * Returns the Tracer object used to create this Span. - */ - tracer(): Tracer; - - /** - * Sets the string name for the logical operation this span represents. - */ - setOperationName(name: string): this; - - /** - * Sets a key:value pair on this Span that also propagates to future - * children of the associated Span. - * - * setBaggageItem() enables powerful functionality given a full-stack - * opentracing integration (e.g., arbitrary application data from a web - * client can make it, transparently, all the way into the depths of a - * storage system), and with it some powerful costs: use this feature with - * care. - * - * IMPORTANT NOTE #1: setBaggageItem() will only propagate baggage items to - * *future* causal descendants of the associated Span. - * - * IMPORTANT NOTE #2: Use this thoughtfully and with care. Every key and - * value is copied into every local *and remote* child of the associated - * Span, and that can add up to a lot of network and cpu overhead. - */ - setBaggageItem(key: string, value: string): this; - - /** - * Returns the value for a baggage item given its key. - * - * @param key - * The key for the given trace attribute. - * @return String value for the given key, or undefined if the key does not - * correspond to a set trace attribute. - */ - getBaggageItem(key: string): string | undefined; - - /** - * Adds a single tag to the span. See `addTags()` for details. - */ - setTag(key: string, value: any): this; - - /** - * Adds the given key value pairs to the set of span tags. - * - * Multiple calls to addTags() results in the tags being the superset of - * all calls. - * - * The behavior of setting the same key multiple times on the same span - * is undefined. - * - * The supported type of the values is implementation-dependent. - * Implementations are expected to safely handle all types of values but - * may choose to ignore unrecognized / unhandle-able values (e.g. objects - * with cyclic references, function objects). - */ - addTags(keyValueMap: { - [key: string]: any; - }): this; - - /** - * Add a log record to this Span, optionally at a user-provided timestamp. - * - * For example: - * - * span.log({ - * size: rpc.size(), // numeric value - * URI: rpc.URI(), // string value - * payload: rpc.payload(), // Object value - * "keys can be arbitrary strings": rpc.foo(), - * }); - * - * span.log({ - * "error.description": someError.description(), - * }, someError.timestampMillis()); - * - * @param keyValuePairs - * An object mapping string keys to arbitrary value types. All - * Tracer implementations should support bool, string, and numeric - * value types, and some may also support Object values. - * @param timestamp - * An optional parameter specifying the timestamp in milliseconds - * since the Unix epoch. Fractional values are allowed so that - * timestamps with sub-millisecond accuracy can be represented. If - * not specified, the implementation is expected to use its notion - * of the current time of the call. - */ - - log(keyValuePairs: { - [key: string]: any; - }, timestamp?: number): this; - - /** - * Sets the end timestamp and finalizes Span state. - * - * With the exception of calls to Span.context() (which are always allowed), - * finish() must be the last call made to any span instance, and to do - * otherwise leads to undefined behavior. - * - * @param finishTime - * Optional finish time in milliseconds as a Unix timestamp. Decimal - * values are supported for timestamps with sub-millisecond accuracy. - * If not specified, the current time (as defined by the - * implementation) will be used. - */ - finish(finishTime?: number): void; -} - -export = DatadogSpan; diff --git a/types/dd-trace/src/opentracing/span_context.d.ts b/types/dd-trace/src/opentracing/span_context.d.ts deleted file mode 100644 index cf9565d5a5..0000000000 --- a/types/dd-trace/src/opentracing/span_context.d.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { SpanContext } from 'opentracing'; - -/** - * SpanContext represents Span state that must propagate to descendant Spans - * and across process boundaries. - * - * SpanContext is logically divided into two pieces: the user-level "Baggage" - * (see setBaggageItem and getBaggageItem) that propagates across Span - * boundaries and any Tracer-implementation-specific fields that are needed to - * identify or otherwise contextualize the associated Span instance (e.g., a - * tuple). - */ -declare class DatadogSpanContext extends SpanContext { - /** - * Use to create references to parent spans. - */ - constructor(props: SpanContextLike); - - public traceId: number; - - public spanId: number; - - public parentId?: number | null; - - public sampled?: boolean; - - public baggageItems?: { [key: string]: string }; - - public trace?: { - started: number[], - finished: number[] - } -} - -interface SpanContextLike { - traceId: number; - spanId: number; -} - -export = DatadogSpanContext; diff --git a/types/dd-trace/src/opentracing/tracer.d.ts b/types/dd-trace/src/opentracing/tracer.d.ts deleted file mode 100644 index 252a0d558c..0000000000 --- a/types/dd-trace/src/opentracing/tracer.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Tracer } from 'opentracing'; - -/** - * Tracer is the entry-point between the instrumentation API and the tracing - * implementation. - */ -declare class DatadogTracer extends Tracer { - -} - -export = DatadogTracer;

{@link https://docs.microsoft.com/outlook/add-ins/understanding-outlook-add-in-permissions | Minimum permission level}ReadWriteItem