Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove the requests package from the TypeScript SDK #1491

Merged
merged 71 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
97419fb
fix: many updates for the TypeScript SDK
jkaster Aug 10, 2024
658d90f
some lint updates, still broken branch
jkaster Aug 10, 2024
0cc4215
some lint updates, still broken branch
jkaster Aug 12, 2024
5d7a44d
fixed extension sdk initialization
jkaster Aug 12, 2024
e53807d
major refactor for TS SDK streaming
jkaster Aug 15, 2024
cc95359
fixing build issues
jkaster Aug 15, 2024
64d39b3
more tweaks
jkaster Aug 15, 2024
9893483
Merge branch 'main' into fetcher
jkaster Aug 15, 2024
797630a
more tweaks
jkaster Aug 15, 2024
7a1039f
now trying to get login to work again
jkaster Aug 16, 2024
8046d13
still fighting self-signed cert issues
jkaster Aug 16, 2024
f399f12
still fighting self-signed cert issues
jkaster Aug 16, 2024
9c90b05
now working on auth issues
jkaster Aug 16, 2024
9d2cbe3
most transport variances are working
jkaster Aug 17, 2024
71ae576
fixing up integration tests
jkaster Aug 20, 2024
4be049c
ref node 22.x in workflows
jkaster Aug 20, 2024
c6af0d7
skipping some problematic jest tests when run from command line
jkaster Aug 20, 2024
15d9cb2
reformatter with prettier is working again
jkaster Aug 21, 2024
a6f1d5a
NodeJS streaming is working again
jkaster Aug 23, 2024
04ab2bc
updated the TS streaming example and examples index
jkaster Aug 23, 2024
7e772c8
jest polyfill for AbortSignal.timeout
jkaster Aug 24, 2024
5a50660
fetchspec test uses timeout override
jkaster Aug 24, 2024
b1361d6
run prettier on all files
jkaster Aug 26, 2024
151627e
working on some CI issues
jkaster Aug 26, 2024
f5f1a8a
working on some CI issues
jkaster Aug 26, 2024
387d59a
gracefully handle the absence of AbortSignal.any
jkaster Aug 27, 2024
0e8f94e
ignore optional lint errors
jkaster Aug 27, 2024
2be4229
fix more CI issues
jkaster Aug 27, 2024
c3eca48
fix more CI issues
jkaster Aug 27, 2024
0548876
fix more CI issues
jkaster Aug 27, 2024
962f8c7
add missing test files
jkaster Aug 28, 2024
2b670fc
fix apix tests
jkaster Aug 28, 2024
deb53e7
fix apix tests
jkaster Aug 28, 2024
670bdf6
only test the current looker release with the curren SDK
jkaster Aug 28, 2024
4c4650c
trying to make jest mocking more durable
jkaster Aug 28, 2024
ea9129a
tweaking tests that only fail in CI
jkaster Aug 29, 2024
9d3b2ad
reducing code duplication
jkaster Aug 29, 2024
8000c31
tweaking jest config again
jkaster Aug 30, 2024
48fd346
dedupe yarn
jkaster Aug 30, 2024
57c51e8
added browser timeout and cancel tests
jkaster Aug 30, 2024
906d75e
Merge branch 'main' into fetcher
jkaster Sep 4, 2024
8fa8080
implement AbortSignal.any for jest
jkaster Sep 4, 2024
d25e083
improved examples, updated sdk-rtl README.md
jkaster Sep 4, 2024
a20b3aa
export sleep function
jkaster Sep 4, 2024
a396002
default error handling some more
jkaster Sep 4, 2024
8ceeee5
stale file cleanup
jkaster Sep 4, 2024
cea6b27
tweaking error creation
jkaster Sep 5, 2024
9321de4
log fetch failed error trying to get more info
jkaster Sep 6, 2024
c0f1707
trying to log error info
jkaster Sep 6, 2024
5189d28
trying to log error info
jkaster Sep 6, 2024
3417152
still trying
jkaster Sep 6, 2024
033fa41
added nest node module
jkaster Sep 6, 2024
c71b836
run integration tests sequentially
jkaster Sep 6, 2024
04766ef
restore parallel jest tests
jkaster Sep 6, 2024
a57997e
try explicit config
jkaster Sep 6, 2024
ac0eab4
try explicit config
jkaster Sep 6, 2024
1ed15e8
fix node test config path
jkaster Sep 6, 2024
8da26d0
another path attempt
jkaster Sep 6, 2024
d9ca13a
yet another path attempt
jkaster Sep 6, 2024
8580edd
use env=node instead!
jkaster Sep 6, 2024
c38b747
GitHub action path issues are insane
jkaster Sep 7, 2024
c0bbc9d
run node tests in parallel again
jkaster Sep 7, 2024
3418018
try to log full error
jkaster Sep 7, 2024
a415abf
implementing my OWN node test suite
jkaster Sep 7, 2024
2215353
using node test runner
jkaster Sep 9, 2024
dfcf52a
full port methods.spec.ts to sdk.test.ts
jkaster Sep 10, 2024
052069e
update TS sdk readmes
jkaster Sep 10, 2024
cd032fe
test failures in CI. Again.
jkaster Sep 10, 2024
bea1ea1
test failures in CI. Again.
jkaster Sep 10, 2024
d4b33e3
correct beforeAll and afterAll synonyms
jkaster Sep 10, 2024
08fc612
another test attempt
jkaster Sep 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/apix-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
matrix:
os:
- ubuntu
node-version: [18.x]
node-version: [22.x]

steps:
- name: Cancel Previous Runs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codegen-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 22.x

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hackathon-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
matrix:
os:
- ubuntu
node-version: [18.x]
node-version: [22.x]

steps:
- name: Cancel Previous Runs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lerna-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 22.x
registry-url: https://wombat-dressing-room.appspot.com

- name: Install dependencies and build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/resources-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 22.x

- name: Install Dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tssdk-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
matrix:
os:
- ubuntu
node-version: [18.x, 20.x]
node-version: [20.x, 22.x]

steps:
- name: Cancel Previous Runs
Expand Down Expand Up @@ -122,7 +122,7 @@ jobs:
runs-on: ${{ matrix.os }}-latest
strategy:
matrix:
node-version: [18.x, 20.x]
node-version: [20.x, 22.x]
os:
- ubuntu
looker: ${{ fromJson(needs.setup.outputs.matrix_json) }}
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
**/storybook-static
**/test/output
**/.eslintrc
*.lock
*.lock
bin/**
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ const config = {
semi: true,
singleQuote: true,
trailingComma: 'es5',
arrowParens: 'avoid',
};
module.exports = config;
4 changes: 2 additions & 2 deletions bin/looker-resources-index/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "Looker",
"license": "MIT",
"devDependencies": {
"@types/node": "14.18.63",
"typescript": "5.1.6"
"@types/node": "22.5.0",
"typescript": "5.5.4"
}
}
4 changes: 0 additions & 4 deletions examples/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ These examples assume that a `looker.ini` has been created in the root of the re

Some other dependencies may be required for the projects to build and run correctly on your local clone.

```bash
yarn install @types/readable-stream @types/request @types/request-promise-native -D
```

## TypeScript SDK packages

The Looker TypeScript SDK has different packages to prevent node dependencies being linked into browser usage of the SDK (the node dependencies are not available in the browser and can cause compilation errors). There are three packages for the Typescript SDK available on npm:
Expand Down
66 changes: 29 additions & 37 deletions examples/typescript/downloadTile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
*/

import * as fs from 'fs';
import { Readable } from 'stream';
import { Looker40SDK as LookerSDK, Looker40SDKStream } from '@looker/sdk';
import type { IDashboardElement, IRequestRunQuery } from '@looker/sdk';
import {
Looker40SDK as LookerSDK,
IDashboardElement,
IRequestRunQuery,
Looker40SDKStream,
} from '@looker/sdk';
import { NodeSettingsIniFile, NodeSession } from '@looker/sdk-node';
NodeSettingsIniFile,
NodeSession,
createWritableStream,
} from '@looker/sdk-node';
import {
getDashboard,
getDashboardTile,
Expand Down Expand Up @@ -77,8 +76,8 @@ const getParams = () => {

/**
* Is this format renderable?
* @param {string} format to render
* @returns {boolean} true if render_task can be used for this format
* @param format to render
* @returns true if render_task can be used for this format
*/
const isRenderable = (format: string) => {
format = format.toLowerCase();
Expand All @@ -87,12 +86,12 @@ const isRenderable = (format: string) => {

/**
* Renders a dashboard tile's query as PNG or JPG
* @param {LookerSDK} sdk object to use
* @param {IDashboardElement} tile to render (using query_id)
* @param {string} format either png or jpg
* @param {number} width defaults to 640
* @param {number} height defaults to 480
* @returns {Promise<string>} name of downloaded file (undefined on failure)
* @param sdk object to use
* @param tile to render (using query_id)
* @param format either png or jpg
* @param width defaults to 640
* @param height defaults to 480
* @returns name of downloaded file (undefined on failure)
*
* **Note:** run_query can also be used for PNG and JPG output, but this function will show an elapsed time ticker via
* the `waitForRender()` callback as the render is progressing
Expand All @@ -113,10 +112,11 @@ const renderTile = async (
throw new Error(`Could not create a render task for ${tile.title}`);
}

// eslint-disable-next-line testing-library/render-result-naming-convention
const result = await waitForRender(sdk, task.id!);
if (result) {
fileName = `${tile.title}.${format}`;
fs.writeFile(fileName, result, 'binary', (err) => {
fs.writeFile(fileName, result, 'binary', err => {
if (err) {
fileName = undefined; // no file was created
throw err;
Expand All @@ -128,48 +128,40 @@ const renderTile = async (

/**
* Use the streaming SDK to download a tile's query
* @param {LookerSDK} sdk to use
* @param {IDashboardElement} tile to download
* @param {string} format to download
* @returns {Promise<string>} name of downloaded file (undefined on failure)
* @param sdk to use
* @param tile to download
* @param format to download
* @returns name of downloaded file (undefined on failure)
*/
const downloadTileAs = async (
sdk: LookerSDK,
tile: IDashboardElement,
format: string
) => {
let fileName;
fileName = `${tile.title}.${format}`;
const fileName = `${tile.title}.${format}`;

const writer = fs.createWriteStream(fileName);
const writer = createWritableStream(fs.createWriteStream(fileName));
const request: IRequestRunQuery = {
result_format: format,
query_id: tile.query_id!,
// apply_formatting: true,
// apply_vis: true
};
const sdkStream = new Looker40SDKStream(sdk.authSession);
await sdkStream.run_query(async (readable: Readable) => {
return new Promise<any>((resolve, reject) => {
readable
.pipe(writer)
.on('error', () => {
fileName = undefined;
throw reject;
})
.on('finish', resolve);
});
await sdkStream.run_query(async (response: Response) => {
await response.body.pipeTo(writer);
return 'streamed';
}, request);

return fileName;
};

/**
* Download a dashboard tile in any of its supported formats
* @param {LookerSDK} sdk initialized Looker SDK
* @param {IDashboardElement} tile Dashboard tile to render
* @param {string} format format of rendering
* @returns {Promise<undefined | string>} Name of file downloaded
* @param sdk initialized Looker SDK
* @param tile Dashboard tile to render
* @param format format of rendering
* @returns Name of file downloaded
*/
const downloadTile = async (
sdk: LookerSDK,
Expand Down
Loading
Loading