@climateriskcommons/crc-framework 0.6.0 → 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,95 +1,90 @@
1
1
  /* @ts-self-types="./crc_framework.d.ts" */
2
2
 
3
- /**
4
- * An explicitly owned, validated curve; call free() when finished.
5
- */
6
- export class PreparedCurve {
7
- static __wrap(ptr) {
8
- const obj = Object.create(PreparedCurve.prototype);
9
- obj.__wbg_ptr = ptr;
10
- PreparedCurveFinalization.register(obj, obj.__wbg_ptr, obj);
11
- return obj;
12
- }
3
+ export class PreparedNumerical {
13
4
  __destroy_into_raw() {
14
5
  const ptr = this.__wbg_ptr;
15
6
  this.__wbg_ptr = 0;
16
- PreparedCurveFinalization.unregister(this);
7
+ PreparedNumericalFinalization.unregister(this);
17
8
  return ptr;
18
9
  }
19
10
  free() {
20
11
  const ptr = this.__destroy_into_raw();
21
- wasm.__wbg_preparedcurve_free(ptr, 0);
12
+ wasm.__wbg_preparednumerical_free(ptr, 0);
22
13
  }
23
14
  /**
24
- * @param {number} q
25
- * @returns {any}
15
+ * @param {string} text
26
16
  */
27
- evaluate(q) {
28
- const ret = wasm.preparedcurve_evaluate(this.__wbg_ptr, q);
17
+ constructor(text) {
18
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
19
+ const len0 = WASM_VECTOR_LEN;
20
+ const ret = wasm.preparednumerical_new(ptr0, len0);
29
21
  if (ret[2]) {
30
22
  throw takeFromExternrefTable0(ret[1]);
31
23
  }
32
- return takeFromExternrefTable0(ret[0]);
24
+ this.__wbg_ptr = ret[0];
25
+ PreparedNumericalFinalization.register(this, this.__wbg_ptr, this);
26
+ return this;
33
27
  }
34
28
  /**
35
- * @param {Float64Array} row
36
- * @param {Float64Array} knots
37
- * @returns {PreparedCurve}
29
+ * @param {Float64Array} probabilities
30
+ * @returns {Float64Array}
38
31
  */
39
- static fromPacked(row, knots) {
40
- const ptr0 = passArrayF64ToWasm0(row, wasm.__wbindgen_malloc);
32
+ quantileBatch(probabilities) {
33
+ const ptr0 = passArrayF64ToWasm0(probabilities, wasm.__wbindgen_malloc);
41
34
  const len0 = WASM_VECTOR_LEN;
42
- const ptr1 = passArrayF64ToWasm0(knots, wasm.__wbindgen_malloc);
43
- const len1 = WASM_VECTOR_LEN;
44
- const ret = wasm.preparedcurve_fromPacked(ptr0, len0, ptr1, len1);
45
- if (ret[2]) {
46
- throw takeFromExternrefTable0(ret[1]);
35
+ const ret = wasm.preparednumerical_quantileBatch(this.__wbg_ptr, ptr0, len0);
36
+ if (ret[3]) {
37
+ throw takeFromExternrefTable0(ret[2]);
47
38
  }
48
- return PreparedCurve.__wrap(ret[0]);
39
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
40
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
41
+ return v2;
49
42
  }
50
43
  /**
51
- * Multiple queries without reparsing the same record.
52
- * @param {Float64Array} probabilities
53
- * @returns {Array<any>}
44
+ * @param {number} q
45
+ * @returns {number}
54
46
  */
55
- quantiles(probabilities) {
56
- const ptr0 = passArrayF64ToWasm0(probabilities, wasm.__wbindgen_malloc);
57
- const len0 = WASM_VECTOR_LEN;
58
- const ret = wasm.preparedcurve_quantiles(this.__wbg_ptr, ptr0, len0);
47
+ quantile(q) {
48
+ const ret = wasm.preparednumerical_quantile(this.__wbg_ptr, q);
59
49
  if (ret[2]) {
60
50
  throw takeFromExternrefTable0(ret[1]);
61
51
  }
62
- return takeFromExternrefTable0(ret[0]);
52
+ return ret[0];
63
53
  }
64
54
  }
65
- if (Symbol.dispose) PreparedCurve.prototype[Symbol.dispose] = PreparedCurve.prototype.free;
55
+ if (Symbol.dispose) PreparedNumerical.prototype[Symbol.dispose] = PreparedNumerical.prototype.free;
66
56
 
67
- /**
68
- * A tile-sized collection reconstructed once and evaluated in one WASM call.
69
- */
70
- export class PreparedCurves {
71
- static __wrap(ptr) {
72
- const obj = Object.create(PreparedCurves.prototype);
73
- obj.__wbg_ptr = ptr;
74
- PreparedCurvesFinalization.register(obj, obj.__wbg_ptr, obj);
75
- return obj;
76
- }
57
+ export class PreparedNumericals {
77
58
  __destroy_into_raw() {
78
59
  const ptr = this.__wbg_ptr;
79
60
  this.__wbg_ptr = 0;
80
- PreparedCurvesFinalization.unregister(this);
61
+ PreparedNumericalsFinalization.unregister(this);
81
62
  return ptr;
82
63
  }
83
64
  free() {
84
65
  const ptr = this.__destroy_into_raw();
85
- wasm.__wbg_preparedcurves_free(ptr, 0);
66
+ wasm.__wbg_preparednumericals_free(ptr, 0);
67
+ }
68
+ /**
69
+ * @param {string} text
70
+ */
71
+ constructor(text) {
72
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
73
+ const len0 = WASM_VECTOR_LEN;
74
+ const ret = wasm.preparednumericals_new(ptr0, len0);
75
+ if (ret[2]) {
76
+ throw takeFromExternrefTable0(ret[1]);
77
+ }
78
+ this.__wbg_ptr = ret[0];
79
+ PreparedNumericalsFinalization.register(this, this.__wbg_ptr, this);
80
+ return this;
86
81
  }
87
82
  /**
88
83
  * @param {number} q
89
84
  * @returns {Float64Array}
90
85
  */
91
- evaluate(q) {
92
- const ret = wasm.preparedcurves_evaluate(this.__wbg_ptr, q);
86
+ quantile(q) {
87
+ const ret = wasm.preparednumericals_quantile(this.__wbg_ptr, q);
93
88
  if (ret[3]) {
94
89
  throw takeFromExternrefTable0(ret[2]);
95
90
  }
@@ -97,57 +92,38 @@ export class PreparedCurves {
97
92
  wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
98
93
  return v1;
99
94
  }
100
- /**
101
- * @param {Float64Array} rows
102
- * @param {Float64Array} knots
103
- * @returns {PreparedCurves}
104
- */
105
- static fromPacked(rows, knots) {
106
- const ptr0 = passArrayF64ToWasm0(rows, wasm.__wbindgen_malloc);
107
- const len0 = WASM_VECTOR_LEN;
108
- const ptr1 = passArrayF64ToWasm0(knots, wasm.__wbindgen_malloc);
109
- const len1 = WASM_VECTOR_LEN;
110
- const ret = wasm.preparedcurves_fromPacked(ptr0, len0, ptr1, len1);
111
- if (ret[2]) {
112
- throw takeFromExternrefTable0(ret[1]);
113
- }
114
- return PreparedCurves.__wrap(ret[0]);
115
- }
116
95
  }
117
- if (Symbol.dispose) PreparedCurves.prototype[Symbol.dispose] = PreparedCurves.prototype.free;
96
+ if (Symbol.dispose) PreparedNumericals.prototype[Symbol.dispose] = PreparedNumericals.prototype.free;
118
97
 
119
98
  /**
120
- * @returns {Array<any>}
99
+ * @param {string} uri
100
+ * @param {string} text
121
101
  */
122
- export function curveKindNames() {
123
- const ret = wasm.curveKindNames();
124
- return ret;
125
- }
126
-
127
- /**
128
- * @returns {Array<any>}
129
- */
130
- export function curveTypeNames() {
131
- const ret = wasm.curveTypeNames();
132
- return ret;
102
+ export function validateDocument(uri, text) {
103
+ const ptr0 = passStringToWasm0(uri, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
104
+ const len0 = WASM_VECTOR_LEN;
105
+ const ptr1 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
106
+ const len1 = WASM_VECTOR_LEN;
107
+ const ret = wasm.validateDocument(ptr0, len0, ptr1, len1);
108
+ if (ret[1]) {
109
+ throw takeFromExternrefTable0(ret[0]);
110
+ }
133
111
  }
134
112
 
135
113
  /**
136
- * @param {Float64Array} row
137
- * @param {Float64Array} knots
138
- * @param {number} q
139
- * @returns {any}
114
+ * @returns {string}
140
115
  */
141
- export function evaluateCurvePacked(row, knots, q) {
142
- const ptr0 = passArrayF64ToWasm0(row, wasm.__wbindgen_malloc);
143
- const len0 = WASM_VECTOR_LEN;
144
- const ptr1 = passArrayF64ToWasm0(knots, wasm.__wbindgen_malloc);
145
- const len1 = WASM_VECTOR_LEN;
146
- const ret = wasm.evaluateCurvePacked(ptr0, len0, ptr1, len1, q);
147
- if (ret[2]) {
148
- throw takeFromExternrefTable0(ret[1]);
116
+ export function version() {
117
+ let deferred1_0;
118
+ let deferred1_1;
119
+ try {
120
+ const ret = wasm.version();
121
+ deferred1_0 = ret[0];
122
+ deferred1_1 = ret[1];
123
+ return getStringFromWasm0(ret[0], ret[1]);
124
+ } finally {
125
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
149
126
  }
150
- return takeFromExternrefTable0(ret[0]);
151
127
  }
152
128
  function __wbg_get_imports() {
153
129
  const import0 = {
@@ -155,6 +131,9 @@ function __wbg_get_imports() {
155
131
  __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
156
132
  throw new Error(getStringFromWasm0(arg0, arg1));
157
133
  },
134
+ __wbg_getRandomValues_a608c4436c19407a: function() { return handleError(function (arg0, arg1) {
135
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
136
+ }, arguments); },
158
137
  __wbg_new_2bdcdfcebdfc34d2: function(arg0, arg1) {
159
138
  const ret = new TypeError(getStringFromWasm0(arg0, arg1));
160
139
  return ret;
@@ -163,24 +142,6 @@ function __wbg_get_imports() {
163
142
  const ret = new RangeError(getStringFromWasm0(arg0, arg1));
164
143
  return ret;
165
144
  },
166
- __wbg_new_ee2291f50781bf1d: function() {
167
- const ret = new Array();
168
- return ret;
169
- },
170
- __wbg_push_2baf45db356cf468: function(arg0, arg1) {
171
- const ret = arg0.push(arg1);
172
- return ret;
173
- },
174
- __wbindgen_generic_0000000000000001: function(arg0) {
175
- // Cast intrinsic for `F64 -> Externref`.
176
- const ret = arg0;
177
- return ret;
178
- },
179
- __wbindgen_generic_0000000000000002: function(arg0, arg1) {
180
- // Cast intrinsic for `Ref(String) -> Externref`.
181
- const ret = getStringFromWasm0(arg0, arg1);
182
- return ret;
183
- },
184
145
  __wbindgen_init_externref_table: function() {
185
146
  const table = wasm.__wbindgen_externrefs;
186
147
  const offset = table.grow(4);
@@ -197,18 +158,29 @@ function __wbg_get_imports() {
197
158
  };
198
159
  }
199
160
 
200
- const PreparedCurveFinalization = (typeof FinalizationRegistry === 'undefined')
161
+ const PreparedNumericalFinalization = (typeof FinalizationRegistry === 'undefined')
201
162
  ? { register: () => {}, unregister: () => {} }
202
- : new FinalizationRegistry(ptr => wasm.__wbg_preparedcurve_free(ptr, 1));
203
- const PreparedCurvesFinalization = (typeof FinalizationRegistry === 'undefined')
163
+ : new FinalizationRegistry(ptr => wasm.__wbg_preparednumerical_free(ptr, 1));
164
+ const PreparedNumericalsFinalization = (typeof FinalizationRegistry === 'undefined')
204
165
  ? { register: () => {}, unregister: () => {} }
205
- : new FinalizationRegistry(ptr => wasm.__wbg_preparedcurves_free(ptr, 1));
166
+ : new FinalizationRegistry(ptr => wasm.__wbg_preparednumericals_free(ptr, 1));
167
+
168
+ function addToExternrefTable0(obj) {
169
+ const idx = wasm.__externref_table_alloc();
170
+ wasm.__wbindgen_externrefs.set(idx, obj);
171
+ return idx;
172
+ }
206
173
 
207
174
  function getArrayF64FromWasm0(ptr, len) {
208
175
  ptr = ptr >>> 0;
209
176
  return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
210
177
  }
211
178
 
179
+ function getArrayU8FromWasm0(ptr, len) {
180
+ ptr = ptr >>> 0;
181
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
182
+ }
183
+
212
184
  let cachedFloat64ArrayMemory0 = null;
213
185
  function getFloat64ArrayMemory0() {
214
186
  if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
@@ -229,6 +201,15 @@ function getUint8ArrayMemory0() {
229
201
  return cachedUint8ArrayMemory0;
230
202
  }
231
203
 
204
+ function handleError(f, args) {
205
+ try {
206
+ return f.apply(this, args);
207
+ } catch (e) {
208
+ const idx = addToExternrefTable0(e);
209
+ wasm.__wbindgen_exn_store(idx);
210
+ }
211
+ }
212
+
232
213
  function passArrayF64ToWasm0(arg, malloc) {
233
214
  const ptr = malloc(arg.length * 8, 8) >>> 0;
234
215
  getFloat64ArrayMemory0().set(arg, ptr / 8);
@@ -236,6 +217,43 @@ function passArrayF64ToWasm0(arg, malloc) {
236
217
  return ptr;
237
218
  }
238
219
 
220
+ function passStringToWasm0(arg, malloc, realloc) {
221
+ if (realloc === undefined) {
222
+ const buf = cachedTextEncoder.encode(arg);
223
+ const ptr = malloc(buf.length, 1) >>> 0;
224
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
225
+ WASM_VECTOR_LEN = buf.length;
226
+ return ptr;
227
+ }
228
+
229
+ let len = arg.length;
230
+ let ptr = malloc(len, 1) >>> 0;
231
+
232
+ const mem = getUint8ArrayMemory0();
233
+
234
+ let offset = 0;
235
+
236
+ for (; offset < len; offset++) {
237
+ const code = arg.charCodeAt(offset);
238
+ if (code > 0x7F) break;
239
+ mem[ptr + offset] = code;
240
+ }
241
+ if (offset !== len) {
242
+ if (offset !== 0) {
243
+ arg = arg.slice(offset);
244
+ }
245
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
246
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
247
+ const ret = cachedTextEncoder.encodeInto(arg, view);
248
+
249
+ offset += ret.written;
250
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
251
+ }
252
+
253
+ WASM_VECTOR_LEN = offset;
254
+ return ptr;
255
+ }
256
+
239
257
  function takeFromExternrefTable0(idx) {
240
258
  const value = wasm.__wbindgen_externrefs.get(idx);
241
259
  wasm.__externref_table_dealloc(idx);
@@ -256,6 +274,19 @@ function decodeText(ptr, len) {
256
274
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
257
275
  }
258
276
 
277
+ const cachedTextEncoder = new TextEncoder();
278
+
279
+ if (!('encodeInto' in cachedTextEncoder)) {
280
+ cachedTextEncoder.encodeInto = function (arg, view) {
281
+ const buf = cachedTextEncoder.encode(arg);
282
+ view.set(buf);
283
+ return {
284
+ read: arg.length,
285
+ written: buf.length
286
+ };
287
+ };
288
+ }
289
+
259
290
  let WASM_VECTOR_LEN = 0;
260
291
 
261
292
  let wasmModule, wasmInstance, wasm;
Binary file
@@ -1,18 +1,20 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
- export const __wbg_preparedcurve_free: (a: number, b: number) => void;
5
- export const __wbg_preparedcurves_free: (a: number, b: number) => void;
6
- export const curveKindNames: () => any;
7
- export const curveTypeNames: () => any;
8
- export const evaluateCurvePacked: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
9
- export const preparedcurve_evaluate: (a: number, b: number) => [number, number, number];
10
- export const preparedcurve_fromPacked: (a: number, b: number, c: number, d: number) => [number, number, number];
11
- export const preparedcurve_quantiles: (a: number, b: number, c: number) => [number, number, number];
12
- export const preparedcurves_evaluate: (a: number, b: number) => [number, number, number, number];
13
- export const preparedcurves_fromPacked: (a: number, b: number, c: number, d: number) => [number, number, number];
4
+ export const __wbg_preparednumerical_free: (a: number, b: number) => void;
5
+ export const __wbg_preparednumericals_free: (a: number, b: number) => void;
6
+ export const preparednumerical_new: (a: number, b: number) => [number, number, number];
7
+ export const preparednumerical_quantile: (a: number, b: number) => [number, number, number];
8
+ export const preparednumerical_quantileBatch: (a: number, b: number, c: number) => [number, number, number, number];
9
+ export const preparednumericals_new: (a: number, b: number) => [number, number, number];
10
+ export const preparednumericals_quantile: (a: number, b: number) => [number, number, number, number];
11
+ export const validateDocument: (a: number, b: number, c: number, d: number) => [number, number];
12
+ export const version: () => [number, number];
13
+ export const __wbindgen_exn_store: (a: number) => void;
14
+ export const __externref_table_alloc: () => number;
14
15
  export const __wbindgen_externrefs: WebAssembly.Table;
15
16
  export const __wbindgen_malloc: (a: number, b: number) => number;
17
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
16
18
  export const __externref_table_dealloc: (a: number) => void;
17
19
  export const __wbindgen_free: (a: number, b: number, c: number) => void;
18
20
  export const __wbindgen_start: () => void;