@cedar-policy/cedar-wasm 4.5.1 → 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.
@@ -1,12 +1,6 @@
1
1
 
2
2
  let imports = {};
3
3
  imports['__wbindgen_placeholder__'] = module.exports;
4
- let wasm;
5
- const { TextDecoder, TextEncoder } = require(`util`);
6
-
7
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
8
-
9
- cachedTextDecoder.decode();
10
4
 
11
5
  let cachedUint8ArrayMemory0 = null;
12
6
 
@@ -17,9 +11,17 @@ function getUint8ArrayMemory0() {
17
11
  return cachedUint8ArrayMemory0;
18
12
  }
19
13
 
14
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
15
+
16
+ cachedTextDecoder.decode();
17
+
18
+ function decodeText(ptr, len) {
19
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
20
+ }
21
+
20
22
  function getStringFromWasm0(ptr, len) {
21
23
  ptr = ptr >>> 0;
22
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
24
+ return decodeText(ptr, len);
23
25
  }
24
26
 
25
27
  function addToExternrefTable0(obj) {
@@ -39,20 +41,18 @@ function handleError(f, args) {
39
41
 
40
42
  let WASM_VECTOR_LEN = 0;
41
43
 
42
- let cachedTextEncoder = new TextEncoder('utf-8');
44
+ const cachedTextEncoder = new TextEncoder();
43
45
 
44
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
45
- ? function (arg, view) {
46
- return cachedTextEncoder.encodeInto(arg, view);
46
+ if (!('encodeInto' in cachedTextEncoder)) {
47
+ cachedTextEncoder.encodeInto = function (arg, view) {
48
+ const buf = cachedTextEncoder.encode(arg);
49
+ view.set(buf);
50
+ return {
51
+ read: arg.length,
52
+ written: buf.length
53
+ };
54
+ }
47
55
  }
48
- : function (arg, view) {
49
- const buf = cachedTextEncoder.encode(arg);
50
- view.set(buf);
51
- return {
52
- read: arg.length,
53
- written: buf.length
54
- };
55
- });
56
56
 
57
57
  function passStringToWasm0(arg, malloc, realloc) {
58
58
 
@@ -83,7 +83,7 @@ function passStringToWasm0(arg, malloc, realloc) {
83
83
  }
84
84
  ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
85
85
  const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
86
- const ret = encodeString(arg, view);
86
+ const ret = cachedTextEncoder.encodeInto(arg, view);
87
87
 
88
88
  offset += ret.written;
89
89
  ptr = realloc(ptr, len, offset, 1) >>> 0;
@@ -108,7 +108,7 @@ function getDataViewMemory0() {
108
108
  /**
109
109
  * @returns {string}
110
110
  */
111
- module.exports.getCedarVersion = function() {
111
+ exports.getCedarVersion = function() {
112
112
  let deferred1_0;
113
113
  let deferred1_1;
114
114
  try {
@@ -124,7 +124,7 @@ module.exports.getCedarVersion = function() {
124
124
  /**
125
125
  * @returns {string}
126
126
  */
127
- module.exports.getCedarSDKVersion = function() {
127
+ exports.getCedarSDKVersion = function() {
128
128
  let deferred1_0;
129
129
  let deferred1_1;
130
130
  try {
@@ -139,23 +139,80 @@ module.exports.getCedarSDKVersion = function() {
139
139
 
140
140
  /**
141
141
  * Get valid request environment
142
- * @param {Template} t
142
+ * @param {Policy} t
143
143
  * @param {Schema} s
144
144
  * @returns {GetValidRequestEnvsResult}
145
145
  */
146
- module.exports.getValidRequestEnvsTemplate = function(t, s) {
147
- const ret = wasm.getValidRequestEnvsTemplate(t, s);
146
+ exports.getValidRequestEnvsPolicy = function(t, s) {
147
+ const ret = wasm.getValidRequestEnvsPolicy(t, s);
148
148
  return ret;
149
149
  };
150
150
 
151
151
  /**
152
152
  * Get valid request environment
153
- * @param {Policy} t
153
+ * @param {Template} t
154
154
  * @param {Schema} s
155
155
  * @returns {GetValidRequestEnvsResult}
156
156
  */
157
- module.exports.getValidRequestEnvsPolicy = function(t, s) {
158
- const ret = wasm.getValidRequestEnvsPolicy(t, s);
157
+ exports.getValidRequestEnvsTemplate = function(t, s) {
158
+ const ret = wasm.getValidRequestEnvsTemplate(t, s);
159
+ return ret;
160
+ };
161
+
162
+ /**
163
+ * Preparse and cache a policy set in thread-local storage
164
+ *
165
+ * # Errors
166
+ *
167
+ * Will return `Err` if the input cannot be parsed. Side-effect free on error.
168
+ * @param {string} pset_id
169
+ * @param {PolicySet} policies
170
+ * @returns {CheckParseAnswer}
171
+ */
172
+ exports.preparsePolicySet = function(pset_id, policies) {
173
+ const ptr0 = passStringToWasm0(pset_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
174
+ const len0 = WASM_VECTOR_LEN;
175
+ const ret = wasm.preparsePolicySet(ptr0, len0, policies);
176
+ return ret;
177
+ };
178
+
179
+ /**
180
+ * Basic interface, using [`AuthorizationCall`] and [`AuthorizationAnswer`] types
181
+ * @param {AuthorizationCall} call
182
+ * @returns {AuthorizationAnswer}
183
+ */
184
+ exports.isAuthorized = function(call) {
185
+ const ret = wasm.isAuthorized(call);
186
+ return ret;
187
+ };
188
+
189
+ /**
190
+ * Stateful authorization using preparsed schemas and policy sets.
191
+ *
192
+ * This function works like [`is_authorized`] but retrieves schemas and policy sets
193
+ * from thread-local cache instead of parsing them on each call.
194
+ * @param {StatefulAuthorizationCall} call
195
+ * @returns {AuthorizationAnswer}
196
+ */
197
+ exports.statefulIsAuthorized = function(call) {
198
+ const ret = wasm.statefulIsAuthorized(call);
199
+ return ret;
200
+ };
201
+
202
+ /**
203
+ * Preparse and cache a schema in thread-local storage
204
+ *
205
+ * # Errors
206
+ *
207
+ * Will return `Err` if the input cannot be parsed. Side-effect free on error.
208
+ * @param {string} schema_name
209
+ * @param {Schema} schema
210
+ * @returns {CheckParseAnswer}
211
+ */
212
+ exports.preparseSchema = function(schema_name, schema) {
213
+ const ptr0 = passStringToWasm0(schema_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
214
+ const len0 = WASM_VECTOR_LEN;
215
+ const ret = wasm.preparseSchema(ptr0, len0, schema);
159
216
  return ret;
160
217
  };
161
218
 
@@ -164,7 +221,7 @@ module.exports.getValidRequestEnvsPolicy = function(t, s) {
164
221
  * @param {EntitiesParsingCall} call
165
222
  * @returns {CheckParseAnswer}
166
223
  */
167
- module.exports.checkParseEntities = function(call) {
224
+ exports.checkParseEntities = function(call) {
168
225
  const ret = wasm.checkParseEntities(call);
169
226
  return ret;
170
227
  };
@@ -174,7 +231,7 @@ module.exports.checkParseEntities = function(call) {
174
231
  * @param {Schema} schema
175
232
  * @returns {CheckParseAnswer}
176
233
  */
177
- module.exports.checkParseSchema = function(schema) {
234
+ exports.checkParseSchema = function(schema) {
178
235
  const ret = wasm.checkParseSchema(schema);
179
236
  return ret;
180
237
  };
@@ -184,7 +241,7 @@ module.exports.checkParseSchema = function(schema) {
184
241
  * @param {PolicySet} policies
185
242
  * @returns {CheckParseAnswer}
186
243
  */
187
- module.exports.checkParsePolicySet = function(policies) {
244
+ exports.checkParsePolicySet = function(policies) {
188
245
  const ret = wasm.checkParsePolicySet(policies);
189
246
  return ret;
190
247
  };
@@ -194,38 +251,38 @@ module.exports.checkParsePolicySet = function(policies) {
194
251
  * @param {ContextParsingCall} call
195
252
  * @returns {CheckParseAnswer}
196
253
  */
197
- module.exports.checkParseContext = function(call) {
254
+ exports.checkParseContext = function(call) {
198
255
  const ret = wasm.checkParseContext(call);
199
256
  return ret;
200
257
  };
201
258
 
202
259
  /**
203
- * Apply the Cedar policy formatter to a policy set in the Cedar policy format
204
- * @param {FormattingCall} call
205
- * @returns {FormattingAnswer}
260
+ * Return the Cedar (textual) representation of a policy.
261
+ * @param {Policy} policy
262
+ * @returns {PolicyToTextAnswer}
206
263
  */
207
- module.exports.formatPolicies = function(call) {
208
- const ret = wasm.formatPolicies(call);
264
+ exports.policyToText = function(policy) {
265
+ const ret = wasm.policyToText(policy);
209
266
  return ret;
210
267
  };
211
268
 
212
269
  /**
213
- * Return the Cedar (textual) representation of a template.
214
- * @param {Template} template
215
- * @returns {PolicyToTextAnswer}
270
+ * Return the Cedar (textual) representation of a schema.
271
+ * @param {Schema} schema
272
+ * @returns {SchemaToTextAnswer}
216
273
  */
217
- module.exports.templateToText = function(template) {
218
- const ret = wasm.templateToText(template);
274
+ exports.schemaToText = function(schema) {
275
+ const ret = wasm.schemaToText(schema);
219
276
  return ret;
220
277
  };
221
278
 
222
279
  /**
223
- * Return the JSON representation of a policy.
224
- * @param {Policy} policy
280
+ * Return the JSON representation of a template.
281
+ * @param {Template} template
225
282
  * @returns {PolicyToJsonAnswer}
226
283
  */
227
- module.exports.policyToJson = function(policy) {
228
- const ret = wasm.policyToJson(policy);
284
+ exports.templateToJson = function(template) {
285
+ const ret = wasm.templateToJson(template);
229
286
  return ret;
230
287
  };
231
288
 
@@ -235,7 +292,7 @@ module.exports.policyToJson = function(policy) {
235
292
  * @param {string} policyset_str
236
293
  * @returns {PolicySetTextToPartsAnswer}
237
294
  */
238
- module.exports.policySetTextToParts = function(policyset_str) {
295
+ exports.policySetTextToParts = function(policyset_str) {
239
296
  const ptr0 = passStringToWasm0(policyset_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
240
297
  const len0 = WASM_VECTOR_LEN;
241
298
  const ret = wasm.policySetTextToParts(ptr0, len0);
@@ -247,61 +304,28 @@ module.exports.policySetTextToParts = function(policyset_str) {
247
304
  * @param {Schema} schema
248
305
  * @returns {SchemaToJsonAnswer}
249
306
  */
250
- module.exports.schemaToJson = function(schema) {
307
+ exports.schemaToJson = function(schema) {
251
308
  const ret = wasm.schemaToJson(schema);
252
309
  return ret;
253
310
  };
254
311
 
255
312
  /**
256
- * Return the Cedar (textual) representation of a schema.
257
- * @param {Schema} schema
258
- * @returns {SchemaToTextAnswer}
259
- */
260
- module.exports.schemaToText = function(schema) {
261
- const ret = wasm.schemaToText(schema);
262
- return ret;
263
- };
264
-
265
- /**
266
- * Return the Cedar (textual) representation of a policy.
313
+ * Return the JSON representation of a policy.
267
314
  * @param {Policy} policy
268
- * @returns {PolicyToTextAnswer}
269
- */
270
- module.exports.policyToText = function(policy) {
271
- const ret = wasm.policyToText(policy);
272
- return ret;
273
- };
274
-
275
- /**
276
- * Return the JSON representation of a template.
277
- * @param {Template} template
278
315
  * @returns {PolicyToJsonAnswer}
279
316
  */
280
- module.exports.templateToJson = function(template) {
281
- const ret = wasm.templateToJson(template);
282
- return ret;
283
- };
284
-
285
- /**
286
- * Parse a policy set and optionally validate it against a provided schema
287
- *
288
- * This is the basic validator interface, using [`ValidationCall`] and
289
- * [`ValidationAnswer`] types
290
- * @param {ValidationCall} call
291
- * @returns {ValidationAnswer}
292
- */
293
- module.exports.validate = function(call) {
294
- const ret = wasm.validate(call);
317
+ exports.policyToJson = function(policy) {
318
+ const ret = wasm.policyToJson(policy);
295
319
  return ret;
296
320
  };
297
321
 
298
322
  /**
299
- * Basic interface, using [`AuthorizationCall`] and [`AuthorizationAnswer`] types
300
- * @param {AuthorizationCall} call
301
- * @returns {AuthorizationAnswer}
323
+ * Return the Cedar (textual) representation of a template.
324
+ * @param {Template} template
325
+ * @returns {PolicyToTextAnswer}
302
326
  */
303
- module.exports.isAuthorized = function(call) {
304
- const ret = wasm.isAuthorized(call);
327
+ exports.templateToText = function(template) {
328
+ const ret = wasm.templateToText(template);
305
329
  return ret;
306
330
  };
307
331
 
@@ -309,7 +333,7 @@ module.exports.isAuthorized = function(call) {
309
333
  * Get language version of Cedar
310
334
  * @returns {string}
311
335
  */
312
- module.exports.getCedarLangVersion = function() {
336
+ exports.getCedarLangVersion = function() {
313
337
  let deferred1_0;
314
338
  let deferred1_1;
315
339
  try {
@@ -322,33 +346,45 @@ module.exports.getCedarLangVersion = function() {
322
346
  }
323
347
  };
324
348
 
325
- module.exports.__wbg_parse_def2e24ef1252aff = function() { return handleError(function (arg0, arg1) {
349
+ /**
350
+ * Apply the Cedar policy formatter to a policy set in the Cedar policy format
351
+ * @param {FormattingCall} call
352
+ * @returns {FormattingAnswer}
353
+ */
354
+ exports.formatPolicies = function(call) {
355
+ const ret = wasm.formatPolicies(call);
356
+ return ret;
357
+ };
358
+
359
+ /**
360
+ * Parse a policy set and optionally validate it against a provided schema
361
+ *
362
+ * This is the basic validator interface, using [`ValidationCall`] and
363
+ * [`ValidationAnswer`] types
364
+ * @param {ValidationCall} call
365
+ * @returns {ValidationAnswer}
366
+ */
367
+ exports.validate = function(call) {
368
+ const ret = wasm.validate(call);
369
+ return ret;
370
+ };
371
+
372
+ exports.__wbg_parse_442f5ba02e5eaf8b = function() { return handleError(function (arg0, arg1) {
326
373
  const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
327
374
  return ret;
328
375
  }, arguments) };
329
376
 
330
- module.exports.__wbg_stringify_f7ed6987935b4a24 = function() { return handleError(function (arg0) {
377
+ exports.__wbg_stringify_b98c93d0a190446a = function() { return handleError(function (arg0) {
331
378
  const ret = JSON.stringify(arg0);
332
379
  return ret;
333
380
  }, arguments) };
334
381
 
335
- module.exports.__wbindgen_init_externref_table = function() {
336
- const table = wasm.__wbindgen_export_2;
337
- const offset = table.grow(4);
338
- table.set(0, undefined);
339
- table.set(offset + 0, undefined);
340
- table.set(offset + 1, null);
341
- table.set(offset + 2, true);
342
- table.set(offset + 3, false);
343
- ;
344
- };
345
-
346
- module.exports.__wbindgen_is_undefined = function(arg0) {
382
+ exports.__wbg_wbindgenisundefined_c4b71d073b92f3c5 = function(arg0) {
347
383
  const ret = arg0 === undefined;
348
384
  return ret;
349
385
  };
350
386
 
351
- module.exports.__wbindgen_string_get = function(arg0, arg1) {
387
+ exports.__wbg_wbindgenstringget_0f16a6ddddef376f = function(arg0, arg1) {
352
388
  const obj = arg1;
353
389
  const ret = typeof(obj) === 'string' ? obj : undefined;
354
390
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -357,17 +393,25 @@ module.exports.__wbindgen_string_get = function(arg0, arg1) {
357
393
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
358
394
  };
359
395
 
360
- module.exports.__wbindgen_throw = function(arg0, arg1) {
396
+ exports.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function(arg0, arg1) {
361
397
  throw new Error(getStringFromWasm0(arg0, arg1));
362
398
  };
363
399
 
364
- const path = require('path').join(__dirname, 'cedar_wasm_bg.wasm');
365
- const bytes = require('fs').readFileSync(path);
400
+ exports.__wbindgen_init_externref_table = function() {
401
+ const table = wasm.__wbindgen_export_2;
402
+ const offset = table.grow(4);
403
+ table.set(0, undefined);
404
+ table.set(offset + 0, undefined);
405
+ table.set(offset + 1, null);
406
+ table.set(offset + 2, true);
407
+ table.set(offset + 3, false);
408
+ ;
409
+ };
366
410
 
367
- const wasmModule = new WebAssembly.Module(bytes);
368
- const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
369
- wasm = wasmInstance.exports;
370
- module.exports.__wasm = wasm;
411
+ const wasmPath = `${__dirname}/cedar_wasm_bg.wasm`;
412
+ const wasmBytes = require('fs').readFileSync(wasmPath);
413
+ const wasmModule = new WebAssembly.Module(wasmBytes);
414
+ const wasm = exports.__wasm = new WebAssembly.Instance(wasmModule, imports).exports;
371
415
 
372
416
  wasm.__wbindgen_start();
373
417
 
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;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cedar-policy/cedar-wasm",
3
3
  "description": "Wasm bindings and typescript types for Cedar lib",
4
- "version": "4.5.1",
4
+ "version": "4.6.1",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
7
7
  "cedar_wasm_bg.wasm",
package/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.6.1",
6
6
  "license": "Apache-2.0",
7
7
  "files": [
8
8
  "esm/package.json",