New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wasm-ast-types

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wasm-ast-types - npm Package Compare versions

Comparing version 0.5.1 to 0.6.0

main/client/client.js

42

main/index.js

@@ -20,11 +20,11 @@ "use strict";

var _wasm = require("./wasm");
var _client = require("./client");
Object.keys(_wasm).forEach(function (key) {
Object.keys(_client).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _wasm[key]) return;
if (key in exports && exports[key] === _client[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _wasm[key];
return _client[key];
}

@@ -34,2 +34,15 @@ });

var _context = require("./context");
Object.keys(_context).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _context[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _context[key];
}
});
});
var _recoil = require("./recoil");

@@ -48,11 +61,11 @@

var _messages = require("./messages");
var _fromPartial = require("./from-partial");
Object.keys(_messages).forEach(function (key) {
Object.keys(_fromPartial).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _messages[key]) return;
if (key in exports && exports[key] === _fromPartial[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _messages[key];
return _fromPartial[key];
}

@@ -73,2 +86,15 @@ });

});
});
var _types = require("./types");
Object.keys(_types).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _types[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _types[key];
}
});
});

22

main/utils/babel.spec.js

@@ -13,6 +13,6 @@ "use strict";

var _generator = _interopRequireDefault(require("@babel/generator"));
var t = _interopRequireWildcard(require("@babel/types"));
var _testUtils = require("../../test-utils");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

@@ -22,10 +22,2 @@

var expectCode = function expectCode(ast) {
expect((0, _generator["default"])(ast).code).toMatchSnapshot();
};
var printCode = function printCode(ast) {
console.log((0, _generator["default"])(ast).code);
};
it('top import', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {

@@ -36,3 +28,3 @@ return _regenerator["default"].wrap(function _callee$(_context) {

case 0:
expectCode((0, _babel.importStmt)(['CosmWasmClient', 'ExecuteResult', 'SigningCosmWasmClient'], '@cosmjs/cosmwasm-stargate'));
(0, _testUtils.expectCode)((0, _babel.importStmt)(['CosmWasmClient', 'ExecuteResult', 'SigningCosmWasmClient'], '@cosmjs/cosmwasm-stargate'));

@@ -51,3 +43,3 @@ case 1:

case 0:
expectCode(t.program([t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier('SG721ReadOnlyInstance'), null, [], t.tSInterfaceBody([t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // methods
(0, _testUtils.expectCode)(t.program([t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier('SG721ReadOnlyInstance'), null, [], t.tSInterfaceBody([t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // methods
t.tSPropertySignature(t.identifier('tokens'), t.tsTypeAnnotation(t.tsFunctionType(null, [(0, _babel.typedIdentifier)('owner', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _babel.typedIdentifier)('startAfter', t.tsTypeAnnotation(t.tsStringKeyword()), true), (0, _babel.typedIdentifier)('limit', t.tsTypeAnnotation(t.tsStringKeyword()), true)], (0, _babel.promiseTypeAnnotation)('TokensResponse'))))]))), // extends

@@ -70,3 +62,3 @@ t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier('SG721Instance'), null, [t.tSExpressionWithTypeArguments(t.identifier('SG721ReadOnlyInstance'))], t.tSInterfaceBody([// contract address

case 0:
expectCode(t.program([t.exportNamedDeclaration((0, _babel.classDeclaration)('SG721QueryClient', [// client
(0, _testUtils.expectCode)(t.program([t.exportNamedDeclaration((0, _babel.classDeclaration)('SG721QueryClient', [// client
(0, _babel.classProperty)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))), // contractAddress

@@ -94,3 +86,3 @@ (0, _babel.classProperty)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor

case 0:
expectCode(t.program([t.exportNamedDeclaration((0, _babel.classDeclaration)('SG721Client', [// client
(0, _testUtils.expectCode)(t.program([t.exportNamedDeclaration((0, _babel.classDeclaration)('SG721Client', [// client
(0, _babel.classProperty)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), // contractAddress

@@ -116,4 +108,4 @@ (0, _babel.classProperty)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor

obj.typeAnnotation = t.tsTypeAnnotation(t.tsTypeLiteral([t.tsPropertySignature(t.identifier('includeExpired'), t.tsTypeAnnotation(t.tsBooleanKeyword())), t.tsPropertySignature(t.identifier('tokenId'), t.tsTypeAnnotation(t.tsStringKeyword()))]));
expectCode(t.program([t.expressionStatement(t.assignmentExpression('=', t.identifier('ownerOf'), (0, _babel.arrowFunctionExpression)([obj], t.blockStatement([// body
(0, _testUtils.expectCode)(t.program([t.expressionStatement(t.assignmentExpression('=', t.identifier('ownerOf'), (0, _babel.arrowFunctionExpression)([obj], t.blockStatement([// body
], []), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier('OwnerOfResponse'))]))))))]));
});

@@ -18,2 +18,15 @@ "use strict";

});
});
var _types = require("./types");
Object.keys(_types).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _types[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _types[key];
}
});
});

@@ -29,27 +29,11 @@ "use strict";

var getTypeStrFromRef = function getTypeStrFromRef($ref) {
switch ($ref) {
case '#/definitions/Binary':
return 'Binary';
if ($ref !== null && $ref !== void 0 && $ref.startsWith('#/definitions/')) {
return $ref.replace('#/definitions/', '');
}
default:
if ($ref !== null && $ref !== void 0 && $ref.startsWith('#/definitions/')) {
return $ref.replace('#/definitions/', '');
}
throw new Error('what is $ref: ' + $ref);
}
throw new Error('what is $ref: ' + $ref);
};
var getTypeFromRef = function getTypeFromRef($ref) {
switch ($ref) {
case '#/definitions/Binary':
return t.tsTypeReference(t.identifier('Binary'));
default:
if ($ref !== null && $ref !== void 0 && $ref.startsWith('#/definitions/')) {
return t.tsTypeReference(t.identifier($ref.replace('#/definitions/', '')));
}
throw new Error('what is $ref: ' + $ref);
}
return t.tsTypeReference(t.identifier(getTypeStrFromRef($ref)));
};

@@ -93,3 +77,3 @@

var getPropertyType = function getPropertyType(schema, prop) {
var getPropertyType = function getPropertyType(context, schema, prop) {
var _schema$properties, _schema$required, _schema$required2;

@@ -192,3 +176,3 @@

function getPropertySignatureFromProp(jsonschema, prop, camelize) {
function getPropertySignatureFromProp(context, jsonschema, prop, camelize) {
if (jsonschema.properties[prop].type === 'object') {

@@ -243,3 +227,3 @@ if (jsonschema.properties[prop].title) {

try {
getPropertyType(jsonschema, prop);
getPropertyType(context, jsonschema, prop);
} catch (e) {

@@ -250,3 +234,3 @@ console.log(e);

var _getPropertyType = getPropertyType(jsonschema, prop),
var _getPropertyType = getPropertyType(context, jsonschema, prop),
type = _getPropertyType.type,

@@ -258,10 +242,15 @@ optional = _getPropertyType.optional;

var getParamsTypeAnnotation = function getParamsTypeAnnotation(jsonschema) {
var getParamsTypeAnnotation = function getParamsTypeAnnotation(context, jsonschema) {
var _jsonschema$propertie;
var camelize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var camelize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var keys = Object.keys((_jsonschema$propertie = jsonschema.properties) !== null && _jsonschema$propertie !== void 0 ? _jsonschema$propertie : {});
if (!keys.length && jsonschema.$ref) {
return t.tsTypeAnnotation(getTypeFromRef(jsonschema.$ref));
}
if (!keys.length) return undefined;
var typedParams = keys.map(function (prop) {
return getPropertySignatureFromProp(jsonschema, prop, camelize);
return getPropertySignatureFromProp(context, jsonschema, prop, camelize);
});

@@ -273,9 +262,22 @@ return t.tsTypeAnnotation(t.tsTypeLiteral((0, _toConsumableArray2["default"])(typedParams)));

var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
var createTypedObjectParams = function createTypedObjectParams(context, jsonschema) {
var _jsonschema$propertie2;
var camelize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var camelize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var keys = Object.keys((_jsonschema$propertie2 = jsonschema.properties) !== null && _jsonschema$propertie2 !== void 0 ? _jsonschema$propertie2 : {});
if (!keys.length) return; // const typedParams = keys.map(prop => getPropertySignatureFromProp(jsonschema, prop, camelize));
if (!keys.length) {
// is there a ref?
if (jsonschema.$ref) {
var _obj = context.refLookup(jsonschema.$ref);
if (_obj) {
return createTypedObjectParams(context, _obj, camelize);
}
} // no results...
return;
}
var params = keys.map(function (prop) {

@@ -285,3 +287,3 @@ return t.objectProperty(camelize ? t.identifier((0, _case.camel)(prop)) : t.identifier(prop), camelize ? t.identifier((0, _case.camel)(prop)) : t.identifier(prop), false, true);

var obj = t.objectPattern((0, _toConsumableArray2["default"])(params));
obj.typeAnnotation = getParamsTypeAnnotation(jsonschema, camelize);
obj.typeAnnotation = getParamsTypeAnnotation(context, jsonschema, camelize);
return obj;

@@ -288,0 +290,0 @@ };

export * from './utils';
export * from './wasm';
export * from './client';
export * from './context';
export * from './recoil';
export * from './messages';
export * from './react-query';
export * from './from-partial';
export * from './react-query';
export * from './types';
import { importStmt } from './babel';
import generate from '@babel/generator';
import * as t from '@babel/types';
import { bindMethod, typedIdentifier, promiseTypeAnnotation, classDeclaration, classProperty, arrowFunctionExpression } from './babel';
const expectCode = ast => {
expect(generate(ast).code).toMatchSnapshot();
};
const printCode = ast => {
console.log(generate(ast).code);
};
import { expectCode } from '../../test-utils';
it('top import', async () => {

@@ -15,0 +6,0 @@ expectCode(importStmt(['CosmWasmClient', 'ExecuteResult', 'SigningCosmWasmClient'], '@cosmjs/cosmwasm-stargate'));

@@ -1,1 +0,2 @@

export * from './babel';
export * from './babel';
export * from './types';

@@ -6,27 +6,11 @@ import * as t from '@babel/types';

const getTypeStrFromRef = $ref => {
switch ($ref) {
case '#/definitions/Binary':
return 'Binary';
if ($ref?.startsWith('#/definitions/')) {
return $ref.replace('#/definitions/', '');
}
default:
if ($ref?.startsWith('#/definitions/')) {
return $ref.replace('#/definitions/', '');
}
throw new Error('what is $ref: ' + $ref);
}
throw new Error('what is $ref: ' + $ref);
};
export const getTypeFromRef = $ref => {
switch ($ref) {
case '#/definitions/Binary':
return t.tsTypeReference(t.identifier('Binary'));
default:
if ($ref?.startsWith('#/definitions/')) {
return t.tsTypeReference(t.identifier($ref.replace('#/definitions/', '')));
}
throw new Error('what is $ref: ' + $ref);
}
return t.tsTypeReference(t.identifier(getTypeStrFromRef($ref)));
};

@@ -65,3 +49,3 @@

};
export const getPropertyType = (schema, prop) => {
export const getPropertyType = (context, schema, prop) => {
const props = schema.properties ?? {};

@@ -155,3 +139,3 @@ let info = props[prop];

};
export function getPropertySignatureFromProp(jsonschema, prop, camelize) {
export function getPropertySignatureFromProp(context, jsonschema, prop, camelize) {
if (jsonschema.properties[prop].type === 'object') {

@@ -196,3 +180,3 @@ if (jsonschema.properties[prop].title) {

try {
getPropertyType(jsonschema, prop);
getPropertyType(context, jsonschema, prop);
} catch (e) {

@@ -206,15 +190,33 @@ console.log(e);

optional
} = getPropertyType(jsonschema, prop);
} = getPropertyType(context, jsonschema, prop);
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(type), optional);
}
export const getParamsTypeAnnotation = (jsonschema, camelize = true) => {
export const getParamsTypeAnnotation = (context, jsonschema, camelize = true) => {
const keys = Object.keys(jsonschema.properties ?? {});
if (!keys.length && jsonschema.$ref) {
return t.tsTypeAnnotation(getTypeFromRef(jsonschema.$ref));
}
if (!keys.length) return undefined;
const typedParams = keys.map(prop => getPropertySignatureFromProp(jsonschema, prop, camelize));
const typedParams = keys.map(prop => getPropertySignatureFromProp(context, jsonschema, prop, camelize));
return t.tsTypeAnnotation(t.tsTypeLiteral([...typedParams]));
};
export const createTypedObjectParams = (jsonschema, camelize = true) => {
export const createTypedObjectParams = (context, jsonschema, camelize = true) => {
const keys = Object.keys(jsonschema.properties ?? {});
if (!keys.length) return; // const typedParams = keys.map(prop => getPropertySignatureFromProp(jsonschema, prop, camelize));
if (!keys.length) {
// is there a ref?
if (jsonschema.$ref) {
const obj = context.refLookup(jsonschema.$ref);
if (obj) {
return createTypedObjectParams(context, obj, camelize);
}
} // no results...
return;
}
const params = keys.map(prop => {

@@ -224,4 +226,4 @@ return t.objectProperty(camelize ? t.identifier(camel(prop)) : t.identifier(prop), camelize ? t.identifier(camel(prop)) : t.identifier(prop), false, true);

const obj = t.objectPattern([...params]);
obj.typeAnnotation = getParamsTypeAnnotation(jsonschema, camelize);
obj.typeAnnotation = getParamsTypeAnnotation(context, jsonschema, camelize);
return obj;
};
{
"name": "wasm-ast-types",
"version": "0.5.1",
"version": "0.6.0",
"description": "CosmWasm TypeScript AST generation",

@@ -86,5 +86,6 @@ "author": "Dan Lynch <pyramation@gmail.com>",

"ast-stringify": "0.1.0",
"case": "1.6.3"
"case": "1.6.3",
"deepmerge": "4.2.2"
},
"gitHead": "213e10e01a8784d82d003821d6d9490b97b7b480"
"gitHead": "51e6e530adc95d8118606379848080dd9bc3c25a"
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc