Files
tubestation/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustSuggest.sys.mjs
Ben Dean-Kawamura 90368cc237 Bug 1955298 - uniffi-bindgen-gecko-js: start using the IR pipeline, r=markh,frontend-codestyle-reviewers
Updated the uniffi-bindgen-gecko-js code to use two things I've been
experimenting with:

* Use the IR pipeline code to generate the structs used to render the
  templates.
* A new test fixture for bindings generators.  This one targets bindings
  generators specifically, it doesn't try test the scaffolding code and
  it's not based on real-world example code.  I originally thought it
  would be a single crate, but I ended up needed 2 in order to test
  external types. (https://bugzilla.mozilla.org/show_bug.cgi?id=1948961)

Differential Revision: https://phabricator.services.mozilla.com/D242385
2025-05-14 21:15:20 +00:00

4128 lines
130 KiB
JavaScript

// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
// Trust me, you don't want to mess with it!
import { UniFFITypeError } from "resource://gre/modules/UniFFI.sys.mjs";
// Objects intended to be used in the unit tests
export var UnitTestObjs = {};
// Write/Read data to/from an ArrayBuffer
class ArrayBufferDataStream {
constructor(arrayBuffer) {
this.dataView = new DataView(arrayBuffer);
this.pos = 0;
}
readUint8() {
let rv = this.dataView.getUint8(this.pos);
this.pos += 1;
return rv;
}
writeUint8(value) {
this.dataView.setUint8(this.pos, value);
this.pos += 1;
}
readUint16() {
let rv = this.dataView.getUint16(this.pos);
this.pos += 2;
return rv;
}
writeUint16(value) {
this.dataView.setUint16(this.pos, value);
this.pos += 2;
}
readUint32() {
let rv = this.dataView.getUint32(this.pos);
this.pos += 4;
return rv;
}
writeUint32(value) {
this.dataView.setUint32(this.pos, value);
this.pos += 4;
}
readUint64() {
let rv = this.dataView.getBigUint64(this.pos);
this.pos += 8;
return Number(rv);
}
writeUint64(value) {
this.dataView.setBigUint64(this.pos, BigInt(value));
this.pos += 8;
}
readInt8() {
let rv = this.dataView.getInt8(this.pos);
this.pos += 1;
return rv;
}
writeInt8(value) {
this.dataView.setInt8(this.pos, value);
this.pos += 1;
}
readInt16() {
let rv = this.dataView.getInt16(this.pos);
this.pos += 2;
return rv;
}
writeInt16(value) {
this.dataView.setInt16(this.pos, value);
this.pos += 2;
}
readInt32() {
let rv = this.dataView.getInt32(this.pos);
this.pos += 4;
return rv;
}
writeInt32(value) {
this.dataView.setInt32(this.pos, value);
this.pos += 4;
}
readInt64() {
let rv = this.dataView.getBigInt64(this.pos);
this.pos += 8;
return Number(rv);
}
writeInt64(value) {
this.dataView.setBigInt64(this.pos, BigInt(value));
this.pos += 8;
}
readFloat32() {
let rv = this.dataView.getFloat32(this.pos);
this.pos += 4;
return rv;
}
writeFloat32(value) {
this.dataView.setFloat32(this.pos, value);
this.pos += 4;
}
readFloat64() {
let rv = this.dataView.getFloat64(this.pos);
this.pos += 8;
return rv;
}
writeFloat64(value) {
this.dataView.setFloat64(this.pos, value);
this.pos += 8;
}
writeString(value) {
const encoder = new TextEncoder();
// Note: in order to efficiently write this data, we first write the
// string data, reserving 4 bytes for the size.
const dest = new Uint8Array(this.dataView.buffer, this.pos + 4);
const encodeResult = encoder.encodeInto(value, dest);
if (encodeResult.read != value.length) {
throw new UniFFIError(
"writeString: out of space when writing to ArrayBuffer. Did the computeSize() method returned the wrong result?"
);
}
const size = encodeResult.written;
// Next, go back and write the size before the string data
this.dataView.setUint32(this.pos, size);
// Finally, advance our position past both the size and string data
this.pos += size + 4;
}
readString() {
const decoder = new TextDecoder();
const size = this.readUint32();
const source = new Uint8Array(this.dataView.buffer, this.pos, size)
const value = decoder.decode(source);
this.pos += size;
return value;
}
readBytes() {
const size = this.readInt32();
const bytes = new Uint8Array(this.dataView.buffer, this.pos, size);
this.pos += size;
return bytes
}
writeBytes(value) {
this.writeUint32(value.length);
value.forEach((elt) => {
this.writeUint8(elt);
})
}
// Reads a pointer from the data stream
// UniFFI Pointers are **always** 8 bytes long. That is enforced
// by the C++ and Rust Scaffolding code.
readPointer(pointerId) {
const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos);
this.pos += 8;
return res;
}
// Writes a pointer into the data stream
// UniFFI Pointers are **always** 8 bytes long. That is enforced
// by the C++ and Rust Scaffolding code.
writePointer(pointerId, value) {
UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos);
this.pos += 8;
}
}
function handleRustResult(result, liftCallback, liftErrCallback) {
switch (result.code) {
case "success":
return liftCallback(result.data);
case "error":
throw liftErrCallback(result.data);
case "internal-error":
if (result.data) {
throw new UniFFIInternalError(FfiConverterString.lift(result.data));
} else {
throw new UniFFIInternalError("Unknown error");
}
default:
throw new UniFFIError(`Unexpected status code: ${result.code}`);
}
}
class UniFFIError {
constructor(message) {
this.message = message;
}
toString() {
return `UniFFIError: ${this.message}`
}
}
class UniFFIInternalError extends UniFFIError {}
// Base class for FFI converters
class FfiConverter {
// throw `UniFFITypeError` if a value to be converted has an invalid type
static checkType(value) {
if (value === undefined ) {
throw new UniFFITypeError(`undefined`);
}
if (value === null ) {
throw new UniFFITypeError(`null`);
}
}
}
// Base class for FFI converters that lift/lower by reading/writing to an ArrayBuffer
class FfiConverterArrayBuffer extends FfiConverter {
static lift(buf) {
return this.read(new ArrayBufferDataStream(buf));
}
static lower(value) {
const buf = new ArrayBuffer(this.computeSize(value));
const dataStream = new ArrayBufferDataStream(buf);
this.write(dataStream, value);
return buf;
}
/**
* Computes the size of the value.
*
* @param {*} _value
* @return {number}
*/
static computeSize(_value) {
throw new UniFFIInternalError("computeSize() should be declared in the derived class");
}
/**
* Reads the type from a data stream.
*
* @param {ArrayBufferDataStream} _dataStream
* @returns {any}
*/
static read(_dataStream) {
throw new UniFFIInternalError("read() should be declared in the derived class");
}
/**
* Writes the type to a data stream.
*
* @param {ArrayBufferDataStream} _dataStream
* @param {any} _value
*/
static write(_dataStream, _value) {
throw new UniFFIInternalError("write() should be declared in the derived class");
}
}
// Symbols that are used to ensure that Object constructors
// can only be used with a proper UniFFI pointer
const uniffiObjectPtr = Symbol("uniffiObjectPtr");
const constructUniffiObject = Symbol("constructUniffiObject");
UnitTestObjs.uniffiObjectPtr = uniffiObjectPtr;
/**
* Determines whether a "raw" sponsored suggestion URL is equivalent to a
* "cooked" URL. The two URLs are equivalent if they are identical except for
* their replaced template parameters, which can be different.
*/
export function rawSuggestionUrlMatches(
rawUrl,
cookedUrl) {
FfiConverterString.checkType(rawUrl);
FfiConverterString.checkType(cookedUrl);
const result = UniFFIScaffolding.callSync(
34, // uniffi_suggest_fn_func_raw_suggestion_url_matches
FfiConverterString.lower(rawUrl),
FfiConverterString.lower(cookedUrl),
)
return handleRustResult(
result,
FfiConverterBoolean.lift.bind(FfiConverterBoolean),
null,
)
}
// Export the FFIConverter object to make external types work.
export class FfiConverterBoolean extends FfiConverter {
static computeSize(_value) {
return 1;
}
static lift(value) {
return value == 1;
}
static lower(value) {
if (value) {
return 1;
} else {
return 0;
}
}
static write(dataStream, value) {
dataStream.writeUint8(this.lower(value))
}
static read(dataStream) {
return this.lift(dataStream.readUint8())
}
}
/**
* Additional data about how an FTS match was made
*/
export class FtsMatchInfo {
constructor(
{
prefix,
stemming
} = {
prefix: undefined,
stemming: undefined
}
) {
try {
FfiConverterBoolean.checkType(prefix)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("prefix");
}
throw e;
}
try {
FfiConverterBoolean.checkType(stemming)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("stemming");
}
throw e;
}
/**
* Was this a prefix match (`water b` matched against `water bottle`)
*/
this.prefix = prefix;
/**
* Did the match require stemming? (`run shoes` matched against `running shoes`)
*/
this.stemming = stemming;
}
equals(other) {
return (
this.prefix == other.prefix
&& this.stemming == other.stemming
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeFtsMatchInfo extends FfiConverterArrayBuffer {
static read(dataStream) {
return new FtsMatchInfo({
prefix: FfiConverterBoolean.read(dataStream),
stemming: FfiConverterBoolean.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterBoolean.write(dataStream, value.prefix);
FfiConverterBoolean.write(dataStream, value.stemming);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterBoolean.computeSize(value.prefix);
totalSize += FfiConverterBoolean.computeSize(value.stemming);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof FtsMatchInfo)) {
throw new UniFFITypeError(`Expected 'FtsMatchInfo', found '${typeof value}'`);
}
try {
FfiConverterBoolean.checkType(value.prefix);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".prefix");
}
throw e;
}
try {
FfiConverterBoolean.checkType(value.stemming);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".stemming");
}
throw e;
}
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterInt64 extends FfiConverter {
static checkType(value) {
super.checkType(value);
if (!Number.isSafeInteger(value)) {
throw new UniFFITypeError(`${value} exceeds the safe integer bounds`);
}
}
static computeSize(_value) {
return 8;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeInt64(value)
}
static read(dataStream) {
return dataStream.readInt64()
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterString extends FfiConverter {
static checkType(value) {
super.checkType(value);
if (typeof value !== "string") {
throw new UniFFITypeError(`${value} is not a string`);
}
}
static lift(buf) {
const decoder = new TextDecoder();
const utf8Arr = new Uint8Array(buf);
return decoder.decode(utf8Arr);
}
static lower(value) {
const encoder = new TextEncoder();
return encoder.encode(value).buffer;
}
static write(dataStream, value) {
dataStream.writeString(value);
}
static read(dataStream) {
return dataStream.readString();
}
static computeSize(value) {
const encoder = new TextEncoder();
return 4 + encoder.encode(value).length
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterFloat64 extends FfiConverter {
static computeSize(_value) {
return 8;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeFloat64(value)
}
static read(dataStream) {
return dataStream.readFloat64()
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterUInt64 extends FfiConverter {
static checkType(value) {
super.checkType(value);
if (!Number.isSafeInteger(value)) {
throw new UniFFITypeError(`${value} exceeds the safe integer bounds`);
}
if (value < 0) {
throw new UniFFITypeError(`${value} exceeds the U64 bounds`);
}
}
static computeSize(_value) {
return 8;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeUint64(value)
}
static read(dataStream) {
return dataStream.readUint64()
}
}
/**
* A single geographic place.
*
* This corresponds to a single row in the main "geoname" table described in
* the GeoNames documentation [1]. We exclude fields we don't need.
*
* [1]: https://download.geonames.org/export/dump/readme.txt
*/
export class Geoname {
constructor(
{
geonameId,
name,
latitude,
longitude,
countryCode,
admin1Code,
population
} = {
geonameId: undefined,
name: undefined,
latitude: undefined,
longitude: undefined,
countryCode: undefined,
admin1Code: undefined,
population: undefined
}
) {
try {
FfiConverterInt64.checkType(geonameId)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("geonameId");
}
throw e;
}
try {
FfiConverterString.checkType(name)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("name");
}
throw e;
}
try {
FfiConverterFloat64.checkType(latitude)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("latitude");
}
throw e;
}
try {
FfiConverterFloat64.checkType(longitude)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("longitude");
}
throw e;
}
try {
FfiConverterString.checkType(countryCode)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("countryCode");
}
throw e;
}
try {
FfiConverterString.checkType(admin1Code)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("admin1Code");
}
throw e;
}
try {
FfiConverterUInt64.checkType(population)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("population");
}
throw e;
}
/**
* The `geonameid` straight from the geoname table.
*/
this.geonameId = geonameId;
/**
* This is pretty much the place's canonical name. Usually there will be a
* row in the alternates table with the same name, but not always. When
* there is such a row, it doesn't always have `is_preferred_name` set, and
* in fact fact there may be another row with a different name with
* `is_preferred_name` set.
*/
this.name = name;
/**
* Latitude in decimal degrees.
*/
this.latitude = latitude;
/**
* Longitude in decimal degrees.
*/
this.longitude = longitude;
/**
* ISO-3166 two-letter uppercase country code, e.g., "US".
*/
this.countryCode = countryCode;
/**
* The top-level administrative region for the place within its country,
* like a state or province. For the U.S., the two-letter uppercase state
* abbreviation.
*/
this.admin1Code = admin1Code;
/**
* Population size.
*/
this.population = population;
}
equals(other) {
return (
this.geonameId == other.geonameId
&& this.name == other.name
&& this.latitude == other.latitude
&& this.longitude == other.longitude
&& this.countryCode == other.countryCode
&& this.admin1Code == other.admin1Code
&& this.population == other.population
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeGeoname extends FfiConverterArrayBuffer {
static read(dataStream) {
return new Geoname({
geonameId: FfiConverterInt64.read(dataStream),
name: FfiConverterString.read(dataStream),
latitude: FfiConverterFloat64.read(dataStream),
longitude: FfiConverterFloat64.read(dataStream),
countryCode: FfiConverterString.read(dataStream),
admin1Code: FfiConverterString.read(dataStream),
population: FfiConverterUInt64.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterInt64.write(dataStream, value.geonameId);
FfiConverterString.write(dataStream, value.name);
FfiConverterFloat64.write(dataStream, value.latitude);
FfiConverterFloat64.write(dataStream, value.longitude);
FfiConverterString.write(dataStream, value.countryCode);
FfiConverterString.write(dataStream, value.admin1Code);
FfiConverterUInt64.write(dataStream, value.population);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterInt64.computeSize(value.geonameId);
totalSize += FfiConverterString.computeSize(value.name);
totalSize += FfiConverterFloat64.computeSize(value.latitude);
totalSize += FfiConverterFloat64.computeSize(value.longitude);
totalSize += FfiConverterString.computeSize(value.countryCode);
totalSize += FfiConverterString.computeSize(value.admin1Code);
totalSize += FfiConverterUInt64.computeSize(value.population);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof Geoname)) {
throw new UniFFITypeError(`Expected 'Geoname', found '${typeof value}'`);
}
try {
FfiConverterInt64.checkType(value.geonameId);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".geonameId");
}
throw e;
}
try {
FfiConverterString.checkType(value.name);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".name");
}
throw e;
}
try {
FfiConverterFloat64.checkType(value.latitude);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".latitude");
}
throw e;
}
try {
FfiConverterFloat64.checkType(value.longitude);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".longitude");
}
throw e;
}
try {
FfiConverterString.checkType(value.countryCode);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".countryCode");
}
throw e;
}
try {
FfiConverterString.checkType(value.admin1Code);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".admin1Code");
}
throw e;
}
try {
FfiConverterUInt64.checkType(value.population);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".population");
}
throw e;
}
}
}
/**
* GeonameMatchType
*/
export const GeonameMatchType = {
/**
* For U.S. states, abbreviations are the usual two-letter codes ("CA").
*/
ABBREVIATION: 1,
/**
* AIRPORT_CODE
*/
AIRPORT_CODE: 2,
/**
* This includes any names that aren't abbreviations or airport codes.
*/
NAME: 3,
};
Object.freeze(GeonameMatchType);
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeGeonameMatchType extends FfiConverterArrayBuffer {
static read(dataStream) {
switch (dataStream.readInt32()) {
case 1:
return GeonameMatchType.ABBREVIATION
case 2:
return GeonameMatchType.AIRPORT_CODE
case 3:
return GeonameMatchType.NAME
default:
throw new UniFFITypeError("Unknown GeonameMatchType variant");
}
}
static write(dataStream, value) {
if (value === GeonameMatchType.ABBREVIATION) {
dataStream.writeInt32(1);
return;
}
if (value === GeonameMatchType.AIRPORT_CODE) {
dataStream.writeInt32(2);
return;
}
if (value === GeonameMatchType.NAME) {
dataStream.writeInt32(3);
return;
}
throw new UniFFITypeError("Unknown GeonameMatchType variant");
}
static computeSize(value) {
return 4;
}
static checkType(value) {
if (!Number.isInteger(value) || value < 1 || value > 3) {
throw new UniFFITypeError(`${value} is not a valid value for GeonameMatchType`);
}
}
}
/**
* A fetched geoname with info on how it was matched.
*/
export class GeonameMatch {
constructor(
{
geoname,
matchType,
prefix
} = {
geoname: undefined,
matchType: undefined,
prefix: undefined
}
) {
try {
FfiConverterTypeGeoname.checkType(geoname)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("geoname");
}
throw e;
}
try {
FfiConverterTypeGeonameMatchType.checkType(matchType)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("matchType");
}
throw e;
}
try {
FfiConverterBoolean.checkType(prefix)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("prefix");
}
throw e;
}
/**
* The geoname that was matched.
*/
this.geoname = geoname;
/**
* The type of name that was matched.
*/
this.matchType = matchType;
/**
* Whether the name was matched by prefix.
*/
this.prefix = prefix;
}
equals(other) {
return (
this.geoname.equals(other.geoname)
&& this.matchType == other.matchType
&& this.prefix == other.prefix
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeGeonameMatch extends FfiConverterArrayBuffer {
static read(dataStream) {
return new GeonameMatch({
geoname: FfiConverterTypeGeoname.read(dataStream),
matchType: FfiConverterTypeGeonameMatchType.read(dataStream),
prefix: FfiConverterBoolean.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterTypeGeoname.write(dataStream, value.geoname);
FfiConverterTypeGeonameMatchType.write(dataStream, value.matchType);
FfiConverterBoolean.write(dataStream, value.prefix);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterTypeGeoname.computeSize(value.geoname);
totalSize += FfiConverterTypeGeonameMatchType.computeSize(value.matchType);
totalSize += FfiConverterBoolean.computeSize(value.prefix);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof GeonameMatch)) {
throw new UniFFITypeError(`Expected 'GeonameMatch', found '${typeof value}'`);
}
try {
FfiConverterTypeGeoname.checkType(value.geoname);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".geoname");
}
throw e;
}
try {
FfiConverterTypeGeonameMatchType.checkType(value.matchType);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".matchType");
}
throw e;
}
try {
FfiConverterBoolean.checkType(value.prefix);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".prefix");
}
throw e;
}
}
}
/**
* Single sample for a Glean labeled_timing_distribution
*/
export class LabeledTimingSample {
constructor(
{
label,
value
} = {
label: undefined,
value: undefined
}
) {
try {
FfiConverterString.checkType(label)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("label");
}
throw e;
}
try {
FfiConverterUInt64.checkType(value)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("value");
}
throw e;
}
/**
* label
*/
this.label = label;
/**
* Time in microseconds
*/
this.value = value;
}
equals(other) {
return (
this.label == other.label
&& this.value == other.value
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeLabeledTimingSample extends FfiConverterArrayBuffer {
static read(dataStream) {
return new LabeledTimingSample({
label: FfiConverterString.read(dataStream),
value: FfiConverterUInt64.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterString.write(dataStream, value.label);
FfiConverterUInt64.write(dataStream, value.value);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterString.computeSize(value.label);
totalSize += FfiConverterUInt64.computeSize(value.value);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof LabeledTimingSample)) {
throw new UniFFITypeError(`Expected 'LabeledTimingSample', found '${typeof value}'`);
}
try {
FfiConverterString.checkType(value.label);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".label");
}
throw e;
}
try {
FfiConverterUInt64.checkType(value.value);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".value");
}
throw e;
}
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterBytes extends FfiConverterArrayBuffer {
static read(dataStream) {
return dataStream.readBytes()
}
static write(dataStream, value) {
dataStream.writeBytes(value)
}
static computeSize(value) {
// The size of the length + 1 byte / item
return 4 + value.length
}
static checkType(value) {
if (!value instanceof Uint8Array) {
throw new UniFFITypeError(`${value} is not an Uint8Array`);
}
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalBytes extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterBytes.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterBytes.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterBytes.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterBytes.computeSize(value)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalString extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterString.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterString.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterString.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterString.computeSize(value)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalTypeFtsMatchInfo extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterTypeFtsMatchInfo.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterTypeFtsMatchInfo.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterTypeFtsMatchInfo.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterTypeFtsMatchInfo.computeSize(value)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalFloat64 extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterFloat64.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterFloat64.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterFloat64.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterFloat64.computeSize(value)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeJsonValue extends FfiConverter {
static lift(buf) {
return FfiConverterString.lift(buf);
}
static lower(buf) {
return FfiConverterString.lower(buf);
}
static write(dataStream, value) {
FfiConverterString.write(dataStream, value);
}
static read(buf) {
return FfiConverterString.read(buf);
}
static computeSize(value) {
return FfiConverterString.computeSize(value);
}
}
// TODO: We should also allow JS to customize the type eventually.
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalTypeJsonValue extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterTypeJsonValue.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterTypeJsonValue.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterTypeJsonValue.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterTypeJsonValue.computeSize(value)
}
}
/**
* A suggestion from the database to show in the address bar.
*/
export class Suggestion {}
/**
* Amp
*/
Suggestion.Amp = class extends Suggestion{
constructor(
title,
url,
rawUrl,
icon,
iconMimetype,
fullKeyword,
blockId,
advertiser,
iabCategory,
impressionUrl,
clickUrl,
rawClickUrl,
score,
ftsMatchInfo
) {
super();
this.title = title;
this.url = url;
this.rawUrl = rawUrl;
this.icon = icon;
this.iconMimetype = iconMimetype;
this.fullKeyword = fullKeyword;
this.blockId = blockId;
this.advertiser = advertiser;
this.iabCategory = iabCategory;
this.impressionUrl = impressionUrl;
this.clickUrl = clickUrl;
this.rawClickUrl = rawClickUrl;
this.score = score;
this.ftsMatchInfo = ftsMatchInfo;
}
}
/**
* Pocket
*/
Suggestion.Pocket = class extends Suggestion{
constructor(
title,
url,
score,
isTopPick
) {
super();
this.title = title;
this.url = url;
this.score = score;
this.isTopPick = isTopPick;
}
}
/**
* Wikipedia
*/
Suggestion.Wikipedia = class extends Suggestion{
constructor(
title,
url,
icon,
iconMimetype,
fullKeyword
) {
super();
this.title = title;
this.url = url;
this.icon = icon;
this.iconMimetype = iconMimetype;
this.fullKeyword = fullKeyword;
}
}
/**
* Amo
*/
Suggestion.Amo = class extends Suggestion{
constructor(
title,
url,
iconUrl,
description,
rating,
numberOfRatings,
guid,
score
) {
super();
this.title = title;
this.url = url;
this.iconUrl = iconUrl;
this.description = description;
this.rating = rating;
this.numberOfRatings = numberOfRatings;
this.guid = guid;
this.score = score;
}
}
/**
* Yelp
*/
Suggestion.Yelp = class extends Suggestion{
constructor(
url,
title,
icon,
iconMimetype,
score,
hasLocationSign,
subjectExactMatch,
locationParam
) {
super();
this.url = url;
this.title = title;
this.icon = icon;
this.iconMimetype = iconMimetype;
this.score = score;
this.hasLocationSign = hasLocationSign;
this.subjectExactMatch = subjectExactMatch;
this.locationParam = locationParam;
}
}
/**
* Mdn
*/
Suggestion.Mdn = class extends Suggestion{
constructor(
title,
url,
description,
score
) {
super();
this.title = title;
this.url = url;
this.description = description;
this.score = score;
}
}
/**
* Weather
*/
Suggestion.Weather = class extends Suggestion{
constructor(
city,
region,
country,
latitude,
longitude,
score
) {
super();
this.city = city;
this.region = region;
this.country = country;
this.latitude = latitude;
this.longitude = longitude;
this.score = score;
}
}
/**
* Fakespot
*/
Suggestion.Fakespot = class extends Suggestion{
constructor(
fakespotGrade,
productId,
rating,
title,
totalReviews,
url,
icon,
iconMimetype,
score,
matchInfo
) {
super();
this.fakespotGrade = fakespotGrade;
this.productId = productId;
this.rating = rating;
this.title = title;
this.totalReviews = totalReviews;
this.url = url;
this.icon = icon;
this.iconMimetype = iconMimetype;
this.score = score;
this.matchInfo = matchInfo;
}
}
/**
* Dynamic
*/
Suggestion.Dynamic = class extends Suggestion{
constructor(
suggestionType,
data,
dismissalKey,
score
) {
super();
this.suggestionType = suggestionType;
this.data = data;
this.dismissalKey = dismissalKey;
this.score = score;
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeSuggestion extends FfiConverterArrayBuffer {
static read(dataStream) {
switch (dataStream.readInt32()) {
case 1:
return new Suggestion.Amp(
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterOptionalBytes.read(dataStream),
FfiConverterOptionalString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterInt64.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterFloat64.read(dataStream),
FfiConverterOptionalTypeFtsMatchInfo.read(dataStream)
);
case 2:
return new Suggestion.Pocket(
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterFloat64.read(dataStream),
FfiConverterBoolean.read(dataStream)
);
case 3:
return new Suggestion.Wikipedia(
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterOptionalBytes.read(dataStream),
FfiConverterOptionalString.read(dataStream),
FfiConverterString.read(dataStream)
);
case 4:
return new Suggestion.Amo(
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterOptionalString.read(dataStream),
FfiConverterInt64.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterFloat64.read(dataStream)
);
case 5:
return new Suggestion.Yelp(
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterOptionalBytes.read(dataStream),
FfiConverterOptionalString.read(dataStream),
FfiConverterFloat64.read(dataStream),
FfiConverterBoolean.read(dataStream),
FfiConverterBoolean.read(dataStream),
FfiConverterString.read(dataStream)
);
case 6:
return new Suggestion.Mdn(
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterFloat64.read(dataStream)
);
case 7:
return new Suggestion.Weather(
FfiConverterOptionalString.read(dataStream),
FfiConverterOptionalString.read(dataStream),
FfiConverterOptionalString.read(dataStream),
FfiConverterOptionalFloat64.read(dataStream),
FfiConverterOptionalFloat64.read(dataStream),
FfiConverterFloat64.read(dataStream)
);
case 8:
return new Suggestion.Fakespot(
FfiConverterString.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterFloat64.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterInt64.read(dataStream),
FfiConverterString.read(dataStream),
FfiConverterOptionalBytes.read(dataStream),
FfiConverterOptionalString.read(dataStream),
FfiConverterFloat64.read(dataStream),
FfiConverterOptionalTypeFtsMatchInfo.read(dataStream)
);
case 9:
return new Suggestion.Dynamic(
FfiConverterString.read(dataStream),
FfiConverterOptionalTypeJsonValue.read(dataStream),
FfiConverterOptionalString.read(dataStream),
FfiConverterFloat64.read(dataStream)
);
default:
throw new UniFFITypeError("Unknown Suggestion variant");
}
}
static write(dataStream, value) {
if (value instanceof Suggestion.Amp) {
dataStream.writeInt32(1);
FfiConverterString.write(dataStream, value.title);
FfiConverterString.write(dataStream, value.url);
FfiConverterString.write(dataStream, value.rawUrl);
FfiConverterOptionalBytes.write(dataStream, value.icon);
FfiConverterOptionalString.write(dataStream, value.iconMimetype);
FfiConverterString.write(dataStream, value.fullKeyword);
FfiConverterInt64.write(dataStream, value.blockId);
FfiConverterString.write(dataStream, value.advertiser);
FfiConverterString.write(dataStream, value.iabCategory);
FfiConverterString.write(dataStream, value.impressionUrl);
FfiConverterString.write(dataStream, value.clickUrl);
FfiConverterString.write(dataStream, value.rawClickUrl);
FfiConverterFloat64.write(dataStream, value.score);
FfiConverterOptionalTypeFtsMatchInfo.write(dataStream, value.ftsMatchInfo);
return;
}
if (value instanceof Suggestion.Pocket) {
dataStream.writeInt32(2);
FfiConverterString.write(dataStream, value.title);
FfiConverterString.write(dataStream, value.url);
FfiConverterFloat64.write(dataStream, value.score);
FfiConverterBoolean.write(dataStream, value.isTopPick);
return;
}
if (value instanceof Suggestion.Wikipedia) {
dataStream.writeInt32(3);
FfiConverterString.write(dataStream, value.title);
FfiConverterString.write(dataStream, value.url);
FfiConverterOptionalBytes.write(dataStream, value.icon);
FfiConverterOptionalString.write(dataStream, value.iconMimetype);
FfiConverterString.write(dataStream, value.fullKeyword);
return;
}
if (value instanceof Suggestion.Amo) {
dataStream.writeInt32(4);
FfiConverterString.write(dataStream, value.title);
FfiConverterString.write(dataStream, value.url);
FfiConverterString.write(dataStream, value.iconUrl);
FfiConverterString.write(dataStream, value.description);
FfiConverterOptionalString.write(dataStream, value.rating);
FfiConverterInt64.write(dataStream, value.numberOfRatings);
FfiConverterString.write(dataStream, value.guid);
FfiConverterFloat64.write(dataStream, value.score);
return;
}
if (value instanceof Suggestion.Yelp) {
dataStream.writeInt32(5);
FfiConverterString.write(dataStream, value.url);
FfiConverterString.write(dataStream, value.title);
FfiConverterOptionalBytes.write(dataStream, value.icon);
FfiConverterOptionalString.write(dataStream, value.iconMimetype);
FfiConverterFloat64.write(dataStream, value.score);
FfiConverterBoolean.write(dataStream, value.hasLocationSign);
FfiConverterBoolean.write(dataStream, value.subjectExactMatch);
FfiConverterString.write(dataStream, value.locationParam);
return;
}
if (value instanceof Suggestion.Mdn) {
dataStream.writeInt32(6);
FfiConverterString.write(dataStream, value.title);
FfiConverterString.write(dataStream, value.url);
FfiConverterString.write(dataStream, value.description);
FfiConverterFloat64.write(dataStream, value.score);
return;
}
if (value instanceof Suggestion.Weather) {
dataStream.writeInt32(7);
FfiConverterOptionalString.write(dataStream, value.city);
FfiConverterOptionalString.write(dataStream, value.region);
FfiConverterOptionalString.write(dataStream, value.country);
FfiConverterOptionalFloat64.write(dataStream, value.latitude);
FfiConverterOptionalFloat64.write(dataStream, value.longitude);
FfiConverterFloat64.write(dataStream, value.score);
return;
}
if (value instanceof Suggestion.Fakespot) {
dataStream.writeInt32(8);
FfiConverterString.write(dataStream, value.fakespotGrade);
FfiConverterString.write(dataStream, value.productId);
FfiConverterFloat64.write(dataStream, value.rating);
FfiConverterString.write(dataStream, value.title);
FfiConverterInt64.write(dataStream, value.totalReviews);
FfiConverterString.write(dataStream, value.url);
FfiConverterOptionalBytes.write(dataStream, value.icon);
FfiConverterOptionalString.write(dataStream, value.iconMimetype);
FfiConverterFloat64.write(dataStream, value.score);
FfiConverterOptionalTypeFtsMatchInfo.write(dataStream, value.matchInfo);
return;
}
if (value instanceof Suggestion.Dynamic) {
dataStream.writeInt32(9);
FfiConverterString.write(dataStream, value.suggestionType);
FfiConverterOptionalTypeJsonValue.write(dataStream, value.data);
FfiConverterOptionalString.write(dataStream, value.dismissalKey);
FfiConverterFloat64.write(dataStream, value.score);
return;
}
throw new UniFFITypeError("Unknown Suggestion variant");
}
static computeSize(value) {
// Size of the Int indicating the variant
let totalSize = 4;
if (value instanceof Suggestion.Amp) {
totalSize += FfiConverterString.computeSize(value.title);
totalSize += FfiConverterString.computeSize(value.url);
totalSize += FfiConverterString.computeSize(value.rawUrl);
totalSize += FfiConverterOptionalBytes.computeSize(value.icon);
totalSize += FfiConverterOptionalString.computeSize(value.iconMimetype);
totalSize += FfiConverterString.computeSize(value.fullKeyword);
totalSize += FfiConverterInt64.computeSize(value.blockId);
totalSize += FfiConverterString.computeSize(value.advertiser);
totalSize += FfiConverterString.computeSize(value.iabCategory);
totalSize += FfiConverterString.computeSize(value.impressionUrl);
totalSize += FfiConverterString.computeSize(value.clickUrl);
totalSize += FfiConverterString.computeSize(value.rawClickUrl);
totalSize += FfiConverterFloat64.computeSize(value.score);
totalSize += FfiConverterOptionalTypeFtsMatchInfo.computeSize(value.ftsMatchInfo);
return totalSize;
}
if (value instanceof Suggestion.Pocket) {
totalSize += FfiConverterString.computeSize(value.title);
totalSize += FfiConverterString.computeSize(value.url);
totalSize += FfiConverterFloat64.computeSize(value.score);
totalSize += FfiConverterBoolean.computeSize(value.isTopPick);
return totalSize;
}
if (value instanceof Suggestion.Wikipedia) {
totalSize += FfiConverterString.computeSize(value.title);
totalSize += FfiConverterString.computeSize(value.url);
totalSize += FfiConverterOptionalBytes.computeSize(value.icon);
totalSize += FfiConverterOptionalString.computeSize(value.iconMimetype);
totalSize += FfiConverterString.computeSize(value.fullKeyword);
return totalSize;
}
if (value instanceof Suggestion.Amo) {
totalSize += FfiConverterString.computeSize(value.title);
totalSize += FfiConverterString.computeSize(value.url);
totalSize += FfiConverterString.computeSize(value.iconUrl);
totalSize += FfiConverterString.computeSize(value.description);
totalSize += FfiConverterOptionalString.computeSize(value.rating);
totalSize += FfiConverterInt64.computeSize(value.numberOfRatings);
totalSize += FfiConverterString.computeSize(value.guid);
totalSize += FfiConverterFloat64.computeSize(value.score);
return totalSize;
}
if (value instanceof Suggestion.Yelp) {
totalSize += FfiConverterString.computeSize(value.url);
totalSize += FfiConverterString.computeSize(value.title);
totalSize += FfiConverterOptionalBytes.computeSize(value.icon);
totalSize += FfiConverterOptionalString.computeSize(value.iconMimetype);
totalSize += FfiConverterFloat64.computeSize(value.score);
totalSize += FfiConverterBoolean.computeSize(value.hasLocationSign);
totalSize += FfiConverterBoolean.computeSize(value.subjectExactMatch);
totalSize += FfiConverterString.computeSize(value.locationParam);
return totalSize;
}
if (value instanceof Suggestion.Mdn) {
totalSize += FfiConverterString.computeSize(value.title);
totalSize += FfiConverterString.computeSize(value.url);
totalSize += FfiConverterString.computeSize(value.description);
totalSize += FfiConverterFloat64.computeSize(value.score);
return totalSize;
}
if (value instanceof Suggestion.Weather) {
totalSize += FfiConverterOptionalString.computeSize(value.city);
totalSize += FfiConverterOptionalString.computeSize(value.region);
totalSize += FfiConverterOptionalString.computeSize(value.country);
totalSize += FfiConverterOptionalFloat64.computeSize(value.latitude);
totalSize += FfiConverterOptionalFloat64.computeSize(value.longitude);
totalSize += FfiConverterFloat64.computeSize(value.score);
return totalSize;
}
if (value instanceof Suggestion.Fakespot) {
totalSize += FfiConverterString.computeSize(value.fakespotGrade);
totalSize += FfiConverterString.computeSize(value.productId);
totalSize += FfiConverterFloat64.computeSize(value.rating);
totalSize += FfiConverterString.computeSize(value.title);
totalSize += FfiConverterInt64.computeSize(value.totalReviews);
totalSize += FfiConverterString.computeSize(value.url);
totalSize += FfiConverterOptionalBytes.computeSize(value.icon);
totalSize += FfiConverterOptionalString.computeSize(value.iconMimetype);
totalSize += FfiConverterFloat64.computeSize(value.score);
totalSize += FfiConverterOptionalTypeFtsMatchInfo.computeSize(value.matchInfo);
return totalSize;
}
if (value instanceof Suggestion.Dynamic) {
totalSize += FfiConverterString.computeSize(value.suggestionType);
totalSize += FfiConverterOptionalTypeJsonValue.computeSize(value.data);
totalSize += FfiConverterOptionalString.computeSize(value.dismissalKey);
totalSize += FfiConverterFloat64.computeSize(value.score);
return totalSize;
}
throw new UniFFITypeError("Unknown Suggestion variant");
}
static checkType(value) {
if (!(value instanceof Suggestion)) {
throw new UniFFITypeError(`${value} is not a subclass instance of Suggestion`);
}
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterSequenceTypeSuggestion extends FfiConverterArrayBuffer {
static read(dataStream) {
const len = dataStream.readInt32();
const arr = [];
for (let i = 0; i < len; i++) {
arr.push(FfiConverterTypeSuggestion.read(dataStream));
}
return arr;
}
static write(dataStream, value) {
dataStream.writeInt32(value.length);
value.forEach((innerValue) => {
FfiConverterTypeSuggestion.write(dataStream, innerValue);
})
}
static computeSize(value) {
// The size of the length
let size = 4;
for (const innerValue of value) {
size += FfiConverterTypeSuggestion.computeSize(innerValue);
}
return size;
}
static checkType(value) {
if (!Array.isArray(value)) {
throw new UniFFITypeError(`${value} is not an array`);
}
value.forEach((innerValue, idx) => {
try {
FfiConverterTypeSuggestion.checkType(innerValue);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(`[${idx}]`);
}
throw e;
}
})
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterSequenceTypeLabeledTimingSample extends FfiConverterArrayBuffer {
static read(dataStream) {
const len = dataStream.readInt32();
const arr = [];
for (let i = 0; i < len; i++) {
arr.push(FfiConverterTypeLabeledTimingSample.read(dataStream));
}
return arr;
}
static write(dataStream, value) {
dataStream.writeInt32(value.length);
value.forEach((innerValue) => {
FfiConverterTypeLabeledTimingSample.write(dataStream, innerValue);
})
}
static computeSize(value) {
// The size of the length
let size = 4;
for (const innerValue of value) {
size += FfiConverterTypeLabeledTimingSample.computeSize(innerValue);
}
return size;
}
static checkType(value) {
if (!Array.isArray(value)) {
throw new UniFFITypeError(`${value} is not an array`);
}
value.forEach((innerValue, idx) => {
try {
FfiConverterTypeLabeledTimingSample.checkType(innerValue);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(`[${idx}]`);
}
throw e;
}
})
}
}
/**
* QueryWithMetricsResult
*/
export class QueryWithMetricsResult {
constructor(
{
suggestions,
queryTimes
} = {
suggestions: undefined,
queryTimes: undefined
}
) {
try {
FfiConverterSequenceTypeSuggestion.checkType(suggestions)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("suggestions");
}
throw e;
}
try {
FfiConverterSequenceTypeLabeledTimingSample.checkType(queryTimes)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("queryTimes");
}
throw e;
}
/**
* suggestions
*/
this.suggestions = suggestions;
/**
* Samples for the `suggest.query_time` metric
*/
this.queryTimes = queryTimes;
}
equals(other) {
return (
this.suggestions == other.suggestions
&& this.queryTimes == other.queryTimes
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeQueryWithMetricsResult extends FfiConverterArrayBuffer {
static read(dataStream) {
return new QueryWithMetricsResult({
suggestions: FfiConverterSequenceTypeSuggestion.read(dataStream),
queryTimes: FfiConverterSequenceTypeLabeledTimingSample.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterSequenceTypeSuggestion.write(dataStream, value.suggestions);
FfiConverterSequenceTypeLabeledTimingSample.write(dataStream, value.queryTimes);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterSequenceTypeSuggestion.computeSize(value.suggestions);
totalSize += FfiConverterSequenceTypeLabeledTimingSample.computeSize(value.queryTimes);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof QueryWithMetricsResult)) {
throw new UniFFITypeError(`Expected 'QueryWithMetricsResult', found '${typeof value}'`);
}
try {
FfiConverterSequenceTypeSuggestion.checkType(value.suggestions);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".suggestions");
}
throw e;
}
try {
FfiConverterSequenceTypeLabeledTimingSample.checkType(value.queryTimes);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".queryTimes");
}
throw e;
}
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterInt32 extends FfiConverter {
static checkType(value) {
super.checkType(value);
if (!Number.isInteger(value)) {
throw new UniFFITypeError(`${value} is not an integer`);
}
if (value < -2147483648 || value > 2147483647) {
throw new UniFFITypeError(`${value} exceeds the I32 bounds`);
}
}
static computeSize(_value) {
return 4;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeInt32(value)
}
static read(dataStream) {
return dataStream.readInt32()
}
}
/**
* Global Suggest configuration data.
*/
export class SuggestGlobalConfig {
constructor(
{
showLessFrequentlyCap
} = {
showLessFrequentlyCap: undefined
}
) {
try {
FfiConverterInt32.checkType(showLessFrequentlyCap)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("showLessFrequentlyCap");
}
throw e;
}
/**
* showLessFrequentlyCap
*/
this.showLessFrequentlyCap = showLessFrequentlyCap;
}
equals(other) {
return (
this.showLessFrequentlyCap == other.showLessFrequentlyCap
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeSuggestGlobalConfig extends FfiConverterArrayBuffer {
static read(dataStream) {
return new SuggestGlobalConfig({
showLessFrequentlyCap: FfiConverterInt32.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterInt32.write(dataStream, value.showLessFrequentlyCap);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterInt32.computeSize(value.showLessFrequentlyCap);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof SuggestGlobalConfig)) {
throw new UniFFITypeError(`Expected 'SuggestGlobalConfig', found '${typeof value}'`);
}
try {
FfiConverterInt32.checkType(value.showLessFrequentlyCap);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".showLessFrequentlyCap");
}
throw e;
}
}
}
/**
* A provider is a source of search suggestions.
*/
export const SuggestionProvider = {
/**
* AMP
*/
AMP: 1,
/**
* WIKIPEDIA
*/
WIKIPEDIA: 2,
/**
* AMO
*/
AMO: 3,
/**
* POCKET
*/
POCKET: 4,
/**
* YELP
*/
YELP: 5,
/**
* MDN
*/
MDN: 6,
/**
* WEATHER
*/
WEATHER: 7,
/**
* FAKESPOT
*/
FAKESPOT: 8,
/**
* DYNAMIC
*/
DYNAMIC: 9,
};
Object.freeze(SuggestionProvider);
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeSuggestionProvider extends FfiConverterArrayBuffer {
static read(dataStream) {
switch (dataStream.readInt32()) {
case 1:
return SuggestionProvider.AMP
case 2:
return SuggestionProvider.WIKIPEDIA
case 3:
return SuggestionProvider.AMO
case 4:
return SuggestionProvider.POCKET
case 5:
return SuggestionProvider.YELP
case 6:
return SuggestionProvider.MDN
case 7:
return SuggestionProvider.WEATHER
case 8:
return SuggestionProvider.FAKESPOT
case 9:
return SuggestionProvider.DYNAMIC
default:
throw new UniFFITypeError("Unknown SuggestionProvider variant");
}
}
static write(dataStream, value) {
if (value === SuggestionProvider.AMP) {
dataStream.writeInt32(1);
return;
}
if (value === SuggestionProvider.WIKIPEDIA) {
dataStream.writeInt32(2);
return;
}
if (value === SuggestionProvider.AMO) {
dataStream.writeInt32(3);
return;
}
if (value === SuggestionProvider.POCKET) {
dataStream.writeInt32(4);
return;
}
if (value === SuggestionProvider.YELP) {
dataStream.writeInt32(5);
return;
}
if (value === SuggestionProvider.MDN) {
dataStream.writeInt32(6);
return;
}
if (value === SuggestionProvider.WEATHER) {
dataStream.writeInt32(7);
return;
}
if (value === SuggestionProvider.FAKESPOT) {
dataStream.writeInt32(8);
return;
}
if (value === SuggestionProvider.DYNAMIC) {
dataStream.writeInt32(9);
return;
}
throw new UniFFITypeError("Unknown SuggestionProvider variant");
}
static computeSize(value) {
return 4;
}
static checkType(value) {
if (!Number.isInteger(value) || value < 1 || value > 9) {
throw new UniFFITypeError(`${value} is not a valid value for SuggestionProvider`);
}
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterSequenceTypeSuggestionProvider extends FfiConverterArrayBuffer {
static read(dataStream) {
const len = dataStream.readInt32();
const arr = [];
for (let i = 0; i < len; i++) {
arr.push(FfiConverterTypeSuggestionProvider.read(dataStream));
}
return arr;
}
static write(dataStream, value) {
dataStream.writeInt32(value.length);
value.forEach((innerValue) => {
FfiConverterTypeSuggestionProvider.write(dataStream, innerValue);
})
}
static computeSize(value) {
// The size of the length
let size = 4;
for (const innerValue of value) {
size += FfiConverterTypeSuggestionProvider.computeSize(innerValue);
}
return size;
}
static checkType(value) {
if (!Array.isArray(value)) {
throw new UniFFITypeError(`${value} is not an array`);
}
value.forEach((innerValue, idx) => {
try {
FfiConverterTypeSuggestionProvider.checkType(innerValue);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(`[${idx}]`);
}
throw e;
}
})
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalSequenceTypeSuggestionProvider extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterSequenceTypeSuggestionProvider.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterSequenceTypeSuggestionProvider.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterSequenceTypeSuggestionProvider.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterSequenceTypeSuggestionProvider.computeSize(value)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterSequenceString extends FfiConverterArrayBuffer {
static read(dataStream) {
const len = dataStream.readInt32();
const arr = [];
for (let i = 0; i < len; i++) {
arr.push(FfiConverterString.read(dataStream));
}
return arr;
}
static write(dataStream, value) {
dataStream.writeInt32(value.length);
value.forEach((innerValue) => {
FfiConverterString.write(dataStream, innerValue);
})
}
static computeSize(value) {
// The size of the length
let size = 4;
for (const innerValue of value) {
size += FfiConverterString.computeSize(innerValue);
}
return size;
}
static checkType(value) {
if (!Array.isArray(value)) {
throw new UniFFITypeError(`${value} is not an array`);
}
value.forEach((innerValue, idx) => {
try {
FfiConverterString.checkType(innerValue);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(`[${idx}]`);
}
throw e;
}
})
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalSequenceString extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterSequenceString.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterSequenceString.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterSequenceString.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterSequenceString.computeSize(value)
}
}
/**
* AmpMatchingStrategy
*/
export const AmpMatchingStrategy = {
/**
* Disable keywords added via keyword expansion.
* This eliminates keywords that for terms related to the "real" keywords, for example
* misspellings like "underarmor" instead of "under armor"'.
*/
NO_KEYWORD_EXPANSION: 1,
/**
* Use FTS matching against the full keywords, joined together.
*/
FTS_AGAINST_FULL_KEYWORDS: 2,
/**
* Use FTS matching against the title field
*/
FTS_AGAINST_TITLE: 3,
};
Object.freeze(AmpMatchingStrategy);
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeAmpMatchingStrategy extends FfiConverterArrayBuffer {
static read(dataStream) {
switch (dataStream.readInt32()) {
case 1:
return AmpMatchingStrategy.NO_KEYWORD_EXPANSION
case 2:
return AmpMatchingStrategy.FTS_AGAINST_FULL_KEYWORDS
case 3:
return AmpMatchingStrategy.FTS_AGAINST_TITLE
default:
throw new UniFFITypeError("Unknown AmpMatchingStrategy variant");
}
}
static write(dataStream, value) {
if (value === AmpMatchingStrategy.NO_KEYWORD_EXPANSION) {
dataStream.writeInt32(1);
return;
}
if (value === AmpMatchingStrategy.FTS_AGAINST_FULL_KEYWORDS) {
dataStream.writeInt32(2);
return;
}
if (value === AmpMatchingStrategy.FTS_AGAINST_TITLE) {
dataStream.writeInt32(3);
return;
}
throw new UniFFITypeError("Unknown AmpMatchingStrategy variant");
}
static computeSize(value) {
return 4;
}
static checkType(value) {
if (!Number.isInteger(value) || value < 1 || value > 3) {
throw new UniFFITypeError(`${value} is not a valid value for AmpMatchingStrategy`);
}
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalTypeAmpMatchingStrategy extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterTypeAmpMatchingStrategy.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterTypeAmpMatchingStrategy.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterTypeAmpMatchingStrategy.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterTypeAmpMatchingStrategy.computeSize(value)
}
}
/**
* Some providers manage multiple suggestion subtypes. Queries, ingests, and
* other operations on those providers must be constrained to a desired subtype.
*/
export class SuggestionProviderConstraints {
constructor(
{
dynamicSuggestionTypes= null,
ampAlternativeMatching= null
} = {
dynamicSuggestionTypes: undefined,
ampAlternativeMatching: undefined
}
) {
try {
FfiConverterOptionalSequenceString.checkType(dynamicSuggestionTypes)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("dynamicSuggestionTypes");
}
throw e;
}
try {
FfiConverterOptionalTypeAmpMatchingStrategy.checkType(ampAlternativeMatching)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("ampAlternativeMatching");
}
throw e;
}
/**
* Which dynamic suggestions should we fetch or ingest? Corresponds to the
* `suggestion_type` value in dynamic suggestions remote settings records.
*/
this.dynamicSuggestionTypes = dynamicSuggestionTypes;
/**
* Which strategy should we use for the AMP queries?
* Use None for the default strategy.
*/
this.ampAlternativeMatching = ampAlternativeMatching;
}
equals(other) {
return (
this.dynamicSuggestionTypes == other.dynamicSuggestionTypes
&& this.ampAlternativeMatching == other.ampAlternativeMatching
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeSuggestionProviderConstraints extends FfiConverterArrayBuffer {
static read(dataStream) {
return new SuggestionProviderConstraints({
dynamicSuggestionTypes: FfiConverterOptionalSequenceString.read(dataStream),
ampAlternativeMatching: FfiConverterOptionalTypeAmpMatchingStrategy.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterOptionalSequenceString.write(dataStream, value.dynamicSuggestionTypes);
FfiConverterOptionalTypeAmpMatchingStrategy.write(dataStream, value.ampAlternativeMatching);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterOptionalSequenceString.computeSize(value.dynamicSuggestionTypes);
totalSize += FfiConverterOptionalTypeAmpMatchingStrategy.computeSize(value.ampAlternativeMatching);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof SuggestionProviderConstraints)) {
throw new UniFFITypeError(`Expected 'SuggestionProviderConstraints', found '${typeof value}'`);
}
try {
FfiConverterOptionalSequenceString.checkType(value.dynamicSuggestionTypes);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".dynamicSuggestionTypes");
}
throw e;
}
try {
FfiConverterOptionalTypeAmpMatchingStrategy.checkType(value.ampAlternativeMatching);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".ampAlternativeMatching");
}
throw e;
}
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalTypeSuggestionProviderConstraints extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterTypeSuggestionProviderConstraints.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterTypeSuggestionProviderConstraints.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterTypeSuggestionProviderConstraints.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterTypeSuggestionProviderConstraints.computeSize(value)
}
}
/**
* Constraints limit which suggestions to ingest from Remote Settings.
*/
export class SuggestIngestionConstraints {
constructor(
{
providers= null,
providerConstraints= null,
emptyOnly= false
} = {
providers: undefined,
providerConstraints: undefined,
emptyOnly: undefined
}
) {
try {
FfiConverterOptionalSequenceTypeSuggestionProvider.checkType(providers)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("providers");
}
throw e;
}
try {
FfiConverterOptionalTypeSuggestionProviderConstraints.checkType(providerConstraints)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("providerConstraints");
}
throw e;
}
try {
FfiConverterBoolean.checkType(emptyOnly)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("emptyOnly");
}
throw e;
}
/**
* providers
*/
this.providers = providers;
/**
* providerConstraints
*/
this.providerConstraints = providerConstraints;
/**
* Only run ingestion if the table `suggestions` is empty
*
*/
this.emptyOnly = emptyOnly;
}
equals(other) {
return (
this.providers == other.providers
&& this.providerConstraints == other.providerConstraints
&& this.emptyOnly == other.emptyOnly
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeSuggestIngestionConstraints extends FfiConverterArrayBuffer {
static read(dataStream) {
return new SuggestIngestionConstraints({
providers: FfiConverterOptionalSequenceTypeSuggestionProvider.read(dataStream),
providerConstraints: FfiConverterOptionalTypeSuggestionProviderConstraints.read(dataStream),
emptyOnly: FfiConverterBoolean.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterOptionalSequenceTypeSuggestionProvider.write(dataStream, value.providers);
FfiConverterOptionalTypeSuggestionProviderConstraints.write(dataStream, value.providerConstraints);
FfiConverterBoolean.write(dataStream, value.emptyOnly);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterOptionalSequenceTypeSuggestionProvider.computeSize(value.providers);
totalSize += FfiConverterOptionalTypeSuggestionProviderConstraints.computeSize(value.providerConstraints);
totalSize += FfiConverterBoolean.computeSize(value.emptyOnly);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof SuggestIngestionConstraints)) {
throw new UniFFITypeError(`Expected 'SuggestIngestionConstraints', found '${typeof value}'`);
}
try {
FfiConverterOptionalSequenceTypeSuggestionProvider.checkType(value.providers);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".providers");
}
throw e;
}
try {
FfiConverterOptionalTypeSuggestionProviderConstraints.checkType(value.providerConstraints);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".providerConstraints");
}
throw e;
}
try {
FfiConverterBoolean.checkType(value.emptyOnly);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".emptyOnly");
}
throw e;
}
}
}
/**
* Ingestion metrics
*
* These are recorded during [crate::Store::ingest] and returned to the consumer to record.
*/
export class SuggestIngestionMetrics {
constructor(
{
ingestionTimes,
downloadTimes
} = {
ingestionTimes: undefined,
downloadTimes: undefined
}
) {
try {
FfiConverterSequenceTypeLabeledTimingSample.checkType(ingestionTimes)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("ingestionTimes");
}
throw e;
}
try {
FfiConverterSequenceTypeLabeledTimingSample.checkType(downloadTimes)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("downloadTimes");
}
throw e;
}
/**
* Samples for the `suggest.ingestion_time` metric
*/
this.ingestionTimes = ingestionTimes;
/**
* Samples for the `suggest.ingestion_download_time` metric
*/
this.downloadTimes = downloadTimes;
}
equals(other) {
return (
this.ingestionTimes == other.ingestionTimes
&& this.downloadTimes == other.downloadTimes
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeSuggestIngestionMetrics extends FfiConverterArrayBuffer {
static read(dataStream) {
return new SuggestIngestionMetrics({
ingestionTimes: FfiConverterSequenceTypeLabeledTimingSample.read(dataStream),
downloadTimes: FfiConverterSequenceTypeLabeledTimingSample.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterSequenceTypeLabeledTimingSample.write(dataStream, value.ingestionTimes);
FfiConverterSequenceTypeLabeledTimingSample.write(dataStream, value.downloadTimes);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterSequenceTypeLabeledTimingSample.computeSize(value.ingestionTimes);
totalSize += FfiConverterSequenceTypeLabeledTimingSample.computeSize(value.downloadTimes);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof SuggestIngestionMetrics)) {
throw new UniFFITypeError(`Expected 'SuggestIngestionMetrics', found '${typeof value}'`);
}
try {
FfiConverterSequenceTypeLabeledTimingSample.checkType(value.ingestionTimes);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".ingestionTimes");
}
throw e;
}
try {
FfiConverterSequenceTypeLabeledTimingSample.checkType(value.downloadTimes);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".downloadTimes");
}
throw e;
}
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalInt32 extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterInt32.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterInt32.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterInt32.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterInt32.computeSize(value)
}
}
/**
* A query for suggestions to show in the address bar.
*/
export class SuggestionQuery {
constructor(
{
keyword,
providers,
providerConstraints= null,
limit= null
} = {
keyword: undefined,
providers: undefined,
providerConstraints: undefined,
limit: undefined
}
) {
try {
FfiConverterString.checkType(keyword)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("keyword");
}
throw e;
}
try {
FfiConverterSequenceTypeSuggestionProvider.checkType(providers)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("providers");
}
throw e;
}
try {
FfiConverterOptionalTypeSuggestionProviderConstraints.checkType(providerConstraints)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("providerConstraints");
}
throw e;
}
try {
FfiConverterOptionalInt32.checkType(limit)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("limit");
}
throw e;
}
/**
* keyword
*/
this.keyword = keyword;
/**
* providers
*/
this.providers = providers;
/**
* providerConstraints
*/
this.providerConstraints = providerConstraints;
/**
* limit
*/
this.limit = limit;
}
equals(other) {
return (
this.keyword == other.keyword
&& this.providers == other.providers
&& this.providerConstraints == other.providerConstraints
&& this.limit == other.limit
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeSuggestionQuery extends FfiConverterArrayBuffer {
static read(dataStream) {
return new SuggestionQuery({
keyword: FfiConverterString.read(dataStream),
providers: FfiConverterSequenceTypeSuggestionProvider.read(dataStream),
providerConstraints: FfiConverterOptionalTypeSuggestionProviderConstraints.read(dataStream),
limit: FfiConverterOptionalInt32.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterString.write(dataStream, value.keyword);
FfiConverterSequenceTypeSuggestionProvider.write(dataStream, value.providers);
FfiConverterOptionalTypeSuggestionProviderConstraints.write(dataStream, value.providerConstraints);
FfiConverterOptionalInt32.write(dataStream, value.limit);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterString.computeSize(value.keyword);
totalSize += FfiConverterSequenceTypeSuggestionProvider.computeSize(value.providers);
totalSize += FfiConverterOptionalTypeSuggestionProviderConstraints.computeSize(value.providerConstraints);
totalSize += FfiConverterOptionalInt32.computeSize(value.limit);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof SuggestionQuery)) {
throw new UniFFITypeError(`Expected 'SuggestionQuery', found '${typeof value}'`);
}
try {
FfiConverterString.checkType(value.keyword);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".keyword");
}
throw e;
}
try {
FfiConverterSequenceTypeSuggestionProvider.checkType(value.providers);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".providers");
}
throw e;
}
try {
FfiConverterOptionalTypeSuggestionProviderConstraints.checkType(value.providerConstraints);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".providerConstraints");
}
throw e;
}
try {
FfiConverterOptionalInt32.checkType(value.limit);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".limit");
}
throw e;
}
}
}
/**
* The type of a geoname.
*/
export const GeonameType = {
/**
* CITY
*/
CITY: 1,
/**
* REGION
*/
REGION: 2,
};
Object.freeze(GeonameType);
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeGeonameType extends FfiConverterArrayBuffer {
static read(dataStream) {
switch (dataStream.readInt32()) {
case 1:
return GeonameType.CITY
case 2:
return GeonameType.REGION
default:
throw new UniFFITypeError("Unknown GeonameType variant");
}
}
static write(dataStream, value) {
if (value === GeonameType.CITY) {
dataStream.writeInt32(1);
return;
}
if (value === GeonameType.REGION) {
dataStream.writeInt32(2);
return;
}
throw new UniFFITypeError("Unknown GeonameType variant");
}
static computeSize(value) {
return 4;
}
static checkType(value) {
if (!Number.isInteger(value) || value < 1 || value > 2) {
throw new UniFFITypeError(`${value} is not a valid value for GeonameType`);
}
}
}
/**
* What should be interrupted when [SuggestStore::interrupt] is called?
*/
export const InterruptKind = {
/**
* Interrupt read operations like [SuggestStore::query]
*/
READ: 1,
/**
* Interrupt write operations. This mostly means [SuggestStore::ingest], but
* other operations may also be interrupted.
*/
WRITE: 2,
/**
* Interrupt both read and write operations,
*/
READ_WRITE: 3,
};
Object.freeze(InterruptKind);
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeInterruptKind extends FfiConverterArrayBuffer {
static read(dataStream) {
switch (dataStream.readInt32()) {
case 1:
return InterruptKind.READ
case 2:
return InterruptKind.WRITE
case 3:
return InterruptKind.READ_WRITE
default:
throw new UniFFITypeError("Unknown InterruptKind variant");
}
}
static write(dataStream, value) {
if (value === InterruptKind.READ) {
dataStream.writeInt32(1);
return;
}
if (value === InterruptKind.WRITE) {
dataStream.writeInt32(2);
return;
}
if (value === InterruptKind.READ_WRITE) {
dataStream.writeInt32(3);
return;
}
throw new UniFFITypeError("Unknown InterruptKind variant");
}
static computeSize(value) {
return 4;
}
static checkType(value) {
if (!Number.isInteger(value) || value < 1 || value > 3) {
throw new UniFFITypeError(`${value} is not a valid value for InterruptKind`);
}
}
}
/**
* The error type for all Suggest component operations. These errors are
* exposed to your application, which should handle them as needed.
*/
export class SuggestApiError extends Error {}
/**
* Network
*/
export class Network extends SuggestApiError {
constructor(
reason,
...params
) {
const message = `reason: ${ reason }`;
super(message, ...params);
this.reason = reason;
}
toString() {
return `Network: ${super.toString()}`
}
}
/**
* The server requested a backoff after too many requests
*/
export class Backoff extends SuggestApiError {
constructor(
seconds,
...params
) {
const message = `seconds: ${ seconds }`;
super(message, ...params);
this.seconds = seconds;
}
toString() {
return `Backoff: ${super.toString()}`
}
}
/**
* An operation was interrupted by calling `SuggestStore.interrupt()`
*/
export class Interrupted extends SuggestApiError {
constructor(
...params
) {
super(...params);
}
toString() {
return `Interrupted: ${super.toString()}`
}
}
/**
* Other
*/
export class Other extends SuggestApiError {
constructor(
reason,
...params
) {
const message = `reason: ${ reason }`;
super(message, ...params);
this.reason = reason;
}
toString() {
return `Other: ${super.toString()}`
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeSuggestApiError extends FfiConverterArrayBuffer {
static read(dataStream) {
switch (dataStream.readInt32()) {
case 1:
return new Network(
FfiConverterString.read(dataStream)
);
case 2:
return new Backoff(
FfiConverterUInt64.read(dataStream)
);
case 3:
return new Interrupted(
);
case 4:
return new Other(
FfiConverterString.read(dataStream)
);
default:
throw new UniFFITypeError("Unknown SuggestApiError variant");
}
}
static computeSize(value) {
// Size of the Int indicating the variant
let totalSize = 4;
if (value instanceof Network) {
totalSize += FfiConverterString.computeSize(value.reason);
return totalSize;
}
if (value instanceof Backoff) {
totalSize += FfiConverterUInt64.computeSize(value.seconds);
return totalSize;
}
if (value instanceof Interrupted) {
return totalSize;
}
if (value instanceof Other) {
totalSize += FfiConverterString.computeSize(value.reason);
return totalSize;
}
throw new UniFFITypeError("Unknown SuggestApiError variant");
}
static write(dataStream, value) {
if (value instanceof Network) {
dataStream.writeInt32(1);
FfiConverterString.write(dataStream, value.reason);
return;
}
if (value instanceof Backoff) {
dataStream.writeInt32(2);
FfiConverterUInt64.write(dataStream, value.seconds);
return;
}
if (value instanceof Interrupted) {
dataStream.writeInt32(3);
return;
}
if (value instanceof Other) {
dataStream.writeInt32(4);
FfiConverterString.write(dataStream, value.reason);
return;
}
throw new UniFFITypeError("Unknown SuggestApiError variant");
}
static errorClass = SuggestApiError;
}
/**
* Per-provider configuration data.
*/
export class SuggestProviderConfig {}
/**
* Weather
*/
SuggestProviderConfig.Weather = class extends SuggestProviderConfig{
constructor(
score,
minKeywordLength
) {
super();
this.score = score;
this.minKeywordLength = minKeywordLength;
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeSuggestProviderConfig extends FfiConverterArrayBuffer {
static read(dataStream) {
switch (dataStream.readInt32()) {
case 1:
return new SuggestProviderConfig.Weather(
FfiConverterFloat64.read(dataStream),
FfiConverterInt32.read(dataStream)
);
default:
throw new UniFFITypeError("Unknown SuggestProviderConfig variant");
}
}
static write(dataStream, value) {
if (value instanceof SuggestProviderConfig.Weather) {
dataStream.writeInt32(1);
FfiConverterFloat64.write(dataStream, value.score);
FfiConverterInt32.write(dataStream, value.minKeywordLength);
return;
}
throw new UniFFITypeError("Unknown SuggestProviderConfig variant");
}
static computeSize(value) {
// Size of the Int indicating the variant
let totalSize = 4;
if (value instanceof SuggestProviderConfig.Weather) {
totalSize += FfiConverterFloat64.computeSize(value.score);
totalSize += FfiConverterInt32.computeSize(value.minKeywordLength);
return totalSize;
}
throw new UniFFITypeError("Unknown SuggestProviderConfig variant");
}
static checkType(value) {
if (!(value instanceof SuggestProviderConfig)) {
throw new UniFFITypeError(`${value} is not a subclass instance of SuggestProviderConfig`);
}
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalTypeGeonameType extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterTypeGeonameType.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterTypeGeonameType.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterTypeGeonameType.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterTypeGeonameType.computeSize(value)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterSequenceTypeGeoname extends FfiConverterArrayBuffer {
static read(dataStream) {
const len = dataStream.readInt32();
const arr = [];
for (let i = 0; i < len; i++) {
arr.push(FfiConverterTypeGeoname.read(dataStream));
}
return arr;
}
static write(dataStream, value) {
dataStream.writeInt32(value.length);
value.forEach((innerValue) => {
FfiConverterTypeGeoname.write(dataStream, innerValue);
})
}
static computeSize(value) {
// The size of the length
let size = 4;
for (const innerValue of value) {
size += FfiConverterTypeGeoname.computeSize(innerValue);
}
return size;
}
static checkType(value) {
if (!Array.isArray(value)) {
throw new UniFFITypeError(`${value} is not an array`);
}
value.forEach((innerValue, idx) => {
try {
FfiConverterTypeGeoname.checkType(innerValue);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(`[${idx}]`);
}
throw e;
}
})
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalSequenceTypeGeoname extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterSequenceTypeGeoname.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterSequenceTypeGeoname.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterSequenceTypeGeoname.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterSequenceTypeGeoname.computeSize(value)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterSequenceTypeGeonameMatch extends FfiConverterArrayBuffer {
static read(dataStream) {
const len = dataStream.readInt32();
const arr = [];
for (let i = 0; i < len; i++) {
arr.push(FfiConverterTypeGeonameMatch.read(dataStream));
}
return arr;
}
static write(dataStream, value) {
dataStream.writeInt32(value.length);
value.forEach((innerValue) => {
FfiConverterTypeGeonameMatch.write(dataStream, innerValue);
})
}
static computeSize(value) {
// The size of the length
let size = 4;
for (const innerValue of value) {
size += FfiConverterTypeGeonameMatch.computeSize(innerValue);
}
return size;
}
static checkType(value) {
if (!Array.isArray(value)) {
throw new UniFFITypeError(`${value} is not an array`);
}
value.forEach((innerValue, idx) => {
try {
FfiConverterTypeGeonameMatch.checkType(innerValue);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(`[${idx}]`);
}
throw e;
}
})
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalTypeSuggestProviderConfig extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterTypeSuggestProviderConfig.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterTypeSuggestProviderConfig.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterTypeSuggestProviderConfig.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterTypeSuggestProviderConfig.computeSize(value)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalTypeInterruptKind extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterTypeInterruptKind.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterTypeInterruptKind.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterTypeInterruptKind.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterTypeInterruptKind.computeSize(value)
}
}
/**
* The store is the entry point to the Suggest component. It incrementally
* downloads suggestions from the Remote Settings service, stores them in a
* local database, and returns them in response to user queries.
*
* Your application should create a single store, and manage it as a singleton.
* The store is thread-safe, and supports concurrent queries and ingests. We
* expect that your application will call [`SuggestStore::query()`] to show
* suggestions as the user types into the address bar, and periodically call
* [`SuggestStore::ingest()`] in the background to update the database with
* new suggestions from Remote Settings.
*
* For responsiveness, we recommend always calling `query()` on a worker
* thread. When the user types new input into the address bar, call
* [`SuggestStore::interrupt()`] on the main thread to cancel the query
* for the old input, and unblock the worker thread for the new query.
*
* The store keeps track of the state needed to support incremental ingestion,
* but doesn't schedule the ingestion work itself, or decide how many
* suggestions to ingest at once. This is for two reasons:
*
* 1. The primitives for scheduling background work vary between platforms, and
* aren't available to the lower-level Rust layer. You might use an idle
* timer on Desktop, `WorkManager` on Android, or `BGTaskScheduler` on iOS.
* 2. Ingestion constraints can change, depending on the platform and the needs
* of your application. A mobile device on a metered connection might want
* to request a small subset of the Suggest data and download the rest
* later, while a desktop on a fast link might download the entire dataset
* on the first launch.
*/
export class SuggestStore {
// Use `init` to instantiate this class.
// DO NOT USE THIS CONSTRUCTOR DIRECTLY
constructor(opts) {
if (!Object.prototype.hasOwnProperty.call(opts, constructUniffiObject)) {
throw new UniFFIError("Attempting to construct an int using the JavaScript constructor directly" +
"Please use a UDL defined constructor, or the init function for the primary constructor")
}
if (!(opts[constructUniffiObject] instanceof UniFFIPointer)) {
throw new UniFFIError("Attempting to create a UniFFI object with a pointer that is not an instance of UniFFIPointer")
}
this[uniffiObjectPtr] = opts[constructUniffiObject];
}
static init(
path,
remoteSettingsService) {
FfiConverterString.checkType(path);
FfiConverterTypeRemoteSettingsService.checkType(remoteSettingsService);
const result = UniFFIScaffolding.callSync(
35, // uniffi_suggest_fn_constructor_suggeststore_new
FfiConverterString.lower(path),
FfiConverterTypeRemoteSettingsService.lower(remoteSettingsService),
)
return handleRustResult(
result,
FfiConverterTypeSuggestStore.lift.bind(FfiConverterTypeSuggestStore),
null,
)
}
/**
* Return whether any suggestions have been dismissed.
*/
async anyDismissedSuggestions() {
const result = await UniFFIScaffolding.callAsyncWrapper(
36, // uniffi_suggest_fn_method_suggeststore_any_dismissed_suggestions
FfiConverterTypeSuggestStore.lower(this),
)
return handleRustResult(
result,
FfiConverterBoolean.lift.bind(FfiConverterBoolean),
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
/**
* Removes all content from the database.
*/
async clear() {
const result = await UniFFIScaffolding.callAsyncWrapper(
37, // uniffi_suggest_fn_method_suggeststore_clear
FfiConverterTypeSuggestStore.lower(this),
)
return handleRustResult(
result,
(result) => undefined,
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
/**
* Clear dismissed suggestions
*/
async clearDismissedSuggestions() {
const result = await UniFFIScaffolding.callAsyncWrapper(
38, // uniffi_suggest_fn_method_suggeststore_clear_dismissed_suggestions
FfiConverterTypeSuggestStore.lower(this),
)
return handleRustResult(
result,
(result) => undefined,
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
/**
* Dismiss a suggestion by its dismissal key.
*
* Dismissed suggestions cannot be fetched again.
*
* Prefer [SuggestStore::dismiss_by_suggestion] if you have a
* `crate::Suggestion`. This method is intended for cases where a
* suggestion originates outside this component.
*/
async dismissByKey(
key) {
FfiConverterString.checkType(key);
const result = await UniFFIScaffolding.callAsyncWrapper(
39, // uniffi_suggest_fn_method_suggeststore_dismiss_by_key
FfiConverterTypeSuggestStore.lower(this),
FfiConverterString.lower(key),
)
return handleRustResult(
result,
(result) => undefined,
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
/**
* Dismiss a suggestion.
*
* Dismissed suggestions cannot be fetched again.
*/
async dismissBySuggestion(
suggestion) {
FfiConverterTypeSuggestion.checkType(suggestion);
const result = await UniFFIScaffolding.callAsyncWrapper(
40, // uniffi_suggest_fn_method_suggeststore_dismiss_by_suggestion
FfiConverterTypeSuggestStore.lower(this),
FfiConverterTypeSuggestion.lower(suggestion),
)
return handleRustResult(
result,
(result) => undefined,
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
/**
* Deprecated, use [SuggestStore::dismiss_by_suggestion] or
* [SuggestStore::dismiss_by_key] instead.
*
* Dismiss a suggestion
*
* Dismissed suggestions will not be returned again
*/
async dismissSuggestion(
suggestionUrl) {
FfiConverterString.checkType(suggestionUrl);
const result = await UniFFIScaffolding.callAsyncWrapper(
41, // uniffi_suggest_fn_method_suggeststore_dismiss_suggestion
FfiConverterTypeSuggestStore.lower(this),
FfiConverterString.lower(suggestionUrl),
)
return handleRustResult(
result,
(result) => undefined,
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
/**
* Fetches geonames stored in the database. A geoname represents a
* geographic place.
*
* `query` is a string that will be matched directly against geoname names.
* It is not a query string in the usual Suggest sense. `match_name_prefix`
* determines whether prefix matching is performed on names excluding
* abbreviations and airport codes. When `true`, names that start with
* `query` will match. When false, names that equal `query` will match.
*
* `geoname_type` restricts returned geonames to a [`GeonameType`].
*
* `filter` restricts returned geonames to certain cities or regions.
* Cities can be restricted to regions by including the regions in
* `filter`, and regions can be restricted to those containing certain
* cities by including the cities in `filter`. This is especially useful
* since city and region names are not unique. `filter` is disjunctive: If
* any item in `filter` matches a geoname, the geoname will be filtered in.
*
* The query can match a single geoname in more than one way. For example,
* it can match both a full name and an abbreviation. The returned vec of
* [`GeonameMatch`] values will include all matches for a geoname, one
* match per `match_type` per geoname. In other words, a matched geoname
* can map to more than one `GeonameMatch`.
*/
async fetchGeonames(
query,
matchNamePrefix,
geonameType,
filter) {
FfiConverterString.checkType(query);
FfiConverterBoolean.checkType(matchNamePrefix);
FfiConverterOptionalTypeGeonameType.checkType(geonameType);
FfiConverterOptionalSequenceTypeGeoname.checkType(filter);
const result = await UniFFIScaffolding.callAsyncWrapper(
42, // uniffi_suggest_fn_method_suggeststore_fetch_geonames
FfiConverterTypeSuggestStore.lower(this),
FfiConverterString.lower(query),
FfiConverterBoolean.lower(matchNamePrefix),
FfiConverterOptionalTypeGeonameType.lower(geonameType),
FfiConverterOptionalSequenceTypeGeoname.lower(filter),
)
return handleRustResult(
result,
FfiConverterSequenceTypeGeonameMatch.lift.bind(FfiConverterSequenceTypeGeonameMatch),
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
/**
* Returns global Suggest configuration data.
*/
async fetchGlobalConfig() {
const result = await UniFFIScaffolding.callAsyncWrapper(
43, // uniffi_suggest_fn_method_suggeststore_fetch_global_config
FfiConverterTypeSuggestStore.lower(this),
)
return handleRustResult(
result,
FfiConverterTypeSuggestGlobalConfig.lift.bind(FfiConverterTypeSuggestGlobalConfig),
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
/**
* Returns per-provider Suggest configuration data.
*/
async fetchProviderConfig(
provider) {
FfiConverterTypeSuggestionProvider.checkType(provider);
const result = await UniFFIScaffolding.callAsyncWrapper(
44, // uniffi_suggest_fn_method_suggeststore_fetch_provider_config
FfiConverterTypeSuggestStore.lower(this),
FfiConverterTypeSuggestionProvider.lower(provider),
)
return handleRustResult(
result,
FfiConverterOptionalTypeSuggestProviderConfig.lift.bind(FfiConverterOptionalTypeSuggestProviderConfig),
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
/**
* Ingests new suggestions from Remote Settings.
*/
async ingest(
constraints) {
FfiConverterTypeSuggestIngestionConstraints.checkType(constraints);
const result = await UniFFIScaffolding.callAsyncWrapper(
45, // uniffi_suggest_fn_method_suggeststore_ingest
FfiConverterTypeSuggestStore.lower(this),
FfiConverterTypeSuggestIngestionConstraints.lower(constraints),
)
return handleRustResult(
result,
FfiConverterTypeSuggestIngestionMetrics.lift.bind(FfiConverterTypeSuggestIngestionMetrics),
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
/**
* Interrupts any ongoing queries.
*
* This should be called when the user types new input into the address
* bar, to ensure that they see fresh suggestions as they type. This
* method does not interrupt any ongoing ingests.
*/
interrupt(
kind = null) {
FfiConverterOptionalTypeInterruptKind.checkType(kind);
const result = UniFFIScaffolding.callSync(
46, // uniffi_suggest_fn_method_suggeststore_interrupt
FfiConverterTypeSuggestStore.lower(this),
FfiConverterOptionalTypeInterruptKind.lower(kind),
)
return handleRustResult(
result,
(result) => undefined,
null,
)
}
/**
* Return whether a suggestion has been dismissed given its dismissal key.
*
* [SuggestStore::query] will never return dismissed suggestions, so
* normally you never need to know whether a suggestion has been dismissed.
* This method is intended for cases where a dismissal key originates
* outside this component.
*/
async isDismissedByKey(
key) {
FfiConverterString.checkType(key);
const result = await UniFFIScaffolding.callAsyncWrapper(
47, // uniffi_suggest_fn_method_suggeststore_is_dismissed_by_key
FfiConverterTypeSuggestStore.lower(this),
FfiConverterString.lower(key),
)
return handleRustResult(
result,
FfiConverterBoolean.lift.bind(FfiConverterBoolean),
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
/**
* Return whether a suggestion has been dismissed.
*
* [SuggestStore::query] will never return dismissed suggestions, so
* normally you never need to know whether a `Suggestion` has been
* dismissed, but this method can be used to do so.
*/
async isDismissedBySuggestion(
suggestion) {
FfiConverterTypeSuggestion.checkType(suggestion);
const result = await UniFFIScaffolding.callAsyncWrapper(
48, // uniffi_suggest_fn_method_suggeststore_is_dismissed_by_suggestion
FfiConverterTypeSuggestStore.lower(this),
FfiConverterTypeSuggestion.lower(suggestion),
)
return handleRustResult(
result,
FfiConverterBoolean.lift.bind(FfiConverterBoolean),
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
/**
* Queries the database for suggestions.
*/
async query(
query) {
FfiConverterTypeSuggestionQuery.checkType(query);
const result = await UniFFIScaffolding.callAsyncWrapper(
49, // uniffi_suggest_fn_method_suggeststore_query
FfiConverterTypeSuggestStore.lower(this),
FfiConverterTypeSuggestionQuery.lower(query),
)
return handleRustResult(
result,
FfiConverterSequenceTypeSuggestion.lift.bind(FfiConverterSequenceTypeSuggestion),
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
/**
* Queries the database for suggestions.
*/
async queryWithMetrics(
query) {
FfiConverterTypeSuggestionQuery.checkType(query);
const result = await UniFFIScaffolding.callAsyncWrapper(
50, // uniffi_suggest_fn_method_suggeststore_query_with_metrics
FfiConverterTypeSuggestStore.lower(this),
FfiConverterTypeSuggestionQuery.lower(query),
)
return handleRustResult(
result,
FfiConverterTypeQueryWithMetricsResult.lift.bind(FfiConverterTypeQueryWithMetricsResult),
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeSuggestStore extends FfiConverter {
static lift(value) {
const opts = {};
opts[constructUniffiObject] = value;
return new SuggestStore(opts);
}
static lower(value) {
const ptr = value[uniffiObjectPtr];
if (!(ptr instanceof UniFFIPointer)) {
throw new UniFFITypeError("Object is not a 'SuggestStore' instance");
}
return ptr;
}
static read(dataStream) {
return this.lift(dataStream.readPointer(6));
}
static write(dataStream, value) {
dataStream.writePointer(6, this.lower(value));
}
static computeSize(value) {
return 8;
}
}
import {
FfiConverterTypeRemoteSettingsServer,
} from "./RustRemoteSettings.sys.mjs";
// Export the FFIConverter object to make external types work.
export { FfiConverterTypeRemoteSettingsServer };
import {
FfiConverterTypeRemoteSettingsService,
} from "./RustRemoteSettings.sys.mjs";
// Export the FFIConverter object to make external types work.
export { FfiConverterTypeRemoteSettingsService };
/**
* Builder for [SuggestStore]
*
* Using a builder is preferred to calling the constructor directly since it's harder to confuse
* the data_path and cache_path strings.
*/
export class SuggestStoreBuilder {
// Use `init` to instantiate this class.
// DO NOT USE THIS CONSTRUCTOR DIRECTLY
constructor(opts) {
if (!Object.prototype.hasOwnProperty.call(opts, constructUniffiObject)) {
throw new UniFFIError("Attempting to construct an int using the JavaScript constructor directly" +
"Please use a UDL defined constructor, or the init function for the primary constructor")
}
if (!(opts[constructUniffiObject] instanceof UniFFIPointer)) {
throw new UniFFIError("Attempting to create a UniFFI object with a pointer that is not an instance of UniFFIPointer")
}
this[uniffiObjectPtr] = opts[constructUniffiObject];
}
static init() {
const result = UniFFIScaffolding.callSync(
51, // uniffi_suggest_fn_constructor_suggeststorebuilder_new
)
return handleRustResult(
result,
FfiConverterTypeSuggestStoreBuilder.lift.bind(FfiConverterTypeSuggestStoreBuilder),
null,
)
}
/**
* build
*/
build() {
const result = UniFFIScaffolding.callSync(
52, // uniffi_suggest_fn_method_suggeststorebuilder_build
FfiConverterTypeSuggestStoreBuilder.lower(this),
)
return handleRustResult(
result,
FfiConverterTypeSuggestStore.lift.bind(FfiConverterTypeSuggestStore),
FfiConverterTypeSuggestApiError.lift.bind(FfiConverterTypeSuggestApiError),
)
}
/**
* Deprecated: this is no longer used by the suggest component.
*/
async cachePath(
path) {
FfiConverterString.checkType(path);
const result = await UniFFIScaffolding.callAsyncWrapper(
53, // uniffi_suggest_fn_method_suggeststorebuilder_cache_path
FfiConverterTypeSuggestStoreBuilder.lower(this),
FfiConverterString.lower(path),
)
return handleRustResult(
result,
FfiConverterTypeSuggestStoreBuilder.lift.bind(FfiConverterTypeSuggestStoreBuilder),
null,
)
}
/**
* dataPath
*/
dataPath(
path) {
FfiConverterString.checkType(path);
const result = UniFFIScaffolding.callSync(
54, // uniffi_suggest_fn_method_suggeststorebuilder_data_path
FfiConverterTypeSuggestStoreBuilder.lower(this),
FfiConverterString.lower(path),
)
return handleRustResult(
result,
FfiConverterTypeSuggestStoreBuilder.lift.bind(FfiConverterTypeSuggestStoreBuilder),
null,
)
}
/**
* Add an sqlite3 extension to load
*
* library_name should be the name of the library without any extension, for example `libmozsqlite3`.
* entrypoint should be the entry point, for example `sqlite3_fts5_init`. If `null` (the default)
* entry point will be used (see https://sqlite.org/loadext.html for details).
*/
loadExtension(
library,
entryPoint) {
FfiConverterString.checkType(library);
FfiConverterOptionalString.checkType(entryPoint);
const result = UniFFIScaffolding.callSync(
55, // uniffi_suggest_fn_method_suggeststorebuilder_load_extension
FfiConverterTypeSuggestStoreBuilder.lower(this),
FfiConverterString.lower(library),
FfiConverterOptionalString.lower(entryPoint),
)
return handleRustResult(
result,
FfiConverterTypeSuggestStoreBuilder.lift.bind(FfiConverterTypeSuggestStoreBuilder),
null,
)
}
/**
* remoteSettingsBucketName
*/
remoteSettingsBucketName(
bucketName) {
FfiConverterString.checkType(bucketName);
const result = UniFFIScaffolding.callSync(
56, // uniffi_suggest_fn_method_suggeststorebuilder_remote_settings_bucket_name
FfiConverterTypeSuggestStoreBuilder.lower(this),
FfiConverterString.lower(bucketName),
)
return handleRustResult(
result,
FfiConverterTypeSuggestStoreBuilder.lift.bind(FfiConverterTypeSuggestStoreBuilder),
null,
)
}
/**
* remoteSettingsServer
*/
remoteSettingsServer(
server) {
FfiConverterTypeRemoteSettingsServer.checkType(server);
const result = UniFFIScaffolding.callSync(
57, // uniffi_suggest_fn_method_suggeststorebuilder_remote_settings_server
FfiConverterTypeSuggestStoreBuilder.lower(this),
FfiConverterTypeRemoteSettingsServer.lower(server),
)
return handleRustResult(
result,
FfiConverterTypeSuggestStoreBuilder.lift.bind(FfiConverterTypeSuggestStoreBuilder),
null,
)
}
/**
* remoteSettingsService
*/
remoteSettingsService(
rsService) {
FfiConverterTypeRemoteSettingsService.checkType(rsService);
const result = UniFFIScaffolding.callSync(
58, // uniffi_suggest_fn_method_suggeststorebuilder_remote_settings_service
FfiConverterTypeSuggestStoreBuilder.lower(this),
FfiConverterTypeRemoteSettingsService.lower(rsService),
)
return handleRustResult(
result,
FfiConverterTypeSuggestStoreBuilder.lift.bind(FfiConverterTypeSuggestStoreBuilder),
null,
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeSuggestStoreBuilder extends FfiConverter {
static lift(value) {
const opts = {};
opts[constructUniffiObject] = value;
return new SuggestStoreBuilder(opts);
}
static lower(value) {
const ptr = value[uniffiObjectPtr];
if (!(ptr instanceof UniFFIPointer)) {
throw new UniFFITypeError("Object is not a 'SuggestStoreBuilder' instance");
}
return ptr;
}
static read(dataStream) {
return this.lift(dataStream.readPointer(7));
}
static write(dataStream, value) {
dataStream.writePointer(7, this.lower(value));
}
static computeSize(value) {
return 8;
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterUInt8 extends FfiConverter {
static checkType(value) {
super.checkType(value);
if (!Number.isInteger(value)) {
throw new UniFFITypeError(`${value} is not an integer`);
}
if (value < 0 || value > 256) {
throw new UniFFITypeError(`${value} exceeds the U8 bounds`);
}
}
static computeSize(_value) {
return 1;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeUint8(value)
}
static read(dataStream) {
return dataStream.readUint8()
}
}