Skip to content

Commit 43fccf6

Browse files
committed
fix: upgrade to new packages
1 parent 53cda6c commit 43fccf6

File tree

9 files changed

+78
-40
lines changed

9 files changed

+78
-40
lines changed

package-lock.json

Lines changed: 23 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"author": "",
2828
"license": "Apache-2.0",
2929
"dependencies": {
30-
"@open-rpc/schema-utils-js": "1.0.3",
30+
"@open-rpc/schema-utils-js": "1.5.0",
31+
"@types/lodash": "^4.14.123",
3132
"commander": "^2.19.0",
3233
"fs-extra": "^7.0.1",
3334
"is-url": "^1.2.4",
@@ -38,7 +39,7 @@
3839
"typescript": "^3.3.3333"
3940
},
4041
"devDependencies": {
41-
"@open-rpc/examples": "1.0.16",
42+
"@open-rpc/examples": "^1.2.1",
4243
"@types/fs-extra": "^5.0.5",
4344
"@types/jest": "^24.0.11",
4445
"ts-jest": "^24.0.0"

src/index.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import path from "path";
55
import examples from "@open-rpc/examples";
66
import refParser from "json-schema-ref-parser";
77
import { promisify } from "util";
8+
import { forEach } from "lodash";
9+
import { types } from "@open-rpc/meta-schema";
10+
import { parse } from "@open-rpc/schema-utils-js";
811

912
const stat = promisify(fs.stat);
1013
const rmdir = promisify(fs.rmdir);
@@ -21,13 +24,13 @@ describe(`Examples to generate Js clients`, () => {
2124
return await rmdir(testDir);
2225
});
2326

24-
Object.values(examples).forEach((example) => {
25-
it(`creates a new client for example: ${example.info.title}`, async () => {
27+
forEach(examples, (example: types.OpenRPC, exampleName: string) => {
28+
it(`creates a new client for example: ${exampleName}`, async () => {
2629
expect.assertions(1);
2730

2831
await clientGen({
2932
clientName: "test",
30-
schema: await refParser.dereference(example),
33+
schema: await parse(JSON.stringify(example)),
3134
});
3235

3336
await expect(stat(`${process.cwd()}/test`)).resolves.toBeTruthy();

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import _bootstrapGeneratedPackage from "./bootstrapGeneratedPackage";
22
import { exec } from "child_process";
3-
import { compile, compileFromFile } from "json-schema-to-typescript";
3+
import { compile } from "json-schema-to-typescript";
44
import * as fs from "fs";
55
import * as fsx from "fs-extra";
66
import * as path from "path";
77
import * as _ from "lodash";
88
import { promisify } from "util";
99
import jsTemplate from "../templates/js/templated/exported-class.template";
10-
import { makeIdForMethodContentDescriptors } from "@open-rpc/schema-utils-js";
10+
import { generateMethodParamId } from "@open-rpc/schema-utils-js";
1111

1212
const cwd = process.cwd();
1313

@@ -47,7 +47,7 @@ const getTypings = async ({ methods }: { methods: [any] }) => {
4747
})))
4848
.filter(({ contentDescriptor }) => contentDescriptor.schema !== undefined)
4949
.map(async ({ method, contentDescriptor }) => ({
50-
typeId: makeIdForMethodContentDescriptors(method, contentDescriptor),
50+
typeId: generateMethodParamId(method, contentDescriptor),
5151
typeName: getTypeName(contentDescriptor),
5252
typings: await compile(contentDescriptor.schema, getTypeName(contentDescriptor), { bannerComment: "" }),
5353
}))
@@ -62,7 +62,7 @@ const getTypings = async ({ methods }: { methods: [any] }) => {
6262

6363
const compileTemplate = async (name: string, schema: any) => {
6464
const typeDefs = await getTypings(schema);
65-
return jsTemplate({ className: name, methods: schema.methods, typeDefs, makeIdForMethodContentDescriptors });
65+
return jsTemplate({ className: name, methods: schema.methods, typeDefs, generateMethodParamId });
6666
};
6767

6868
const copyStatic = async (destinationDirectoryName: string) => {

templates/js/static/_package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"author": "",
1515
"license": "ISC",
1616
"dependencies": {
17-
"@open-rpc/schema-utils-js": "1.0.3",
17+
"@open-rpc/schema-utils-js": "1.5.0",
1818
"json-schema": "^0.2.3",
1919
"ajv": "^6.10.0",
2020
"jayson": "^2.1.2",

templates/js/static/package-lock.json

Lines changed: 32 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/js/static/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"sourceMap": true,
99
"outDir": "build",
1010
"declarationDir": "build",
11-
"declaration": true
11+
"declaration": true,
12+
"resolveJsonModule": true
1213
}
1314
}

templates/js/templated/exported-class.template.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default template(`
44
import * as jayson from "jayson/promise";
55
import ajv from "ajv";
66
import _ from "lodash";
7-
import { makeIdForMethodContentDescriptors } from "@open-rpc/schema-utils-js";
7+
import { generateMethodParamId } from "@open-rpc/schema-utils-js";
88
99
class ParameterValidationError extends Error {
1010
constructor(public message: string, public errors: ajv.ErrorObject[] | undefined | null) {
@@ -28,7 +28,7 @@ export default class <%= className %> {
2828
method.params.forEach((param: any, i: number) => {
2929
return this.validator.addSchema(
3030
param.schema,
31-
makeIdForMethodContentDescriptors(method, param),
31+
generateMethodParamId(method, param),
3232
);
3333
})
3434
});
@@ -37,7 +37,7 @@ export default class <%= className %> {
3737
public validate(methodName: string, methodObject: any, params: any[]) {
3838
return _.chain((methodObject as any).params)
3939
.map((param: any, index: number) => {
40-
const idForMethod = makeIdForMethodContentDescriptors(methodObject, param);
40+
const idForMethod = generateMethodParamId(methodObject, param);
4141
const isValid = this.validator.validate(idForMethod, params[index]);
4242
if (!isValid) {
4343
const message = [
@@ -78,7 +78,7 @@ export default class <%= className %> {
7878
/**
7979
* <%= method.summary %>
8080
*/
81-
public <%= method.name %>(<%= _.map(method.params, (param, i) => paramNames[i] + ': ' + typeDefs[makeIdForMethodContentDescriptors(method, param)].typeName).join(', ') %>): Promise<<%= (typeDefs[makeIdForMethodContentDescriptors(method, method.result)] || {typeName: 'any'}).typeName %>> {
81+
public <%= method.name %>(<%= _.map(method.params, (param, i) => paramNames[i] + ': ' + typeDefs[generateMethodParamId(method, param)].typeName).join(', ') %>): Promise<<%= (typeDefs[generateMethodParamId(method, method.result)] || {typeName: 'any'}).typeName %>> {
8282
return this.request({method: "<%= method.name %>", params: Array.from(arguments)});
8383
}<% }) %>
8484
}

tslint.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
],
55
"rules": {
66
"ordered-imports": false,
7-
"indent": [true, "spaces", 2]
7+
"indent": [true, "spaces", 2],
8+
"no-implicit-dependencies": true,
9+
"no-unused-variable": true
810
}
911
}

0 commit comments

Comments
 (0)