wasm-ast-types 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
- exports.getType = exports.getPropertyType = exports.forEmptyNameFix = exports.createTypedObjectParams = void 0;
10
+ exports.getType = exports.getPropertyType = exports.createTypedObjectParams = void 0;
11
11
 
12
12
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
13
 
@@ -23,16 +23,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
23
23
 
24
24
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
25
 
26
- var forEmptyNameFix = function forEmptyNameFix(name) {
27
- if (name.endsWith('For_Empty')) {
28
- return name.replace(/For_Empty$/, '_for_Empty');
29
- }
30
-
31
- return name;
32
- };
33
-
34
- exports.forEmptyNameFix = forEmptyNameFix;
35
-
36
26
  var getTypeFromRef = function getTypeFromRef($ref) {
37
27
  switch ($ref) {
38
28
  case '#/definitions/Binary':
@@ -182,7 +172,7 @@ var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
182
172
  var typedParams = keys.map(function (prop) {
183
173
  if (jsonschema.properties[prop].type === 'object') {
184
174
  if (jsonschema.properties[prop].title) {
185
- return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(forEmptyNameFix(jsonschema.properties[prop].title)))));
175
+ return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(jsonschema.properties[prop].title))));
186
176
  } else {
187
177
  throw new Error('createTypedObjectParams() contact maintainer');
188
178
  }
@@ -199,17 +189,15 @@ var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
199
189
  var uniqUnionTypes = (0, _toConsumableArray2["default"])(new Set(unionTypes));
200
190
 
201
191
  if (uniqUnionTypes.length === 1) {
202
- return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(forEmptyNameFix(uniqUnionTypes[0])))), isOptional);
192
+ return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(uniqUnionTypes[0]))), isOptional);
203
193
  } else {
204
194
  return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(uniqUnionTypes.map(function (typ) {
205
- return t.tsTypeReference(t.identifier(forEmptyNameFix(typ)));
195
+ return t.tsTypeReference(t.identifier(typ));
206
196
  }))), isOptional);
207
197
  }
208
198
  } else if (Array.isArray(jsonschema.properties[prop].oneOf)) {
209
199
  var _jsonschema$required2;
210
200
 
211
- var oneOf = JSON.stringify(jsonschema.properties[prop].oneOf, null, 2);
212
-
213
201
  var _isOptional = !((_jsonschema$required2 = jsonschema.required) !== null && _jsonschema$required2 !== void 0 && _jsonschema$required2.includes(prop));
214
202
 
215
203
  var _unionTypes = jsonschema.properties[prop].oneOf.map(function (el) {
@@ -220,10 +208,10 @@ var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
220
208
  var _uniqUnionTypes = (0, _toConsumableArray2["default"])(new Set(_unionTypes));
221
209
 
222
210
  if (_uniqUnionTypes.length === 1) {
223
- return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(forEmptyNameFix(_uniqUnionTypes[0])))), _isOptional);
211
+ return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(_uniqUnionTypes[0]))), _isOptional);
224
212
  } else {
225
213
  return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(_uniqUnionTypes.map(function (typ) {
226
- return t.tsTypeReference(t.identifier(forEmptyNameFix(typ)));
214
+ return t.tsTypeReference(t.identifier(typ));
227
215
  }))), _isOptional);
228
216
  }
229
217
  }
package/main/wasm.js CHANGED
@@ -163,7 +163,7 @@ var createTypeOrInterface = function createTypeOrInterface(Type, jsonschema) {
163
163
 
164
164
  if (jsonschema.type !== 'object') {
165
165
  if (!jsonschema.type) {
166
- return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, t.tsTypeReference(t.identifier((0, _types2.forEmptyNameFix)(jsonschema.title)))));
166
+ return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, t.tsTypeReference(t.identifier(jsonschema.title))));
167
167
  }
168
168
 
169
169
  return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, (0, _types2.getType)(jsonschema.type)));
@@ -1,13 +1,6 @@
1
1
  import * as t from '@babel/types';
2
2
  import { camel } from 'case';
3
3
  import { propertySignature } from './babel';
4
- export const forEmptyNameFix = name => {
5
- if (name.endsWith('For_Empty')) {
6
- return name.replace(/For_Empty$/, '_for_Empty');
7
- }
8
-
9
- return name;
10
- };
11
4
 
12
5
  const getTypeFromRef = $ref => {
13
6
  switch ($ref) {
@@ -143,7 +136,7 @@ export const createTypedObjectParams = (jsonschema, camelize = true) => {
143
136
  const typedParams = keys.map(prop => {
144
137
  if (jsonschema.properties[prop].type === 'object') {
145
138
  if (jsonschema.properties[prop].title) {
146
- return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(forEmptyNameFix(jsonschema.properties[prop].title)))));
139
+ return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(jsonschema.properties[prop].title))));
147
140
  } else {
148
141
  throw new Error('createTypedObjectParams() contact maintainer');
149
142
  }
@@ -158,12 +151,11 @@ export const createTypedObjectParams = (jsonschema, camelize = true) => {
158
151
  const uniqUnionTypes = [...new Set(unionTypes)];
159
152
 
160
153
  if (uniqUnionTypes.length === 1) {
161
- return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(forEmptyNameFix(uniqUnionTypes[0])))), isOptional);
154
+ return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(uniqUnionTypes[0]))), isOptional);
162
155
  } else {
163
- return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(uniqUnionTypes.map(typ => t.tsTypeReference(t.identifier(forEmptyNameFix(typ)))))), isOptional);
156
+ return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(uniqUnionTypes.map(typ => t.tsTypeReference(t.identifier(typ))))), isOptional);
164
157
  }
165
158
  } else if (Array.isArray(jsonschema.properties[prop].oneOf)) {
166
- const oneOf = JSON.stringify(jsonschema.properties[prop].oneOf, null, 2);
167
159
  const isOptional = !jsonschema.required?.includes(prop);
168
160
  const unionTypes = jsonschema.properties[prop].oneOf.map(el => {
169
161
  if (el.title) return el.title;
@@ -172,9 +164,9 @@ export const createTypedObjectParams = (jsonschema, camelize = true) => {
172
164
  const uniqUnionTypes = [...new Set(unionTypes)];
173
165
 
174
166
  if (uniqUnionTypes.length === 1) {
175
- return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(forEmptyNameFix(uniqUnionTypes[0])))), isOptional);
167
+ return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(uniqUnionTypes[0]))), isOptional);
176
168
  } else {
177
- return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(uniqUnionTypes.map(typ => t.tsTypeReference(t.identifier(forEmptyNameFix(typ)))))), isOptional);
169
+ return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(uniqUnionTypes.map(typ => t.tsTypeReference(t.identifier(typ))))), isOptional);
178
170
  }
179
171
  }
180
172
 
package/module/wasm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as t from '@babel/types';
2
2
  import { camel, pascal } from 'case';
3
3
  import { bindMethod, typedIdentifier, promiseTypeAnnotation, classDeclaration, classProperty, arrowFunctionExpression, getMessageProperties } from './utils';
4
- import { getPropertyType, getType, createTypedObjectParams, forEmptyNameFix } from './utils/types';
4
+ import { getPropertyType, getType, createTypedObjectParams } from './utils/types';
5
5
  import { identifier, tsTypeOperator, propertySignature } from './utils/babel';
6
6
  export const createWasmQueryMethod = jsonschema => {
7
7
  const underscoreName = Object.keys(jsonschema.properties)[0];
@@ -103,7 +103,7 @@ export const createQueryInterface = (className, queryMsg) => {
103
103
  export const createTypeOrInterface = (Type, jsonschema) => {
104
104
  if (jsonschema.type !== 'object') {
105
105
  if (!jsonschema.type) {
106
- return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, t.tsTypeReference(t.identifier(forEmptyNameFix(jsonschema.title)))));
106
+ return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, t.tsTypeReference(t.identifier(jsonschema.title))));
107
107
  }
108
108
 
109
109
  return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, getType(jsonschema.type)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wasm-ast-types",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "CosmWasm TypeScript AST generation",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/pyramation/cosmwasm-typescript-gen/tree/master/packages/wasm-ast-types#readme",
@@ -85,5 +85,5 @@
85
85
  "ast-stringify": "0.1.0",
86
86
  "case": "1.6.3"
87
87
  },
88
- "gitHead": "aade6ffc08df51adc9922d4cd813fe8ef5bebfa1"
88
+ "gitHead": "bf8f96d8f70a2bdfff2f210dc07c26c14575478b"
89
89
  }