Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

Commit 496f52c

Browse files
authored
feat: update types and generation script (#1336)
1 parent f67a841 commit 496f52c

3 files changed

Lines changed: 1609 additions & 531 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"pretest": "npm run compile",
4444
"docs-test": "linkinator docs",
4545
"predocs-test": "npm run docs",
46-
"types": "dtsd bigquery v2 > ./src/types.d.ts",
46+
"types": "node scripts/gen-types.js",
4747
"prelint": "cd samples; npm link ../; npm install",
4848
"precompile": "gts clean"
4949
},

scripts/gen-types.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
const {fetch} = require('discovery-tsd');
16+
const TypeGenerator = require('discovery-tsd/src/generator');
17+
const prettier = require('prettier');
18+
const fs = require('fs');
19+
const {promisify} = require('util');
20+
21+
const writeFile = promisify(fs.writeFile);
22+
23+
const LICENSE = `// Copyright 2024 Google LLC
24+
//
25+
// Licensed under the Apache License, Version 2.0 (the "License");
26+
// you may not use this file except in compliance with the License.
27+
// You may obtain a copy of the License at
28+
//
29+
// https://www.apache.org/licenses/LICENSE-2.0
30+
//
31+
// Unless required by applicable law or agreed to in writing, software
32+
// distributed under the License is distributed on an "AS IS" BASIS,
33+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34+
// See the License for the specific language governing permissions and
35+
// limitations under the License.`;
36+
37+
function overridedRender() {
38+
const source = this.template({
39+
title: this.title ? this.converter.toJSDoc(this.title) : '',
40+
name: this.name,
41+
schemas: this.schemas.map(schema => this.converter.createType(schema)),
42+
resources: this.resources.map(resource => resource.render()),
43+
});
44+
45+
const patched = source.replaceAll(
46+
'formatOptions.useInt64Timestamp',
47+
"'formatOptions.useInt64Timestamp'"
48+
);
49+
const sourceWithLicense = LICENSE + '\n' + patched;
50+
51+
return prettier.format(sourceWithLicense, {
52+
parser: 'typescript',
53+
singleQuote: true,
54+
});
55+
}
56+
57+
async function genTypes() {
58+
const json = await fetch('bigquery', 'v2');
59+
const generator = new TypeGenerator(json);
60+
generator.render = overridedRender.bind(generator);
61+
const types = await generator.render();
62+
await writeFile('./src/types.d.ts', types);
63+
}
64+
65+
genTypes();

0 commit comments

Comments
 (0)