@cedar-policy/cedar-wasm 4.2.0 → 4.3.0

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,11 +1,27 @@
1
1
  let wasm;
2
2
 
3
+ const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
4
+
5
+ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
6
+
7
+ let cachedUint8ArrayMemory0 = null;
8
+
9
+ function getUint8ArrayMemory0() {
10
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
11
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
12
+ }
13
+ return cachedUint8ArrayMemory0;
14
+ }
15
+
16
+ function getStringFromWasm0(ptr, len) {
17
+ ptr = ptr >>> 0;
18
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
19
+ }
20
+
3
21
  const heap = new Array(128).fill(undefined);
4
22
 
5
23
  heap.push(undefined, null, true, false);
6
24
 
7
- function getObject(idx) { return heap[idx]; }
8
-
9
25
  let heap_next = heap.length;
10
26
 
11
27
  function addHeapObject(obj) {
@@ -17,6 +33,16 @@ function addHeapObject(obj) {
17
33
  return idx;
18
34
  }
19
35
 
36
+ function handleError(f, args) {
37
+ try {
38
+ return f.apply(this, args);
39
+ } catch (e) {
40
+ wasm.__wbindgen_exn_store(addHeapObject(e));
41
+ }
42
+ }
43
+
44
+ function getObject(idx) { return heap[idx]; }
45
+
20
46
  function dropObject(idx) {
21
47
  if (idx < 132) return;
22
48
  heap[idx] = heap_next;
@@ -31,15 +57,6 @@ function takeObject(idx) {
31
57
 
32
58
  let WASM_VECTOR_LEN = 0;
33
59
 
34
- let cachedUint8ArrayMemory0 = null;
35
-
36
- function getUint8ArrayMemory0() {
37
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
38
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
39
- }
40
- return cachedUint8ArrayMemory0;
41
- }
42
-
43
60
  const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
44
61
 
45
62
  const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
@@ -106,46 +123,37 @@ function getDataViewMemory0() {
106
123
  }
107
124
  return cachedDataViewMemory0;
108
125
  }
109
-
110
- const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
111
-
112
- if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
113
-
114
- function getStringFromWasm0(ptr, len) {
115
- ptr = ptr >>> 0;
116
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
117
- }
118
126
  /**
119
- * Get valid request environment
120
- * @param {Template} t
121
- * @param {Schema} s
122
- * @returns {GetValidRequestEnvsResult}
123
- */
127
+ * Get valid request environment
128
+ * @param {Template} t
129
+ * @param {Schema} s
130
+ * @returns {GetValidRequestEnvsResult}
131
+ */
124
132
  export function getValidRequestEnvsTemplate(t, s) {
125
133
  const ret = wasm.getValidRequestEnvsTemplate(addHeapObject(t), addHeapObject(s));
126
134
  return takeObject(ret);
127
135
  }
128
136
 
129
137
  /**
130
- * Get valid request environment
131
- * @param {Policy} t
132
- * @param {Schema} s
133
- * @returns {GetValidRequestEnvsResult}
134
- */
138
+ * Get valid request environment
139
+ * @param {Policy} t
140
+ * @param {Schema} s
141
+ * @returns {GetValidRequestEnvsResult}
142
+ */
135
143
  export function getValidRequestEnvsPolicy(t, s) {
136
144
  const ret = wasm.getValidRequestEnvsPolicy(addHeapObject(t), addHeapObject(s));
137
145
  return takeObject(ret);
138
146
  }
139
147
 
140
148
  /**
141
- * @returns {string}
142
- */
149
+ * @returns {string}
150
+ */
143
151
  export function getCedarVersion() {
144
152
  let deferred1_0;
145
153
  let deferred1_1;
146
154
  try {
147
155
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
148
- wasm.getCedarVersion(retptr);
156
+ wasm.getCedarSDKVersion(retptr);
149
157
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
150
158
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
151
159
  deferred1_0 = r0;
@@ -158,144 +166,177 @@ export function getCedarVersion() {
158
166
  }
159
167
 
160
168
  /**
161
- * Basic interface, using [`AuthorizationCall`] and [`AuthorizationAnswer`] types
162
- * @param {AuthorizationCall} call
163
- * @returns {AuthorizationAnswer}
164
- */
165
- export function isAuthorized(call) {
166
- const ret = wasm.isAuthorized(addHeapObject(call));
167
- return takeObject(ret);
169
+ * @returns {string}
170
+ */
171
+ export function getCedarSDKVersion() {
172
+ let deferred1_0;
173
+ let deferred1_1;
174
+ try {
175
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
176
+ wasm.getCedarSDKVersion(retptr);
177
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
178
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
179
+ deferred1_0 = r0;
180
+ deferred1_1 = r1;
181
+ return getStringFromWasm0(r0, r1);
182
+ } finally {
183
+ wasm.__wbindgen_add_to_stack_pointer(16);
184
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
185
+ }
168
186
  }
169
187
 
170
188
  /**
171
- * Parse a policy set and optionally validate it against a provided schema
172
- *
173
- * This is the basic validator interface, using [`ValidationCall`] and
174
- * [`ValidationAnswer`] types
175
- * @param {ValidationCall} call
176
- * @returns {ValidationAnswer}
177
- */
189
+ * Parse a policy set and optionally validate it against a provided schema
190
+ *
191
+ * This is the basic validator interface, using [`ValidationCall`] and
192
+ * [`ValidationAnswer`] types
193
+ * @param {ValidationCall} call
194
+ * @returns {ValidationAnswer}
195
+ */
178
196
  export function validate(call) {
179
197
  const ret = wasm.validate(addHeapObject(call));
180
198
  return takeObject(ret);
181
199
  }
182
200
 
183
201
  /**
184
- * Apply the Cedar policy formatter to a policy set in the Cedar policy format
185
- * @param {FormattingCall} call
186
- * @returns {FormattingAnswer}
187
- */
188
- export function formatPolicies(call) {
189
- const ret = wasm.formatPolicies(addHeapObject(call));
190
- return takeObject(ret);
202
+ * Get language version of Cedar
203
+ * @returns {string}
204
+ */
205
+ export function getCedarLangVersion() {
206
+ let deferred1_0;
207
+ let deferred1_1;
208
+ try {
209
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
210
+ wasm.getCedarLangVersion(retptr);
211
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
212
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
213
+ deferred1_0 = r0;
214
+ deferred1_1 = r1;
215
+ return getStringFromWasm0(r0, r1);
216
+ } finally {
217
+ wasm.__wbindgen_add_to_stack_pointer(16);
218
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
219
+ }
191
220
  }
192
221
 
193
222
  /**
194
- * Return the Cedar (textual) representation of a policy.
195
- * @param {Policy} policy
196
- * @returns {PolicyToTextAnswer}
197
- */
223
+ * Return the Cedar (textual) representation of a policy.
224
+ * @param {Policy} policy
225
+ * @returns {PolicyToTextAnswer}
226
+ */
198
227
  export function policyToText(policy) {
199
228
  const ret = wasm.policyToText(addHeapObject(policy));
200
229
  return takeObject(ret);
201
230
  }
202
231
 
203
232
  /**
204
- * Return the Cedar (textual) representation of a template.
205
- * @param {Template} template
206
- * @returns {PolicyToTextAnswer}
207
- */
233
+ * Return the Cedar (textual) representation of a template.
234
+ * @param {Template} template
235
+ * @returns {PolicyToTextAnswer}
236
+ */
208
237
  export function templateToText(template) {
209
238
  const ret = wasm.templateToText(addHeapObject(template));
210
239
  return takeObject(ret);
211
240
  }
212
241
 
213
242
  /**
214
- * Return the JSON representation of a policy.
215
- * @param {Policy} policy
216
- * @returns {PolicyToJsonAnswer}
217
- */
243
+ * Return the JSON representation of a policy.
244
+ * @param {Policy} policy
245
+ * @returns {PolicyToJsonAnswer}
246
+ */
218
247
  export function policyToJson(policy) {
219
248
  const ret = wasm.policyToJson(addHeapObject(policy));
220
249
  return takeObject(ret);
221
250
  }
222
251
 
223
252
  /**
224
- * Return the JSON representation of a template.
225
- * @param {Template} template
226
- * @returns {PolicyToJsonAnswer}
227
- */
253
+ * Return the JSON representation of a template.
254
+ * @param {Template} template
255
+ * @returns {PolicyToJsonAnswer}
256
+ */
228
257
  export function templateToJson(template) {
229
258
  const ret = wasm.templateToJson(addHeapObject(template));
230
259
  return takeObject(ret);
231
260
  }
232
261
 
233
262
  /**
234
- * Return the Cedar (textual) representation of a schema.
235
- * @param {Schema} schema
236
- * @returns {SchemaToTextAnswer}
237
- */
263
+ * Return the Cedar (textual) representation of a schema.
264
+ * @param {Schema} schema
265
+ * @returns {SchemaToTextAnswer}
266
+ */
238
267
  export function schemaToText(schema) {
239
268
  const ret = wasm.schemaToText(addHeapObject(schema));
240
269
  return takeObject(ret);
241
270
  }
242
271
 
243
272
  /**
244
- * Return the JSON representation of a schema.
245
- * @param {Schema} schema
246
- * @returns {SchemaToJsonAnswer}
247
- */
273
+ * Return the JSON representation of a schema.
274
+ * @param {Schema} schema
275
+ * @returns {SchemaToJsonAnswer}
276
+ */
248
277
  export function schemaToJson(schema) {
249
278
  const ret = wasm.schemaToJson(addHeapObject(schema));
250
279
  return takeObject(ret);
251
280
  }
252
281
 
253
282
  /**
254
- * Check whether a policy set successfully parses.
255
- * @param {PolicySet} policies
256
- * @returns {CheckParseAnswer}
257
- */
283
+ * Check whether a policy set successfully parses.
284
+ * @param {PolicySet} policies
285
+ * @returns {CheckParseAnswer}
286
+ */
258
287
  export function checkParsePolicySet(policies) {
259
288
  const ret = wasm.checkParsePolicySet(addHeapObject(policies));
260
289
  return takeObject(ret);
261
290
  }
262
291
 
263
292
  /**
264
- * Check whether a schema successfully parses.
265
- * @param {Schema} schema
266
- * @returns {CheckParseAnswer}
267
- */
293
+ * Check whether a schema successfully parses.
294
+ * @param {Schema} schema
295
+ * @returns {CheckParseAnswer}
296
+ */
268
297
  export function checkParseSchema(schema) {
269
298
  const ret = wasm.checkParseSchema(addHeapObject(schema));
270
299
  return takeObject(ret);
271
300
  }
272
301
 
273
302
  /**
274
- * Check whether a set of entities successfully parses.
275
- * @param {EntitiesParsingCall} call
276
- * @returns {CheckParseAnswer}
277
- */
303
+ * Check whether a set of entities successfully parses.
304
+ * @param {EntitiesParsingCall} call
305
+ * @returns {CheckParseAnswer}
306
+ */
278
307
  export function checkParseEntities(call) {
279
308
  const ret = wasm.checkParseEntities(addHeapObject(call));
280
309
  return takeObject(ret);
281
310
  }
282
311
 
283
312
  /**
284
- * Check whether a context successfully parses.
285
- * @param {ContextParsingCall} call
286
- * @returns {CheckParseAnswer}
287
- */
313
+ * Check whether a context successfully parses.
314
+ * @param {ContextParsingCall} call
315
+ * @returns {CheckParseAnswer}
316
+ */
288
317
  export function checkParseContext(call) {
289
318
  const ret = wasm.checkParseContext(addHeapObject(call));
290
319
  return takeObject(ret);
291
320
  }
292
321
 
293
- function handleError(f, args) {
294
- try {
295
- return f.apply(this, args);
296
- } catch (e) {
297
- wasm.__wbindgen_exn_store(addHeapObject(e));
298
- }
322
+ /**
323
+ * Basic interface, using [`AuthorizationCall`] and [`AuthorizationAnswer`] types
324
+ * @param {AuthorizationCall} call
325
+ * @returns {AuthorizationAnswer}
326
+ */
327
+ export function isAuthorized(call) {
328
+ const ret = wasm.isAuthorized(addHeapObject(call));
329
+ return takeObject(ret);
330
+ }
331
+
332
+ /**
333
+ * Apply the Cedar policy formatter to a policy set in the Cedar policy format
334
+ * @param {FormattingCall} call
335
+ * @returns {FormattingAnswer}
336
+ */
337
+ export function formatPolicies(call) {
338
+ const ret = wasm.formatPolicies(addHeapObject(call));
339
+ return takeObject(ret);
299
340
  }
300
341
 
301
342
  async function __wbg_load(module, imports) {
@@ -306,7 +347,7 @@ async function __wbg_load(module, imports) {
306
347
 
307
348
  } catch (e) {
308
349
  if (module.headers.get('Content-Type') != 'application/wasm') {
309
- 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);
350
+ 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);
310
351
 
311
352
  } else {
312
353
  throw e;
@@ -332,6 +373,18 @@ async function __wbg_load(module, imports) {
332
373
  function __wbg_get_imports() {
333
374
  const imports = {};
334
375
  imports.wbg = {};
376
+ imports.wbg.__wbg_parse_def2e24ef1252aff = function() { return handleError(function (arg0, arg1) {
377
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
378
+ return addHeapObject(ret);
379
+ }, arguments) };
380
+ imports.wbg.__wbg_stringify_f7ed6987935b4a24 = function() { return handleError(function (arg0) {
381
+ const ret = JSON.stringify(getObject(arg0));
382
+ return addHeapObject(ret);
383
+ }, arguments) };
384
+ imports.wbg.__wbindgen_is_undefined = function(arg0) {
385
+ const ret = getObject(arg0) === undefined;
386
+ return ret;
387
+ };
335
388
  imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
336
389
  const ret = getObject(arg0);
337
390
  return addHeapObject(ret);
@@ -339,10 +392,6 @@ function __wbg_get_imports() {
339
392
  imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
340
393
  takeObject(arg0);
341
394
  };
342
- imports.wbg.__wbindgen_is_undefined = function(arg0) {
343
- const ret = getObject(arg0) === undefined;
344
- return ret;
345
- };
346
395
  imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
347
396
  const obj = getObject(arg1);
348
397
  const ret = typeof(obj) === 'string' ? obj : undefined;
@@ -351,14 +400,6 @@ function __wbg_get_imports() {
351
400
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
352
401
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
353
402
  };
354
- imports.wbg.__wbg_parse_52202f117ec9ecfa = function() { return handleError(function (arg0, arg1) {
355
- const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
356
- return addHeapObject(ret);
357
- }, arguments) };
358
- imports.wbg.__wbg_stringify_bbf45426c92a6bf5 = function() { return handleError(function (arg0) {
359
- const ret = JSON.stringify(getObject(arg0));
360
- return addHeapObject(ret);
361
- }, arguments) };
362
403
  imports.wbg.__wbindgen_throw = function(arg0, arg1) {
363
404
  throw new Error(getStringFromWasm0(arg0, arg1));
364
405
  };
@@ -385,10 +426,13 @@ function initSync(module) {
385
426
  if (wasm !== undefined) return wasm;
386
427
 
387
428
 
388
- if (typeof module !== 'undefined' && Object.getPrototypeOf(module) === Object.prototype)
389
- ({module} = module)
390
- else
391
- console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
429
+ if (typeof module !== 'undefined') {
430
+ if (Object.getPrototypeOf(module) === Object.prototype) {
431
+ ({module} = module)
432
+ } else {
433
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
434
+ }
435
+ }
392
436
 
393
437
  const imports = __wbg_get_imports();
394
438
 
@@ -407,10 +451,13 @@ async function __wbg_init(module_or_path) {
407
451
  if (wasm !== undefined) return wasm;
408
452
 
409
453
 
410
- if (typeof module_or_path !== 'undefined' && Object.getPrototypeOf(module_or_path) === Object.prototype)
411
- ({module_or_path} = module_or_path)
412
- else
413
- console.warn('using deprecated parameters for the initialization function; pass a single object instead')
454
+ if (typeof module_or_path !== 'undefined') {
455
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
456
+ ({module_or_path} = module_or_path)
457
+ } else {
458
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
459
+ }
460
+ }
414
461
 
415
462
  if (typeof module_or_path === 'undefined') {
416
463
  module_or_path = new URL('cedar_wasm_bg.wasm', import.meta.url);
Binary file
@@ -1,24 +1,26 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
- export function getValidRequestEnvsTemplate(a: number, b: number): number;
5
- export function getValidRequestEnvsPolicy(a: number, b: number): number;
6
- export function getCedarVersion(a: number): void;
7
- export function isAuthorized(a: number): number;
8
- export function validate(a: number): number;
9
- export function formatPolicies(a: number): number;
10
- export function policyToText(a: number): number;
11
- export function templateToText(a: number): number;
12
- export function policyToJson(a: number): number;
13
- export function templateToJson(a: number): number;
14
- export function schemaToText(a: number): number;
15
- export function schemaToJson(a: number): number;
16
- export function checkParsePolicySet(a: number): number;
17
- export function checkParseSchema(a: number): number;
18
- export function checkParseEntities(a: number): number;
19
- export function checkParseContext(a: number): number;
20
- export function __wbindgen_malloc(a: number, b: number): number;
21
- export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
22
- export function __wbindgen_add_to_stack_pointer(a: number): number;
23
- export function __wbindgen_free(a: number, b: number, c: number): void;
24
- export function __wbindgen_exn_store(a: number): void;
4
+ export const getValidRequestEnvsTemplate: (a: number, b: number) => number;
5
+ export const getValidRequestEnvsPolicy: (a: number, b: number) => number;
6
+ export const getCedarSDKVersion: (a: number) => void;
7
+ export const getCedarVersion: (a: number) => void;
8
+ export const validate: (a: number) => number;
9
+ export const getCedarLangVersion: (a: number) => void;
10
+ export const policyToText: (a: number) => number;
11
+ export const templateToText: (a: number) => number;
12
+ export const policyToJson: (a: number) => number;
13
+ export const templateToJson: (a: number) => number;
14
+ export const schemaToText: (a: number) => number;
15
+ export const schemaToJson: (a: number) => number;
16
+ export const checkParsePolicySet: (a: number) => number;
17
+ export const checkParseSchema: (a: number) => number;
18
+ export const checkParseEntities: (a: number) => number;
19
+ export const checkParseContext: (a: number) => number;
20
+ export const isAuthorized: (a: number) => number;
21
+ export const formatPolicies: (a: number) => number;
22
+ export const __wbindgen_exn_store: (a: number) => void;
23
+ export const __wbindgen_malloc: (a: number, b: number) => number;
24
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
25
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
26
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
package/web/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@cedar-policy/cedar-wasm",
3
- "type": "module",
4
3
  "description": "Wasm bindings and typescript types for Cedar lib",
5
- "version": "4.2.0",
4
+ "version": "4.3.0",
6
5
  "license": "Apache-2.0",
7
6
  "files": [
8
7
  "cedar_wasm_bg.wasm",
9
8
  "cedar_wasm.js",
10
9
  "cedar_wasm.d.ts"
11
10
  ],
12
- "main": "cedar_wasm.js",
11
+ "module": "cedar_wasm.js",
13
12
  "types": "cedar_wasm.d.ts",
14
13
  "sideEffects": [
15
14
  "./snippets/*"
16
- ]
15
+ ],
16
+ "type": "module"
17
17
  }