@cedar-policy/cedar-wasm 4.8.0 → 4.8.2

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.
@@ -3,11 +3,26 @@ export function __wbg_set_wasm(val) {
3
3
  wasm = val;
4
4
  }
5
5
 
6
+ function addToExternrefTable0(obj) {
7
+ const idx = wasm.__externref_table_alloc();
8
+ wasm.__wbindgen_externrefs.set(idx, obj);
9
+ return idx;
10
+ }
6
11
 
7
- let WASM_VECTOR_LEN = 0;
12
+ let cachedDataViewMemory0 = null;
13
+ function getDataViewMemory0() {
14
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
15
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
16
+ }
17
+ return cachedDataViewMemory0;
18
+ }
8
19
 
9
- let cachedUint8ArrayMemory0 = null;
20
+ function getStringFromWasm0(ptr, len) {
21
+ ptr = ptr >>> 0;
22
+ return decodeText(ptr, len);
23
+ }
10
24
 
25
+ let cachedUint8ArrayMemory0 = null;
11
26
  function getUint8ArrayMemory0() {
12
27
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
13
28
  cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
@@ -15,21 +30,20 @@ function getUint8ArrayMemory0() {
15
30
  return cachedUint8ArrayMemory0;
16
31
  }
17
32
 
18
- const cachedTextEncoder = new TextEncoder();
19
-
20
- if (!('encodeInto' in cachedTextEncoder)) {
21
- cachedTextEncoder.encodeInto = function (arg, view) {
22
- const buf = cachedTextEncoder.encode(arg);
23
- view.set(buf);
24
- return {
25
- read: arg.length,
26
- written: buf.length
27
- };
33
+ function handleError(f, args) {
34
+ try {
35
+ return f.apply(this, args);
36
+ } catch (e) {
37
+ const idx = addToExternrefTable0(e);
38
+ wasm.__wbindgen_exn_store(idx);
28
39
  }
29
40
  }
30
41
 
31
- function passStringToWasm0(arg, malloc, realloc) {
42
+ function isLikeNone(x) {
43
+ return x === undefined || x === null;
44
+ }
32
45
 
46
+ function passStringToWasm0(arg, malloc, realloc) {
33
47
  if (realloc === undefined) {
34
48
  const buf = cachedTextEncoder.encode(arg);
35
49
  const ptr = malloc(buf.length, 1) >>> 0;
@@ -50,7 +64,6 @@ function passStringToWasm0(arg, malloc, realloc) {
50
64
  if (code > 0x7F) break;
51
65
  mem[ptr + offset] = code;
52
66
  }
53
-
54
67
  if (offset !== len) {
55
68
  if (offset !== 0) {
56
69
  arg = arg.slice(offset);
@@ -67,23 +80,8 @@ function passStringToWasm0(arg, malloc, realloc) {
67
80
  return ptr;
68
81
  }
69
82
 
70
- function isLikeNone(x) {
71
- return x === undefined || x === null;
72
- }
73
-
74
- let cachedDataViewMemory0 = null;
75
-
76
- function getDataViewMemory0() {
77
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
78
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
79
- }
80
- return cachedDataViewMemory0;
81
- }
82
-
83
83
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
84
-
85
84
  cachedTextDecoder.decode();
86
-
87
85
  const MAX_SAFARI_DECODE_BYTES = 2146435072;
88
86
  let numBytesDecoded = 0;
89
87
  function decodeText(ptr, len) {
@@ -96,33 +94,80 @@ function decodeText(ptr, len) {
96
94
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
97
95
  }
98
96
 
99
- function getStringFromWasm0(ptr, len) {
100
- ptr = ptr >>> 0;
101
- return decodeText(ptr, len);
97
+ const cachedTextEncoder = new TextEncoder();
98
+
99
+ if (!('encodeInto' in cachedTextEncoder)) {
100
+ cachedTextEncoder.encodeInto = function (arg, view) {
101
+ const buf = cachedTextEncoder.encode(arg);
102
+ view.set(buf);
103
+ return {
104
+ read: arg.length,
105
+ written: buf.length
106
+ };
107
+ }
102
108
  }
103
109
 
104
- function addToExternrefTable0(obj) {
105
- const idx = wasm.__externref_table_alloc();
106
- wasm.__wbindgen_externrefs.set(idx, obj);
107
- return idx;
110
+ let WASM_VECTOR_LEN = 0;
111
+
112
+ /**
113
+ * Check whether a context successfully parses.
114
+ * @param {ContextParsingCall} call
115
+ * @returns {CheckParseAnswer}
116
+ */
117
+ export function checkParseContext(call) {
118
+ const ret = wasm.checkParseContext(call);
119
+ return ret;
108
120
  }
109
121
 
110
- function handleError(f, args) {
111
- try {
112
- return f.apply(this, args);
113
- } catch (e) {
114
- const idx = addToExternrefTable0(e);
115
- wasm.__wbindgen_exn_store(idx);
116
- }
122
+ /**
123
+ * Check whether a set of entities successfully parses.
124
+ * @param {EntitiesParsingCall} call
125
+ * @returns {CheckParseAnswer}
126
+ */
127
+ export function checkParseEntities(call) {
128
+ const ret = wasm.checkParseEntities(call);
129
+ return ret;
130
+ }
131
+
132
+ /**
133
+ * Check whether a policy set successfully parses.
134
+ * @param {PolicySet} policies
135
+ * @returns {CheckParseAnswer}
136
+ */
137
+ export function checkParsePolicySet(policies) {
138
+ const ret = wasm.checkParsePolicySet(policies);
139
+ return ret;
140
+ }
141
+
142
+ /**
143
+ * Check whether a schema successfully parses.
144
+ * @param {Schema} schema
145
+ * @returns {CheckParseAnswer}
146
+ */
147
+ export function checkParseSchema(schema) {
148
+ const ret = wasm.checkParseSchema(schema);
149
+ return ret;
150
+ }
151
+
152
+ /**
153
+ * Apply the Cedar policy formatter to a policy set in the Cedar policy format
154
+ * @param {FormattingCall} call
155
+ * @returns {FormattingAnswer}
156
+ */
157
+ export function formatPolicies(call) {
158
+ const ret = wasm.formatPolicies(call);
159
+ return ret;
117
160
  }
161
+
118
162
  /**
163
+ * Get language version of Cedar
119
164
  * @returns {string}
120
165
  */
121
- export function getCedarVersion() {
166
+ export function getCedarLangVersion() {
122
167
  let deferred1_0;
123
168
  let deferred1_1;
124
169
  try {
125
- const ret = wasm.getCedarVersion();
170
+ const ret = wasm.getCedarLangVersion();
126
171
  deferred1_0 = ret[0];
127
172
  deferred1_1 = ret[1];
128
173
  return getStringFromWasm0(ret[0], ret[1]);
@@ -147,6 +192,22 @@ export function getCedarSDKVersion() {
147
192
  }
148
193
  }
149
194
 
195
+ /**
196
+ * @returns {string}
197
+ */
198
+ export function getCedarVersion() {
199
+ let deferred1_0;
200
+ let deferred1_1;
201
+ try {
202
+ const ret = wasm.getCedarVersion();
203
+ deferred1_0 = ret[0];
204
+ deferred1_1 = ret[1];
205
+ return getStringFromWasm0(ret[0], ret[1]);
206
+ } finally {
207
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
208
+ }
209
+ }
210
+
150
211
  /**
151
212
  * Get valid request environment
152
213
  * @param {Policy} t
@@ -169,40 +230,6 @@ export function getValidRequestEnvsTemplate(t, s) {
169
230
  return ret;
170
231
  }
171
232
 
172
- /**
173
- * Preparse and cache a schema in thread-local storage
174
- *
175
- * # Errors
176
- *
177
- * Will return `Err` if the input cannot be parsed. Side-effect free on error.
178
- * @param {string} schema_name
179
- * @param {Schema} schema
180
- * @returns {CheckParseAnswer}
181
- */
182
- export function preparseSchema(schema_name, schema) {
183
- const ptr0 = passStringToWasm0(schema_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
184
- const len0 = WASM_VECTOR_LEN;
185
- const ret = wasm.preparseSchema(ptr0, len0, schema);
186
- return ret;
187
- }
188
-
189
- /**
190
- * Preparse and cache a policy set in thread-local storage
191
- *
192
- * # Errors
193
- *
194
- * Will return `Err` if the input cannot be parsed. Side-effect free on error.
195
- * @param {string} pset_id
196
- * @param {PolicySet} policies
197
- * @returns {CheckParseAnswer}
198
- */
199
- export function preparsePolicySet(pset_id, policies) {
200
- const ptr0 = passStringToWasm0(pset_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
201
- const len0 = WASM_VECTOR_LEN;
202
- const ret = wasm.preparsePolicySet(ptr0, len0, policies);
203
- return ret;
204
- }
205
-
206
233
  /**
207
234
  * Basic interface, using [`AuthorizationCall`] and [`AuthorizationAnswer`] types
208
235
  * @param {AuthorizationCall} call
@@ -214,95 +241,69 @@ export function isAuthorized(call) {
214
241
  }
215
242
 
216
243
  /**
217
- * Stateful authorization using preparsed schemas and policy sets.
218
- *
219
- * This function works like [`is_authorized`] but retrieves schemas and policy sets
220
- * from thread-local cache instead of parsing them on each call.
221
- * @param {StatefulAuthorizationCall} call
222
- * @returns {AuthorizationAnswer}
223
- */
224
- export function statefulIsAuthorized(call) {
225
- const ret = wasm.statefulIsAuthorized(call);
226
- return ret;
227
- }
228
-
229
- /**
230
- * Get language version of Cedar
231
- * @returns {string}
232
- */
233
- export function getCedarLangVersion() {
234
- let deferred1_0;
235
- let deferred1_1;
236
- try {
237
- const ret = wasm.getCedarLangVersion();
238
- deferred1_0 = ret[0];
239
- deferred1_1 = ret[1];
240
- return getStringFromWasm0(ret[0], ret[1]);
241
- } finally {
242
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
243
- }
244
- }
245
-
246
- /**
247
- * Apply the Cedar policy formatter to a policy set in the Cedar policy format
248
- * @param {FormattingCall} call
249
- * @returns {FormattingAnswer}
250
- */
251
- export function formatPolicies(call) {
252
- const ret = wasm.formatPolicies(call);
253
- return ret;
254
- }
255
-
256
- /**
257
- * Parse a policy set and optionally validate it against a provided schema
258
- *
259
- * This is the basic validator interface, using [`ValidationCall`] and
260
- * [`ValidationAnswer`] types
261
- * @param {ValidationCall} call
262
- * @returns {ValidationAnswer}
244
+ * Takes a `PolicySet` represented as string and return the policies
245
+ * and templates split into vecs and sorted by id.
246
+ * @param {string} policyset_str
247
+ * @returns {PolicySetTextToPartsAnswer}
263
248
  */
264
- export function validate(call) {
265
- const ret = wasm.validate(call);
249
+ export function policySetTextToParts(policyset_str) {
250
+ const ptr0 = passStringToWasm0(policyset_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
251
+ const len0 = WASM_VECTOR_LEN;
252
+ const ret = wasm.policySetTextToParts(ptr0, len0);
266
253
  return ret;
267
254
  }
268
255
 
269
256
  /**
270
- * Check whether a context successfully parses.
271
- * @param {ContextParsingCall} call
272
- * @returns {CheckParseAnswer}
257
+ * Return the JSON representation of a policy.
258
+ * @param {Policy} policy
259
+ * @returns {PolicyToJsonAnswer}
273
260
  */
274
- export function checkParseContext(call) {
275
- const ret = wasm.checkParseContext(call);
261
+ export function policyToJson(policy) {
262
+ const ret = wasm.policyToJson(policy);
276
263
  return ret;
277
264
  }
278
265
 
279
266
  /**
280
- * Check whether a schema successfully parses.
281
- * @param {Schema} schema
282
- * @returns {CheckParseAnswer}
267
+ * Return the Cedar (textual) representation of a policy.
268
+ * @param {Policy} policy
269
+ * @returns {PolicyToTextAnswer}
283
270
  */
284
- export function checkParseSchema(schema) {
285
- const ret = wasm.checkParseSchema(schema);
271
+ export function policyToText(policy) {
272
+ const ret = wasm.policyToText(policy);
286
273
  return ret;
287
274
  }
288
275
 
289
276
  /**
290
- * Check whether a policy set successfully parses.
277
+ * Preparse and cache a policy set in thread-local storage
278
+ *
279
+ * # Errors
280
+ *
281
+ * Will return `Err` if the input cannot be parsed. Side-effect free on error.
282
+ * @param {string} pset_id
291
283
  * @param {PolicySet} policies
292
284
  * @returns {CheckParseAnswer}
293
285
  */
294
- export function checkParsePolicySet(policies) {
295
- const ret = wasm.checkParsePolicySet(policies);
286
+ export function preparsePolicySet(pset_id, policies) {
287
+ const ptr0 = passStringToWasm0(pset_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
288
+ const len0 = WASM_VECTOR_LEN;
289
+ const ret = wasm.preparsePolicySet(ptr0, len0, policies);
296
290
  return ret;
297
291
  }
298
292
 
299
293
  /**
300
- * Check whether a set of entities successfully parses.
301
- * @param {EntitiesParsingCall} call
294
+ * Preparse and cache a schema in thread-local storage
295
+ *
296
+ * # Errors
297
+ *
298
+ * Will return `Err` if the input cannot be parsed. Side-effect free on error.
299
+ * @param {string} schema_name
300
+ * @param {Schema} schema
302
301
  * @returns {CheckParseAnswer}
303
302
  */
304
- export function checkParseEntities(call) {
305
- const ret = wasm.checkParseEntities(call);
303
+ export function preparseSchema(schema_name, schema) {
304
+ const ptr0 = passStringToWasm0(schema_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
305
+ const len0 = WASM_VECTOR_LEN;
306
+ const ret = wasm.preparseSchema(ptr0, len0, schema);
306
307
  return ret;
307
308
  }
308
309
 
@@ -327,35 +328,25 @@ export function schemaToText(schema) {
327
328
  }
328
329
 
329
330
  /**
330
- * Takes a `PolicySet` represented as string and return the policies
331
- * and templates split into vecs and sorted by id.
332
- * @param {string} policyset_str
333
- * @returns {PolicySetTextToPartsAnswer}
334
- */
335
- export function policySetTextToParts(policyset_str) {
336
- const ptr0 = passStringToWasm0(policyset_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
337
- const len0 = WASM_VECTOR_LEN;
338
- const ret = wasm.policySetTextToParts(ptr0, len0);
339
- return ret;
340
- }
341
-
342
- /**
343
- * Return the Cedar (textual) representation of a policy.
344
- * @param {Policy} policy
345
- * @returns {PolicyToTextAnswer}
331
+ * Stateful authorization using preparsed schemas and policy sets.
332
+ *
333
+ * This function works like [`is_authorized`] but retrieves schemas and policy sets
334
+ * from thread-local cache instead of parsing them on each call.
335
+ * @param {StatefulAuthorizationCall} call
336
+ * @returns {AuthorizationAnswer}
346
337
  */
347
- export function policyToText(policy) {
348
- const ret = wasm.policyToText(policy);
338
+ export function statefulIsAuthorized(call) {
339
+ const ret = wasm.statefulIsAuthorized(call);
349
340
  return ret;
350
341
  }
351
342
 
352
343
  /**
353
- * Return the JSON representation of a policy.
354
- * @param {Policy} policy
344
+ * Return the JSON representation of a template.
345
+ * @param {Template} template
355
346
  * @returns {PolicyToJsonAnswer}
356
347
  */
357
- export function policyToJson(policy) {
358
- const ret = wasm.policyToJson(policy);
348
+ export function templateToJson(template) {
349
+ const ret = wasm.templateToJson(template);
359
350
  return ret;
360
351
  }
361
352
 
@@ -370,21 +361,24 @@ export function templateToText(template) {
370
361
  }
371
362
 
372
363
  /**
373
- * Return the JSON representation of a template.
374
- * @param {Template} template
375
- * @returns {PolicyToJsonAnswer}
364
+ * Parse a policy set and optionally validate it against a provided schema
365
+ *
366
+ * This is the basic validator interface, using [`ValidationCall`] and
367
+ * [`ValidationAnswer`] types
368
+ * @param {ValidationCall} call
369
+ * @returns {ValidationAnswer}
376
370
  */
377
- export function templateToJson(template) {
378
- const ret = wasm.templateToJson(template);
371
+ export function validate(call) {
372
+ const ret = wasm.validate(call);
379
373
  return ret;
380
374
  }
381
375
 
382
- export function __wbg___wbindgen_is_undefined_2d472862bd29a478(arg0) {
376
+ export function __wbg___wbindgen_is_undefined_f6b95eab589e0269(arg0) {
383
377
  const ret = arg0 === undefined;
384
378
  return ret;
385
379
  };
386
380
 
387
- export function __wbg___wbindgen_string_get_e4f06c90489ad01b(arg0, arg1) {
381
+ export function __wbg___wbindgen_string_get_a2a31e16edf96e42(arg0, arg1) {
388
382
  const obj = arg1;
389
383
  const ret = typeof(obj) === 'string' ? obj : undefined;
390
384
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -393,16 +387,16 @@ export function __wbg___wbindgen_string_get_e4f06c90489ad01b(arg0, arg1) {
393
387
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
394
388
  };
395
389
 
396
- export function __wbg___wbindgen_throw_b855445ff6a94295(arg0, arg1) {
390
+ export function __wbg___wbindgen_throw_dd24417ed36fc46e(arg0, arg1) {
397
391
  throw new Error(getStringFromWasm0(arg0, arg1));
398
392
  };
399
393
 
400
- export function __wbg_parse_2a704d6b78abb2b8() { return handleError(function (arg0, arg1) {
394
+ export function __wbg_parse_a09a54cf72639456() { return handleError(function (arg0, arg1) {
401
395
  const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
402
396
  return ret;
403
397
  }, arguments) };
404
398
 
405
- export function __wbg_stringify_b5fb28f6465d9c3e() { return handleError(function (arg0) {
399
+ export function __wbg_stringify_655a6390e1f5eb6b() { return handleError(function (arg0) {
406
400
  const ret = JSON.stringify(arg0);
407
401
  return ret;
408
402
  }, arguments) };
@@ -415,6 +409,4 @@ export function __wbindgen_init_externref_table() {
415
409
  table.set(offset + 1, null);
416
410
  table.set(offset + 2, true);
417
411
  table.set(offset + 3, false);
418
- ;
419
412
  };
420
-
Binary file
@@ -5,12 +5,11 @@ 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;
8
9
  export const isAuthorized: (a: any) => any;
9
10
  export const preparsePolicySet: (a: number, b: number, c: any) => any;
10
11
  export const preparseSchema: (a: number, b: number, c: any) => any;
11
12
  export const statefulIsAuthorized: (a: any) => any;
12
- export const getCedarLangVersion: () => [number, number];
13
- export const formatPolicies: (a: any) => any;
14
13
  export const validate: (a: any) => any;
15
14
  export const checkParseContext: (a: any) => any;
16
15
  export const checkParseEntities: (a: any) => any;
@@ -23,6 +22,7 @@ export const schemaToJson: (a: any) => any;
23
22
  export const schemaToText: (a: any) => any;
24
23
  export const templateToJson: (a: any) => any;
25
24
  export const templateToText: (a: any) => any;
25
+ export const getCedarLangVersion: () => [number, number];
26
26
  export const __wbindgen_malloc: (a: number, b: number) => number;
27
27
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
28
28
  export const __wbindgen_exn_store: (a: number) => void;
package/esm/package.json CHANGED
@@ -2,7 +2,7 @@
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.0",
5
+ "version": "4.8.2",
6
6
  "license": "Apache-2.0",
7
7
  "files": [
8
8
  "cedar_wasm_bg.wasm",