github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/development/wasm/example/wasm.html (about)

     1  <!DOCTYPE html>
     2  <html>
     3  
     4  <head>
     5      <meta charset="utf-8">
     6      <script src="wasm_exec.js"></script>
     7      <script>
     8          // Based on: https://github.com/golang/go/blob/master/misc/wasm/wasm_exec.html
     9          if (WebAssembly) {
    10              // WebAssembly.instantiateStreaming is not currently available in Safari
    11              if (WebAssembly && !WebAssembly.instantiateStreaming) { // polyfill
    12                  WebAssembly.instantiateStreaming = async (resp, importObject) => {
    13                      const source = await (await resp).arrayBuffer();
    14                      return await WebAssembly.instantiate(source, importObject);
    15                  };
    16              }
    17  
    18              const go = new Go();
    19              WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {
    20                  go.run(result.instance);
    21              });
    22          } else {
    23              console.log("WebAssembly is not supported in your browser")
    24          }
    25      </script>
    26      <script>
    27          function test() {
    28              const response = runSpiceDBDeveloperRequest(
    29                  JSON.stringify({
    30                      'context': {
    31                          'schema': `definition user {}
    32                          
    33                              definition document {
    34                                  relation viewer: user
    35                                  permission view = viewer
    36                              }`
    37                          ,
    38                          'relationships': [
    39                              {
    40                                  resource_and_relation: {
    41                                      namespace: 'document',
    42                                      object_id: 'somedoc',
    43                                      relation: 'viewer',
    44                                  },
    45                                  subject: {
    46                                          namespace: 'user',
    47                                          object_id: 'foo',
    48                                          relation: '...'
    49                                  }
    50                              }
    51                          ],
    52                      },
    53                      'operations': [
    54                          {
    55                              'checkParameters': {
    56                                  resource: {
    57                                      namespace: 'document',
    58                                      object_id: 'somedoc',
    59                                      relation: 'view',
    60                                  },
    61                                  subject: {
    62                                      namespace: 'user',
    63                                      object_id: 'foo',
    64                                      relation: '...',
    65                                  }
    66                              }
    67                          },
    68                          {
    69                              'assertionsParameters': {
    70                                  assertions_yaml: `
    71                                  assertTrue:
    72                                  - document:somedoc#view@user:foo
    73                                  assertFalse: []
    74                                  `
    75                              }
    76                          },
    77                          {
    78                              'validationParameters': {
    79                                  validation_yaml: `
    80                                  document:somedoc#view:
    81                                  - "[user:foo] is <document:somedoc#viewer>"
    82                                  `
    83                              }
    84                          }
    85                      ]
    86                  }))
    87              console.log(JSON.parse(response))
    88          }
    89      </script>
    90  </head>
    91  
    92  <body>
    93      <button onClick="test()">Test</button>
    94  </body>
    95  
    96  </html>