-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
51 lines (45 loc) · 1.65 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* Import this module to get access to the Datex namespace.
* The Datex runtime is not automatically initialized.
* It needs to be initialized by calling init() and setting assigning the Blockchain
* module to Datex.Runtime.Blockchain:
*
* ```ts
* import {Datex, init} from "datex-core-legacy/mod.ts";
* import { Blockchain } from "datex-core-legacy/network/blockchain_adapter.ts"
* Datex.Runtime.Blockchain = Blockchain;
* await init()
* ```
*
* Loading Datex this way is required when bundling, otherwise the
* imports cannot be resolved correctly.
* If the source code is not bundled, "datex-core-legacy/datex.ts" can be imported.
*/
import * as Datex from "./datex_all.ts";
export {Datex};
export * from "./js_adapter/decorators.ts";
export * from "./datex_short.ts";
export {init} from "./init.ts";
/**
* Polyfills
*/
Object.defineProperty(globalThis.Promise, "withResolvers", {value: function withResolvers() {
if (!this) throw new TypeError("Promise.withResolvers called on non-object")
const out: any = {}
out.promise = new this((resolve_:any, reject_:any) => {
out.resolve = resolve_
out.reject = reject_
})
return out
}})
declare global {
interface PromiseConstructor {
withResolvers<T>(): {
promise: Promise<T>,
resolve: (r:T) => void,
reject: (e:unknown) => void
};
}
}
if ((globalThis as any).Datex) throw new Error(`The datex-core-js-legacy library was imported more than once from different sources`);// (v${Datex.Runtime?.VERSION??'X'} from ${Datex.libURL??'unknown'} and v${globalThis.Datex?.Runtime?.VERSION??'X'} from ${globalThis.Datex?.libURL??'unknown'}). Check your imports!`)
(globalThis as any).Datex = Datex;