Skip to content

Commit c3267a6

Browse files
authored
🤖 Merge PR DefinitelyTyped#74501 Update Environment to support Crypto API by @idleberg
1 parent ec30052 commit c3267a6

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

types/nova-editor-node/index.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,24 @@ interface Credentials {
328328
removePassword(service: string, user: User): null;
329329
}
330330

331+
/// https://docs.nova.app/api-reference/crypto/
332+
333+
type IntegerTypedArray =
334+
| Int8Array
335+
| Uint8Array
336+
| Uint8ClampedArray
337+
| Int16Array
338+
| Uint16Array
339+
| Int32Array
340+
| Uint32Array
341+
| BigInt64Array
342+
| BigUint64Array;
343+
344+
interface Crypto {
345+
getRandomValues<T extends IntegerTypedArray>(typedArray: T): T;
346+
randomUUID(): string;
347+
}
348+
331349
/// https://docs.nova.app/api-reference/disposable/
332350

333351
declare class Disposable {
@@ -359,6 +377,7 @@ interface Environment {
359377
readonly clipboard: Clipboard;
360378
readonly config: Configuration;
361379
readonly credentials: Credentials;
380+
readonly crypto: Crypto;
362381
readonly extension: Extension;
363382
readonly environment: { [key: string]: string };
364383
readonly path: Path;

types/nova-editor-node/nova-editor-node-tests.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ const charset2 = charset1.intersect(Charset.letters);
102102
// $ExpectType Promise<string>
103103
nova.clipboard.readText();
104104

105+
/// https://docs.nova.app/api-reference/crypto/
106+
107+
const uint8Array = new Uint8Array(16);
108+
// $ExpectType Uint8Array || Uint8Array<ArrayBuffer>
109+
nova.crypto.getRandomValues(uint8Array);
110+
111+
const int32Array = new Int32Array(10);
112+
// $ExpectType Int32Array || Int32Array<ArrayBuffer>
113+
nova.crypto.getRandomValues(int32Array);
114+
115+
const bigUint64Array = new BigUint64Array(4);
116+
// $ExpectType BigUint64Array || BigUint64Array<ArrayBuffer>
117+
nova.crypto.getRandomValues(bigUint64Array);
118+
119+
// $ExpectType string
120+
nova.crypto.randomUUID();
121+
105122
/// https://novadocs.panic.com/api-reference/completion-item/
106123

107124
const completionItem = new CompletionItem("label", CompletionItemKind.Struct);

0 commit comments

Comments
 (0)