Skip to content

Commit 86ab782

Browse files
authored
fix: add new generators for the TypeScript SDK (looker-open-source#1563)
Synchronized the latest sdk-codegen code from internal development. The MSW and SDK data hooks generators aren't yet ready for public consumption but they do work for internal testing
1 parent dfc0637 commit 86ab782

Some content is hidden

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

44 files changed

+1248
-1002
lines changed

examplesIndex.json

+871-751
Large diffs are not rendered by default.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"@types/blueimp-md5": "^2.7.0",
101101
"@types/ini": "^1.3.30",
102102
"@types/jest": "29.2.4",
103-
"@types/js-yaml": "^3.12.1",
103+
"@types/js-yaml": "4.0.9",
104104
"@types/lodash": "4.14.172",
105105
"@types/node": "22.5.4",
106106
"@types/prettier": "2.7.3",
@@ -136,7 +136,7 @@
136136
"jest-environment-node": "29.7.0",
137137
"jest-junit": "12.3.0",
138138
"jest-styled-components": "7.1.1",
139-
"js-yaml": "3.14.1",
139+
"js-yaml": "4.1.0",
140140
"jsdom": "21.1.2",
141141
"lerna": "3.22.1",
142142
"lint-staged": "10.2.2",

packages/api-explorer/src/utils/sdkLanguage.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
*/
2626

27-
import type { ArgValues } from '@looker/sdk-codegen';
27+
import type { ArgValues } from '@looker/sdk-rtl';
2828
import { codeGenerators } from '@looker/sdk-codegen';
2929

3030
export const allAlias = 'all';
@@ -36,7 +36,7 @@ export const allAlias = 'all';
3636
export const allSdkLanguages = (): Record<string, string> => {
3737
const languages: ArgValues = {};
3838
codeGenerators.forEach(gen => {
39-
const alias = gen.extension.toString().match(/\.(\w+)\b/)![1];
39+
const alias = (gen.extension.toString().match(/\.(\w+)\b/) ?? [])[1];
4040
languages[alias] = gen.language;
4141
});
4242

packages/sdk-codegen-scripts/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
"cross-env": "^7.0.2"
3737
},
3838
"devDependencies": {
39-
"@openapitools/openapi-generator-cli": "^2.1.23",
40-
"@types/config": "^0.0.36",
41-
"dotenv": "^8.2.0",
39+
"@openapitools/openapi-generator-cli": "2.7.0",
40+
"@types/config": "0.0.36",
41+
"dotenv": "8.2.0",
4242
"expect": "29.7.0",
4343
"file-type": "^16.5.4",
4444
"ini": "^1.3.8",
45-
"js-yaml": "3.14.1",
45+
"js-yaml": "4.1.0",
4646
"openapi3-ts": "2.0.2",
4747
"@types/prettier": "2.7.3",
4848
"prettier": "2.8.8",

packages/sdk-codegen-scripts/scripts/mineDeclarations.ts

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import {
6666
}
6767
}
6868
const indexFile = path.join(root, indexName);
69+
/* eslint-disable no-console */
6970
console.log(`Mining declarations from ${sourcePath} ...`);
7071

7172
const miner = new DeclarationMiner(
@@ -78,6 +79,7 @@ import {
7879
fs.writeFileSync(indexFile, JSON.stringify(result, null, 2), {
7980
encoding: 'utf-8',
8081
});
82+
/* eslint-disable no-console */
8183
console.log(
8284
`${
8385
Object.entries(result.methods).length +
@@ -89,12 +91,14 @@ import {
8991
fs.writeFileSync(indexCopy, JSON.stringify(result, null, 2), {
9092
encoding: 'utf-8',
9193
});
94+
/* eslint-disable no-console */
9295
console.log(`Copied declaration nuggets to ${indexCopy}`);
9396
const examplesIndex = 'examplesIndex.json';
9497
const examples = path.join(root, examplesIndex);
9598
if (fs.existsSync(examples)) {
9699
const examplesCopy = path.join(copyPath, examplesIndex);
97100
fs.copyFileSync(examples, examplesCopy);
101+
/* eslint-disable no-console */
98102
console.log(`Copied example nuggets to ${examplesCopy}`);
99103
}
100104
}

packages/sdk-codegen-scripts/scripts/mineExamples.ts

+2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ import { ExampleMiner } from '../src/exampleMiner';
3333
const root = path.join(__dirname, '/../../../');
3434
const sourcePath = total < 1 ? root : path.join(root, args[0]);
3535
const indexFile = path.join(sourcePath, '/examplesIndex.json');
36+
/* eslint-disable no-console */
3637
console.log(`Mining examples from ${sourcePath} ...`);
3738
const miner = new ExampleMiner(sourcePath);
3839
const result = miner.execute();
3940
fs.writeFileSync(indexFile, JSON.stringify(result, null, 2), {
4041
encoding: 'utf-8',
4142
});
43+
/* eslint-disable no-console */
4244
console.log(
4345
`${Object.entries(result.nuggets).length} nuggets written to ${indexFile}`
4446
);

packages/sdk-codegen-scripts/scripts/register.ts

+1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
import { registerApp } from './utils';
2828
(async () => {
2929
const result = await registerApp();
30+
/* eslint-disable no-console */
3031
console.log(result);
3132
})();

packages/sdk-codegen-scripts/scripts/specLinter.ts

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const getOptions = () => {
6060
status: 'beta',
6161
};
6262
const args = process.argv.slice(1);
63+
/* eslint-disable no-console */
6364
console.log(`${args[0]} [fileA] [fileB] [format] [status]\n
6465
format=csv|md
6566
status=beta|all
@@ -84,6 +85,7 @@ status=beta|all
8485
}
8586
result.status = args[4].toLowerCase();
8687
}
88+
/* eslint-disable no-console */
8789
console.log(`using:\n${JSON.stringify(result, null, 2)}`);
8890

8991
return result;
@@ -127,6 +129,7 @@ function checkSpecs() {
127129
writeFileSync(outFile, result, {
128130
encoding: 'utf-8',
129131
});
132+
/* eslint-disable no-console */
130133
console.log(`Wrote ${diff.length} method differences to ${outFile}`);
131134
}
132135

packages/sdk-codegen-scripts/scripts/utils.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import {
3535
logConvertSpec,
3636
} from '../../sdk-codegen-scripts/src/fetchSpec';
3737

38+
/* eslint no-console: 0 */
39+
3840
const supportedApiVersions = ['3.1', '4.0'];
3941

4042
const homeToRoost = '../../../';
@@ -105,10 +107,10 @@ const brokenPromise = (message: string) => Promise.reject(new Error(message));
105107
export const registerApp = async () => {
106108
const args = process.argv.slice(2);
107109
const total = args.length;
108-
// eslint-disable-next-line node/no-path-concat
109-
const iniFile = total < 1 ? `${__dirname}/../../../looker.ini` : args[0];
110-
// eslint-disable-next-line node/no-path-concat
111-
const configFile = total < 2 ? `${__dirname}/appconfig.json` : args[1];
110+
const iniFile =
111+
total < 1 ? path.join(__dirname, '/../../../looker.ini') : args[0];
112+
const configFile =
113+
total < 2 ? path.join(__dirname, 'appconfig.json') : args[1];
112114
let result = '';
113115
console.log(
114116
`Using ${iniFile} to register the OAuth application configured in ${configFile}`

packages/sdk-codegen-scripts/scripts/vox.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ import {
3838
update_artifacts,
3939
} from '@looker/sdk';
4040

41+
/* eslint no-console: 0 */
42+
4143
const root = path.join(__dirname, '/../../../');
4244
const indexFile = path.join(root, 'hackathons.json');
4345
const compareFile = path.join(root, 'hackCompare.json');
44-
const utf8 = { encoding: 'utf-8' };
46+
const utf8 = 'utf8';
4547
const content = fs.readFileSync(indexFile, utf8);
4648
const artifacts = JSON.parse(content) as IArtifact[];
4749
const sdk = LookerNodeSDK.init40();
@@ -120,10 +122,12 @@ const findOrMakeUser = async (art: IArtifact) => {
120122
create_user(sdk, { first_name: f.first_name, last_name: f.last_name })
121123
);
122124
}
123-
if (!user?.group_ids?.includes(group.id!)) {
124-
await sdk.ok(add_group_user(sdk, group.id!, { user_id: user.id! }));
125+
if (!user?.group_ids?.includes(group.id ?? '')) {
126+
await sdk.ok(
127+
add_group_user(sdk, group.id ?? '', { user_id: user.id ?? '' })
128+
);
125129
}
126-
return swapUserId(art, user.id!);
130+
return swapUserId(art, user.id ?? '');
127131
};
128132

129133
// const removeHackUsers = async () => {

packages/sdk-codegen-scripts/src/convert.apispec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ describe('spec conversion', () => {
527527
expect(keys).toHaveLength(Object.keys(defs).length);
528528
});
529529

530-
it.skip('matches a reference OpenAPI conversion', () => {
530+
/** eslint-disable jest/no-disabled-tests */
531+
it('matches a reference OpenAPI conversion', { skip: true }, () => {
531532
// TODO There is a different branch to address this
532533
const spec = upgradeSpec(swaggerSource);
533534
expect(spec).toBeDefined();

packages/sdk-codegen-scripts/src/declarationMiner.spec.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
import path from 'path';
28+
import fs from 'fs';
2829
import { NodeSettingsIniFile } from '@looker/sdk-node';
2930
import { TestConfig } from '@looker/sdk-codegen-utils';
3031

@@ -43,17 +44,22 @@ const config = TestConfig(specToModel);
4344
* Tests are skipped if this configuration is not found.
4445
*/
4546
describe('Declaration miner', () => {
46-
const settings = new NodeSettingsIniFile(
47-
'',
48-
path.join(config.rootPath, 'looker.ini'),
49-
'Miner'
50-
).readConfig();
47+
let sourcePath = '';
48+
let originOverride = '';
49+
const iniFile = path.join(config.rootPath, 'looker.ini');
50+
if (fs.existsSync(iniFile)) {
51+
const settings = new NodeSettingsIniFile(
52+
'',
53+
path.join(config.rootPath, 'looker.ini'),
54+
'Miner'
55+
).readConfig();
5156

52-
const sourcePath = settings.base_url;
53-
const originOverride = settings.origin_override;
54-
const isConfigured = () => !!sourcePath;
57+
sourcePath = settings.base_url;
58+
originOverride = settings?.origin_override;
59+
}
60+
const isConfigured = () => Boolean(sourcePath);
5561

56-
test('should mine files matching the probe settings', () => {
62+
it('should mine files matching the probe settings', () => {
5763
if (!isConfigured()) return;
5864
const miner = new DeclarationMiner(
5965
sourcePath,
@@ -75,7 +81,7 @@ describe('Declaration miner', () => {
7581
});
7682
});
7783

78-
test('should retrieve remoteOrigin', () => {
84+
it('should retrieve remoteOrigin', () => {
7985
if (!isConfigured()) return;
8086
const miner = new DeclarationMiner(
8187
sourcePath,

packages/sdk-codegen-scripts/src/declarationMiner.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ export const rubyMethodProbe = {
6060
declarationPattern:
6161
/(?<verb>GET|POST|DELETE|PUT|PATCH)\s(?:"|')\/api\/3\.x(?<path>\S+)(?:"|')/i,
6262
matchToSpecKeyTransform: (match: RegExpExecArray) => {
63-
const verb = match.groups!.verb.toLocaleUpperCase();
64-
const path = match
65-
.groups!.path.replace(':#', '')
63+
const verb = match.groups?.verb.toLocaleUpperCase();
64+
const path = match.groups?.path
65+
.replace(':#', '')
6666
.replace('#', '')
6767
.replace(/:(\w+)/g, '{$1}');
6868
const key = `${verb} ${path}`;
@@ -76,6 +76,7 @@ export const rubyMethodProbe = {
7676
export const rubyTypeProbe: IProbe = {
7777
fileNamePattern: /^(?!test).*_mapper.rb$/,
7878
declarationPattern: /class\s(?<typeName>\w+)Mapper/i,
79+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7980
matchToSpecKeyTransform: (match: RegExpExecArray) => match.groups!.typeName,
8081
};
8182

packages/sdk-codegen-scripts/src/exampleMiner.spec.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ import {
3838
getRemoteHttpOrigin,
3939
} from './exampleMiner';
4040

41-
describe('example mining', () => {
41+
/** eslint-disable jest/no-disabled-tests */
42+
describe.skip('example mining', () => {
4243
const sourcePath = path.join(__dirname, '/../../../examples');
4344
const exampleFile = (fileName: string) =>
4445
path.join(sourcePath, '/', fileName);
@@ -72,7 +73,7 @@ describe('example mining', () => {
7273
it('getCommitHash', () => {
7374
const actual = getCommitHash();
7475
expect(actual).toBeDefined();
75-
expect(actual.length).toEqual(40);
76+
expect(actual).toHaveLength(40);
7677
});
7778
it('getRemoteHttpOrigin', () => {
7879
const actual = getRemoteHttpOrigin();
@@ -112,7 +113,7 @@ describe('example mining', () => {
112113
it('processes standard url patterns', () => {
113114
const md = '[summary1](example.ts#strip me!)';
114115
const actual = marker.mineContent('example/typescript/README.md', md);
115-
expect(actual.length).toEqual(1);
116+
expect(actual).toHaveLength(1);
116117
const first = actual[0];
117118
expect(first.summary).toEqual('summary1');
118119
expect(first.sourceFile).toEqual('example/typescript/example.ts');
@@ -124,7 +125,7 @@ describe('example mining', () => {
124125
'packages/sdk-codegen/README.md',
125126
md
126127
);
127-
expect(actual.length).toEqual(2);
128+
expect(actual).toHaveLength(2);
128129
const first = actual[0];
129130
expect(first.summary).toEqual('TypeScript');
130131
expect(first.sourceFile).toEqual(
@@ -141,7 +142,7 @@ describe('example mining', () => {
141142
const md =
142143
'Logout all users on the instance [[link]](logout_all_users.rb)';
143144
const actual = marker.mineContent('example/ruby/README.md', md);
144-
expect(actual.length).toEqual(1);
145+
expect(actual).toHaveLength(1);
145146
const first = actual[0];
146147
expect(first.summary).toEqual('Logout all users on the instance');
147148
expect(first.sourceFile).toEqual('example/ruby/logout_all_users.rb');
@@ -150,16 +151,17 @@ describe('example mining', () => {
150151
const md =
151152
'\t - Logout all users on the instance [[link]](logout_all_users.rb)';
152153
const actual = marker.mineContent('example/ruby/README.md', md);
153-
expect(actual.length).toEqual(1);
154+
expect(actual).toHaveLength(1);
154155
const first = actual[0];
155156
expect(first.summary).toEqual('Logout all users on the instance');
156157
expect(first.sourceFile).toEqual('example/ruby/logout_all_users.rb');
157158
});
159+
/** eslint-disable jest/no-disabled-tests */
158160
it.skip('processes multiple link url patterns and strips leading dash', () => {
159161
const md =
160162
'\t - Logout all users on the instance [[link]](logout_all_users.rb) logs in [[link]](logs_in.rb)';
161163
const actual = marker.mineContent('example/ruby/README.md', md);
162-
expect(actual.length).toEqual(2);
164+
expect(actual).toHaveLength(2);
163165
const first = actual[0];
164166
expect(first.summary).toEqual('Logout all users on the instance');
165167
expect(first.sourceFile).toEqual('example/ruby/logout_all_users.rb');
@@ -182,31 +184,37 @@ describe('example mining', () => {
182184
expect(actual).toEqual(expected);
183185
};
184186

187+
/** eslint-disable jest/expect-expect */
185188
it('is empty for no sdk calls', () => {
186189
probe('', []);
187190
probe('one() two() three()', []);
188191
probe('foo.one() bar.two() boo.three()', []);
189192
probe('foo.one()\nbar.two()\nboo.three()', []);
190193
});
191194

195+
/** eslint-disable jest/expect-expect */
192196
it('ignores ok and finds ts calls', () => {
193197
probe(`const value = await sdk.ok(sdk.me())`, [
194198
{ sdk: 'sdk', operationId: 'me', line: 1, column: 27 },
195199
]);
196200
});
197201

202+
/** eslint-disable jest/expect-expect */
198203
it('ignores ok and finds kotlin calls', () => {
199204
probe(`val look = sdk.ok<Look>(sdk.create_look(WriteLookWithQuery(`, [
200205
{ sdk: 'sdk', operationId: 'create_look', line: 1, column: 24 },
201206
]);
202207
});
203208

209+
/** eslint-disable jest/no-disabled-tests */
210+
/** eslint-disable jest/expect-expect */
204211
it.skip('ignores comments and ok', () => {
205212
probe(
206213
`// this is a code comment sdk.comment()\nconst value = await coreSDK.ok(coreSDK.me())`,
207214
[{ sdk: 'coreSDK', operationId: 'me', line: 2, column: 33 }]
208215
);
209216
});
217+
/** eslint jest/expect-expect: 1 */
210218

211219
it('mines a python file', () => {
212220
const fileName = exampleFile('python/run_look_with_filters.py');

packages/sdk-codegen-scripts/src/prettify.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
2525
*/
2626

27+
// eslint-disable @looker/license-header
2728
import { prettify } from './prettify';
2829

2930
describe('prettify', () => {

packages/sdk-codegen-scripts/src/prettify.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ const prettierTs: prettier.Options = {
4444
* @param options prettier.Options to override the default processing. Typescript options are the default
4545
*/
4646
export const prettify = (code: string, options: prettier.Options = {}) => {
47-
const merged: prettier.Options = { ...prettierTs, ...{ options } };
47+
const merged: prettier.Options = { ...prettierTs, ...options };
4848
return prettier.format(code, merged);
4949
};

0 commit comments

Comments
 (0)