github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/oauth2/apis_js_wasm.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package oauth2 5 6 import ( 7 "github.com/primecitizens/pcz/std/ffi/js" 8 "github.com/primecitizens/pcz/std/plat/js/webext/oauth2/bindings" 9 ) 10 11 type OAuth2Info struct { 12 // AutoApprove is "OAuth2Info.auto_approve" 13 // 14 // Optional 15 // 16 // NOTE: FFI_USE_AutoApprove MUST be set to true to make this field effective. 17 AutoApprove bool 18 // ClientId is "OAuth2Info.client_id" 19 // 20 // Optional 21 ClientId js.String 22 // Scopes is "OAuth2Info.scopes" 23 // 24 // Optional 25 Scopes js.Array[js.String] 26 27 FFI_USE_AutoApprove bool // for AutoApprove. 28 29 FFI_USE bool 30 } 31 32 // FromRef calls UpdateFrom and returns a OAuth2Info with all fields set. 33 func (p OAuth2Info) FromRef(ref js.Ref) OAuth2Info { 34 p.UpdateFrom(ref) 35 return p 36 } 37 38 // New creates a new OAuth2Info in the application heap. 39 func (p OAuth2Info) New() js.Ref { 40 return bindings.OAuth2InfoJSLoad( 41 js.Pointer(&p), js.True, 0, 42 ) 43 } 44 45 // UpdateFrom copies value of all fields of the heap object to p. 46 func (p *OAuth2Info) UpdateFrom(ref js.Ref) { 47 bindings.OAuth2InfoJSStore( 48 js.Pointer(p), ref, 49 ) 50 } 51 52 // Update writes all fields of the p to the heap object referenced by ref. 53 func (p *OAuth2Info) Update(ref js.Ref) { 54 bindings.OAuth2InfoJSLoad( 55 js.Pointer(p), js.False, ref, 56 ) 57 } 58 59 // FreeMembers frees fields with heap reference, if recursive is true 60 // free all heap references reachable from p. 61 func (p *OAuth2Info) FreeMembers(recursive bool) { 62 js.Free( 63 p.ClientId.Ref(), 64 p.Scopes.Ref(), 65 ) 66 p.ClientId = p.ClientId.FromRef(js.Undefined) 67 p.Scopes = p.Scopes.FromRef(js.Undefined) 68 } 69 70 type ManifestKeys struct { 71 // Oauth2 is "ManifestKeys.oauth2" 72 // 73 // Optional 74 // 75 // NOTE: Oauth2.FFI_USE MUST be set to true to get Oauth2 used. 76 Oauth2 OAuth2Info 77 78 FFI_USE bool 79 } 80 81 // FromRef calls UpdateFrom and returns a ManifestKeys with all fields set. 82 func (p ManifestKeys) FromRef(ref js.Ref) ManifestKeys { 83 p.UpdateFrom(ref) 84 return p 85 } 86 87 // New creates a new ManifestKeys in the application heap. 88 func (p ManifestKeys) New() js.Ref { 89 return bindings.ManifestKeysJSLoad( 90 js.Pointer(&p), js.True, 0, 91 ) 92 } 93 94 // UpdateFrom copies value of all fields of the heap object to p. 95 func (p *ManifestKeys) UpdateFrom(ref js.Ref) { 96 bindings.ManifestKeysJSStore( 97 js.Pointer(p), ref, 98 ) 99 } 100 101 // Update writes all fields of the p to the heap object referenced by ref. 102 func (p *ManifestKeys) Update(ref js.Ref) { 103 bindings.ManifestKeysJSLoad( 104 js.Pointer(p), js.False, ref, 105 ) 106 } 107 108 // FreeMembers frees fields with heap reference, if recursive is true 109 // free all heap references reachable from p. 110 func (p *ManifestKeys) FreeMembers(recursive bool) { 111 if recursive { 112 p.Oauth2.FreeMembers(true) 113 } 114 }