Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 16 additions & 6 deletions types/bencode/bencode-tests.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import * as bencode from "bencode";
import bencode from "bencode";

bencode.byteLength("abcde"); // $ExpectType number
bencode.encodingLength("abcde"); // $ExpectType number
bencode.encode([1, 2, 3, 4], new Buffer([]), 1); // $ExpectType Buffer || Buffer<ArrayBufferLike>
bencode.decode(new Buffer("abcde"), 1, 3); // $ExpectType any
bencode.decode(new Buffer("abcde"), 1, 3, "utf-8"); // $ExpectType any
bencode.decode(new Buffer("abcde"), 1, "utf-8"); // $ExpectType any
bencode.decode(new Buffer("abcde"), "utf-8"); // $ExpectType any

bencode.encode([1, 2, 3, 4]); // $ExpectType Uint8Array || Uint8Array<ArrayBuffer>
bencode.encode([1, 2, 3, 4], new Uint8Array(100)); // $ExpectType Uint8Array || Uint8Array<ArrayBuffer>
bencode.encode([1, 2, 3, 4], new Uint8Array(100), 0); // $ExpectType Uint8Array || Uint8Array<ArrayBuffer>

bencode.encode.bytes; // $ExpectType number
bencode.encode._floatConversionDetected; // $ExpectType boolean

bencode.decode(new Uint8Array([100, 51, 58, 97, 98, 99, 101])); // $ExpectType any
bencode.decode(new Uint8Array([100, 51, 58, 97, 98, 99, 101]), "utf-8"); // $ExpectType any
bencode.decode(new Uint8Array([100, 51, 58, 97, 98, 99, 101]), 1, 3); // $ExpectType any
bencode.decode(new Uint8Array([100, 51, 58, 97, 98, 99, 101]), 1, 3, "utf-8"); // $ExpectType any
bencode.decode(new Uint8Array([100, 51, 58, 97, 98, 99, 101]), 1, "utf-8"); // $ExpectType any

bencode.decode.bytes; // $ExpectType number
65 changes: 52 additions & 13 deletions types/bencode/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
/// <reference types="node" />

export function byteLength(value: any): number;
export function encodingLength(value: any): number;
export function encode(data: any, buffer?: Buffer, offset?: number): Buffer;
export function decode(data: Buffer, encoding?: string): any;
export function decode(data: Buffer, start?: number, encoding?: string): any;
export function decode(
data: Buffer,
start?: number,
end?: number,
encoding?: string,
): any;
/**
* Determines the amount of bytes needed to encode the given value.
*/
declare function byteLength(value: any): number;

/**
* Determines the amount of bytes needed to encode the given value.
* Alias for {@link byteLength}.
*/
declare function encodingLength(value: any): number;

/**
* Encodes data in bencode.
*
* @param data Data to encode. Supports Uint8Array, Array, String, Object, Number, Boolean, Map, Set.
* @param buffer If provided, the encoded data will be written into this buffer at the given offset.
* @param offset Offset into the buffer to start writing.
* @returns The encoded data as a Uint8Array, or the provided buffer.
*/
declare function encode(data: any, buffer?: Uint8Array, offset?: number): Uint8Array;
declare namespace encode {
/** The number of bytes written in the last encode call. */
let bytes: number;
/** Set to true if a float value was coerced to an integer during encoding. */
let _floatConversionDetected: boolean;
}

/**
* Decodes bencoded data.
*
* @param data The bencoded data to decode.
* @param start Optional start position in the data buffer.
* @param end Optional end position in the data buffer.
* @param encoding If provided, byte strings will be automatically converted to strings using this encoding.
* @returns The decoded data.
*/
declare function decode(data: Uint8Array | string, encoding?: string): any;
declare function decode(data: Uint8Array | string, start?: number, encoding?: string): any;
declare function decode(data: Uint8Array | string, start?: number, end?: number, encoding?: string): any;
declare namespace decode {
/** The number of bytes consumed in the last decode call. */
let bytes: number;
}

declare const bencode: {
byteLength: typeof byteLength;
encodingLength: typeof encodingLength;
encode: typeof encode;
decode: typeof decode;
};

export default bencode;
15 changes: 10 additions & 5 deletions types/bencode/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
{
"private": true,
"name": "@types/bencode",
"version": "2.0.9999",
"version": "4.0.9999",
"type": "module",
"exports": {
".": {
"types": {
"default": "./index.d.ts"
}
}
},
"projects": [
"https://github.com/themasch/node-bencode#readme"
"https://github.com/webtorrent/node-bencode#readme"
],
"dependencies": {
"@types/node": "*"
},
"devDependencies": {
"@types/bencode": "workspace:."
},
Expand Down
15 changes: 8 additions & 7 deletions types/xrm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6016,13 +6016,6 @@ declare namespace Xrm {
* @see {@link https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-webapi External Link: Xrm.WebApi (Client API reference)}
*/
interface WebApi extends WebApiOffline {
/**
* Returns a boolean value indicating whether an entity is offline enabled.
* @param entityLogicalName Logical name of the entity. For example: "account".
* @returns true if the entity is offline enabled; otherwise false.
*/
isAvailableOffline(entityLogicalName: string): boolean;

/**
* Provides methods to use Web API to create and manage records and execute Web API actions and functions in Customer Engagement when connected to the Customer Engagement server (online mode).
* @see {@link https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-webapi/online External Link: Xrm.WebApi.online (Client API reference)}
Expand Down Expand Up @@ -6159,6 +6152,14 @@ declare namespace Xrm {
* @see {@link https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-webapi/updaterecord External Link: updateRecord (Client API reference)}
*/
updateRecord(entityLogicalName: string, id: string, data: any): Async.PromiseLike<UpdateResponse>;

/**
* Returns a boolean value indicating whether an entity is offline enabled.
* @param entityLogicalName Logical name of the entity. For example: "account".
* @returns true if the entity is offline enabled; otherwise false.
* @see {@link https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-webapi/isavailableoffline External Link: isAvailableOffline (Client API reference)}
*/
isAvailableOffline(entityLogicalName: string): boolean;
}

/**
Expand Down
21 changes: 21 additions & 0 deletions types/xrm/xrm-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,3 +844,24 @@ function testItemCollectionGet(formContext: Xrm.FormContext) {
// $ExpectType Tab
formContext.ui.tabs.get<Xrm.Controls.Tab>("tabName");
}
// Demonstrate Xrm.WebApi.offline.isAvailableOffline

// Test with a typical entity logical name
// $ExpectType boolean
const isAccountAvailableOffline = Xrm.WebApi.offline.isAvailableOffline("account");

// Test with a custom entity logical name
// $ExpectType boolean
const isCustomEntityAvailableOffline = Xrm.WebApi.offline.isAvailableOffline("new_customentity");

// Should error with missing parameter
// @ts-expect-error
Xrm.WebApi.offline.isAvailableOffline();

// Should error with a non-string parameter
// @ts-expect-error
Xrm.WebApi.offline.isAvailableOffline(12345);

// Should error with extra parameters
// @ts-expect-error
Xrm.WebApi.offline.isAvailableOffline("account", "extra");