Skip to content

Commit

Permalink
JS2 Backend Typescript fixes (rust-diplomat#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
ambiguousname authored Jul 17, 2024
1 parent 7e97f85 commit 41dc4a1
Show file tree
Hide file tree
Showing 62 changed files with 195 additions and 229 deletions.
10 changes: 4 additions & 6 deletions example/js/lib/api/diplomat-runtime.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/js2/api/DataProvider.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated by diplomat-tool
import type { u8, i8, u16, i16, u32, i32, u64, i64, usize, isize, f32, f64, pointer, char } from "./diplomat-runtime.d.ts";
import type { pointer, char } from "./diplomat-runtime.d.ts";


/** An data provider, capable of loading data keys from some source.
Expand Down
2 changes: 1 addition & 1 deletion example/js2/api/FixedDecimal.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated by diplomat-tool
import type { u8, i8, u16, i16, u32, i32, u64, i64, usize, isize, f32, f64, pointer, char } from "./diplomat-runtime.d.ts";
import type { pointer, char } from "./diplomat-runtime.d.ts";


/** See the [Rust documentation for `FixedDecimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html) for more information.
Expand Down
2 changes: 1 addition & 1 deletion example/js2/api/FixedDecimalFormatter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { DataProvider } from "./DataProvider"
import type { FixedDecimal } from "./FixedDecimal"
import type { FixedDecimalFormatterOptions } from "./FixedDecimalFormatterOptions"
import type { Locale } from "./Locale"
import type { u8, i8, u16, i16, u32, i32, u64, i64, usize, isize, f32, f64, pointer, char } from "./diplomat-runtime.d.ts";
import type { pointer, char } from "./diplomat-runtime.d.ts";


/** An Fixed Decimal Format object, capable of formatting a [`FixedDecimal`] as a string.
Expand Down
2 changes: 1 addition & 1 deletion example/js2/api/FixedDecimalFormatterOptions.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// generated by diplomat-tool
import type { FixedDecimalGroupingStrategy } from "./FixedDecimalGroupingStrategy"
import type { u8, i8, u16, i16, u32, i32, u64, i64, usize, isize, f32, f64, pointer, char } from "./diplomat-runtime.d.ts";
import type { pointer, char } from "./diplomat-runtime.d.ts";

export class FixedDecimalFormatterOptions {
#groupingStrategy;
Expand Down
2 changes: 1 addition & 1 deletion example/js2/api/FixedDecimalGroupingStrategy.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated by diplomat-tool
import type { u8, i8, u16, i16, u32, i32, u64, i64, usize, isize, f32, f64, pointer, char } from "./diplomat-runtime.d.ts";
import type { pointer, char } from "./diplomat-runtime.d.ts";

// Base enumerator definition
export class FixedDecimalGroupingStrategy {
Expand Down
2 changes: 1 addition & 1 deletion example/js2/api/Locale.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated by diplomat-tool
import type { u8, i8, u16, i16, u32, i32, u64, i64, usize, isize, f32, f64, pointer, char } from "./diplomat-runtime.d.ts";
import type { pointer, char } from "./diplomat-runtime.d.ts";


/** An Locale, capable of representing strings like `"en-US"`.
Expand Down
12 changes: 0 additions & 12 deletions example/js2/api/diplomat-runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,5 @@ export class FFIError<E> extends Error {
error_value: E;
}

export type u8 = number;
export type i8 = number;
export type u16 = number;
export type i16 = number;
export type u32 = number;
export type i32 = number;
export type u64 = bigint;
export type i64 = bigint;
export type usize = number;
export type isize = number;
export type f32 = number;
export type f64 = number;
export type char = string;
export type pointer = number;
10 changes: 4 additions & 6 deletions example/js2/api/diplomat-runtime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class DiplomatBuf {
}

static slice = (wasm, list, rustType) => {
const elementSize = rustType == "u8" || rustType == "i8" || rustType == "bool" ? 1 :
const elementSize = rustType == "u8" || rustType == "i8" || rustType == "boolean" ? 1 :
rustType == "u16" || rustType == "i16" ? 2 :
rustType == "u64" || rustType == "i64" || rustType == "f64" ? 8 :
4;
Expand All @@ -115,11 +115,11 @@ export class DiplomatBuf {

// Create an array view of the buffer. This gives us the `set` method which correctly handles untyped values
const destination =
rustType == "u8" || rustType == "bool" ? new Uint8Array(wasm.memory.buffer, ptr, byteLength) :
rustType == "u8" || rustType == "boolean" ? new Uint8Array(wasm.memory.buffer, ptr, byteLength) :
rustType == "i8" ? new Int8Array(wasm.memory.buffer, ptr, byteLength) :
rustType == "u16" ? new Uint16Array(wasm.memory.buffer, ptr, byteLength) :
rustType == "i16" ? new Int16Array(wasm.memory.buffer, ptr, byteLength) :
rustType == "i32" || rustType == "isize" ? new Int32Array(wasm.memory.buffer, ptr, byteLength) :
rustType == "i32" ? new Int32Array(wasm.memory.buffer, ptr, byteLength) :
rustType == "u64" ? new BigUint64Array(wasm.memory.buffer, ptr, byteLength) :
rustType == "i64" ? new BigInt64Array(wasm.memory.buffer, ptr, byteLength) :
rustType == "f32" ? new Float32Array(wasm.memory.buffer, ptr, byteLength) :
Expand Down Expand Up @@ -160,7 +160,7 @@ export class DiplomatBuf {
var arrayType;
switch (bufferType) {
case "u8":
case "bool":
case "boolean":
arrayType = Uint8Array;
break;
case "i8":
Expand All @@ -173,11 +173,9 @@ export class DiplomatBuf {
arrayType = Int16Array;
break;
case "i32":
case "isize":
arrayType = Int32Array;
break;
case "u32":
case "usize":
arrayType = Uint32Array;
break;
case "i64":
Expand Down
14 changes: 7 additions & 7 deletions example/js2/api/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

export { FFIError, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, char } from './diplomat-runtime';
export { FFIError, char } from './diplomat-runtime';


export { FixedDecimalFormatterOptions } from "./FixedDecimalFormatterOptions.mjs"
export { FixedDecimalFormatterOptions } from "./FixedDecimalFormatterOptions"

export { DataProvider } from "./DataProvider.mjs"
export { DataProvider } from "./DataProvider"

export { FixedDecimalFormatter } from "./FixedDecimalFormatter.mjs"
export { FixedDecimalFormatter } from "./FixedDecimalFormatter"

export { FixedDecimal } from "./FixedDecimal.mjs"
export { FixedDecimal } from "./FixedDecimal"

export { Locale } from "./Locale.mjs"
export { Locale } from "./Locale"

export { FixedDecimalGroupingStrategy } from "./FixedDecimalGroupingStrategy.mjs"
export { FixedDecimalGroupingStrategy } from "./FixedDecimalGroupingStrategy"
6 changes: 3 additions & 3 deletions feature_tests/js/api/Float64Vec.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions feature_tests/js/api/diplomat-runtime.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js2/api/AttrOpaque1Renamed.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js2/api/Bar.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js2/api/BorrowedFields.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js2/api/BorrowedFieldsReturning.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js2/api/BorrowedFieldsWithBounds.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js2/api/ContiguousEnum.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js2/api/CyclicStructA.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js2/api/CyclicStructB.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js2/api/ErrorEnum.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js2/api/ErrorStruct.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions feature_tests/js2/api/Float64Vec.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions feature_tests/js2/api/Float64Vec.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js2/api/Foo.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js2/api/ImportedStruct.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js2/api/MyEnum.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 41dc4a1

Please sign in to comment.