1// generated by diplomat-tool 2import { DataError } from "./DataError.mjs" 3import { LocaleFallbacker } from "./LocaleFallbacker.mjs" 4import wasm from "./diplomat-wasm.mjs"; 5import * as diplomatRuntime from "./diplomat-runtime.mjs"; 6 7 8/** An ICU4X data provider, capable of loading ICU4X data keys from some source. 9* 10*Currently the only source supported is loading from "blob" formatted data from a bytes buffer or the file system. 11* 12*If you wish to use ICU4X's builtin "compiled data", use the version of the constructors that do not have `_with_provider` 13*in their names. 14* 15*See the [Rust documentation for `icu_provider`](https://docs.rs/icu_provider/latest/icu_provider/index.html) for more information. 16*/ 17const DataProvider_box_destroy_registry = new FinalizationRegistry((ptr) => { 18 wasm.icu4x_DataProvider_destroy_mv1(ptr); 19}); 20 21export class DataProvider { 22 23 // Internal ptr reference: 24 #ptr = null; 25 26 // Lifetimes are only to keep dependencies alive. 27 // Since JS won't garbage collect until there are no incoming edges. 28 #selfEdge = []; 29 30 #internalConstructor(symbol, ptr, selfEdge) { 31 if (symbol !== diplomatRuntime.internalConstructor) { 32 console.error("DataProvider is an Opaque type. You cannot call its constructor."); 33 return; 34 } 35 36 this.#ptr = ptr; 37 this.#selfEdge = selfEdge; 38 39 // Are we being borrowed? If not, we can register. 40 if (this.#selfEdge.length === 0) { 41 DataProvider_box_destroy_registry.register(this, this.#ptr); 42 } 43 44 return this; 45 } 46 get ffiValue() { 47 return this.#ptr; 48 } 49 50 forkByKey(other) { 51 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 52 53 const result = wasm.icu4x_DataProvider_fork_by_key_mv1(diplomatReceive.buffer, this.ffiValue, other.ffiValue); 54 55 try { 56 if (!diplomatReceive.resultFlag) { 57 const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 58 throw new globalThis.Error('DataError: ' + cause.value, { cause }); 59 } 60 61 } 62 63 finally { 64 diplomatReceive.free(); 65 } 66 } 67 68 forkByLocale(other) { 69 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 70 71 const result = wasm.icu4x_DataProvider_fork_by_locale_mv1(diplomatReceive.buffer, this.ffiValue, other.ffiValue); 72 73 try { 74 if (!diplomatReceive.resultFlag) { 75 const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 76 throw new globalThis.Error('DataError: ' + cause.value, { cause }); 77 } 78 79 } 80 81 finally { 82 diplomatReceive.free(); 83 } 84 } 85 86 enableLocaleFallbackWith(fallbacker) { 87 const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); 88 89 const result = wasm.icu4x_DataProvider_enable_locale_fallback_with_mv1(diplomatReceive.buffer, this.ffiValue, fallbacker.ffiValue); 90 91 try { 92 if (!diplomatReceive.resultFlag) { 93 const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); 94 throw new globalThis.Error('DataError: ' + cause.value, { cause }); 95 } 96 97 } 98 99 finally { 100 diplomatReceive.free(); 101 } 102 } 103 104 constructor(symbol, ptr, selfEdge) { 105 return this.#internalConstructor(...arguments) 106 } 107}