@cedar-policy/cedar-wasm 4.5.1 → 4.7.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.
@@ -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;
45
-
46
- let cachedTextEncoder = new lTextEncoder('utf-8');
54
+ const cachedTextEncoder = new TextEncoder();
47
55
 
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;
@@ -112,11 +118,11 @@ function getDataViewMemory0() {
112
118
  /**
113
119
  * @returns {string}
114
120
  */
115
- export function getCedarVersion() {
121
+ export function getCedarSDKVersion() {
116
122
  let deferred1_0;
117
123
  let deferred1_1;
118
124
  try {
119
- const ret = wasm.getCedarVersion();
125
+ const ret = wasm.getCedarSDKVersion();
120
126
  deferred1_0 = ret[0];
121
127
  deferred1_1 = ret[1];
122
128
  return getStringFromWasm0(ret[0], ret[1]);
@@ -128,11 +134,11 @@ export function getCedarVersion() {
128
134
  /**
129
135
  * @returns {string}
130
136
  */
131
- export function getCedarSDKVersion() {
137
+ export function getCedarVersion() {
132
138
  let deferred1_0;
133
139
  let deferred1_1;
134
140
  try {
135
- const ret = wasm.getCedarSDKVersion();
141
+ const ret = wasm.getCedarVersion();
136
142
  deferred1_0 = ret[0];
137
143
  deferred1_1 = ret[1];
138
144
  return getStringFromWasm0(ret[0], ret[1]);
@@ -143,43 +149,80 @@ export function getCedarSDKVersion() {
143
149
 
144
150
  /**
145
151
  * Get valid request environment
146
- * @param {Template} t
152
+ * @param {Policy} t
147
153
  * @param {Schema} s
148
154
  * @returns {GetValidRequestEnvsResult}
149
155
  */
150
- export function getValidRequestEnvsTemplate(t, s) {
151
- const ret = wasm.getValidRequestEnvsTemplate(t, s);
156
+ export function getValidRequestEnvsPolicy(t, s) {
157
+ const ret = wasm.getValidRequestEnvsPolicy(t, s);
152
158
  return ret;
153
159
  }
154
160
 
155
161
  /**
156
162
  * Get valid request environment
157
- * @param {Policy} t
163
+ * @param {Template} t
158
164
  * @param {Schema} s
159
165
  * @returns {GetValidRequestEnvsResult}
160
166
  */
161
- export function getValidRequestEnvsPolicy(t, s) {
162
- const ret = wasm.getValidRequestEnvsPolicy(t, s);
167
+ export function getValidRequestEnvsTemplate(t, s) {
168
+ const ret = wasm.getValidRequestEnvsTemplate(t, s);
163
169
  return ret;
164
170
  }
165
171
 
166
172
  /**
167
- * Check whether a set of entities successfully parses.
168
- * @param {EntitiesParsingCall} call
173
+ * Stateful authorization using preparsed schemas and policy sets.
174
+ *
175
+ * This function works like [`is_authorized`] but retrieves schemas and policy sets
176
+ * from thread-local cache instead of parsing them on each call.
177
+ * @param {StatefulAuthorizationCall} call
178
+ * @returns {AuthorizationAnswer}
179
+ */
180
+ export function statefulIsAuthorized(call) {
181
+ const ret = wasm.statefulIsAuthorized(call);
182
+ return ret;
183
+ }
184
+
185
+ /**
186
+ * Basic interface, using [`AuthorizationCall`] and [`AuthorizationAnswer`] types
187
+ * @param {AuthorizationCall} call
188
+ * @returns {AuthorizationAnswer}
189
+ */
190
+ export function isAuthorized(call) {
191
+ const ret = wasm.isAuthorized(call);
192
+ return ret;
193
+ }
194
+
195
+ /**
196
+ * Preparse and cache a policy set in thread-local storage
197
+ *
198
+ * # Errors
199
+ *
200
+ * Will return `Err` if the input cannot be parsed. Side-effect free on error.
201
+ * @param {string} pset_id
202
+ * @param {PolicySet} policies
169
203
  * @returns {CheckParseAnswer}
170
204
  */
171
- export function checkParseEntities(call) {
172
- const ret = wasm.checkParseEntities(call);
205
+ export function preparsePolicySet(pset_id, policies) {
206
+ const ptr0 = passStringToWasm0(pset_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
207
+ const len0 = WASM_VECTOR_LEN;
208
+ const ret = wasm.preparsePolicySet(ptr0, len0, policies);
173
209
  return ret;
174
210
  }
175
211
 
176
212
  /**
177
- * Check whether a schema successfully parses.
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
178
219
  * @param {Schema} schema
179
220
  * @returns {CheckParseAnswer}
180
221
  */
181
- export function checkParseSchema(schema) {
182
- 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);
183
226
  return ret;
184
227
  }
185
228
 
@@ -204,32 +247,22 @@ export function checkParseContext(call) {
204
247
  }
205
248
 
206
249
  /**
207
- * Apply the Cedar policy formatter to a policy set in the Cedar policy format
208
- * @param {FormattingCall} call
209
- * @returns {FormattingAnswer}
210
- */
211
- export function formatPolicies(call) {
212
- const ret = wasm.formatPolicies(call);
213
- return ret;
214
- }
215
-
216
- /**
217
- * Return the Cedar (textual) representation of a template.
218
- * @param {Template} template
219
- * @returns {PolicyToTextAnswer}
250
+ * Check whether a schema successfully parses.
251
+ * @param {Schema} schema
252
+ * @returns {CheckParseAnswer}
220
253
  */
221
- export function templateToText(template) {
222
- const ret = wasm.templateToText(template);
254
+ export function checkParseSchema(schema) {
255
+ const ret = wasm.checkParseSchema(schema);
223
256
  return ret;
224
257
  }
225
258
 
226
259
  /**
227
- * Return the JSON representation of a policy.
228
- * @param {Policy} policy
229
- * @returns {PolicyToJsonAnswer}
260
+ * Check whether a set of entities successfully parses.
261
+ * @param {EntitiesParsingCall} call
262
+ * @returns {CheckParseAnswer}
230
263
  */
231
- export function policyToJson(policy) {
232
- const ret = wasm.policyToJson(policy);
264
+ export function checkParseEntities(call) {
265
+ const ret = wasm.checkParseEntities(call);
233
266
  return ret;
234
267
  }
235
268
 
@@ -247,22 +280,12 @@ export function policySetTextToParts(policyset_str) {
247
280
  }
248
281
 
249
282
  /**
250
- * Return the JSON representation of a schema.
251
- * @param {Schema} schema
252
- * @returns {SchemaToJsonAnswer}
253
- */
254
- export function schemaToJson(schema) {
255
- const ret = wasm.schemaToJson(schema);
256
- return ret;
257
- }
258
-
259
- /**
260
- * Return the Cedar (textual) representation of a schema.
261
- * @param {Schema} schema
262
- * @returns {SchemaToTextAnswer}
283
+ * Return the JSON representation of a template.
284
+ * @param {Template} template
285
+ * @returns {PolicyToJsonAnswer}
263
286
  */
264
- export function schemaToText(schema) {
265
- const ret = wasm.schemaToText(schema);
287
+ export function templateToJson(template) {
288
+ const ret = wasm.templateToJson(template);
266
289
  return ret;
267
290
  }
268
291
 
@@ -277,35 +300,42 @@ export function policyToText(policy) {
277
300
  }
278
301
 
279
302
  /**
280
- * Return the JSON representation of a template.
303
+ * Return the JSON representation of a schema.
304
+ * @param {Schema} schema
305
+ * @returns {SchemaToJsonAnswer}
306
+ */
307
+ export function schemaToJson(schema) {
308
+ const ret = wasm.schemaToJson(schema);
309
+ return ret;
310
+ }
311
+
312
+ /**
313
+ * Return the Cedar (textual) representation of a template.
281
314
  * @param {Template} template
282
- * @returns {PolicyToJsonAnswer}
315
+ * @returns {PolicyToTextAnswer}
283
316
  */
284
- export function templateToJson(template) {
285
- const ret = wasm.templateToJson(template);
317
+ export function templateToText(template) {
318
+ const ret = wasm.templateToText(template);
286
319
  return ret;
287
320
  }
288
321
 
289
322
  /**
290
- * Parse a policy set and optionally validate it against a provided schema
291
- *
292
- * This is the basic validator interface, using [`ValidationCall`] and
293
- * [`ValidationAnswer`] types
294
- * @param {ValidationCall} call
295
- * @returns {ValidationAnswer}
323
+ * Return the JSON representation of a policy.
324
+ * @param {Policy} policy
325
+ * @returns {PolicyToJsonAnswer}
296
326
  */
297
- export function validate(call) {
298
- const ret = wasm.validate(call);
327
+ export function policyToJson(policy) {
328
+ const ret = wasm.policyToJson(policy);
299
329
  return ret;
300
330
  }
301
331
 
302
332
  /**
303
- * Basic interface, using [`AuthorizationCall`] and [`AuthorizationAnswer`] types
304
- * @param {AuthorizationCall} call
305
- * @returns {AuthorizationAnswer}
333
+ * Return the Cedar (textual) representation of a schema.
334
+ * @param {Schema} schema
335
+ * @returns {SchemaToTextAnswer}
306
336
  */
307
- export function isAuthorized(call) {
308
- const ret = wasm.isAuthorized(call);
337
+ export function schemaToText(schema) {
338
+ const ret = wasm.schemaToText(schema);
309
339
  return ret;
310
340
  }
311
341
 
@@ -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
@@ -5,11 +5,15 @@ 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 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;
8
12
  export const checkParseContext: (a: any) => any;
9
13
  export const checkParseEntities: (a: any) => any;
10
14
  export const checkParsePolicySet: (a: any) => any;
11
15
  export const checkParseSchema: (a: any) => any;
12
- export const formatPolicies: (a: any) => any;
16
+ export const getCedarLangVersion: () => [number, number];
13
17
  export const policySetTextToParts: (a: number, b: number) => any;
14
18
  export const policyToJson: (a: any) => any;
15
19
  export const policyToText: (a: any) => any;
@@ -17,9 +21,8 @@ export const schemaToJson: (a: any) => any;
17
21
  export const schemaToText: (a: any) => any;
18
22
  export const templateToJson: (a: any) => any;
19
23
  export const templateToText: (a: any) => any;
24
+ export const formatPolicies: (a: any) => any;
20
25
  export const validate: (a: any) => any;
21
- export const isAuthorized: (a: any) => any;
22
- export const getCedarLangVersion: () => [number, number];
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.1",
5
+ "version": "4.7.0",
6
6
  "license": "Apache-2.0",
7
7
  "files": [
8
8
  "cedar_wasm_bg.wasm",