From 079137f5220050539284cb3b923671f745f08ab8 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Thu, 3 Oct 2024 18:37:28 -0700 Subject: [PATCH 1/3] lexgen: use json.RawMessage for 'unknown' in some situations --- lex/type_schema.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lex/type_schema.go b/lex/type_schema.go index aeeb7389d..8d62f21a2 100644 --- a/lex/type_schema.go +++ b/lex/type_schema.go @@ -3,6 +3,7 @@ package lex import ( "fmt" "io" + "log/slog" "strings" ) @@ -538,9 +539,11 @@ func (s *TypeSchema) typeNameForField(name, k string, v TypeSchema) (string, err // TODO: maybe do a native type? return "string", nil case "unknown": - // NOTE: sometimes a record, for which we want LexiconTypeDecoder, sometimes any object - if k == "didDoc" || k == "plcOp" { - return "interface{}", nil + if v.needsCbor { + slog.Warn("'unknown' field type in CBOR lexicon schema", "ref", v.id) + } + if !v.needsCbor && v.prefix == "com.atproto" { + return "*json.RawMessage", nil } else { return "*util.LexiconTypeDecoder", nil } From 54717cc476370a3e2c041485567691f6c9733caa Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Thu, 3 Oct 2024 18:38:54 -0700 Subject: [PATCH 2/3] lexgen with json.RawMessage changes --- api/atproto/admindefs.go | 24 +++++++++---------- .../identitygetRecommendedDidCredentials.go | 8 +++---- api/atproto/identitysignPlcOperation.go | 14 +++++------ api/atproto/identitysubmitPlcOperation.go | 4 ++-- api/atproto/repoapplyWrites.go | 16 ++++++------- api/atproto/repocreateRecord.go | 4 ++-- api/atproto/repodescribeRepo.go | 5 ++-- api/atproto/repogetRecord.go | 8 +++---- api/atproto/repolistRecords.go | 8 +++---- api/atproto/repoputRecord.go | 4 ++-- api/atproto/servercreateAccount.go | 9 +++---- api/atproto/servercreateSession.go | 19 ++++++++------- api/atproto/servergetSession.go | 15 ++++++------ api/atproto/serverrefreshSession.go | 13 +++++----- 14 files changed, 78 insertions(+), 73 deletions(-) diff --git a/api/atproto/admindefs.go b/api/atproto/admindefs.go index f674117d6..7569c0cad 100644 --- a/api/atproto/admindefs.go +++ b/api/atproto/admindefs.go @@ -5,22 +5,22 @@ package atproto // schema: com.atproto.admin.defs import ( - "github.com/bluesky-social/indigo/lex/util" + "encoding/json" ) // AdminDefs_AccountView is a "accountView" in the com.atproto.admin.defs schema. type AdminDefs_AccountView struct { - DeactivatedAt *string `json:"deactivatedAt,omitempty" cborgen:"deactivatedAt,omitempty"` - Did string `json:"did" cborgen:"did"` - Email *string `json:"email,omitempty" cborgen:"email,omitempty"` - EmailConfirmedAt *string `json:"emailConfirmedAt,omitempty" cborgen:"emailConfirmedAt,omitempty"` - Handle string `json:"handle" cborgen:"handle"` - IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` - InviteNote *string `json:"inviteNote,omitempty" cborgen:"inviteNote,omitempty"` - InvitedBy *ServerDefs_InviteCode `json:"invitedBy,omitempty" cborgen:"invitedBy,omitempty"` - Invites []*ServerDefs_InviteCode `json:"invites,omitempty" cborgen:"invites,omitempty"` - InvitesDisabled *bool `json:"invitesDisabled,omitempty" cborgen:"invitesDisabled,omitempty"` - RelatedRecords []*util.LexiconTypeDecoder `json:"relatedRecords,omitempty" cborgen:"relatedRecords,omitempty"` + DeactivatedAt *string `json:"deactivatedAt,omitempty" cborgen:"deactivatedAt,omitempty"` + Did string `json:"did" cborgen:"did"` + Email *string `json:"email,omitempty" cborgen:"email,omitempty"` + EmailConfirmedAt *string `json:"emailConfirmedAt,omitempty" cborgen:"emailConfirmedAt,omitempty"` + Handle string `json:"handle" cborgen:"handle"` + IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` + InviteNote *string `json:"inviteNote,omitempty" cborgen:"inviteNote,omitempty"` + InvitedBy *ServerDefs_InviteCode `json:"invitedBy,omitempty" cborgen:"invitedBy,omitempty"` + Invites []*ServerDefs_InviteCode `json:"invites,omitempty" cborgen:"invites,omitempty"` + InvitesDisabled *bool `json:"invitesDisabled,omitempty" cborgen:"invitesDisabled,omitempty"` + RelatedRecords []*json.RawMessage `json:"relatedRecords,omitempty" cborgen:"relatedRecords,omitempty"` } // AdminDefs_RepoBlobRef is a "repoBlobRef" in the com.atproto.admin.defs schema. diff --git a/api/atproto/identitygetRecommendedDidCredentials.go b/api/atproto/identitygetRecommendedDidCredentials.go index 282564f33..c8c9aa99e 100644 --- a/api/atproto/identitygetRecommendedDidCredentials.go +++ b/api/atproto/identitygetRecommendedDidCredentials.go @@ -6,8 +6,8 @@ package atproto import ( "context" + "encoding/json" - "github.com/bluesky-social/indigo/lex/util" "github.com/bluesky-social/indigo/xrpc" ) @@ -15,9 +15,9 @@ import ( type IdentityGetRecommendedDidCredentials_Output struct { AlsoKnownAs []string `json:"alsoKnownAs,omitempty" cborgen:"alsoKnownAs,omitempty"` // rotationKeys: Recommended rotation keys for PLC dids. Should be undefined (or ignored) for did:webs. - RotationKeys []string `json:"rotationKeys,omitempty" cborgen:"rotationKeys,omitempty"` - Services *util.LexiconTypeDecoder `json:"services,omitempty" cborgen:"services,omitempty"` - VerificationMethods *util.LexiconTypeDecoder `json:"verificationMethods,omitempty" cborgen:"verificationMethods,omitempty"` + RotationKeys []string `json:"rotationKeys,omitempty" cborgen:"rotationKeys,omitempty"` + Services *json.RawMessage `json:"services,omitempty" cborgen:"services,omitempty"` + VerificationMethods *json.RawMessage `json:"verificationMethods,omitempty" cborgen:"verificationMethods,omitempty"` } // IdentityGetRecommendedDidCredentials calls the XRPC method "com.atproto.identity.getRecommendedDidCredentials". diff --git a/api/atproto/identitysignPlcOperation.go b/api/atproto/identitysignPlcOperation.go index 3ce82253b..c4200d8b4 100644 --- a/api/atproto/identitysignPlcOperation.go +++ b/api/atproto/identitysignPlcOperation.go @@ -6,25 +6,25 @@ package atproto import ( "context" + "encoding/json" - "github.com/bluesky-social/indigo/lex/util" "github.com/bluesky-social/indigo/xrpc" ) // IdentitySignPlcOperation_Input is the input argument to a com.atproto.identity.signPlcOperation call. type IdentitySignPlcOperation_Input struct { - AlsoKnownAs []string `json:"alsoKnownAs,omitempty" cborgen:"alsoKnownAs,omitempty"` - RotationKeys []string `json:"rotationKeys,omitempty" cborgen:"rotationKeys,omitempty"` - Services *util.LexiconTypeDecoder `json:"services,omitempty" cborgen:"services,omitempty"` + AlsoKnownAs []string `json:"alsoKnownAs,omitempty" cborgen:"alsoKnownAs,omitempty"` + RotationKeys []string `json:"rotationKeys,omitempty" cborgen:"rotationKeys,omitempty"` + Services *json.RawMessage `json:"services,omitempty" cborgen:"services,omitempty"` // token: A token received through com.atproto.identity.requestPlcOperationSignature - Token *string `json:"token,omitempty" cborgen:"token,omitempty"` - VerificationMethods *util.LexiconTypeDecoder `json:"verificationMethods,omitempty" cborgen:"verificationMethods,omitempty"` + Token *string `json:"token,omitempty" cborgen:"token,omitempty"` + VerificationMethods *json.RawMessage `json:"verificationMethods,omitempty" cborgen:"verificationMethods,omitempty"` } // IdentitySignPlcOperation_Output is the output of a com.atproto.identity.signPlcOperation call. type IdentitySignPlcOperation_Output struct { // operation: A signed DID PLC operation. - Operation *util.LexiconTypeDecoder `json:"operation" cborgen:"operation"` + Operation *json.RawMessage `json:"operation" cborgen:"operation"` } // IdentitySignPlcOperation calls the XRPC method "com.atproto.identity.signPlcOperation". diff --git a/api/atproto/identitysubmitPlcOperation.go b/api/atproto/identitysubmitPlcOperation.go index 31106aad1..87666cfc6 100644 --- a/api/atproto/identitysubmitPlcOperation.go +++ b/api/atproto/identitysubmitPlcOperation.go @@ -6,14 +6,14 @@ package atproto import ( "context" + "encoding/json" - "github.com/bluesky-social/indigo/lex/util" "github.com/bluesky-social/indigo/xrpc" ) // IdentitySubmitPlcOperation_Input is the input argument to a com.atproto.identity.submitPlcOperation call. type IdentitySubmitPlcOperation_Input struct { - Operation *util.LexiconTypeDecoder `json:"operation" cborgen:"operation"` + Operation *json.RawMessage `json:"operation" cborgen:"operation"` } // IdentitySubmitPlcOperation calls the XRPC method "com.atproto.identity.submitPlcOperation". diff --git a/api/atproto/repoapplyWrites.go b/api/atproto/repoapplyWrites.go index 436a9f13d..112b7ac6a 100644 --- a/api/atproto/repoapplyWrites.go +++ b/api/atproto/repoapplyWrites.go @@ -19,10 +19,10 @@ import ( // // RECORDTYPE: RepoApplyWrites_Create type RepoApplyWrites_Create struct { - LexiconTypeID string `json:"$type,const=com.atproto.repo.applyWrites#create" cborgen:"$type,const=com.atproto.repo.applyWrites#create"` - Collection string `json:"collection" cborgen:"collection"` - Rkey *string `json:"rkey,omitempty" cborgen:"rkey,omitempty"` - Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"` + LexiconTypeID string `json:"$type,const=com.atproto.repo.applyWrites#create" cborgen:"$type,const=com.atproto.repo.applyWrites#create"` + Collection string `json:"collection" cborgen:"collection"` + Rkey *string `json:"rkey,omitempty" cborgen:"rkey,omitempty"` + Value *json.RawMessage `json:"value" cborgen:"value"` } // RepoApplyWrites_CreateResult is a "createResult" in the com.atproto.repo.applyWrites schema. @@ -162,10 +162,10 @@ func (t *RepoApplyWrites_Output_Results_Elem) UnmarshalJSON(b []byte) error { // // RECORDTYPE: RepoApplyWrites_Update type RepoApplyWrites_Update struct { - LexiconTypeID string `json:"$type,const=com.atproto.repo.applyWrites#update" cborgen:"$type,const=com.atproto.repo.applyWrites#update"` - Collection string `json:"collection" cborgen:"collection"` - Rkey string `json:"rkey" cborgen:"rkey"` - Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"` + LexiconTypeID string `json:"$type,const=com.atproto.repo.applyWrites#update" cborgen:"$type,const=com.atproto.repo.applyWrites#update"` + Collection string `json:"collection" cborgen:"collection"` + Rkey string `json:"rkey" cborgen:"rkey"` + Value *json.RawMessage `json:"value" cborgen:"value"` } // RepoApplyWrites_UpdateResult is a "updateResult" in the com.atproto.repo.applyWrites schema. diff --git a/api/atproto/repocreateRecord.go b/api/atproto/repocreateRecord.go index 4c3935ea3..39ae104c8 100644 --- a/api/atproto/repocreateRecord.go +++ b/api/atproto/repocreateRecord.go @@ -6,8 +6,8 @@ package atproto import ( "context" + "encoding/json" - "github.com/bluesky-social/indigo/lex/util" "github.com/bluesky-social/indigo/xrpc" ) @@ -16,7 +16,7 @@ type RepoCreateRecord_Input struct { // collection: The NSID of the record collection. Collection string `json:"collection" cborgen:"collection"` // record: The record itself. Must contain a $type field. - Record *util.LexiconTypeDecoder `json:"record" cborgen:"record"` + Record *json.RawMessage `json:"record" cborgen:"record"` // repo: The handle or DID of the repo (aka, current account). Repo string `json:"repo" cborgen:"repo"` // rkey: The Record Key. diff --git a/api/atproto/repodescribeRepo.go b/api/atproto/repodescribeRepo.go index ba1bcf501..ac8636b73 100644 --- a/api/atproto/repodescribeRepo.go +++ b/api/atproto/repodescribeRepo.go @@ -6,6 +6,7 @@ package atproto import ( "context" + "encoding/json" "github.com/bluesky-social/indigo/xrpc" ) @@ -16,8 +17,8 @@ type RepoDescribeRepo_Output struct { Collections []string `json:"collections" cborgen:"collections"` Did string `json:"did" cborgen:"did"` // didDoc: The complete DID document for this account. - DidDoc interface{} `json:"didDoc" cborgen:"didDoc"` - Handle string `json:"handle" cborgen:"handle"` + DidDoc *json.RawMessage `json:"didDoc" cborgen:"didDoc"` + Handle string `json:"handle" cborgen:"handle"` // handleIsCorrect: Indicates if handle is currently valid (resolves bi-directionally) HandleIsCorrect bool `json:"handleIsCorrect" cborgen:"handleIsCorrect"` } diff --git a/api/atproto/repogetRecord.go b/api/atproto/repogetRecord.go index 0ce4ba9e9..fbc789c5b 100644 --- a/api/atproto/repogetRecord.go +++ b/api/atproto/repogetRecord.go @@ -6,16 +6,16 @@ package atproto import ( "context" + "encoding/json" - "github.com/bluesky-social/indigo/lex/util" "github.com/bluesky-social/indigo/xrpc" ) // RepoGetRecord_Output is the output of a com.atproto.repo.getRecord call. type RepoGetRecord_Output struct { - Cid *string `json:"cid,omitempty" cborgen:"cid,omitempty"` - Uri string `json:"uri" cborgen:"uri"` - Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"` + Cid *string `json:"cid,omitempty" cborgen:"cid,omitempty"` + Uri string `json:"uri" cborgen:"uri"` + Value *json.RawMessage `json:"value" cborgen:"value"` } // RepoGetRecord calls the XRPC method "com.atproto.repo.getRecord". diff --git a/api/atproto/repolistRecords.go b/api/atproto/repolistRecords.go index d60fe49d4..bb4467871 100644 --- a/api/atproto/repolistRecords.go +++ b/api/atproto/repolistRecords.go @@ -6,8 +6,8 @@ package atproto import ( "context" + "encoding/json" - "github.com/bluesky-social/indigo/lex/util" "github.com/bluesky-social/indigo/xrpc" ) @@ -19,9 +19,9 @@ type RepoListRecords_Output struct { // RepoListRecords_Record is a "record" in the com.atproto.repo.listRecords schema. type RepoListRecords_Record struct { - Cid string `json:"cid" cborgen:"cid"` - Uri string `json:"uri" cborgen:"uri"` - Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"` + Cid string `json:"cid" cborgen:"cid"` + Uri string `json:"uri" cborgen:"uri"` + Value *json.RawMessage `json:"value" cborgen:"value"` } // RepoListRecords calls the XRPC method "com.atproto.repo.listRecords". diff --git a/api/atproto/repoputRecord.go b/api/atproto/repoputRecord.go index 5b8a77343..82d9699b5 100644 --- a/api/atproto/repoputRecord.go +++ b/api/atproto/repoputRecord.go @@ -6,8 +6,8 @@ package atproto import ( "context" + "encoding/json" - "github.com/bluesky-social/indigo/lex/util" "github.com/bluesky-social/indigo/xrpc" ) @@ -16,7 +16,7 @@ type RepoPutRecord_Input struct { // collection: The NSID of the record collection. Collection string `json:"collection" cborgen:"collection"` // record: The record to write. - Record *util.LexiconTypeDecoder `json:"record" cborgen:"record"` + Record *json.RawMessage `json:"record" cborgen:"record"` // repo: The handle or DID of the repo (aka, current account). Repo string `json:"repo" cborgen:"repo"` // rkey: The Record Key. diff --git a/api/atproto/servercreateAccount.go b/api/atproto/servercreateAccount.go index bfaf358ef..a2e73c31e 100644 --- a/api/atproto/servercreateAccount.go +++ b/api/atproto/servercreateAccount.go @@ -6,6 +6,7 @@ package atproto import ( "context" + "encoding/json" "github.com/bluesky-social/indigo/xrpc" ) @@ -21,7 +22,7 @@ type ServerCreateAccount_Input struct { // password: Initial account password. May need to meet instance-specific password strength requirements. Password *string `json:"password,omitempty" cborgen:"password,omitempty"` // plcOp: A signed DID PLC operation to be submitted as part of importing an existing account to this instance. NOTE: this optional field may be updated when full account migration is implemented. - PlcOp *interface{} `json:"plcOp,omitempty" cborgen:"plcOp,omitempty"` + PlcOp *json.RawMessage `json:"plcOp,omitempty" cborgen:"plcOp,omitempty"` // recoveryKey: DID PLC rotation key (aka, recovery key) to be included in PLC creation operation. RecoveryKey *string `json:"recoveryKey,omitempty" cborgen:"recoveryKey,omitempty"` VerificationCode *string `json:"verificationCode,omitempty" cborgen:"verificationCode,omitempty"` @@ -36,9 +37,9 @@ type ServerCreateAccount_Output struct { // did: The DID of the new account. Did string `json:"did" cborgen:"did"` // didDoc: Complete DID document. - DidDoc *interface{} `json:"didDoc,omitempty" cborgen:"didDoc,omitempty"` - Handle string `json:"handle" cborgen:"handle"` - RefreshJwt string `json:"refreshJwt" cborgen:"refreshJwt"` + DidDoc *json.RawMessage `json:"didDoc,omitempty" cborgen:"didDoc,omitempty"` + Handle string `json:"handle" cborgen:"handle"` + RefreshJwt string `json:"refreshJwt" cborgen:"refreshJwt"` } // ServerCreateAccount calls the XRPC method "com.atproto.server.createAccount". diff --git a/api/atproto/servercreateSession.go b/api/atproto/servercreateSession.go index 109182bf6..4aa7f0ef8 100644 --- a/api/atproto/servercreateSession.go +++ b/api/atproto/servercreateSession.go @@ -6,6 +6,7 @@ package atproto import ( "context" + "encoding/json" "github.com/bluesky-social/indigo/xrpc" ) @@ -20,15 +21,15 @@ type ServerCreateSession_Input struct { // ServerCreateSession_Output is the output of a com.atproto.server.createSession call. type ServerCreateSession_Output struct { - AccessJwt string `json:"accessJwt" cborgen:"accessJwt"` - Active *bool `json:"active,omitempty" cborgen:"active,omitempty"` - Did string `json:"did" cborgen:"did"` - DidDoc *interface{} `json:"didDoc,omitempty" cborgen:"didDoc,omitempty"` - Email *string `json:"email,omitempty" cborgen:"email,omitempty"` - EmailAuthFactor *bool `json:"emailAuthFactor,omitempty" cborgen:"emailAuthFactor,omitempty"` - EmailConfirmed *bool `json:"emailConfirmed,omitempty" cborgen:"emailConfirmed,omitempty"` - Handle string `json:"handle" cborgen:"handle"` - RefreshJwt string `json:"refreshJwt" cborgen:"refreshJwt"` + AccessJwt string `json:"accessJwt" cborgen:"accessJwt"` + Active *bool `json:"active,omitempty" cborgen:"active,omitempty"` + Did string `json:"did" cborgen:"did"` + DidDoc *json.RawMessage `json:"didDoc,omitempty" cborgen:"didDoc,omitempty"` + Email *string `json:"email,omitempty" cborgen:"email,omitempty"` + EmailAuthFactor *bool `json:"emailAuthFactor,omitempty" cborgen:"emailAuthFactor,omitempty"` + EmailConfirmed *bool `json:"emailConfirmed,omitempty" cborgen:"emailConfirmed,omitempty"` + Handle string `json:"handle" cborgen:"handle"` + RefreshJwt string `json:"refreshJwt" cborgen:"refreshJwt"` // status: If active=false, this optional field indicates a possible reason for why the account is not active. If active=false and no status is supplied, then the host makes no claim for why the repository is no longer being hosted. Status *string `json:"status,omitempty" cborgen:"status,omitempty"` } diff --git a/api/atproto/servergetSession.go b/api/atproto/servergetSession.go index dfea79d9f..078eb7d1b 100644 --- a/api/atproto/servergetSession.go +++ b/api/atproto/servergetSession.go @@ -6,19 +6,20 @@ package atproto import ( "context" + "encoding/json" "github.com/bluesky-social/indigo/xrpc" ) // ServerGetSession_Output is the output of a com.atproto.server.getSession call. type ServerGetSession_Output struct { - Active *bool `json:"active,omitempty" cborgen:"active,omitempty"` - Did string `json:"did" cborgen:"did"` - DidDoc *interface{} `json:"didDoc,omitempty" cborgen:"didDoc,omitempty"` - Email *string `json:"email,omitempty" cborgen:"email,omitempty"` - EmailAuthFactor *bool `json:"emailAuthFactor,omitempty" cborgen:"emailAuthFactor,omitempty"` - EmailConfirmed *bool `json:"emailConfirmed,omitempty" cborgen:"emailConfirmed,omitempty"` - Handle string `json:"handle" cborgen:"handle"` + Active *bool `json:"active,omitempty" cborgen:"active,omitempty"` + Did string `json:"did" cborgen:"did"` + DidDoc *json.RawMessage `json:"didDoc,omitempty" cborgen:"didDoc,omitempty"` + Email *string `json:"email,omitempty" cborgen:"email,omitempty"` + EmailAuthFactor *bool `json:"emailAuthFactor,omitempty" cborgen:"emailAuthFactor,omitempty"` + EmailConfirmed *bool `json:"emailConfirmed,omitempty" cborgen:"emailConfirmed,omitempty"` + Handle string `json:"handle" cborgen:"handle"` // status: If active=false, this optional field indicates a possible reason for why the account is not active. If active=false and no status is supplied, then the host makes no claim for why the repository is no longer being hosted. Status *string `json:"status,omitempty" cborgen:"status,omitempty"` } diff --git a/api/atproto/serverrefreshSession.go b/api/atproto/serverrefreshSession.go index ef5109860..d97775089 100644 --- a/api/atproto/serverrefreshSession.go +++ b/api/atproto/serverrefreshSession.go @@ -6,18 +6,19 @@ package atproto import ( "context" + "encoding/json" "github.com/bluesky-social/indigo/xrpc" ) // ServerRefreshSession_Output is the output of a com.atproto.server.refreshSession call. type ServerRefreshSession_Output struct { - AccessJwt string `json:"accessJwt" cborgen:"accessJwt"` - Active *bool `json:"active,omitempty" cborgen:"active,omitempty"` - Did string `json:"did" cborgen:"did"` - DidDoc *interface{} `json:"didDoc,omitempty" cborgen:"didDoc,omitempty"` - Handle string `json:"handle" cborgen:"handle"` - RefreshJwt string `json:"refreshJwt" cborgen:"refreshJwt"` + AccessJwt string `json:"accessJwt" cborgen:"accessJwt"` + Active *bool `json:"active,omitempty" cborgen:"active,omitempty"` + Did string `json:"did" cborgen:"did"` + DidDoc *json.RawMessage `json:"didDoc,omitempty" cborgen:"didDoc,omitempty"` + Handle string `json:"handle" cborgen:"handle"` + RefreshJwt string `json:"refreshJwt" cborgen:"refreshJwt"` // status: Hosting status of the account. If not specified, then assume 'active'. Status *string `json:"status,omitempty" cborgen:"status,omitempty"` } From 502cdbf9dd88eefb3f152f1f07f90fd978194fa8 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Thu, 3 Oct 2024 18:38:33 -0700 Subject: [PATCH 3/3] show how to decode some unknown types --- automod/capture/fetch.go | 13 +++++++++++-- automod/capture/testing.go | 7 ++++++- cmd/athome/handlers.go | 3 ++- repomgr/repomgr.go | 16 ++++++++++++---- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/automod/capture/fetch.go b/automod/capture/fetch.go index be3719de6..b57853e33 100644 --- a/automod/capture/fetch.go +++ b/automod/capture/fetch.go @@ -9,6 +9,7 @@ import ( "github.com/bluesky-social/indigo/atproto/identity" "github.com/bluesky-social/indigo/atproto/syntax" "github.com/bluesky-social/indigo/automod" + lexutil "github.com/bluesky-social/indigo/lex/util" "github.com/bluesky-social/indigo/xrpc" ) @@ -36,8 +37,12 @@ func FetchAndProcessRecord(ctx context.Context, eng *automod.Engine, aturi synta return fmt.Errorf("expected a CID in getRecord response") } recCID := syntax.CID(*out.Cid) + var ltd lexutil.LexiconTypeDecoder + if err = ltd.UnmarshalJSON(*out.Value); err != nil { + return err + } recBuf := new(bytes.Buffer) - if err := out.Value.Val.MarshalCBOR(recBuf); err != nil { + if err := ltd.Val.MarshalCBOR(recBuf); err != nil { return err } recBytes := recBuf.Bytes() @@ -85,8 +90,12 @@ func FetchAndProcessRecent(ctx context.Context, eng *automod.Engine, atid syntax return fmt.Errorf("parsing PDS record response: %v", err) } recCID := syntax.CID(rec.Cid) + var ltd lexutil.LexiconTypeDecoder + if err = ltd.UnmarshalJSON(*rec.Value); err != nil { + return err + } recBuf := new(bytes.Buffer) - if err := rec.Value.Val.MarshalCBOR(recBuf); err != nil { + if err := ltd.Val.MarshalCBOR(recBuf); err != nil { return err } recBytes := recBuf.Bytes() diff --git a/automod/capture/testing.go b/automod/capture/testing.go index 998aaef48..3ffef8c61 100644 --- a/automod/capture/testing.go +++ b/automod/capture/testing.go @@ -10,6 +10,7 @@ import ( "github.com/bluesky-social/indigo/atproto/identity" "github.com/bluesky-social/indigo/atproto/syntax" "github.com/bluesky-social/indigo/automod" + lexutil "github.com/bluesky-social/indigo/lex/util" ) func MustLoadCapture(capPath string) AccountCapture { @@ -57,7 +58,11 @@ func ProcessCaptureRules(eng *automod.Engine, capture AccountCapture) error { } recCID := syntax.CID(pr.Cid) recBuf := new(bytes.Buffer) - if err := pr.Value.Val.MarshalCBOR(recBuf); err != nil { + var ltd lexutil.LexiconTypeDecoder + if err = ltd.UnmarshalJSON(*pr.Value); err != nil { + return err + } + if err := ltd.Val.MarshalCBOR(recBuf); err != nil { return err } recBytes := recBuf.Bytes() diff --git a/cmd/athome/handlers.go b/cmd/athome/handlers.go index 229cf1eb3..844708353 100644 --- a/cmd/athome/handlers.go +++ b/cmd/athome/handlers.go @@ -142,7 +142,8 @@ func (srv *Server) WebRepoRSS(c echo.Context) error { if err != nil { return err } - rec := p.Post.Record.Val.(*appbsky.FeedPost) + + rec := p.Post.Record // only top-level posts in RSS if rec.Reply != nil { continue diff --git a/repomgr/repomgr.go b/repomgr/repomgr.go index ad90a43b2..6bab26197 100644 --- a/repomgr/repomgr.go +++ b/repomgr/repomgr.go @@ -692,7 +692,11 @@ func (rm *RepoManager) BatchWrite(ctx context.Context, user models.Uid, writes [ } nsid := c.Collection + "/" + rkey - cc, err := r.PutRecord(ctx, nsid, c.Value.Val) + var ltd lexutil.LexiconTypeDecoder + if err = ltd.UnmarshalJSON(*c.Value); err != nil { + return err + } + cc, err := r.PutRecord(ctx, nsid, ltd.Val) if err != nil { return err } @@ -705,14 +709,18 @@ func (rm *RepoManager) BatchWrite(ctx context.Context, user models.Uid, writes [ } if rm.hydrateRecords { - op.Record = c.Value.Val + op.Record = ltd.Val } ops = append(ops, op) case w.RepoApplyWrites_Update != nil: u := w.RepoApplyWrites_Update - cc, err := r.PutRecord(ctx, u.Collection+"/"+u.Rkey, u.Value.Val) + var ltd lexutil.LexiconTypeDecoder + if err = ltd.UnmarshalJSON(*u.Value); err != nil { + return err + } + cc, err := r.PutRecord(ctx, u.Collection+"/"+u.Rkey, ltd.Val) if err != nil { return err } @@ -725,7 +733,7 @@ func (rm *RepoManager) BatchWrite(ctx context.Context, user models.Uid, writes [ } if rm.hydrateRecords { - op.Record = u.Value.Val + op.Record = ltd.Val } ops = append(ops, op)