@cedar-policy/cedar-wasm 4.8.2 → 4.9.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.
package/web/cedar_wasm.js CHANGED
@@ -1,110 +1,4 @@
1
- let wasm;
2
-
3
- function addToExternrefTable0(obj) {
4
- const idx = wasm.__externref_table_alloc();
5
- wasm.__wbindgen_externrefs.set(idx, obj);
6
- return idx;
7
- }
8
-
9
- let cachedDataViewMemory0 = null;
10
- function getDataViewMemory0() {
11
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
12
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
13
- }
14
- return cachedDataViewMemory0;
15
- }
16
-
17
- function getStringFromWasm0(ptr, len) {
18
- ptr = ptr >>> 0;
19
- return decodeText(ptr, len);
20
- }
21
-
22
- let cachedUint8ArrayMemory0 = null;
23
- function getUint8ArrayMemory0() {
24
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
25
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
26
- }
27
- return cachedUint8ArrayMemory0;
28
- }
29
-
30
- function handleError(f, args) {
31
- try {
32
- return f.apply(this, args);
33
- } catch (e) {
34
- const idx = addToExternrefTable0(e);
35
- wasm.__wbindgen_exn_store(idx);
36
- }
37
- }
38
-
39
- function isLikeNone(x) {
40
- return x === undefined || x === null;
41
- }
42
-
43
- function passStringToWasm0(arg, malloc, realloc) {
44
- if (realloc === undefined) {
45
- const buf = cachedTextEncoder.encode(arg);
46
- const ptr = malloc(buf.length, 1) >>> 0;
47
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
48
- WASM_VECTOR_LEN = buf.length;
49
- return ptr;
50
- }
51
-
52
- let len = arg.length;
53
- let ptr = malloc(len, 1) >>> 0;
54
-
55
- const mem = getUint8ArrayMemory0();
56
-
57
- let offset = 0;
58
-
59
- for (; offset < len; offset++) {
60
- const code = arg.charCodeAt(offset);
61
- if (code > 0x7F) break;
62
- mem[ptr + offset] = code;
63
- }
64
- if (offset !== len) {
65
- if (offset !== 0) {
66
- arg = arg.slice(offset);
67
- }
68
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
69
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
70
- const ret = cachedTextEncoder.encodeInto(arg, view);
71
-
72
- offset += ret.written;
73
- ptr = realloc(ptr, len, offset, 1) >>> 0;
74
- }
75
-
76
- WASM_VECTOR_LEN = offset;
77
- return ptr;
78
- }
79
-
80
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
81
- cachedTextDecoder.decode();
82
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
83
- let numBytesDecoded = 0;
84
- function decodeText(ptr, len) {
85
- numBytesDecoded += len;
86
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
87
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
88
- cachedTextDecoder.decode();
89
- numBytesDecoded = len;
90
- }
91
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
92
- }
93
-
94
- const cachedTextEncoder = new TextEncoder();
95
-
96
- if (!('encodeInto' in cachedTextEncoder)) {
97
- cachedTextEncoder.encodeInto = function (arg, view) {
98
- const buf = cachedTextEncoder.encode(arg);
99
- view.set(buf);
100
- return {
101
- read: arg.length,
102
- written: buf.length
103
- };
104
- }
105
- }
106
-
107
- let WASM_VECTOR_LEN = 0;
1
+ /* @ts-self-types="./cedar_wasm.d.ts" */
108
2
 
109
3
  /**
110
4
  * Check whether a context successfully parses.
@@ -237,6 +131,17 @@ export function isAuthorized(call) {
237
131
  return ret;
238
132
  }
239
133
 
134
+ /**
135
+ * Basic interface for partial evaluation, using [`AuthorizationCall`] and
136
+ * [`PartialAuthorizationAnswer`] types
137
+ * @param {PartialAuthorizationCall} call
138
+ * @returns {PartialAuthorizationAnswer}
139
+ */
140
+ export function isAuthorizedPartial(call) {
141
+ const ret = wasm.isAuthorizedPartial(call);
142
+ return ret;
143
+ }
144
+
240
145
  /**
241
146
  * Takes a `PolicySet` represented as string and return the policies
242
147
  * and templates split into vecs and sorted by id.
@@ -314,6 +219,23 @@ export function schemaToJson(schema) {
314
219
  return ret;
315
220
  }
316
221
 
222
+ /**
223
+ * Convert a Cedar schema string to JSON format with resolved types.
224
+ *
225
+ * This function resolves ambiguous "`EntityOrCommon`" types to their specific
226
+ * Entity or `CommonType` classifications using the schema's type definitions.
227
+ * This is primarily meant to be used when working with schemas programmatically,
228
+ * for example when creating a schema building UI.
229
+ * @param {string} schema_str
230
+ * @returns {SchemaToJsonWithResolvedTypesAnswer}
231
+ */
232
+ export function schemaToJsonWithResolvedTypes(schema_str) {
233
+ const ptr0 = passStringToWasm0(schema_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
234
+ const len0 = WASM_VECTOR_LEN;
235
+ const ret = wasm.schemaToJsonWithResolvedTypes(ptr0, len0);
236
+ return ret;
237
+ }
238
+
317
239
  /**
318
240
  * Return the Cedar (textual) representation of a schema.
319
241
  * @param {Schema} schema
@@ -370,7 +292,163 @@ export function validate(call) {
370
292
  return ret;
371
293
  }
372
294
 
373
- const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
295
+ function __wbg_get_imports() {
296
+ const import0 = {
297
+ __proto__: null,
298
+ __wbg___wbindgen_is_undefined_9e4d92534c42d778: function(arg0) {
299
+ const ret = arg0 === undefined;
300
+ return ret;
301
+ },
302
+ __wbg___wbindgen_string_get_72fb696202c56729: function(arg0, arg1) {
303
+ const obj = arg1;
304
+ const ret = typeof(obj) === 'string' ? obj : undefined;
305
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
306
+ var len1 = WASM_VECTOR_LEN;
307
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
308
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
309
+ },
310
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
311
+ throw new Error(getStringFromWasm0(arg0, arg1));
312
+ },
313
+ __wbg_parse_708461a1feddfb38: function() { return handleError(function (arg0, arg1) {
314
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
315
+ return ret;
316
+ }, arguments); },
317
+ __wbg_stringify_8d1cc6ff383e8bae: function() { return handleError(function (arg0) {
318
+ const ret = JSON.stringify(arg0);
319
+ return ret;
320
+ }, arguments); },
321
+ __wbindgen_init_externref_table: function() {
322
+ const table = wasm.__wbindgen_externrefs;
323
+ const offset = table.grow(4);
324
+ table.set(0, undefined);
325
+ table.set(offset + 0, undefined);
326
+ table.set(offset + 1, null);
327
+ table.set(offset + 2, true);
328
+ table.set(offset + 3, false);
329
+ },
330
+ };
331
+ return {
332
+ __proto__: null,
333
+ "./cedar_wasm_bg.js": import0,
334
+ };
335
+ }
336
+
337
+ function addToExternrefTable0(obj) {
338
+ const idx = wasm.__externref_table_alloc();
339
+ wasm.__wbindgen_externrefs.set(idx, obj);
340
+ return idx;
341
+ }
342
+
343
+ let cachedDataViewMemory0 = null;
344
+ function getDataViewMemory0() {
345
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
346
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
347
+ }
348
+ return cachedDataViewMemory0;
349
+ }
350
+
351
+ function getStringFromWasm0(ptr, len) {
352
+ ptr = ptr >>> 0;
353
+ return decodeText(ptr, len);
354
+ }
355
+
356
+ let cachedUint8ArrayMemory0 = null;
357
+ function getUint8ArrayMemory0() {
358
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
359
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
360
+ }
361
+ return cachedUint8ArrayMemory0;
362
+ }
363
+
364
+ function handleError(f, args) {
365
+ try {
366
+ return f.apply(this, args);
367
+ } catch (e) {
368
+ const idx = addToExternrefTable0(e);
369
+ wasm.__wbindgen_exn_store(idx);
370
+ }
371
+ }
372
+
373
+ function isLikeNone(x) {
374
+ return x === undefined || x === null;
375
+ }
376
+
377
+ function passStringToWasm0(arg, malloc, realloc) {
378
+ if (realloc === undefined) {
379
+ const buf = cachedTextEncoder.encode(arg);
380
+ const ptr = malloc(buf.length, 1) >>> 0;
381
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
382
+ WASM_VECTOR_LEN = buf.length;
383
+ return ptr;
384
+ }
385
+
386
+ let len = arg.length;
387
+ let ptr = malloc(len, 1) >>> 0;
388
+
389
+ const mem = getUint8ArrayMemory0();
390
+
391
+ let offset = 0;
392
+
393
+ for (; offset < len; offset++) {
394
+ const code = arg.charCodeAt(offset);
395
+ if (code > 0x7F) break;
396
+ mem[ptr + offset] = code;
397
+ }
398
+ if (offset !== len) {
399
+ if (offset !== 0) {
400
+ arg = arg.slice(offset);
401
+ }
402
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
403
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
404
+ const ret = cachedTextEncoder.encodeInto(arg, view);
405
+
406
+ offset += ret.written;
407
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
408
+ }
409
+
410
+ WASM_VECTOR_LEN = offset;
411
+ return ptr;
412
+ }
413
+
414
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
415
+ cachedTextDecoder.decode();
416
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
417
+ let numBytesDecoded = 0;
418
+ function decodeText(ptr, len) {
419
+ numBytesDecoded += len;
420
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
421
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
422
+ cachedTextDecoder.decode();
423
+ numBytesDecoded = len;
424
+ }
425
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
426
+ }
427
+
428
+ const cachedTextEncoder = new TextEncoder();
429
+
430
+ if (!('encodeInto' in cachedTextEncoder)) {
431
+ cachedTextEncoder.encodeInto = function (arg, view) {
432
+ const buf = cachedTextEncoder.encode(arg);
433
+ view.set(buf);
434
+ return {
435
+ read: arg.length,
436
+ written: buf.length
437
+ };
438
+ };
439
+ }
440
+
441
+ let WASM_VECTOR_LEN = 0;
442
+
443
+ let wasmModule, wasm;
444
+ function __wbg_finalize_init(instance, module) {
445
+ wasm = instance.exports;
446
+ wasmModule = module;
447
+ cachedDataViewMemory0 = null;
448
+ cachedUint8ArrayMemory0 = null;
449
+ wasm.__wbindgen_start();
450
+ return wasm;
451
+ }
374
452
 
375
453
  async function __wbg_load(module, imports) {
376
454
  if (typeof Response === 'function' && module instanceof Response) {
@@ -378,14 +456,12 @@ async function __wbg_load(module, imports) {
378
456
  try {
379
457
  return await WebAssembly.instantiateStreaming(module, imports);
380
458
  } catch (e) {
381
- const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
459
+ const validResponse = module.ok && expectedResponseType(module.type);
382
460
 
383
461
  if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
384
462
  console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
385
463
 
386
- } else {
387
- throw e;
388
- }
464
+ } else { throw e; }
389
465
  }
390
466
  }
391
467
 
@@ -400,63 +476,20 @@ async function __wbg_load(module, imports) {
400
476
  return instance;
401
477
  }
402
478
  }
403
- }
404
479
 
405
- function __wbg_get_imports() {
406
- const imports = {};
407
- imports.wbg = {};
408
- imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
409
- const ret = arg0 === undefined;
410
- return ret;
411
- };
412
- imports.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42 = function(arg0, arg1) {
413
- const obj = arg1;
414
- const ret = typeof(obj) === 'string' ? obj : undefined;
415
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
416
- var len1 = WASM_VECTOR_LEN;
417
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
418
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
419
- };
420
- imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
421
- throw new Error(getStringFromWasm0(arg0, arg1));
422
- };
423
- imports.wbg.__wbg_parse_a09a54cf72639456 = function() { return handleError(function (arg0, arg1) {
424
- const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
425
- return ret;
426
- }, arguments) };
427
- imports.wbg.__wbg_stringify_655a6390e1f5eb6b = function() { return handleError(function (arg0) {
428
- const ret = JSON.stringify(arg0);
429
- return ret;
430
- }, arguments) };
431
- imports.wbg.__wbindgen_init_externref_table = function() {
432
- const table = wasm.__wbindgen_externrefs;
433
- const offset = table.grow(4);
434
- table.set(0, undefined);
435
- table.set(offset + 0, undefined);
436
- table.set(offset + 1, null);
437
- table.set(offset + 2, true);
438
- table.set(offset + 3, false);
439
- };
440
-
441
- return imports;
442
- }
443
-
444
- function __wbg_finalize_init(instance, module) {
445
- wasm = instance.exports;
446
- __wbg_init.__wbindgen_wasm_module = module;
447
- cachedDataViewMemory0 = null;
448
- cachedUint8ArrayMemory0 = null;
449
-
450
-
451
- wasm.__wbindgen_start();
452
- return wasm;
480
+ function expectedResponseType(type) {
481
+ switch (type) {
482
+ case 'basic': case 'cors': case 'default': return true;
483
+ }
484
+ return false;
485
+ }
453
486
  }
454
487
 
455
488
  function initSync(module) {
456
489
  if (wasm !== undefined) return wasm;
457
490
 
458
491
 
459
- if (typeof module !== 'undefined') {
492
+ if (module !== undefined) {
460
493
  if (Object.getPrototypeOf(module) === Object.prototype) {
461
494
  ({module} = module)
462
495
  } else {
@@ -476,7 +509,7 @@ async function __wbg_init(module_or_path) {
476
509
  if (wasm !== undefined) return wasm;
477
510
 
478
511
 
479
- if (typeof module_or_path !== 'undefined') {
512
+ if (module_or_path !== undefined) {
480
513
  if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
481
514
  ({module_or_path} = module_or_path)
482
515
  } else {
@@ -484,7 +517,7 @@ async function __wbg_init(module_or_path) {
484
517
  }
485
518
  }
486
519
 
487
- if (typeof module_or_path === 'undefined') {
520
+ if (module_or_path === undefined) {
488
521
  module_or_path = new URL('cedar_wasm_bg.wasm', import.meta.url);
489
522
  }
490
523
  const imports = __wbg_get_imports();
@@ -498,5 +531,4 @@ async function __wbg_init(module_or_path) {
498
531
  return __wbg_finalize_init(instance, module);
499
532
  }
500
533
 
501
- export { initSync };
502
- export default __wbg_init;
534
+ export { initSync, __wbg_init as default };
Binary file
@@ -5,20 +5,22 @@ export const getCedarSDKVersion: () => [number, number];
5
5
  export const getValidRequestEnvsPolicy: (a: any, b: any) => any;
6
6
  export const getValidRequestEnvsTemplate: (a: any, b: any) => any;
7
7
  export const getCedarVersion: () => [number, number];
8
- export const formatPolicies: (a: any) => any;
9
8
  export const isAuthorized: (a: any) => any;
9
+ export const isAuthorizedPartial: (a: any) => any;
10
10
  export const preparsePolicySet: (a: number, b: number, c: any) => any;
11
11
  export const preparseSchema: (a: number, b: number, c: any) => any;
12
12
  export const statefulIsAuthorized: (a: any) => any;
13
- export const validate: (a: any) => any;
14
13
  export const checkParseContext: (a: any) => any;
15
14
  export const checkParseEntities: (a: any) => any;
16
15
  export const checkParsePolicySet: (a: any) => any;
17
16
  export const checkParseSchema: (a: any) => any;
17
+ export const formatPolicies: (a: any) => any;
18
+ export const validate: (a: any) => any;
18
19
  export const policySetTextToParts: (a: number, b: number) => any;
19
20
  export const policyToJson: (a: any) => any;
20
21
  export const policyToText: (a: any) => any;
21
22
  export const schemaToJson: (a: any) => any;
23
+ export const schemaToJsonWithResolvedTypes: (a: number, b: number) => any;
22
24
  export const schemaToText: (a: any) => any;
23
25
  export const templateToJson: (a: any) => any;
24
26
  export const templateToText: (a: any) => any;
package/web/package.json CHANGED
@@ -2,8 +2,12 @@
2
2
  "name": "@cedar-policy/cedar-wasm",
3
3
  "type": "module",
4
4
  "description": "Wasm bindings and typescript types for Cedar lib",
5
- "version": "4.8.2",
5
+ "version": "4.9.1",
6
6
  "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/cedar-policy/cedar"
10
+ },
7
11
  "files": [
8
12
  "cedar_wasm_bg.wasm",
9
13
  "cedar_wasm.js",