Skip to content

Commit ce7b822

Browse files
committed
style: 💄 fix linter issues
1 parent 0a99549 commit ce7b822

File tree

98 files changed

+3243
-4753
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+3243
-4753
lines changed

src/__bench__/encode.ts

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,76 @@
11
/* tslint:disable no-console */
22

3-
import { TypeSystem } from "..";
4-
import { CborEncoder } from "@jsonjoy.com/json-pack/lib/cbor/CborEncoder";
5-
import { JsonEncoder } from "@jsonjoy.com/json-pack/lib/json/JsonEncoder";
6-
import type { CompiledBinaryEncoder } from "../codegen/types";
7-
import { EncodingFormat } from "@jsonjoy.com/json-pack/lib/constants";
8-
import { Writer } from "@jsonjoy.com/util/lib/buffers/Writer";
3+
import {TypeSystem} from '..';
4+
import {CborEncoder} from '@jsonjoy.com/json-pack/lib/cbor/CborEncoder';
5+
import {JsonEncoder} from '@jsonjoy.com/json-pack/lib/json/JsonEncoder';
6+
import type {CompiledBinaryEncoder} from '../codegen/types';
7+
import {EncodingFormat} from '@jsonjoy.com/json-pack/lib/constants';
8+
import {Writer} from '@jsonjoy.com/util/lib/buffers/Writer';
99

1010
const system = new TypeSystem();
11-
const { t } = system;
11+
const {t} = system;
1212

1313
const response = system.alias(
14-
"Response",
14+
'Response',
1515
t.Object(
1616
t.prop(
17-
"collection",
17+
'collection',
1818
t.Object(
19-
t.prop("id", t.String({ ascii: true, noJsonEscape: true })),
20-
t.prop("ts", t.num.options({ format: "u64" })),
21-
t.prop("cid", t.String({ ascii: true, noJsonEscape: true })),
22-
t.prop("prid", t.String({ ascii: true, noJsonEscape: true })),
23-
t.prop("slug", t.String({ ascii: true, noJsonEscape: true })),
24-
t.propOpt("name", t.str),
25-
t.propOpt("src", t.str),
26-
t.propOpt("doc", t.str),
27-
t.propOpt("longText", t.str),
28-
t.prop("active", t.bool),
29-
t.prop("views", t.Array(t.num)),
19+
t.prop('id', t.String({ascii: true, noJsonEscape: true})),
20+
t.prop('ts', t.num.options({format: 'u64'})),
21+
t.prop('cid', t.String({ascii: true, noJsonEscape: true})),
22+
t.prop('prid', t.String({ascii: true, noJsonEscape: true})),
23+
t.prop('slug', t.String({ascii: true, noJsonEscape: true})),
24+
t.propOpt('name', t.str),
25+
t.propOpt('src', t.str),
26+
t.propOpt('doc', t.str),
27+
t.propOpt('longText', t.str),
28+
t.prop('active', t.bool),
29+
t.prop('views', t.Array(t.num)),
3030
),
3131
),
3232
t.prop(
33-
"block",
33+
'block',
3434
t.Object(
35-
t.prop("id", t.String({ ascii: true, noJsonEscape: true })),
36-
t.prop("ts", t.num.options({ format: "u64" })),
37-
t.prop("cid", t.String({ ascii: true, noJsonEscape: true })),
38-
t.prop("slug", t.String({ ascii: true, noJsonEscape: true })),
35+
t.prop('id', t.String({ascii: true, noJsonEscape: true})),
36+
t.prop('ts', t.num.options({format: 'u64'})),
37+
t.prop('cid', t.String({ascii: true, noJsonEscape: true})),
38+
t.prop('slug', t.String({ascii: true, noJsonEscape: true})),
3939
),
4040
),
4141
),
4242
);
4343

4444
const json = {
4545
collection: {
46-
id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
46+
id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
4747
ts: Date.now(),
48-
cid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
49-
prid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
50-
slug: "slug-name",
51-
name: "Super collection",
48+
cid: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
49+
prid: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
50+
slug: 'slug-name',
51+
name: 'Super collection',
5252
src: '{"foo": "bar"}',
5353
longText:
54-
"After implementing a workaround for the first issue and merging the changes to another feature branch with some extra code and tests, the following error was printed in the stage’s log “JavaScript heap out of memory error.”",
54+
'After implementing a workaround for the first issue and merging the changes to another feature branch with some extra code and tests, the following error was printed in the stage’s log “JavaScript heap out of memory error.”',
5555
active: true,
5656
views: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
5757
},
5858
block: {
59-
id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
59+
id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
6060
ts: Date.now(),
61-
cid: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
62-
slug: "slug-name",
61+
cid: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
62+
slug: 'slug-name',
6363
},
6464
};
6565

6666
const jsonTextEncoder = response.type.jsonTextEncoder();
67-
const jsonEncoderFn = response.type.encoder(
68-
EncodingFormat.Json,
69-
) as CompiledBinaryEncoder;
70-
const cborEncoderFn = response.type.encoder(
71-
EncodingFormat.Cbor,
72-
) as CompiledBinaryEncoder;
67+
const jsonEncoderFn = response.type.encoder(EncodingFormat.Json) as CompiledBinaryEncoder;
68+
const cborEncoderFn = response.type.encoder(EncodingFormat.Cbor) as CompiledBinaryEncoder;
7369

7470
const jsonEncoder = new JsonEncoder(new Writer());
7571
const cborEncoder = new CborEncoder();
7672

77-
const { Suite } = require("benchmark");
73+
const {Suite} = require('benchmark');
7874
const suite = new Suite();
7975
suite
8076
.add(`json-type "json" text encoder and Buffer.from()`, () => {
@@ -94,14 +90,11 @@ suite
9490
.add(`Buffer.from(JSON.stringify())`, () => {
9591
Buffer.from(JSON.stringify(json));
9692
})
97-
.on("cycle", (event: any) => {
98-
console.log(
99-
String(event.target) +
100-
`, ${Math.round(1000000000 / event.target.hz)} ns/op`,
101-
);
93+
.on('cycle', (event: any) => {
94+
console.log(String(event.target) + `, ${Math.round(1000000000 / event.target.hz)} ns/op`);
10295
})
103-
.on("complete", () => {
104-
console.log("Fastest is " + suite.filter("fastest").map("name"));
96+
.on('complete', () => {
97+
console.log('Fastest is ' + suite.filter('fastest').map('name'));
10598
})
10699
.run();
107100

src/__demos__/json-type.ts

Lines changed: 42 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,149 +6,137 @@
66

77
/* tslint:disable no-console */
88

9-
import { EncodingFormat } from "@jsonjoy.com/json-pack/lib/constants";
10-
import { TypeSystem } from "../../json-type";
9+
import {EncodingFormat} from '@jsonjoy.com/json-pack/lib/constants';
10+
import {TypeSystem} from '../../json-type';
1111

1212
console.clear();
1313

1414
const system = new TypeSystem();
15-
const { t } = system;
15+
const {t} = system;
1616

1717
const type = t
1818
.Object(
19-
t
20-
.prop("id", t.str.options({ ascii: true, min: 40, max: 80 }))
21-
.options({ title: "Every object has an ID" }),
22-
t.propOpt("name", t.str),
23-
t.prop("age", t.num.options({ format: "u8", gt: 16, lt: 100 })),
24-
t.prop("verified", t.bool),
25-
t.prop(
26-
"sex",
27-
t.Or(
28-
t.Const(<const>"male"),
29-
t.Const(<const>"female"),
30-
t.Const(<const>"other"),
31-
t.Const<null>(null),
32-
),
33-
),
19+
t.prop('id', t.str.options({ascii: true, min: 40, max: 80})).options({title: 'Every object has an ID'}),
20+
t.propOpt('name', t.str),
21+
t.prop('age', t.num.options({format: 'u8', gt: 16, lt: 100})),
22+
t.prop('verified', t.bool),
23+
t.prop('sex', t.Or(t.Const(<const>'male'), t.Const(<const>'female'), t.Const(<const>'other'), t.Const<null>(null))),
3424
)
3525
.options({
36-
title: "My object",
26+
title: 'My object',
3727
});
3828

3929
console.log();
40-
console.log("Print to string:");
30+
console.log('Print to string:');
4131
console.log();
42-
console.log(type + "");
32+
console.log(type + '');
4333

4434
console.log();
45-
console.log("Generate random value:");
35+
console.log('Generate random value:');
4636
console.log();
4737
console.log(type.random());
4838

4939
console.log();
50-
console.log("Can output JSON Type schema:");
40+
console.log('Can output JSON Type schema:');
5141
console.log();
5242
console.log(type.getSchema());
5343

5444
console.log();
55-
console.log("Can output JSON Schema schema:");
45+
console.log('Can output JSON Schema schema:');
5646
console.log();
5747
console.log(type.toJsonSchema());
5848

5949
console.log();
60-
console.log("Can export and import the schema:");
50+
console.log('Can export and import the schema:');
6151
const type2 = t.import(type.getSchema());
6252
console.log();
63-
console.log(type2 + "");
53+
console.log(type2 + '');
6454

6555
console.log();
6656

67-
console.log("Can validate the schema.");
57+
console.log('Can validate the schema.');
6858
type2.validateSchema();
6959

70-
console.log("Can validate data.");
60+
console.log('Can validate data.');
7161
type2.validate({
72-
id: "1234567890123456789012345678901234567890",
73-
name: "John Doe",
62+
id: '1234567890123456789012345678901234567890',
63+
name: 'John Doe',
7464
age: 18,
7565
verified: true,
76-
sex: "male",
66+
sex: 'male',
7767
});
7868

7969
console.log();
80-
console.log("Can serialize value to JSON:");
70+
console.log('Can serialize value to JSON:');
8171
console.log();
8272
console.log(
8373
type2.toJson({
84-
id: "1234567890123456789012345678901234567890",
85-
name: "John Doe",
74+
id: '1234567890123456789012345678901234567890',
75+
name: 'John Doe',
8676
age: 18,
8777
verified: true,
88-
sex: "male",
78+
sex: 'male',
8979
}),
9080
);
9181

9282
console.log();
93-
console.log("Can create a JSON Type schema out of a sample object:");
83+
console.log('Can create a JSON Type schema out of a sample object:');
9484
const sample = {
95-
id: "1234567890123456789012345678901234567890",
96-
name: "John Doe",
85+
id: '1234567890123456789012345678901234567890',
86+
name: 'John Doe',
9787
age: 18,
9888
};
99-
const user = system.alias("User", t.from(sample));
89+
const user = system.alias('User', t.from(sample));
10090
console.log();
10191
console.log(sample);
10292
console.log();
103-
console.log(user.type + "");
93+
console.log(user.type + '');
10494

10595
console.log();
106-
console.log("Can generate TypeScript types for a schema:");
96+
console.log('Can generate TypeScript types for a schema:');
10797
console.log();
10898
console.log(user.toTypeScriptAst());
10999
console.log();
110100
console.log(user.toTypeScript());
111101

112102
console.log();
113-
console.log("Can compile a fast JSON serializer:");
103+
console.log('Can compile a fast JSON serializer:');
114104
console.log();
115105
console.log(user.type.compileEncoder(EncodingFormat.Json).toString());
116106

117107
console.log();
118-
console.log("Can compile a fast CBOR serializer:");
108+
console.log('Can compile a fast CBOR serializer:');
119109
console.log();
120-
console.log(user.type.compileCborEncoder({ system }).toString());
110+
console.log(user.type.compileCborEncoder({system}).toString());
121111

122112
console.log();
123-
console.log("Can compile a fast MessagePack serializer:");
113+
console.log('Can compile a fast MessagePack serializer:');
124114
console.log();
125-
console.log(user.type.compileMessagePackEncoder({ system }).toString());
115+
console.log(user.type.compileMessagePackEncoder({system}).toString());
126116

127117
console.log();
128-
console.log("Can compile a fast validator, which returns booleans as errors:");
118+
console.log('Can compile a fast validator, which returns booleans as errors:');
129119
console.log();
130120
const validator = user.type.compileValidator({
131-
errors: "boolean",
121+
errors: 'boolean',
132122
skipObjectExtraFieldsCheck: true,
133123
});
134124
console.log(validator.toString());
135125

136126
console.log();
137-
console.log(
138-
"Can compile a fast validator, which returns JSON strings as errors:",
139-
);
127+
console.log('Can compile a fast validator, which returns JSON strings as errors:');
140128
console.log();
141129
const validator2 = user.type.compileValidator({
142-
errors: "string",
130+
errors: 'string',
143131
skipObjectExtraFieldsCheck: true,
144132
});
145133
console.log(validator2.toString());
146134

147135
console.log();
148-
console.log("Can compile a fast validator, which returns objects as errors:");
136+
console.log('Can compile a fast validator, which returns objects as errors:');
149137
console.log();
150138
const validator3 = user.type.compileValidator({
151-
errors: "object",
139+
errors: 'object',
152140
skipObjectExtraFieldsCheck: true,
153141
});
154142
console.log(validator3.toString());

0 commit comments

Comments
 (0)