wasm-ast-types 0.4.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +129 -0
- package/main/{wasm.js → client/client.js} +56 -40
- package/main/client/index.js +18 -0
- package/main/client/test/ts-client.arrays.spec.js +25 -0
- package/main/client/test/ts-client.cw-named-groups.test.js +25 -0
- package/main/client/test/ts-client.cw-proposal-single.test.js +30 -0
- package/main/client/test/ts-client.empty-enums.spec.js +19 -0
- package/main/client/test/ts-client.sg721.spec.js +25 -0
- package/main/client/test/ts-client.spec.js +106 -0
- package/main/client/test/ts-client.vectis.spec.js +56 -0
- package/main/context/context.js +48 -0
- package/main/context/index.js +18 -0
- package/main/{messages.js → from-partial/from-partial.js} +17 -60
- package/main/from-partial/from-partial.spec.js +20 -0
- package/main/from-partial/index.js +18 -0
- package/main/index.js +34 -8
- package/main/react-query/index.js +18 -0
- package/main/react-query/react-query.js +267 -0
- package/main/{react-query.spec.js → react-query/react-query.spec.js} +36 -39
- package/main/recoil/index.js +18 -0
- package/main/{recoil.js → recoil/recoil.js} +7 -26
- package/main/{recoil.spec.js → recoil/recoil.spec.js} +9 -14
- package/main/utils/babel.js +28 -2
- package/main/utils/babel.spec.js +7 -15
- package/main/utils/index.js +13 -0
- package/main/utils/types.js +100 -78
- package/module/{wasm.js → client/client.js} +45 -35
- package/module/client/index.js +1 -0
- package/module/client/test/ts-client.arrays.spec.js +17 -0
- package/module/client/test/ts-client.cw-named-groups.test.js +17 -0
- package/module/client/test/ts-client.cw-proposal-single.test.js +21 -0
- package/module/client/test/ts-client.empty-enums.spec.js +11 -0
- package/module/client/test/ts-client.sg721.spec.js +17 -0
- package/module/client/test/ts-client.spec.js +85 -0
- package/module/client/test/ts-client.vectis.spec.js +44 -0
- package/module/context/context.js +25 -0
- package/module/context/index.js +1 -0
- package/module/{messages.js → from-partial/from-partial.js} +16 -57
- package/module/from-partial/from-partial.spec.js +12 -0
- package/module/from-partial/index.js +1 -0
- package/module/index.js +5 -3
- package/module/react-query/index.js +1 -0
- package/module/react-query/react-query.js +222 -0
- package/module/react-query/react-query.spec.js +53 -0
- package/module/recoil/index.js +1 -0
- package/module/{recoil.js → recoil/recoil.js} +6 -20
- package/module/recoil/recoil.spec.js +15 -0
- package/module/utils/babel.js +15 -0
- package/module/utils/babel.spec.js +1 -10
- package/module/utils/index.js +2 -1
- package/module/utils/types.js +83 -74
- package/package.json +26 -24
- package/types/src/client/client.d.ts +17 -0
- package/types/src/client/index.d.ts +1 -0
- package/types/src/client/test/ts-client.cw-named-groups.test.d.ts +1 -0
- package/types/src/client/test/ts-client.cw-proposal-single.test.d.ts +1 -0
- package/types/src/context/context.d.ts +20 -0
- package/types/src/context/index.d.ts +1 -0
- package/types/src/from-partial/from-partial.d.ts +4 -0
- package/types/src/from-partial/index.d.ts +1 -0
- package/types/src/index.d.ts +7 -0
- package/types/src/react-query/index.d.ts +1 -0
- package/types/src/react-query/react-query.d.ts +81 -0
- package/types/src/recoil/index.d.ts +1 -0
- package/types/{recoil.d.ts → src/recoil/recoil.d.ts} +5 -5
- package/types/{types.d.ts → src/types.d.ts} +17 -0
- package/types/{utils.d.ts → src/utils/babel.d.ts} +21 -1
- package/types/src/utils/index.d.ts +2 -0
- package/types/src/utils/types.d.ts +18 -0
- package/types/test-utils/index.d.ts +2 -0
- package/main/messages.spec.js +0 -24
- package/main/react-query.js +0 -155
- package/main/wasm.arrays.spec.js +0 -30
- package/main/wasm.cw-named-groups.test.js +0 -30
- package/main/wasm.cw-proposal-single.test.js +0 -32
- package/main/wasm.empty-enums.spec.js +0 -24
- package/main/wasm.sg721.spec.js +0 -30
- package/main/wasm.spec.js +0 -95
- package/main/wasm.vectis.spec.js +0 -53
- package/module/messages.spec.js +0 -18
- package/module/react-query.js +0 -120
- package/module/react-query.spec.js +0 -59
- package/module/recoil.spec.js +0 -22
- package/module/wasm.arrays.spec.js +0 -24
- package/module/wasm.cw-named-groups.test.js +0 -24
- package/module/wasm.cw-proposal-single.test.js +0 -25
- package/module/wasm.empty-enums.spec.js +0 -18
- package/module/wasm.sg721.spec.js +0 -24
- package/module/wasm.spec.js +0 -76
- package/module/wasm.vectis.spec.js +0 -43
- package/types/amino/amino-interfaces.d.ts +0 -6
- package/types/amino/from-amino.d.ts +0 -13
- package/types/amino/index.d.ts +0 -3
- package/types/amino/to-amino.d.ts +0 -11
- package/types/index.d.ts +0 -5
- package/types/messages.d.ts +0 -4
- package/types/react-query.d.ts +0 -32
- package/types/wasm.d.ts +0 -24
@@ -0,0 +1,17 @@
|
|
1
|
+
import * as t from '@babel/types';
|
2
|
+
import { QueryMsg, ExecuteMsg } from '../types';
|
3
|
+
import { RenderContext } from '../context';
|
4
|
+
import { JSONSchema } from '../types';
|
5
|
+
export declare const CONSTANT_EXEC_PARAMS: (t.AssignmentPattern | t.Identifier)[];
|
6
|
+
export declare const FIXED_EXECUTE_PARAMS: t.Identifier[];
|
7
|
+
export declare const createWasmQueryMethod: (context: RenderContext, jsonschema: any) => t.ClassProperty;
|
8
|
+
export declare const createQueryClass: (context: RenderContext, className: string, implementsClassName: string, queryMsg: QueryMsg) => t.ExportNamedDeclaration;
|
9
|
+
export declare const getWasmMethodArgs: (context: RenderContext, jsonschema: JSONSchema) => t.ObjectProperty[];
|
10
|
+
export declare const createWasmExecMethod: (context: RenderContext, jsonschema: JSONSchema) => t.ClassProperty;
|
11
|
+
export declare const createExecuteClass: (context: RenderContext, className: string, implementsClassName: string, extendsClassName: string, execMsg: ExecuteMsg) => t.ExportNamedDeclaration;
|
12
|
+
export declare const createExecuteInterface: (context: RenderContext, className: string, extendsClassName: string | null, execMsg: ExecuteMsg) => t.ExportNamedDeclaration;
|
13
|
+
export declare const createPropertyFunctionWithObjectParams: (context: RenderContext, methodName: string, responseType: string, jsonschema: JSONSchema) => t.TSPropertySignature;
|
14
|
+
export declare const createPropertyFunctionWithObjectParamsForExec: (context: RenderContext, methodName: string, responseType: string, jsonschema: JSONSchema) => t.TSPropertySignature;
|
15
|
+
export declare const createQueryInterface: (context: RenderContext, className: string, queryMsg: QueryMsg) => t.ExportNamedDeclaration;
|
16
|
+
export declare const createTypeOrInterface: (context: RenderContext, Type: string, jsonschema: JSONSchema) => t.ExportNamedDeclaration;
|
17
|
+
export declare const createTypeInterface: (context: RenderContext, jsonschema: JSONSchema) => t.ExportNamedDeclaration;
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './client';
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { JSONSchema } from "../types";
|
2
|
+
export interface ReactQueryOptions {
|
3
|
+
optionalClient?: boolean;
|
4
|
+
v4?: boolean;
|
5
|
+
mutations?: boolean;
|
6
|
+
camelize?: boolean;
|
7
|
+
}
|
8
|
+
export interface RenderOptions {
|
9
|
+
reactQuery: ReactQueryOptions;
|
10
|
+
}
|
11
|
+
export interface RenderContext {
|
12
|
+
schema: JSONSchema;
|
13
|
+
options: RenderOptions;
|
14
|
+
}
|
15
|
+
export declare const defaultOptions: RenderOptions;
|
16
|
+
export declare class RenderContext implements RenderContext {
|
17
|
+
schema: JSONSchema;
|
18
|
+
constructor(schema: JSONSchema, options?: RenderOptions);
|
19
|
+
refLookup($ref: string): JSONSchema;
|
20
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './context';
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import * as t from '@babel/types';
|
2
|
+
import { ExecuteMsg } from '../types';
|
3
|
+
export declare const createFromPartialClass: (context: RenderContext, className: string, implementsClassName: string, execMsg: ExecuteMsg) => t.ExportNamedDeclaration;
|
4
|
+
export declare const createFromPartialInterface: (context: RenderContext, className: string, execMsg: ExecuteMsg) => t.ExportNamedDeclaration;
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './from-partial';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './react-query';
|
@@ -0,0 +1,81 @@
|
|
1
|
+
import * as t from '@babel/types';
|
2
|
+
import { ExecuteMsg, QueryMsg } from '../types';
|
3
|
+
import { RenderContext } from '../context';
|
4
|
+
import { JSONSchema } from '../types';
|
5
|
+
interface ReactQueryHookQuery {
|
6
|
+
context: RenderContext;
|
7
|
+
hookName: string;
|
8
|
+
hookParamsTypeName: string;
|
9
|
+
hookKeyName: string;
|
10
|
+
responseType: string;
|
11
|
+
methodName: string;
|
12
|
+
jsonschema: any;
|
13
|
+
}
|
14
|
+
interface ReactQueryHooks {
|
15
|
+
context: RenderContext;
|
16
|
+
queryMsg: QueryMsg;
|
17
|
+
contractName: string;
|
18
|
+
QueryClient: string;
|
19
|
+
}
|
20
|
+
export declare const createReactQueryHooks: ({ context, queryMsg, contractName, QueryClient }: ReactQueryHooks) => any;
|
21
|
+
export declare const createReactQueryHook: ({ context, hookName, hookParamsTypeName, responseType, hookKeyName, methodName, jsonschema }: ReactQueryHookQuery) => t.ExportNamedDeclaration;
|
22
|
+
interface ReactQueryMutationHookInterface {
|
23
|
+
context: RenderContext;
|
24
|
+
ExecuteClient: string;
|
25
|
+
mutationHookParamsTypeName: string;
|
26
|
+
jsonschema: JSONSchema;
|
27
|
+
useMutationTypeParameter: t.TSTypeParameterInstantiation;
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* Example:
|
31
|
+
```
|
32
|
+
export interface Cw4UpdateMembersMutation {
|
33
|
+
client: Cw4GroupClient
|
34
|
+
args: {
|
35
|
+
tokenId: string
|
36
|
+
remove: string[]
|
37
|
+
}
|
38
|
+
options?: Omit<
|
39
|
+
UseMutationOptions<ExecuteResult, Error, Pick<Cw4UpdateMembersMutation, 'args'>>,
|
40
|
+
'mutationFn'
|
41
|
+
>
|
42
|
+
}
|
43
|
+
```
|
44
|
+
*/
|
45
|
+
export declare const createReactQueryMutationArgsInterface: ({ context, ExecuteClient, mutationHookParamsTypeName, useMutationTypeParameter, jsonschema, }: ReactQueryMutationHookInterface) => t.ExportNamedDeclaration;
|
46
|
+
interface ReactQueryMutationHooks {
|
47
|
+
context: RenderContext;
|
48
|
+
execMsg: ExecuteMsg;
|
49
|
+
contractName: string;
|
50
|
+
ExecuteClient: string;
|
51
|
+
}
|
52
|
+
export declare const createReactQueryMutationHooks: ({ context, execMsg, contractName, ExecuteClient }: ReactQueryMutationHooks) => any;
|
53
|
+
interface ReactQueryMutationHook {
|
54
|
+
context: RenderContext;
|
55
|
+
mutationHookName: string;
|
56
|
+
mutationHookParamsTypeName: string;
|
57
|
+
execMethodName: string;
|
58
|
+
useMutationTypeParameter: t.TSTypeParameterInstantiation;
|
59
|
+
hasMsg: boolean;
|
60
|
+
}
|
61
|
+
/**
|
62
|
+
*
|
63
|
+
* Example:
|
64
|
+
```
|
65
|
+
export const useCw4UpdateMembersMutation = ({ client, options }: Omit<Cw4UpdateMembersMutation, 'args'>) =>
|
66
|
+
useMutation<ExecuteResult, Error, Pick<Cw4UpdateMembersMutation, 'args'>>(
|
67
|
+
({ args }) => client.updateMembers(args),
|
68
|
+
options
|
69
|
+
)
|
70
|
+
```
|
71
|
+
*/
|
72
|
+
export declare const createReactQueryMutationHook: ({ context, mutationHookName, mutationHookParamsTypeName, execMethodName, useMutationTypeParameter, hasMsg, }: ReactQueryMutationHook) => t.ExportNamedDeclaration;
|
73
|
+
interface ReactQueryHookQueryInterface {
|
74
|
+
context: RenderContext;
|
75
|
+
QueryClient: string;
|
76
|
+
hookParamsTypeName: string;
|
77
|
+
responseType: string;
|
78
|
+
jsonschema: any;
|
79
|
+
}
|
80
|
+
export declare const createReactQueryHookInterface: ({ context, QueryClient, hookParamsTypeName, responseType, jsonschema }: ReactQueryHookQueryInterface) => t.ExportNamedDeclaration;
|
81
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './recoil';
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
|
-
import { QueryMsg } from '
|
3
|
-
|
4
|
-
export declare const createRecoilSelector: (keyPrefix: string, QueryClient: string, methodName: string) => t.ExportNamedDeclaration;
|
5
|
-
export declare const createRecoilSelectors: (keyPrefix: string, QueryClient: string, queryMsg: QueryMsg) => any;
|
2
|
+
import { QueryMsg } from '../types';
|
3
|
+
import { RenderContext } from '../context';
|
4
|
+
export declare const createRecoilSelector: (context: RenderContext, keyPrefix: string, QueryClient: string, methodName: string) => t.ExportNamedDeclaration;
|
5
|
+
export declare const createRecoilSelectors: (context: RenderContext, keyPrefix: string, QueryClient: string, queryMsg: QueryMsg) => any;
|
6
6
|
export declare const createRecoilQueryClientType: () => {
|
7
7
|
type: string;
|
8
8
|
id: {
|
@@ -27,4 +27,4 @@ export declare const createRecoilQueryClientType: () => {
|
|
27
27
|
}[];
|
28
28
|
};
|
29
29
|
};
|
30
|
-
export declare const createRecoilQueryClient: (keyPrefix: string, QueryClient: string) => t.ExportNamedDeclaration;
|
30
|
+
export declare const createRecoilQueryClient: (context: RenderContext, keyPrefix: string, QueryClient: string) => t.ExportNamedDeclaration;
|
@@ -22,3 +22,20 @@ export interface ExecuteMsg {
|
|
22
22
|
allOf?: any;
|
23
23
|
anyOf?: any;
|
24
24
|
}
|
25
|
+
export interface JSONSchema {
|
26
|
+
$ref?: string;
|
27
|
+
$schema?: string;
|
28
|
+
additionalProperties?: boolean;
|
29
|
+
allOf?: JSONSchema[];
|
30
|
+
anyOf?: JSONSchema[];
|
31
|
+
definitions?: Record<string, JSONSchema>;
|
32
|
+
description?: string;
|
33
|
+
oneOf?: JSONSchema[];
|
34
|
+
properties?: Record<string, JSONSchema>;
|
35
|
+
patternProperties?: Record<string, JSONSchema>;
|
36
|
+
items?: JSONSchema[] | JSONSchema;
|
37
|
+
additionalItems?: JSONSchema;
|
38
|
+
required?: string[];
|
39
|
+
title?: string;
|
40
|
+
type?: string;
|
41
|
+
}
|
@@ -1,6 +1,14 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
|
-
import { Field, QueryMsg, ExecuteMsg } from '
|
2
|
+
import { Field, QueryMsg, ExecuteMsg } from '../types';
|
3
3
|
import { TSTypeAnnotation, TSExpressionWithTypeArguments } from '@babel/types';
|
4
|
+
export declare const propertySignature: (name: string, typeAnnotation: t.TSTypeAnnotation, optional?: boolean) => {
|
5
|
+
type: string;
|
6
|
+
key: t.Identifier;
|
7
|
+
typeAnnotation: t.TSTypeAnnotation;
|
8
|
+
optional: boolean;
|
9
|
+
};
|
10
|
+
export declare const identifier: (name: string, typeAnnotation: t.TSTypeAnnotation, optional?: boolean) => t.Identifier;
|
11
|
+
export declare const tsTypeOperator: (typeAnnotation: t.TSType, operator: string) => t.TSTypeOperator;
|
4
12
|
export declare const getMessageProperties: (msg: QueryMsg | ExecuteMsg) => any;
|
5
13
|
export declare const tsPropertySignature: (key: t.Expression, typeAnnotation: t.TSTypeAnnotation, optional: boolean) => t.TSPropertySignature;
|
6
14
|
export declare const tsObjectPattern: (properties: (t.RestElement | t.ObjectProperty)[], typeAnnotation: t.TSTypeAnnotation) => t.ObjectPattern;
|
@@ -31,3 +39,15 @@ export declare const getFieldDimensionality: (field: Field) => {
|
|
31
39
|
};
|
32
40
|
export declare const memberExpressionOrIdentifier: (names: any) => any;
|
33
41
|
export declare const memberExpressionOrIdentifierSnake: (names: any) => any;
|
42
|
+
/**
|
43
|
+
* If optional, return a conditional, otherwise just the expression
|
44
|
+
*/
|
45
|
+
export declare const optionalConditionalExpression: (test: t.Expression, expression: t.Expression, alternate: t.Expression, optional?: boolean) => t.Expression;
|
46
|
+
export declare const typeRefOrOptionalUnion: (identifier: t.Identifier, optional?: boolean) => t.TSType;
|
47
|
+
export declare const parameterizedTypeReference: (identifier: string, from: t.TSType, omit: string | Array<string>) => t.TSTypeReference;
|
48
|
+
/**
|
49
|
+
* omitTypeReference(t.tsTypeReference(t.identifier('Cw4UpdateMembersMutation'),),'args').....
|
50
|
+
* Omit<Cw4UpdateMembersMutation, 'args'>
|
51
|
+
*/
|
52
|
+
export declare const omitTypeReference: (from: t.TSType, omit: string | Array<string>) => t.TSTypeReference;
|
53
|
+
export declare const pickTypeReference: (from: t.TSType, pick: string | Array<string>) => t.TSTypeReference;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import * as t from '@babel/types';
|
2
|
+
import { TSTypeAnnotation } from '@babel/types';
|
3
|
+
import { RenderContext } from '../context';
|
4
|
+
import { JSONSchema } from '../types';
|
5
|
+
export declare const getTypeFromRef: ($ref: any) => t.TSTypeReference;
|
6
|
+
export declare const getType: (type: any) => t.TSBooleanKeyword | t.TSNumberKeyword | t.TSStringKeyword;
|
7
|
+
export declare const getPropertyType: (context: RenderContext, schema: JSONSchema, prop: string) => {
|
8
|
+
type: any;
|
9
|
+
optional: boolean;
|
10
|
+
};
|
11
|
+
export declare function getPropertySignatureFromProp(context: RenderContext, jsonschema: JSONSchema, prop: string, camelize: boolean): {
|
12
|
+
type: string;
|
13
|
+
key: t.Identifier;
|
14
|
+
typeAnnotation: t.TSTypeAnnotation;
|
15
|
+
optional: boolean;
|
16
|
+
};
|
17
|
+
export declare const getParamsTypeAnnotation: (context: RenderContext, jsonschema: any, camelize?: boolean) => t.TSTypeAnnotation;
|
18
|
+
export declare const createTypedObjectParams: (context: RenderContext, jsonschema: JSONSchema, camelize?: boolean) => t.ObjectPattern;
|
package/main/messages.spec.js
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
var _generator = _interopRequireDefault(require("@babel/generator"));
|
6
|
-
|
7
|
-
var _execute_msg_for__empty = _interopRequireDefault(require("./../../../__fixtures__/basic/execute_msg_for__empty.json"));
|
8
|
-
|
9
|
-
var _messages = require("./messages");
|
10
|
-
|
11
|
-
var expectCode = function expectCode(ast) {
|
12
|
-
expect((0, _generator["default"])(ast).code).toMatchSnapshot();
|
13
|
-
};
|
14
|
-
|
15
|
-
var printCode = function printCode(ast) {
|
16
|
-
console.log((0, _generator["default"])(ast).code);
|
17
|
-
};
|
18
|
-
|
19
|
-
it('execute classes', function () {
|
20
|
-
expectCode((0, _messages.createFromPartialClass)('SG721MessageComposer', 'SG721Message', _execute_msg_for__empty["default"]));
|
21
|
-
});
|
22
|
-
it('createFromPartialInterface', function () {
|
23
|
-
expectCode((0, _messages.createFromPartialInterface)('SG721Message', _execute_msg_for__empty["default"]));
|
24
|
-
});
|
package/main/react-query.js
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
6
|
-
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
8
|
-
value: true
|
9
|
-
});
|
10
|
-
exports.createReactQueryHooks = exports.createReactQueryHookInterface = exports.createReactQueryHook = void 0;
|
11
|
-
|
12
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
13
|
-
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
15
|
-
|
16
|
-
var t = _interopRequireWildcard(require("@babel/types"));
|
17
|
-
|
18
|
-
var _case = require("case");
|
19
|
-
|
20
|
-
var _utils = require("./utils");
|
21
|
-
|
22
|
-
var _babel = require("./utils/babel");
|
23
|
-
|
24
|
-
var _types2 = require("./utils/types");
|
25
|
-
|
26
|
-
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); }
|
27
|
-
|
28
|
-
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; }
|
29
|
-
|
30
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
31
|
-
|
32
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
33
|
-
|
34
|
-
var DEFAULT_OPTIONS = {
|
35
|
-
optionalClient: false,
|
36
|
-
v4: false
|
37
|
-
};
|
38
|
-
|
39
|
-
var createReactQueryHooks = function createReactQueryHooks(_ref) {
|
40
|
-
var queryMsg = _ref.queryMsg,
|
41
|
-
contractName = _ref.contractName,
|
42
|
-
QueryClient = _ref.QueryClient,
|
43
|
-
_ref$options = _ref.options,
|
44
|
-
options = _ref$options === void 0 ? {} : _ref$options;
|
45
|
-
// merge the user options with the defaults
|
46
|
-
options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options);
|
47
|
-
return (0, _utils.getMessageProperties)(queryMsg).reduce(function (m, schema) {
|
48
|
-
var underscoreName = Object.keys(schema.properties)[0];
|
49
|
-
var methodName = (0, _case.camel)(underscoreName);
|
50
|
-
var hookName = "use".concat((0, _case.pascal)(contractName)).concat((0, _case.pascal)(methodName), "Query");
|
51
|
-
var hookParamsTypeName = "".concat((0, _case.pascal)(contractName)).concat((0, _case.pascal)(methodName), "Query");
|
52
|
-
var responseType = (0, _case.pascal)("".concat(methodName, "Response"));
|
53
|
-
var getterKey = (0, _case.camel)("".concat(contractName).concat((0, _case.pascal)(methodName)));
|
54
|
-
var jsonschema = schema.properties[underscoreName];
|
55
|
-
return [createReactQueryHookInterface({
|
56
|
-
hookParamsTypeName: hookParamsTypeName,
|
57
|
-
responseType: responseType,
|
58
|
-
QueryClient: QueryClient,
|
59
|
-
jsonschema: jsonschema,
|
60
|
-
options: options
|
61
|
-
}), createReactQueryHook({
|
62
|
-
methodName: methodName,
|
63
|
-
hookName: hookName,
|
64
|
-
hookParamsTypeName: hookParamsTypeName,
|
65
|
-
responseType: responseType,
|
66
|
-
hookKeyName: getterKey,
|
67
|
-
jsonschema: jsonschema,
|
68
|
-
options: options
|
69
|
-
})].concat((0, _toConsumableArray2["default"])(m));
|
70
|
-
}, []);
|
71
|
-
};
|
72
|
-
|
73
|
-
exports.createReactQueryHooks = createReactQueryHooks;
|
74
|
-
|
75
|
-
var createReactQueryHook = function createReactQueryHook(_ref2) {
|
76
|
-
var _jsonschema$propertie;
|
77
|
-
|
78
|
-
var hookName = _ref2.hookName,
|
79
|
-
hookParamsTypeName = _ref2.hookParamsTypeName,
|
80
|
-
responseType = _ref2.responseType,
|
81
|
-
hookKeyName = _ref2.hookKeyName,
|
82
|
-
methodName = _ref2.methodName,
|
83
|
-
jsonschema = _ref2.jsonschema,
|
84
|
-
_ref2$options = _ref2.options,
|
85
|
-
options = _ref2$options === void 0 ? {} : _ref2$options;
|
86
|
-
// merge the user options with the defaults
|
87
|
-
options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options);
|
88
|
-
var keys = Object.keys((_jsonschema$propertie = jsonschema.properties) !== null && _jsonschema$propertie !== void 0 ? _jsonschema$propertie : {});
|
89
|
-
var args = [];
|
90
|
-
|
91
|
-
if (keys.length) {
|
92
|
-
args = [t.objectExpression((0, _toConsumableArray2["default"])(keys.map(function (prop) {
|
93
|
-
return t.objectProperty(t.identifier((0, _case.camel)(prop)), t.memberExpression(t.identifier('args'), t.identifier((0, _case.camel)(prop))));
|
94
|
-
})))];
|
95
|
-
}
|
96
|
-
|
97
|
-
var props = ['client', 'options'];
|
98
|
-
|
99
|
-
if (keys.length) {
|
100
|
-
props = ['client', 'args', 'options'];
|
101
|
-
}
|
102
|
-
|
103
|
-
return t.exportNamedDeclaration(t.functionDeclaration(t.identifier(hookName), [(0, _utils.tsObjectPattern)((0, _toConsumableArray2["default"])(props.map(function (prop) {
|
104
|
-
return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
|
105
|
-
})), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(hookParamsTypeName))))], t.blockStatement([t.returnStatement((0, _utils.callExpression)(t.identifier('useQuery'), [t.arrayExpression(generateUseQueryQueryKey(hookKeyName, props, options.optionalClient)), t.arrowFunctionExpression([], (0, _babel.optionalConditionalExpression)(t.identifier('client'), t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(methodName)), args), t.identifier('undefined'), options.optionalClient), false), options.optionalClient ? t.objectExpression([t.spreadElement(t.identifier('options')), t.objectProperty(t.identifier('enabled'), t.logicalExpression('&&', t.unaryExpression('!', t.unaryExpression('!', t.identifier('client'))), t.conditionalExpression( // explicitly check for undefined
|
106
|
-
t.binaryExpression('!=', t.optionalMemberExpression(t.identifier('options'), t.identifier('enabled'), false, true), t.identifier('undefined')), t.memberExpression(t.identifier('options'), t.identifier('enabled')), t.booleanLiteral(true))))]) : t.identifier('options')], t.tsTypeParameterInstantiation([(0, _babel.typeRefOrOptionalUnion)(t.identifier(responseType), options.optionalClient), t.tsTypeReference(t.identifier('Error')), t.tsTypeReference(t.identifier(responseType)), t.tsArrayType(t.tsParenthesizedType(t.tsUnionType([t.tsStringKeyword(), t.tsUndefinedKeyword()])))])))])));
|
107
|
-
};
|
108
|
-
|
109
|
-
exports.createReactQueryHook = createReactQueryHook;
|
110
|
-
|
111
|
-
var createReactQueryHookInterface = function createReactQueryHookInterface(_ref3) {
|
112
|
-
var QueryClient = _ref3.QueryClient,
|
113
|
-
hookParamsTypeName = _ref3.hookParamsTypeName,
|
114
|
-
responseType = _ref3.responseType,
|
115
|
-
jsonschema = _ref3.jsonschema,
|
116
|
-
_ref3$options = _ref3.options,
|
117
|
-
options = _ref3$options === void 0 ? {} : _ref3$options;
|
118
|
-
// merge the user options with the defaults
|
119
|
-
options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options);
|
120
|
-
var typedUseQueryOptions = t.tsTypeReference(t.identifier('UseQueryOptions'), t.tsTypeParameterInstantiation([(0, _babel.typeRefOrOptionalUnion)(t.identifier(responseType), options.optionalClient), t.tsTypeReference(t.identifier('Error')), t.tsTypeReference(t.identifier(responseType)), t.tsArrayType(t.tsParenthesizedType(t.tsUnionType([t.tsStringKeyword(), t.tsUndefinedKeyword()])))]));
|
121
|
-
var body = [(0, _utils.tsPropertySignature)(t.identifier('client'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(QueryClient))), options.optionalClient), (0, _utils.tsPropertySignature)(t.identifier('options'), t.tsTypeAnnotation(options.v4 ? t.tSIntersectionType([t.tsTypeReference(t.identifier('Omit'), t.tsTypeParameterInstantiation([typedUseQueryOptions, t.tsLiteralType(t.stringLiteral("'queryKey' | 'queryFn' | 'initialData'"))])), t.tSTypeLiteral([t.tsPropertySignature(t.identifier('initialData?'), t.tsTypeAnnotation(t.tsUndefinedKeyword()))])]) : typedUseQueryOptions), true)];
|
122
|
-
var props = getProps(jsonschema, true);
|
123
|
-
|
124
|
-
if (props.length) {
|
125
|
-
body.push(t.tsPropertySignature(t.identifier('args'), t.tsTypeAnnotation(t.tsTypeLiteral(props))));
|
126
|
-
}
|
127
|
-
|
128
|
-
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(hookParamsTypeName), null, [], t.tsInterfaceBody(body)));
|
129
|
-
};
|
130
|
-
|
131
|
-
exports.createReactQueryHookInterface = createReactQueryHookInterface;
|
132
|
-
|
133
|
-
var getProps = function getProps(jsonschema, camelize) {
|
134
|
-
var _jsonschema$propertie2;
|
135
|
-
|
136
|
-
var keys = Object.keys((_jsonschema$propertie2 = jsonschema.properties) !== null && _jsonschema$propertie2 !== void 0 ? _jsonschema$propertie2 : {});
|
137
|
-
if (!keys.length) return [];
|
138
|
-
return keys.map(function (prop) {
|
139
|
-
var _getPropertyType = (0, _types2.getPropertyType)(jsonschema, prop),
|
140
|
-
type = _getPropertyType.type,
|
141
|
-
optional = _getPropertyType.optional;
|
142
|
-
|
143
|
-
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
|
144
|
-
});
|
145
|
-
};
|
146
|
-
|
147
|
-
function generateUseQueryQueryKey(hookKeyName, props, optionalClient) {
|
148
|
-
var queryKey = [t.stringLiteral(hookKeyName), t.optionalMemberExpression(t.identifier('client'), t.identifier('contractAddress'), false, optionalClient)];
|
149
|
-
|
150
|
-
if (props.includes('args')) {
|
151
|
-
queryKey.push(t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify')), [t.identifier('args')]));
|
152
|
-
}
|
153
|
-
|
154
|
-
return queryKey;
|
155
|
-
}
|
package/main/wasm.arrays.spec.js
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
var _generator = _interopRequireDefault(require("@babel/generator"));
|
6
|
-
|
7
|
-
var _schema = _interopRequireDefault(require("./../../../__fixtures__/arrays/schema/schema.json"));
|
8
|
-
|
9
|
-
var _wasm = require("./wasm");
|
10
|
-
|
11
|
-
var expectCode = function expectCode(ast) {
|
12
|
-
expect((0, _generator["default"])(ast).code).toMatchSnapshot();
|
13
|
-
};
|
14
|
-
|
15
|
-
var printCode = function printCode(ast) {
|
16
|
-
console.log((0, _generator["default"])(ast).code);
|
17
|
-
};
|
18
|
-
|
19
|
-
it('execute_msg_for__empty', function () {
|
20
|
-
expectCode((0, _wasm.createTypeInterface)(_schema["default"]));
|
21
|
-
});
|
22
|
-
it('query classes', function () {
|
23
|
-
expectCode((0, _wasm.createQueryClass)('SG721QueryClient', 'SG721ReadOnlyInstance', _schema["default"]));
|
24
|
-
});
|
25
|
-
it('execute classes array types', function () {
|
26
|
-
expectCode((0, _wasm.createExecuteClass)('SG721Client', 'SG721Instance', null, _schema["default"]));
|
27
|
-
});
|
28
|
-
it('execute interfaces no extends', function () {
|
29
|
-
expectCode((0, _wasm.createExecuteInterface)('SG721Instance', null, _schema["default"]));
|
30
|
-
});
|
@@ -1,30 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
var _generator = _interopRequireDefault(require("@babel/generator"));
|
6
|
-
|
7
|
-
var _execute_msg = _interopRequireDefault(require("./../../../__fixtures__/daodao/cw-named-groups/execute_msg.json"));
|
8
|
-
|
9
|
-
var _wasm = require("./wasm");
|
10
|
-
|
11
|
-
var expectCode = function expectCode(ast) {
|
12
|
-
expect((0, _generator["default"])(ast).code).toMatchSnapshot();
|
13
|
-
};
|
14
|
-
|
15
|
-
var printCode = function printCode(ast) {
|
16
|
-
console.log((0, _generator["default"])(ast).code);
|
17
|
-
};
|
18
|
-
|
19
|
-
it('execute_msg', function () {
|
20
|
-
expectCode((0, _wasm.createTypeInterface)(_execute_msg["default"]));
|
21
|
-
});
|
22
|
-
it('query classes', function () {
|
23
|
-
expectCode((0, _wasm.createQueryClass)('SG721QueryClient', 'SG721ReadOnlyInstance', _execute_msg["default"]));
|
24
|
-
});
|
25
|
-
it('execute classes array types', function () {
|
26
|
-
expectCode((0, _wasm.createExecuteClass)('SG721Client', 'SG721Instance', null, _execute_msg["default"]));
|
27
|
-
});
|
28
|
-
it('execute interfaces no extends', function () {
|
29
|
-
expectCode((0, _wasm.createExecuteInterface)('SG721Instance', null, _execute_msg["default"]));
|
30
|
-
});
|
@@ -1,32 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
var _generator = _interopRequireDefault(require("@babel/generator"));
|
6
|
-
|
7
|
-
var _execute_msg = _interopRequireDefault(require("./../../../__fixtures__/daodao/cw-proposal-single/execute_msg.json"));
|
8
|
-
|
9
|
-
var _query_msg = _interopRequireDefault(require("./../../../__fixtures__/daodao/cw-proposal-single/query_msg.json"));
|
10
|
-
|
11
|
-
var _wasm = require("./wasm");
|
12
|
-
|
13
|
-
var expectCode = function expectCode(ast) {
|
14
|
-
expect((0, _generator["default"])(ast).code).toMatchSnapshot();
|
15
|
-
};
|
16
|
-
|
17
|
-
var printCode = function printCode(ast) {
|
18
|
-
console.log((0, _generator["default"])(ast).code);
|
19
|
-
};
|
20
|
-
|
21
|
-
it('execute_msg_for', function () {
|
22
|
-
expectCode((0, _wasm.createTypeInterface)(_execute_msg["default"]));
|
23
|
-
});
|
24
|
-
it('query classes', function () {
|
25
|
-
expectCode((0, _wasm.createQueryClass)('SG721QueryClient', 'SG721ReadOnlyInstance', _query_msg["default"]));
|
26
|
-
});
|
27
|
-
it('execute classes array types', function () {
|
28
|
-
expectCode((0, _wasm.createExecuteClass)('SG721Client', 'SG721Instance', null, _execute_msg["default"]));
|
29
|
-
});
|
30
|
-
it('execute interfaces no extends', function () {
|
31
|
-
expectCode((0, _wasm.createExecuteInterface)('SG721Instance', null, _execute_msg["default"]));
|
32
|
-
});
|
@@ -1,24 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
var _generator = _interopRequireDefault(require("@babel/generator"));
|
6
|
-
|
7
|
-
var _query_msg = _interopRequireDefault(require("./../../../__fixtures__/daodao/cw-admin-factory/query_msg.json"));
|
8
|
-
|
9
|
-
var _wasm = require("./wasm");
|
10
|
-
|
11
|
-
var expectCode = function expectCode(ast) {
|
12
|
-
expect((0, _generator["default"])(ast).code).toMatchSnapshot();
|
13
|
-
};
|
14
|
-
|
15
|
-
var printCode = function printCode(ast) {
|
16
|
-
console.log((0, _generator["default"])(ast).code);
|
17
|
-
};
|
18
|
-
|
19
|
-
it('query classes', function () {
|
20
|
-
expectCode((0, _wasm.createQueryClass)('SG721QueryClient', 'SG721ReadOnlyInstance', _query_msg["default"]));
|
21
|
-
});
|
22
|
-
it('query interface', function () {
|
23
|
-
expectCode((0, _wasm.createQueryInterface)('ReadOnlyInstance', _query_msg["default"]));
|
24
|
-
});
|
package/main/wasm.sg721.spec.js
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
|
-
var _generator = _interopRequireDefault(require("@babel/generator"));
|
6
|
-
|
7
|
-
var _execute_msg_for__empty = _interopRequireDefault(require("./../../../__fixtures__/sg721/execute_msg_for__empty.json"));
|
8
|
-
|
9
|
-
var _wasm = require("./wasm");
|
10
|
-
|
11
|
-
var expectCode = function expectCode(ast) {
|
12
|
-
expect((0, _generator["default"])(ast).code).toMatchSnapshot();
|
13
|
-
};
|
14
|
-
|
15
|
-
var printCode = function printCode(ast) {
|
16
|
-
console.log((0, _generator["default"])(ast).code);
|
17
|
-
};
|
18
|
-
|
19
|
-
it('execute_msg_for__empty', function () {
|
20
|
-
expectCode((0, _wasm.createTypeInterface)(_execute_msg_for__empty["default"]));
|
21
|
-
});
|
22
|
-
it('query classes', function () {
|
23
|
-
expectCode((0, _wasm.createQueryClass)('SG721QueryClient', 'SG721ReadOnlyInstance', _execute_msg_for__empty["default"]));
|
24
|
-
});
|
25
|
-
it('execute classes array types', function () {
|
26
|
-
expectCode((0, _wasm.createExecuteClass)('SG721Client', 'SG721Instance', null, _execute_msg_for__empty["default"]));
|
27
|
-
});
|
28
|
-
it('execute interfaces no extends', function () {
|
29
|
-
expectCode((0, _wasm.createExecuteInterface)('SG721Instance', null, _execute_msg_for__empty["default"]));
|
30
|
-
});
|