Skip to content

Commit

Permalink
PKG -- [root] Fix type declaration generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Nov 26, 2023
1 parent 6966ec7 commit c613ad0
Show file tree
Hide file tree
Showing 57 changed files with 603 additions and 108 deletions.
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"main": "dist/config.js",
"module": "dist/config.module.js",
"unpkg": "dist/config.umd.js",
"types": "dist/config.d.ts",
"types": "types/config.d.ts",
"scripts": {
"prepublishOnly": "npm test && npm run build",
"test": "jest",
Expand Down
6 changes: 2 additions & 4 deletions packages/config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// Change this to match your project
"include": ["src/**/*"],
"compilerOptions": {
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "types"
"declarationDir": "types",
"rootDir": "src"
}
}
1 change: 1 addition & 0 deletions packages/fcl-bundle/src/build/get-input-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ module.exports = function getInputOptions(package, build) {
"**/*.cjs",
"**/*.mjs",
],
useTsconfigDeclarationDir: true,
}),
replace({
preventAssignment: true,
Expand Down
8 changes: 3 additions & 5 deletions packages/fcl-bundle/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// Change this to match your project
"include": ["src/**/*"],
"compilerOptions": {
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "types",
"declarationDir": "types",
"rootDir": "src"
}
}
}
8 changes: 3 additions & 5 deletions packages/fcl-wc/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// Change this to match your project
"include": ["src/**/*"],
"compilerOptions": {
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "types",
"declarationDir": "types",
"rootDir": "src"
}
}
}
2 changes: 1 addition & 1 deletion packages/fcl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"source": {
"src/fcl.js": {
"cjs": "./dist/fcl.js",
"cjs": "./dist/fcl.ts",
"esm": "./dist/fcl.module.js",
"umd": "./dist/fcl.umd.min.js"
},
Expand Down
30 changes: 5 additions & 25 deletions packages/fcl/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
{
"extends": "../../tsconfig",
// Change this to match your project
"exclude": [
"src/**/*.test.js",
],
"include": ["src/**/*"],
"compilerOptions": {
// Tells TypeScript to read JS files, as
// normally they are ignored as source files
"allowJs": true,
// Generate d.ts files
"declaration": true,
// This compiler run should
// only output d.ts files
"emitDeclarationOnly": true,
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "types",
// go to js file when using IDE functions like
// "Go to Definition" in VSCode
"declarationMap": false,
"typeRoots": [
"../config/config",
"../sdk/sdk",
"../util-address/types",
"../util-encode-key/types"
]
"declarationDir": "types",
"rootDir": "src"
}
}
}
2 changes: 1 addition & 1 deletion packages/rlp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"main": "dist/rlp.js",
"module": "dist/rlp.module.js",
"unpkg": "dist/rlp.umd.js",
"types": "dist/index.d.ts",
"types": "types/index.d.ts",
"scripts": {
"prepublishOnly": "npm test && npm run build",
"test": "jest",
Expand Down
6 changes: 2 additions & 4 deletions packages/rlp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// Change this to match your project
"include": ["src/**/*"],
"compilerOptions": {
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "types"
"declarationDir": "types",
"rootDir": "src"
}
}
41 changes: 41 additions & 0 deletions packages/rlp/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/// <reference types="node" />
import { Buffer } from "buffer";
export { Buffer };
type EncodeInput = Buffer | string | number | Uint8Array | null | undefined | EncodeInput[];
/**
* Built on top of rlp library, removing the BN dependency for the flow.
* Package : https://github.com/ethereumjs/rlp
* RLP License : https://github.com/ethereumjs/rlp/blob/master/LICENSE
*
* ethereumjs/rlp is licensed under the
* Mozilla Public License 2.0
* Permissions of this weak copyleft license are conditioned on making available source code of licensed files and modifications of those files under the same license (or in certain cases, one of the GNU licenses). Copyright and license notices must be preserved. Contributors provide an express grant of patent rights. However, a larger work using the licensed work may be distributed under different terms and without source code for files added in the larger work.
*/
/**
* @param input - will be converted to buffer
* @returns returns buffer of encoded data
*/
export declare function encode(input: EncodeInput): Buffer;
/**
* Built on top of rlp library, removing the BN dependency for the flow.
* Package : https://github.com/ethereumjs/rlp
* RLP License : https://github.com/ethereumjs/rlp/blob/master/LICENSE
*
* ethereumjs/rlp is licensed under the
* Mozilla Public License 2.0
* Permissions of this weak copyleft license are conditioned on making available source code of licensed files and modifications of those files under the same license (or in certain cases, one of the GNU licenses). Copyright and license notices must be preserved. Contributors provide an express grant of patent rights. However, a larger work using the licensed work may be distributed under different terms and without source code for files added in the larger work.
*/
/**
* @param input - will be converted to buffer
* @param stream Is the input a stream (false by default)
* @returns returns buffer of encoded data
*/
export declare function decode(input: Buffer | Uint8Array, stream?: boolean): Buffer;
/**
* Get the length of the RLP input
* @param input
* @returns The length of the input or an empty Buffer if no input
*/
export declare function getLength(input: Buffer | Uint8Array | null | undefined | string | number): number;
/** Transform anything into a Buffer */
export declare function toBuffer(v: Buffer | string | number | Uint8Array | null | undefined): Buffer;
6 changes: 2 additions & 4 deletions packages/sdk/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// Change this to match your project
"include": ["src/**/*"],
"compilerOptions": {
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "types"
"declarationDir": "types",
"rootDir": "src"
}
}
8 changes: 3 additions & 5 deletions packages/transport-http/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// Change this to match your project
"include": ["src/**/*"],
"compilerOptions": {
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "types",
"declarationDir": "types",
"rootDir": "src"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function connectSubscribeEvents(ix: any, context?: any, opts?: any): Promise<any>;
25 changes: 25 additions & 0 deletions packages/transport-http/types/connect-ws.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { StreamConnection } from "@onflow/typedefs";
export declare class WebsocketError extends Error {
code?: number;
reason?: string;
wasClean?: boolean;
constructor({ code, reason, message, wasClean, }: {
code?: number;
reason?: string;
message?: string;
wasClean?: boolean;
});
}
type WebSocketConnection<T> = StreamConnection<{
data: T;
}>;
export declare function connectWs<T>({ hostname, path, params, getParams, retryLimit, retryIntervalMs, }: {
hostname: string;
path: string;
params?: Record<string, string>;
getParams?: () => Record<string, string> | undefined;
retryLimit?: number;
retryIntervalMs?: number;
}): WebSocketConnection<T>;
export declare function buildConnectionUrl(hostname: string, path?: string, params?: Record<string, string | number | string[] | number[] | null | undefined>): string;
export {};
41 changes: 41 additions & 0 deletions packages/transport-http/types/http-request.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Creates an HTTP Request to be sent to a REST Access API via Fetch API.
*
* @param {object} options - Options for the HTTP Request
* @param {String} options.hostname - Access API Hostname
* @param {String} options.path - Path to the resource on the Access API
* @param {String} options.method - HTTP Method
* @param {object} options.body - HTTP Request Body
* @param {object} [options.headers] - HTTP Request Headers
* @param {boolean} [options.enableRequestLogging=true] - Enable/Disable request logging
* @param {number} [options.retryLimit=5] - Number of times to retry request
* @param {number} [options.retryIntervalMs=1000] - Time in milliseconds to wait before retrying request
* @param {number} [options.timeoutLimit=30000] - Time in milliseconds to wait before timing out request
*
* @returns JSON object response from Access API.
*/
export function httpRequest({ hostname, path, method, body, headers, retryLimit, retryIntervalMs, timeoutLimit, enableRequestLogging, }: {
hostname: string;
path: string;
method: string;
body: object;
headers?: object | undefined;
enableRequestLogging?: boolean | undefined;
retryLimit?: number | undefined;
retryIntervalMs?: number | undefined;
timeoutLimit?: number | undefined;
}): Promise<any>;
export class HTTPRequestError extends Error {
constructor({ error, hostname, path, method, requestBody, responseBody, responseStatusText, statusCode, }: {
error: any;
hostname: any;
path: any;
method: any;
requestBody: any;
responseBody: any;
responseStatusText: any;
statusCode: any;
});
statusCode: any;
errorMessage: any;
}
15 changes: 15 additions & 0 deletions packages/transport-http/types/sdk-send-http.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export { sendExecuteScript } from "./send-execute-script";
export { sendGetAccount } from "./send-get-account";
export { sendGetBlockHeader } from "./send-get-block-header";
export { sendGetBlock } from "./send-get-block";
export { sendGetCollection } from "./send-get-collection";
export { sendGetEvents } from "./send-get-events";
export { sendGetTransaction } from "./send-get-transaction";
export { sendGetTransactionStatus } from "./send-get-transaction-status";
export { sendPing } from "./send-ping";
export { sendTransaction } from "./send-transaction";
export { sendGetNetworkParameters } from "./send-get-network-parameters";
export { connectSubscribeEvents } from "./connect-subscribe-events";
export { send } from "./send-http";
export { WebsocketError } from "./connect-ws";
export { HTTPRequestError } from "./http-request.js";
1 change: 1 addition & 0 deletions packages/transport-http/types/send-execute-script.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function sendExecuteScript(ix: any, context?: {}, opts?: {}): Promise<any>;
1 change: 1 addition & 0 deletions packages/transport-http/types/send-get-account.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function sendGetAccount(ix: any, context?: {}, opts?: {}): Promise<any>;
1 change: 1 addition & 0 deletions packages/transport-http/types/send-get-block-header.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function sendGetBlockHeader(ix: any, context?: {}, opts?: {}): Promise<any>;
1 change: 1 addition & 0 deletions packages/transport-http/types/send-get-block.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function sendGetBlock(ix: any, context?: {}, opts?: {}): Promise<any>;
1 change: 1 addition & 0 deletions packages/transport-http/types/send-get-collection.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function sendGetCollection(ix: any, context?: {}, opts?: {}): Promise<any>;
1 change: 1 addition & 0 deletions packages/transport-http/types/send-get-events.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function sendGetEvents(ix: any, context?: {}, opts?: {}): Promise<any>;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function sendGetNetworkParameters(ix: any, context?: {}, opts?: {}): Promise<any>;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function sendGetTransactionStatus(ix: any, context?: {}, opts?: {}): Promise<any>;
1 change: 1 addition & 0 deletions packages/transport-http/types/send-get-transaction.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function sendGetTransaction(ix: any, context?: {}, opts?: {}): Promise<any>;
1 change: 1 addition & 0 deletions packages/transport-http/types/send-http.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function send(ix: any, context?: {}, opts?: {}): Promise<any>;
1 change: 1 addition & 0 deletions packages/transport-http/types/send-ping.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function sendPing(ix: any, context?: {}, opts?: {}): Promise<any>;
1 change: 1 addition & 0 deletions packages/transport-http/types/send-transaction.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function sendTransaction(ix: any, context?: {}, opts?: {}): Promise<any>;
1 change: 1 addition & 0 deletions packages/transport-http/types/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function safeParseJSON(data: any): any;
1 change: 1 addition & 0 deletions packages/transport-http/types/websocket.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const WebSocket: new (url: string | URL, protocols?: string | string[] | undefined) => WebSocket;
2 changes: 1 addition & 1 deletion packages/typedefs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"main": "dist/typedefs.js",
"module": "dist/typedefs.module.js",
"unpkg": "dist/typedefs.umd.js",
"types": "dist/index.d.ts",
"types": "types/index.d.ts",
"scripts": {
"prepublishOnly": "npm test && npm run build",
"test": "jest",
Expand Down
8 changes: 3 additions & 5 deletions packages/typedefs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// Change this to match your project
"include": ["src/**/*"],
"compilerOptions": {
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "types",
"declarationDir": "types",
"rootDir": "src"
}
}
}
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"main": "dist/types.js",
"module": "dist/types.module.js",
"unpkg": "dist/types.umd.js",
"types": "dist/types.d.ts",
"types": "types/types.d.ts",
"scripts": {
"prepublishOnly": "npm test && npm run build",
"test": "jest",
Expand Down
8 changes: 3 additions & 5 deletions packages/types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// Change this to match your project
"include": ["src/**/*"],
"compilerOptions": {
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "types",
"declarationDir": "types",
"rootDir": "src"
}
}
}
Loading

0 comments on commit c613ad0

Please sign in to comment.