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