From fad0f9fa6eee2834094c2caa189a7426cfb19df6 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Wed, 20 Mar 2024 16:01:40 +0000 Subject: [PATCH] Switch consumers over to `events_v2` --- rs/canister/api/can.did | 1 + rs/consumer/agent_runtime/src/lib.rs | 2 +- rs/consumer/cdk_runtime/src/lib.rs | 2 +- ts/consumer/src/candid/idl.js | 12 ++++++++++-- ts/consumer/src/candid/types.d.ts | 9 +++++++-- ts/consumer/src/client.ts | 2 +- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/rs/canister/api/can.did b/rs/canister/api/can.did index 5425fac..00a203c 100644 --- a/rs/canister/api/can.did +++ b/rs/canister/api/can.did @@ -32,6 +32,7 @@ type WhitelistedPrincipals = record { }; service : (InitArgs) -> { events : (EventsArgs) -> (EventsResponse) query; + events_v2 : (EventsArgs) -> (EventsResponse) query; push_events : (PushEventsArgs) -> (); push_events_v2 : (PushEventsArgs) -> (); whitelisted_principals : () -> (WhitelistedPrincipals) query; diff --git a/rs/consumer/agent_runtime/src/lib.rs b/rs/consumer/agent_runtime/src/lib.rs index 2cc4333..3fcfc6d 100644 --- a/rs/consumer/agent_runtime/src/lib.rs +++ b/rs/consumer/agent_runtime/src/lib.rs @@ -20,7 +20,7 @@ impl AgentRuntime { ) -> Result { match self .agent - .query(&canister_id, "events") + .query(&canister_id, "events_v2") .with_arg(candid::encode_one(args).unwrap()) .call() .await diff --git a/rs/consumer/cdk_runtime/src/lib.rs b/rs/consumer/cdk_runtime/src/lib.rs index 12f7908..62ecf30 100644 --- a/rs/consumer/cdk_runtime/src/lib.rs +++ b/rs/consumer/cdk_runtime/src/lib.rs @@ -13,7 +13,7 @@ impl CdkRuntime { canister_id: Principal, args: EventsArgs, ) -> Result { - match ic_cdk::call(canister_id, "events", (args,)).await { + match ic_cdk::call(canister_id, "events_v2", (args,)).await { Ok((response,)) => Ok(response), Err((code, msg)) => Err((code as i32, msg)), } diff --git a/ts/consumer/src/candid/idl.js b/ts/consumer/src/candid/idl.js index b5e4908..92a7926 100644 --- a/ts/consumer/src/candid/idl.js +++ b/ts/consumer/src/candid/idl.js @@ -2,6 +2,7 @@ export const idlFactory = ({ IDL }) => { const InitArgs = IDL.Record({ 'push_events_whitelist' : IDL.Vec(IDL.Principal), 'read_events_whitelist' : IDL.Vec(IDL.Principal), + 'time_granularity' : IDL.Opt(IDL.Nat64), }); const EventsArgs = IDL.Record({ 'start' : IDL.Nat64, 'length' : IDL.Nat64 }); const IndexedEvent = IDL.Record({ @@ -16,10 +17,14 @@ export const idlFactory = ({ IDL }) => { 'events' : IDL.Vec(IndexedEvent), 'latest_event_index' : IDL.Opt(IDL.Nat64), }); + const Anonymizable = IDL.Variant({ + 'Anonymize' : IDL.Text, + 'Public' : IDL.Text, + }); const IdempotentEvent = IDL.Record({ - 'source' : IDL.Opt(IDL.Text), + 'source' : IDL.Opt(Anonymizable), 'name' : IDL.Text, - 'user' : IDL.Opt(IDL.Text), + 'user' : IDL.Opt(Anonymizable), 'timestamp' : IDL.Nat64, 'payload' : IDL.Vec(IDL.Nat8), 'idempotency_key' : IDL.Nat, @@ -31,7 +36,9 @@ export const idlFactory = ({ IDL }) => { }); return IDL.Service({ 'events' : IDL.Func([EventsArgs], [EventsResponse], ['query']), + 'events_v2' : IDL.Func([EventsArgs], [EventsResponse], ['query']), 'push_events' : IDL.Func([PushEventsArgs], [], []), + 'push_events_v2' : IDL.Func([PushEventsArgs], [], []), 'whitelisted_principals' : IDL.Func([], [WhitelistedPrincipals], ['query']), }); }; @@ -39,6 +46,7 @@ export const init = ({ IDL }) => { const InitArgs = IDL.Record({ 'push_events_whitelist' : IDL.Vec(IDL.Principal), 'read_events_whitelist' : IDL.Vec(IDL.Principal), + 'time_granularity' : IDL.Opt(IDL.Nat64), }); return [InitArgs]; }; diff --git a/ts/consumer/src/candid/types.d.ts b/ts/consumer/src/candid/types.d.ts index 8a4957c..ecbcbcb 100644 --- a/ts/consumer/src/candid/types.d.ts +++ b/ts/consumer/src/candid/types.d.ts @@ -1,15 +1,17 @@ import type { Principal } from '@dfinity/principal'; import type { ActorMethod } from '@dfinity/agent'; +export type Anonymizable = { 'Anonymize' : string } | + { 'Public' : string }; export interface EventsArgs { 'start' : bigint, 'length' : bigint } export interface EventsResponse { 'events' : Array, 'latest_event_index' : [] | [bigint], } export interface IdempotentEvent { - 'source' : [] | [string], + 'source' : [] | [Anonymizable], 'name' : string, - 'user' : [] | [string], + 'user' : [] | [Anonymizable], 'timestamp' : bigint, 'payload' : Uint8Array | number[], 'idempotency_key' : bigint, @@ -25,6 +27,7 @@ export interface IndexedEvent { export interface InitArgs { 'push_events_whitelist' : Array, 'read_events_whitelist' : Array, + 'time_granularity' : [] | [bigint], } export interface PushEventsArgs { 'events' : Array } export interface WhitelistedPrincipals { @@ -33,6 +36,8 @@ export interface WhitelistedPrincipals { } export interface _SERVICE { 'events' : ActorMethod<[EventsArgs], EventsResponse>, + 'events_v2' : ActorMethod<[EventsArgs], EventsResponse>, 'push_events' : ActorMethod<[PushEventsArgs], undefined>, + 'push_events_v2' : ActorMethod<[PushEventsArgs], undefined>, 'whitelisted_principals' : ActorMethod<[], WhitelistedPrincipals>, } diff --git a/ts/consumer/src/client.ts b/ts/consumer/src/client.ts index dc04cf8..a8ae96b 100644 --- a/ts/consumer/src/client.ts +++ b/ts/consumer/src/client.ts @@ -27,7 +27,7 @@ export class Client { } public async events(start: bigint, length: bigint): Promise { - const candid = await this.canister.events({ + const candid = await this.canister.events_v2({ start, length, });