github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/instanceid/apis_js_wasm.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  package instanceid
     5  
     6  import (
     7  	"github.com/primecitizens/pcz/std/core/abi"
     8  	"github.com/primecitizens/pcz/std/ffi/js"
     9  	"github.com/primecitizens/pcz/std/plat/js/webext/instanceid/bindings"
    10  )
    11  
    12  type DeleteTokenArgDeleteTokenParams struct {
    13  	// AuthorizedEntity is "DeleteTokenArgDeleteTokenParams.authorizedEntity"
    14  	//
    15  	// Required
    16  	AuthorizedEntity js.String
    17  	// Scope is "DeleteTokenArgDeleteTokenParams.scope"
    18  	//
    19  	// Required
    20  	Scope js.String
    21  
    22  	FFI_USE bool
    23  }
    24  
    25  // FromRef calls UpdateFrom and returns a DeleteTokenArgDeleteTokenParams with all fields set.
    26  func (p DeleteTokenArgDeleteTokenParams) FromRef(ref js.Ref) DeleteTokenArgDeleteTokenParams {
    27  	p.UpdateFrom(ref)
    28  	return p
    29  }
    30  
    31  // New creates a new DeleteTokenArgDeleteTokenParams in the application heap.
    32  func (p DeleteTokenArgDeleteTokenParams) New() js.Ref {
    33  	return bindings.DeleteTokenArgDeleteTokenParamsJSLoad(
    34  		js.Pointer(&p), js.True, 0,
    35  	)
    36  }
    37  
    38  // UpdateFrom copies value of all fields of the heap object to p.
    39  func (p *DeleteTokenArgDeleteTokenParams) UpdateFrom(ref js.Ref) {
    40  	bindings.DeleteTokenArgDeleteTokenParamsJSStore(
    41  		js.Pointer(p), ref,
    42  	)
    43  }
    44  
    45  // Update writes all fields of the p to the heap object referenced by ref.
    46  func (p *DeleteTokenArgDeleteTokenParams) Update(ref js.Ref) {
    47  	bindings.DeleteTokenArgDeleteTokenParamsJSLoad(
    48  		js.Pointer(p), js.False, ref,
    49  	)
    50  }
    51  
    52  // FreeMembers frees fields with heap reference, if recursive is true
    53  // free all heap references reachable from p.
    54  func (p *DeleteTokenArgDeleteTokenParams) FreeMembers(recursive bool) {
    55  	js.Free(
    56  		p.AuthorizedEntity.Ref(),
    57  		p.Scope.Ref(),
    58  	)
    59  	p.AuthorizedEntity = p.AuthorizedEntity.FromRef(js.Undefined)
    60  	p.Scope = p.Scope.FromRef(js.Undefined)
    61  }
    62  
    63  type GetTokenArgGetTokenParams struct {
    64  	// AuthorizedEntity is "GetTokenArgGetTokenParams.authorizedEntity"
    65  	//
    66  	// Required
    67  	AuthorizedEntity js.String
    68  	// Options is "GetTokenArgGetTokenParams.options"
    69  	//
    70  	// Optional
    71  	Options js.String
    72  	// Scope is "GetTokenArgGetTokenParams.scope"
    73  	//
    74  	// Required
    75  	Scope js.String
    76  
    77  	FFI_USE bool
    78  }
    79  
    80  // FromRef calls UpdateFrom and returns a GetTokenArgGetTokenParams with all fields set.
    81  func (p GetTokenArgGetTokenParams) FromRef(ref js.Ref) GetTokenArgGetTokenParams {
    82  	p.UpdateFrom(ref)
    83  	return p
    84  }
    85  
    86  // New creates a new GetTokenArgGetTokenParams in the application heap.
    87  func (p GetTokenArgGetTokenParams) New() js.Ref {
    88  	return bindings.GetTokenArgGetTokenParamsJSLoad(
    89  		js.Pointer(&p), js.True, 0,
    90  	)
    91  }
    92  
    93  // UpdateFrom copies value of all fields of the heap object to p.
    94  func (p *GetTokenArgGetTokenParams) UpdateFrom(ref js.Ref) {
    95  	bindings.GetTokenArgGetTokenParamsJSStore(
    96  		js.Pointer(p), ref,
    97  	)
    98  }
    99  
   100  // Update writes all fields of the p to the heap object referenced by ref.
   101  func (p *GetTokenArgGetTokenParams) Update(ref js.Ref) {
   102  	bindings.GetTokenArgGetTokenParamsJSLoad(
   103  		js.Pointer(p), js.False, ref,
   104  	)
   105  }
   106  
   107  // FreeMembers frees fields with heap reference, if recursive is true
   108  // free all heap references reachable from p.
   109  func (p *GetTokenArgGetTokenParams) FreeMembers(recursive bool) {
   110  	js.Free(
   111  		p.AuthorizedEntity.Ref(),
   112  		p.Options.Ref(),
   113  		p.Scope.Ref(),
   114  	)
   115  	p.AuthorizedEntity = p.AuthorizedEntity.FromRef(js.Undefined)
   116  	p.Options = p.Options.FromRef(js.Undefined)
   117  	p.Scope = p.Scope.FromRef(js.Undefined)
   118  }
   119  
   120  // HasFuncDeleteID returns true if the function "WEBEXT.instanceID.deleteID" exists.
   121  func HasFuncDeleteID() bool {
   122  	return js.True == bindings.HasFuncDeleteID()
   123  }
   124  
   125  // FuncDeleteID returns the function "WEBEXT.instanceID.deleteID".
   126  func FuncDeleteID() (fn js.Func[func() js.Promise[js.Void]]) {
   127  	bindings.FuncDeleteID(
   128  		js.Pointer(&fn),
   129  	)
   130  	return
   131  }
   132  
   133  // DeleteID calls the function "WEBEXT.instanceID.deleteID" directly.
   134  func DeleteID() (ret js.Promise[js.Void]) {
   135  	bindings.CallDeleteID(
   136  		js.Pointer(&ret),
   137  	)
   138  
   139  	return
   140  }
   141  
   142  // TryDeleteID calls the function "WEBEXT.instanceID.deleteID"
   143  // in a try/catch block and returns (_, err, ok = false) when it went through
   144  // the catch clause.
   145  func TryDeleteID() (ret js.Promise[js.Void], exception js.Any, ok bool) {
   146  	ok = js.True == bindings.TryDeleteID(
   147  		js.Pointer(&ret), js.Pointer(&exception),
   148  	)
   149  
   150  	return
   151  }
   152  
   153  // HasFuncDeleteToken returns true if the function "WEBEXT.instanceID.deleteToken" exists.
   154  func HasFuncDeleteToken() bool {
   155  	return js.True == bindings.HasFuncDeleteToken()
   156  }
   157  
   158  // FuncDeleteToken returns the function "WEBEXT.instanceID.deleteToken".
   159  func FuncDeleteToken() (fn js.Func[func(deleteTokenParams DeleteTokenArgDeleteTokenParams) js.Promise[js.Void]]) {
   160  	bindings.FuncDeleteToken(
   161  		js.Pointer(&fn),
   162  	)
   163  	return
   164  }
   165  
   166  // DeleteToken calls the function "WEBEXT.instanceID.deleteToken" directly.
   167  func DeleteToken(deleteTokenParams DeleteTokenArgDeleteTokenParams) (ret js.Promise[js.Void]) {
   168  	bindings.CallDeleteToken(
   169  		js.Pointer(&ret),
   170  		js.Pointer(&deleteTokenParams),
   171  	)
   172  
   173  	return
   174  }
   175  
   176  // TryDeleteToken calls the function "WEBEXT.instanceID.deleteToken"
   177  // in a try/catch block and returns (_, err, ok = false) when it went through
   178  // the catch clause.
   179  func TryDeleteToken(deleteTokenParams DeleteTokenArgDeleteTokenParams) (ret js.Promise[js.Void], exception js.Any, ok bool) {
   180  	ok = js.True == bindings.TryDeleteToken(
   181  		js.Pointer(&ret), js.Pointer(&exception),
   182  		js.Pointer(&deleteTokenParams),
   183  	)
   184  
   185  	return
   186  }
   187  
   188  // HasFuncGetCreationTime returns true if the function "WEBEXT.instanceID.getCreationTime" exists.
   189  func HasFuncGetCreationTime() bool {
   190  	return js.True == bindings.HasFuncGetCreationTime()
   191  }
   192  
   193  // FuncGetCreationTime returns the function "WEBEXT.instanceID.getCreationTime".
   194  func FuncGetCreationTime() (fn js.Func[func() js.Promise[js.Number[float64]]]) {
   195  	bindings.FuncGetCreationTime(
   196  		js.Pointer(&fn),
   197  	)
   198  	return
   199  }
   200  
   201  // GetCreationTime calls the function "WEBEXT.instanceID.getCreationTime" directly.
   202  func GetCreationTime() (ret js.Promise[js.Number[float64]]) {
   203  	bindings.CallGetCreationTime(
   204  		js.Pointer(&ret),
   205  	)
   206  
   207  	return
   208  }
   209  
   210  // TryGetCreationTime calls the function "WEBEXT.instanceID.getCreationTime"
   211  // in a try/catch block and returns (_, err, ok = false) when it went through
   212  // the catch clause.
   213  func TryGetCreationTime() (ret js.Promise[js.Number[float64]], exception js.Any, ok bool) {
   214  	ok = js.True == bindings.TryGetCreationTime(
   215  		js.Pointer(&ret), js.Pointer(&exception),
   216  	)
   217  
   218  	return
   219  }
   220  
   221  // HasFuncGetID returns true if the function "WEBEXT.instanceID.getID" exists.
   222  func HasFuncGetID() bool {
   223  	return js.True == bindings.HasFuncGetID()
   224  }
   225  
   226  // FuncGetID returns the function "WEBEXT.instanceID.getID".
   227  func FuncGetID() (fn js.Func[func() js.Promise[js.String]]) {
   228  	bindings.FuncGetID(
   229  		js.Pointer(&fn),
   230  	)
   231  	return
   232  }
   233  
   234  // GetID calls the function "WEBEXT.instanceID.getID" directly.
   235  func GetID() (ret js.Promise[js.String]) {
   236  	bindings.CallGetID(
   237  		js.Pointer(&ret),
   238  	)
   239  
   240  	return
   241  }
   242  
   243  // TryGetID calls the function "WEBEXT.instanceID.getID"
   244  // in a try/catch block and returns (_, err, ok = false) when it went through
   245  // the catch clause.
   246  func TryGetID() (ret js.Promise[js.String], exception js.Any, ok bool) {
   247  	ok = js.True == bindings.TryGetID(
   248  		js.Pointer(&ret), js.Pointer(&exception),
   249  	)
   250  
   251  	return
   252  }
   253  
   254  // HasFuncGetToken returns true if the function "WEBEXT.instanceID.getToken" exists.
   255  func HasFuncGetToken() bool {
   256  	return js.True == bindings.HasFuncGetToken()
   257  }
   258  
   259  // FuncGetToken returns the function "WEBEXT.instanceID.getToken".
   260  func FuncGetToken() (fn js.Func[func(getTokenParams GetTokenArgGetTokenParams) js.Promise[js.String]]) {
   261  	bindings.FuncGetToken(
   262  		js.Pointer(&fn),
   263  	)
   264  	return
   265  }
   266  
   267  // GetToken calls the function "WEBEXT.instanceID.getToken" directly.
   268  func GetToken(getTokenParams GetTokenArgGetTokenParams) (ret js.Promise[js.String]) {
   269  	bindings.CallGetToken(
   270  		js.Pointer(&ret),
   271  		js.Pointer(&getTokenParams),
   272  	)
   273  
   274  	return
   275  }
   276  
   277  // TryGetToken calls the function "WEBEXT.instanceID.getToken"
   278  // in a try/catch block and returns (_, err, ok = false) when it went through
   279  // the catch clause.
   280  func TryGetToken(getTokenParams GetTokenArgGetTokenParams) (ret js.Promise[js.String], exception js.Any, ok bool) {
   281  	ok = js.True == bindings.TryGetToken(
   282  		js.Pointer(&ret), js.Pointer(&exception),
   283  		js.Pointer(&getTokenParams),
   284  	)
   285  
   286  	return
   287  }
   288  
   289  type OnTokenRefreshEventCallbackFunc func(this js.Ref) js.Ref
   290  
   291  func (fn OnTokenRefreshEventCallbackFunc) Register() js.Func[func()] {
   292  	return js.RegisterCallback[func()](
   293  		fn, abi.FuncPCABIInternal(fn),
   294  	)
   295  }
   296  
   297  func (fn OnTokenRefreshEventCallbackFunc) DispatchCallback(
   298  	targetPC uintptr, ctx *js.CallbackContext,
   299  ) {
   300  	args := ctx.Args()
   301  	if len(args) != 0+1 /* js this */ ||
   302  		targetPC != uintptr(abi.FuncPCABIInternal(fn)) {
   303  		js.ThrowInvalidCallbackInvocation()
   304  	}
   305  
   306  	if ctx.Return(fn(
   307  		args[0],
   308  	)) {
   309  		return
   310  	}
   311  
   312  	js.ThrowCallbackValueNotReturned()
   313  }
   314  
   315  type OnTokenRefreshEventCallback[T any] struct {
   316  	Fn  func(arg T, this js.Ref) js.Ref
   317  	Arg T
   318  }
   319  
   320  func (cb *OnTokenRefreshEventCallback[T]) Register() js.Func[func()] {
   321  	return js.RegisterCallback[func()](
   322  		cb, abi.FuncPCABIInternal(cb.Fn),
   323  	)
   324  }
   325  
   326  func (cb *OnTokenRefreshEventCallback[T]) DispatchCallback(
   327  	targetPC uintptr, ctx *js.CallbackContext,
   328  ) {
   329  	args := ctx.Args()
   330  	if len(args) != 0+1 /* js this */ ||
   331  		targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) {
   332  		js.ThrowInvalidCallbackInvocation()
   333  	}
   334  
   335  	if ctx.Return(cb.Fn(
   336  		cb.Arg,
   337  		args[0],
   338  	)) {
   339  		return
   340  	}
   341  
   342  	js.ThrowCallbackValueNotReturned()
   343  }
   344  
   345  // HasFuncOnTokenRefresh returns true if the function "WEBEXT.instanceID.onTokenRefresh.addListener" exists.
   346  func HasFuncOnTokenRefresh() bool {
   347  	return js.True == bindings.HasFuncOnTokenRefresh()
   348  }
   349  
   350  // FuncOnTokenRefresh returns the function "WEBEXT.instanceID.onTokenRefresh.addListener".
   351  func FuncOnTokenRefresh() (fn js.Func[func(callback js.Func[func()])]) {
   352  	bindings.FuncOnTokenRefresh(
   353  		js.Pointer(&fn),
   354  	)
   355  	return
   356  }
   357  
   358  // OnTokenRefresh calls the function "WEBEXT.instanceID.onTokenRefresh.addListener" directly.
   359  func OnTokenRefresh(callback js.Func[func()]) (ret js.Void) {
   360  	bindings.CallOnTokenRefresh(
   361  		js.Pointer(&ret),
   362  		callback.Ref(),
   363  	)
   364  
   365  	return
   366  }
   367  
   368  // TryOnTokenRefresh calls the function "WEBEXT.instanceID.onTokenRefresh.addListener"
   369  // in a try/catch block and returns (_, err, ok = false) when it went through
   370  // the catch clause.
   371  func TryOnTokenRefresh(callback js.Func[func()]) (ret js.Void, exception js.Any, ok bool) {
   372  	ok = js.True == bindings.TryOnTokenRefresh(
   373  		js.Pointer(&ret), js.Pointer(&exception),
   374  		callback.Ref(),
   375  	)
   376  
   377  	return
   378  }
   379  
   380  // HasFuncOffTokenRefresh returns true if the function "WEBEXT.instanceID.onTokenRefresh.removeListener" exists.
   381  func HasFuncOffTokenRefresh() bool {
   382  	return js.True == bindings.HasFuncOffTokenRefresh()
   383  }
   384  
   385  // FuncOffTokenRefresh returns the function "WEBEXT.instanceID.onTokenRefresh.removeListener".
   386  func FuncOffTokenRefresh() (fn js.Func[func(callback js.Func[func()])]) {
   387  	bindings.FuncOffTokenRefresh(
   388  		js.Pointer(&fn),
   389  	)
   390  	return
   391  }
   392  
   393  // OffTokenRefresh calls the function "WEBEXT.instanceID.onTokenRefresh.removeListener" directly.
   394  func OffTokenRefresh(callback js.Func[func()]) (ret js.Void) {
   395  	bindings.CallOffTokenRefresh(
   396  		js.Pointer(&ret),
   397  		callback.Ref(),
   398  	)
   399  
   400  	return
   401  }
   402  
   403  // TryOffTokenRefresh calls the function "WEBEXT.instanceID.onTokenRefresh.removeListener"
   404  // in a try/catch block and returns (_, err, ok = false) when it went through
   405  // the catch clause.
   406  func TryOffTokenRefresh(callback js.Func[func()]) (ret js.Void, exception js.Any, ok bool) {
   407  	ok = js.True == bindings.TryOffTokenRefresh(
   408  		js.Pointer(&ret), js.Pointer(&exception),
   409  		callback.Ref(),
   410  	)
   411  
   412  	return
   413  }
   414  
   415  // HasFuncHasOnTokenRefresh returns true if the function "WEBEXT.instanceID.onTokenRefresh.hasListener" exists.
   416  func HasFuncHasOnTokenRefresh() bool {
   417  	return js.True == bindings.HasFuncHasOnTokenRefresh()
   418  }
   419  
   420  // FuncHasOnTokenRefresh returns the function "WEBEXT.instanceID.onTokenRefresh.hasListener".
   421  func FuncHasOnTokenRefresh() (fn js.Func[func(callback js.Func[func()]) bool]) {
   422  	bindings.FuncHasOnTokenRefresh(
   423  		js.Pointer(&fn),
   424  	)
   425  	return
   426  }
   427  
   428  // HasOnTokenRefresh calls the function "WEBEXT.instanceID.onTokenRefresh.hasListener" directly.
   429  func HasOnTokenRefresh(callback js.Func[func()]) (ret bool) {
   430  	bindings.CallHasOnTokenRefresh(
   431  		js.Pointer(&ret),
   432  		callback.Ref(),
   433  	)
   434  
   435  	return
   436  }
   437  
   438  // TryHasOnTokenRefresh calls the function "WEBEXT.instanceID.onTokenRefresh.hasListener"
   439  // in a try/catch block and returns (_, err, ok = false) when it went through
   440  // the catch clause.
   441  func TryHasOnTokenRefresh(callback js.Func[func()]) (ret bool, exception js.Any, ok bool) {
   442  	ok = js.True == bindings.TryHasOnTokenRefresh(
   443  		js.Pointer(&ret), js.Pointer(&exception),
   444  		callback.Ref(),
   445  	)
   446  
   447  	return
   448  }