Socket
Socket
Sign inDemoInstall

gd-sprest-def

Package Overview
Dependencies
0
Maintainers
1
Versions
145
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.4 to 1.2.5

lib/enumTypes.ts

41

clean.js
var fs = require('fs');
var https = require("https");

@@ -33,8 +32,2 @@ // Deletes a directory

// See if the file exists
if (fs.existsSync("./graph.xml")) {
// Delete the file
fs.unlinkSync("./graph.xml");
}
// Create the folder

@@ -44,34 +37,2 @@ fs.mkdirSync("./lib");

// Log
console.log("Successfully cleaned the library");
// Log
console.log("Getting the graph api metadata");
// Get the metadata
https.get("https://graph.microsoft.com/v1.0/$metadata", (res) => {
let data = "";
// Read the data
res.on("data", function (chunk) { data += chunk; });
// Wait for the read to complete
res.on("end", function () {
// Fix TypeScript Issues
// Rename the "case" type
// Rename the "return" type
let content = data.toString()
.replace('<EntityType Name="case"', '<EntityType Name="_case"')
.replace('<Action Name="delete"', '<Action Name="_delete"')
.replace('<Action Name="false"', '<Action Name="_false"')
.replace('<Action Name="if"', '<Action Name="_if"')
.replace('<Action Name="import"', '<Action Name="_import"')
.replace('<Action Name="return"', '<Action Name="_return"')
.replace('<Action Name="true"', '<Action Name="_true"');
// Write the file
fs.writeFileSync("graph.xml", content);
// Log
console.log("Graph metadata updated.");
});
});
console.log("Successfully cleaned the library");

@@ -5,4 +5,2 @@ import * as AppServices from "./AppServices";

export { BusinessData }
import * as graph from "./graph";
export { graph }
import * as Office from "./Office";

@@ -13,2 +11,4 @@ export { Office }

import * as SharePoint from "./SharePoint";
export { SharePoint }
export { SharePoint }
import * as Graph from "./Graph";
export { Graph }

@@ -232,2 +232,8 @@ let fs = require("fs");

}
} else if (type.indexOf("graph.") >= 0) {
let typeInfo = type.split('.');
let typeName = typeInfo[typeInfo.length - 1];
if (enumInterfaces[typeName]) {
return "graph." + typeName;
}
}

@@ -242,2 +248,3 @@

.replace(/Edm\.DateTime/, 'any')
.replace(/Edm\.Date/, 'any')
.replace(/Edm\.Decimal/, 'number')

@@ -253,2 +260,3 @@ .replace(/Edm\.Double/, 'number')

.replace(/Edm\.String/, 'string')
.replace(/Edm\.TimeOfDay/, 'any')
.replace(/Edm\.Time/, 'any')

@@ -285,9 +293,10 @@ .replace(/^Collection\(/, 'Array<')

// Process the metadata
function processMetadata(schemas) {
let directories = {};
// Process the Graph metadata
function processGraph(schemas) {
let complexTypes = {};
let endPoints = {};
let enums = {};
let enumInterfaces = {};
let methods = {};
let methodTypes = {};
let entities = {};
let graphEndPoints = {};

@@ -297,12 +306,3 @@ // Parse the schemas

let schema = schemas[i];
let isGraph = (schema.$ ? schema.$.Alias : null) == "graph";
// Ensure a namespace name exists
let ns = schema.$ ? schema.$.Namespace : null;
if (ns) {
// Set the directory name
directories[ns] = directories[ns] || {};
directories[ns]._api = [];
} else { continue; }
// Parse the schema

@@ -315,7 +315,16 @@ for (let key in schema) {

// See if it's an
if (key == "Annotations") {
// Parse the annotations
for (let annotation of value) {
}
// Continue
continue;
}
// See if it's an enumerator
if (key == "EnumType") {
// Parse the enums
for (let j = 0; j < value.length; j++) {
let enumInfo = value[j];
for (let enumInfo of value) {
let name = enumInfo.$.Name;

@@ -328,5 +337,3 @@

// Parse the members
for (let k = 0; k < enumInfo.Member.length; k++) {
let member = enumInfo.Member[k];
for (let member of enumInfo.Member) {
// Add the member

@@ -350,2 +357,340 @@ enumInterface += "\t" + member.$.Name + ": " + member.$.Value + ";\n"

// See if this is a complex type
if (key == "ComplexType") {
// Parse the values
for (let complexType of value) {
let name = complexType.$.Name;
let returnType = complexType.BaseType;
// Parse the properties
let props = [];
let complexTypesProps = complexType.Property || [];
for (let prop of complexTypesProps) {
// Add the property
props.push({ name: prop.$.Name, returnType: prop.$.Type, nullable: prop.$.Nullable });
}
// Add the entity type
complexTypes[name] = { name, returnType, props };
}
}
// See if this is an entity type
if (key == "EntityType") {
// Parse the values
for (let entityType of value) {
let name = entityType.$.Name;
let returnType = entityType.BaseType;
// Parse the properties
let props = [];
let entityProps = entityType.Property || [];
for (let prop of entityProps) {
// Add the property
props.push({ name: prop.$.Name, returnType: prop.$.Type, nullable: prop.$.Nullable });
}
// Parse the methods
let methods = [];
let subMethods = entityType.NavigationProperty || [];
for (let subMethod of subMethods) {
// Set the method name
let name = subMethod.$.Name;
let nameInfo = name.split('/');
if (nameInfo.length > 1) {
name = nameInfo[nameInfo.length - 1];
}
// Set the return type
let returnType = subMethod.$.Type;
let returnTypeInfo = returnType.split('/');
if (returnTypeInfo.length > 1) {
returnType = returnTypeInfo[returnTypeInfo.length - 1];
}
// Add the method
methods.push({ name, returnType });
}
// Add the entity type
entities[name] = { name, returnType, props, methods };
}
// Continue
continue;
}
// See if this is an entity container
if (key == "EntityContainer") {
// Parse the values
for (let val of value) {
// Parse the entity types
let entitySets = val.EntitySet || [];
for (let i = 0; i < entitySets.length; i++) {
let entitySet = entitySets[i];
let name = entitySet.$.Name;
let returnType = entitySet.$.EntityType;
// Parse the methods
let methods = [];
let subMethods = entitySet.NavigationPropertyBinding || [];
for (let subMethod of subMethods) {
// Set the method name
let name = subMethod.$.Path;
let nameInfo = name.split('/');
if (nameInfo.length > 1) {
name = nameInfo[nameInfo.length - 1];
}
// Set the return type
let returnType = subMethod.$.Target;
let returnTypeInfo = returnType.split('/');
if (returnTypeInfo.length > 1) {
returnType = returnTypeInfo[returnTypeInfo.length - 1];
}
// Add the method
methods.push({ name, returnType });
}
// Add the endpoint
endPoints[name] = { name: name, returnType, methods };
}
// Parse the singletons
let singletons = val.Singleton || [];
for (let singleton of singletons) {
let name = singleton.$.Name;
let returnType = singleton.$.Type;
// Parse the methods
let methods = [];
let subMethods = singleton.NavigationPropertyBinding || [];
for (let subMethod of subMethods) {
// Set the method name
let name = subMethod.$.Path;
let nameInfo = name.split('/');
if (nameInfo.length > 1) {
name = nameInfo[nameInfo.length - 1];
}
// Set the return type
let returnType = subMethod.$.Target;
let returnTypeInfo = returnType.split('/');
if (returnTypeInfo.length > 1) {
returnType = returnTypeInfo[returnTypeInfo.length - 1];
}
// Add the method
methods.push({ name, returnType });
}
// Add the endpoint
graphEndPoints[name] = { name, returnType, methods };
// Continue
continue;
}
}
// Continue
continue;
}
}
}
// Method to get the type
let getGraphType = (returnType = "") => {
// See if the return type is in not an Edm
if (returnType.indexOf("graph." == 0)) {
// Set the return type information
let isCollection = returnType.indexOf("Collection(") == 0;
let info = (isCollection ? returnType.replace("Collection(", "").replace(")", "") : returnType).split('.');
// See if this is a collection using "s" at the end
let name = info[info.length - 1];
let name2 = null;
if (!isCollection && name[name.length - 1] == "s") {
// Set the name
name2 = name.substring(name.length - 1);
}
// See if it's a complex type
if (complexTypes[name]) {
// Set the return type
returnType = "ComplexTypes." + name;
} else if (complexTypes[name2]) {
// Set the return type
returnType = "ComplexTypes." + name2 + "[]";
}
// Else, see if it's an entity
else if (entities[name]) {
// Set the return type
returnType = "EntityTypes." + name;
}
// Else, see if it's an entity
else if (entities[name2]) {
// Set the return type
returnType = "EntityTypes." + name2 + "[]";
}
// Else, see if it's an enum
else if (enums[name]) {
// Set the return type
returnType = "EnumTypes." + name;
}
// Else, see if it's an enum
else if (enums[name2]) {
// Set the return type
returnType = "EnumTypes." + name2 + "[]";
}
// Else, see if it's a basic type
else if (info[0] == "Edm") {
returnType = getType(returnType);
}
// Update the collection
isCollection ? returnType += "[]" : null;
}
// Return the type
return returnType;
}
// Make the graph directory
if (fs.existsSync("lib/microsoft/Graph") == false) { fs.mkdirSync("lib/microsoft/Graph"); }
// Create the endpoints
let content = ["import { IBaseResult } from \"../../base\";"];
for (let name in endPoints) {
let endPoint = endPoints[name];
// Parse the methods
let methods = [];
for (let method of endPoint.methods) {
// Add the method
methods.push("\t" + method.name + ": IBaseResult<" + getGraphType(method.returnType) + ">;");
}
// Add the endpoint
content.push(`/*********************************************
* ${name}
**********************************************/
export interface ${name} extends IBaseResult<${getGraphType(endPoint.returnType.replace("microsoft.graph.", "graph."))}> {
${methods.join('\n')}
}`);
}
fs.writeFileSync("lib/microsoft/graph/api.d.ts", content.join('\n'));
// Create the enum definitions
content = [];
for (let key in enumInterfaces) { content.push(enumInterfaces[key]); }
fs.writeFileSync("lib/microsoft/graph/enumTypes.d.ts", content.join('\n'));
// Append the export of the enums
fs.appendFileSync("lib/microsoft/graph/index.d.ts", [
'export * as API from "./api";',
'export * as ComplexTypes from "./complexTypes";',
'export * as EntityTypes from "./entityTypes";',
'export * as Enums from "./enumTypes";'
].join('\n'));
// Append the graph endpoint
fs.appendFileSync("lib/Microsoft/index.d.ts", [
'\nimport * as Graph from "./Graph";',
'export { Graph }'
].join('\n'));
// Create the graph enum types
content = ["import * as GraphTypes from \"./microsoft/graph/enumTypes\";\n"];
for (let key in enums) { content.push(enums[key]); }
fs.writeFileSync("lib/enumTypes.ts", content.join('\n'));
// Create the complex types
content = [
"import * as EnumTypes from \"./enumTypes.d\";",
];
for (let name in complexTypes) {
let complexType = complexTypes[name];
// Parse the properties
let props = [];
for (let prop of complexType.props) {
// Add the property
props.push("\t" + prop.name + ": " + getGraphType(prop.returnType) + ";");
}
// Add the endpoint
content.push(`/*********************************************
* ${name}
**********************************************/
export interface ${name} ${complexType.returnType ? "extends " + complexType.returnType : ""} {
${props.join('\n')}
}`);
}
fs.writeFileSync("lib/microsoft/graph/complexTypes.d.ts", content.join('\n').replace(/ComplexTypes./g, ""));
// Create the entities
content = [
"import { IBaseResult } from \"../../base\";",
"import * as ComplexTypes from \"./complexTypes.d\";",
"import * as EnumTypes from \"./enumTypes.d\";\n",
];
for (let name in entities) {
let entity = entities[name];
// Parse the properties
let props = [];
for (let prop of entity.props) {
// Add the property
props.push("\t" + prop.name + ": " + getGraphType(prop.returnType) + ";");
}
// Parse the methods
let methods = [];
for (let method of entity.methods) {
// Add the method
methods.push("\t" + method.name + ": IBaseResult<" + getGraphType(method.returnType) + ">;");
}
// Add the endpoint
content.push(`/*********************************************
* ${name}
**********************************************/
export interface ${name} ${entity.returnType ? "extends " + entity.returnType : ""} {
${props.join('\n')}
${methods.join('\n')}
}`);
}
fs.writeFileSync("lib/microsoft/graph/entityTypes.d.ts", content.join('\n').replace(/EntityTypes./g, ""));
}
// Process the REST metadata
function processREST(schemas) {
let directories = {};
let enumInterfaces = {};
let methods = {};
let methodTypes = {};
// Parse the schemas
for (let i = 0; i < schemas.length; i++) {
let schema = schemas[i];
// Ensure a namespace name exists
let ns = schema.$ ? schema.$.Namespace : null;
if (ns) {
// Set the directory name
directories[ns] = directories[ns] || {};
directories[ns]._api = [];
} else { continue; }
// Parse the schema
for (let key in schema) {
let value = schema[key];
// Skip the attributes
if (key == "$") { continue; }
// See if this is a collection

@@ -490,20 +835,5 @@ if (value.length > 0) {

// Create the enum definitions
let enumContent = [];
for (let key in enumInterfaces) { enumContent.push(enumInterfaces[key]); }
fs.writeFileSync("lib/microsoft/graph/enums.d.ts", enumContent.join('\n'));
// Generate the index files
generateIndexFiles("lib");
// Append the export of the enums
fs.appendFileSync("lib/microsoft/graph/index.d.ts", [
'\nexport * from "./enums";'
].join('\n'));
// Create the graph enum types
enumContent = ["import * as GraphTypes from \"./microsoft/graph/enums.d\";\n"];
for (let key in enums) { enumContent.push(enums[key]); }
fs.writeFileSync("lib/enums.ts", enumContent.join('\n'));
// Append the index file

@@ -1004,11 +1334,9 @@ fs.appendFileSync("lib/index.d.ts", [

parser(rest, function (err, restXML) {
// Process the REST metadata
processREST(restXML["edmx:Edmx"]["edmx:DataServices"][0].Schema);
// Parse the xml
parser(graph, function (err, graphXML) {
// Combine the schemas
let schemas = restXML["edmx:Edmx"]["edmx:DataServices"][0].Schema.concat(
graphXML["edmx:Edmx"]["edmx:DataServices"][0].Schema
);
// Process the metadata
processMetadata(schemas);
//processMetadata(graphXML["edmx:Edmx"]["edmx:DataServices"][0].Schema);
// Process the Graph metadata
processGraph(graphXML["edmx:Edmx"]["edmx:DataServices"][0].Schema);
});

@@ -1015,0 +1343,0 @@ });

{
"name": "gd-sprest-def",
"version": "1.2.4",
"version": "1.2.5",
"description": "TypeScript definition files generated from the $metadata REST endpoint in SharePoint.",

@@ -15,3 +15,4 @@ "author": "Gunjan Datta <me@dattabase.com> (https://gunjandatta.github.io)",

"clean": "node clean.js",
"package": "npm run clean && npm run build"
"package": "npm run clean && npm run build",
"update": "node update.js"
},

@@ -18,0 +19,0 @@ "repository": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc