-
Notifications
You must be signed in to change notification settings - Fork 2
Simpler consensus helpers #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
1,014 changes: 519 additions & 495 deletions
1,014
src/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.ts
Large diffs are not rendered by default.
Oops, something went wrong.
187 changes: 100 additions & 87 deletions
187
src/generated-sdk/capabilities/internal/actionandtrigger/v1/basic_sdk_gen.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,128 @@ | ||
import { fromBinary, toBinary, fromJson, create } from '@bufbuild/protobuf' | ||
import { Mode, type CapabilityResponse } from '@cre/generated/sdk/v1alpha/sdk_pb' | ||
import { callCapability } from '@cre/sdk/utils/capabilities/call-capability' | ||
import { CapabilityError } from '@cre/sdk/utils/capabilities/capability-error' | ||
import { type Trigger } from '@cre/sdk/utils/triggers/trigger-interface' | ||
import { type Any, AnySchema } from '@bufbuild/protobuf/wkt' | ||
import { getTypeUrl } from '@cre/sdk/utils/typeurl' | ||
import { fromBinary, toBinary, fromJson, create } from "@bufbuild/protobuf"; | ||
import { | ||
ConfigSchema, | ||
InputSchema, | ||
OutputSchema, | ||
TriggerEventSchema, | ||
type ConfigJson, | ||
type InputJson, | ||
type Output, | ||
type TriggerEvent, | ||
} from '@cre/generated/capabilities/internal/actionandtrigger/v1/action_and_trigger_pb' | ||
Mode, | ||
type CapabilityResponse, | ||
} from "@cre/generated/sdk/v1alpha/sdk_pb"; | ||
import { callCapability } from "@cre/sdk/utils/capabilities/call-capability"; | ||
import { CapabilityError } from "@cre/sdk/utils/capabilities/capability-error"; | ||
import { type Trigger } from "@cre/sdk/utils/triggers/trigger-interface"; | ||
import { type Any, AnySchema } from "@bufbuild/protobuf/wkt"; | ||
import { getTypeUrl } from "@cre/sdk/utils/typeurl"; | ||
import { | ||
ConfigSchema, | ||
InputSchema, | ||
OutputSchema, | ||
TriggerEventSchema, | ||
type Config, | ||
type ConfigJson, | ||
type Input, | ||
type InputJson, | ||
type Output, | ||
type TriggerEvent, | ||
} from "@cre/generated/capabilities/internal/actionandtrigger/v1/action_and_trigger_pb"; | ||
|
||
/** | ||
* Basic Capability | ||
* | ||
* | ||
* Capability ID: basic-test-action-trigger@1.0.0 | ||
* Default Mode: Mode.DON | ||
* Capability Name: basic-test-action-trigger | ||
* Capability Version: 1.0.0 | ||
*/ | ||
export class BasicCapability { | ||
/** The capability ID for this service */ | ||
static readonly CAPABILITY_ID = 'basic-test-action-trigger@1.0.0' | ||
|
||
/** The default execution mode for this capability */ | ||
static readonly DEFAULT_MODE = Mode.DON | ||
/** The capability ID for this service */ | ||
static readonly CAPABILITY_ID = "basic-test-action-trigger@1.0.0"; | ||
/** The default execution mode for this capability */ | ||
static readonly DEFAULT_MODE = Mode.DON; | ||
|
||
static readonly CAPABILITY_NAME = 'basic-test-action-trigger' | ||
static readonly CAPABILITY_VERSION = '1.0.0' | ||
static readonly CAPABILITY_NAME = "basic-test-action-trigger"; | ||
static readonly CAPABILITY_VERSION = "1.0.0"; | ||
|
||
constructor(private readonly mode: Mode = BasicCapability.DEFAULT_MODE) {} | ||
|
||
async action(input: InputJson): Promise<Output> { | ||
const payload = { | ||
typeUrl: getTypeUrl(InputSchema), | ||
value: toBinary(InputSchema, fromJson(InputSchema, input)), | ||
} | ||
const capabilityId = BasicCapability.CAPABILITY_ID | ||
constructor( | ||
private readonly mode: Mode = BasicCapability.DEFAULT_MODE | ||
) {} | ||
|
||
return callCapability({ | ||
capabilityId, | ||
method: 'Action', | ||
mode: this.mode, | ||
payload, | ||
}).then((capabilityResponse: CapabilityResponse) => { | ||
if (capabilityResponse.response.case === 'error') { | ||
throw new CapabilityError(capabilityResponse.response.value, { | ||
capabilityId, | ||
method: 'Action', | ||
mode: this.mode, | ||
}) | ||
} | ||
async action(input: Input | InputJson): Promise<Output> { | ||
// biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages | ||
const value = (input as any).$typeName ? input as Input : fromJson(InputSchema, input as InputJson) | ||
const payload = { | ||
typeUrl: getTypeUrl(InputSchema), | ||
value: toBinary(InputSchema, value), | ||
}; | ||
const capabilityId = BasicCapability.CAPABILITY_ID; | ||
|
||
return callCapability({ | ||
capabilityId, | ||
method: "Action", | ||
mode: this.mode, | ||
payload, | ||
}).then((capabilityResponse: CapabilityResponse) => { | ||
if (capabilityResponse.response.case === "error") { | ||
throw new CapabilityError(capabilityResponse.response.value, { | ||
capabilityId, | ||
method: "Action", | ||
mode: this.mode, | ||
}); | ||
} | ||
|
||
if (capabilityResponse.response.case !== 'payload') { | ||
throw new CapabilityError('No payload in response', { | ||
capabilityId, | ||
method: 'Action', | ||
mode: this.mode, | ||
}) | ||
} | ||
if (capabilityResponse.response.case !== "payload") { | ||
throw new CapabilityError("No payload in response", { | ||
capabilityId, | ||
method: "Action", | ||
mode: this.mode, | ||
}); | ||
} | ||
|
||
return fromBinary(OutputSchema, capabilityResponse.response.value.value) | ||
}) | ||
} | ||
return fromBinary(OutputSchema, capabilityResponse.response.value.value); | ||
}); | ||
} | ||
|
||
trigger(config: ConfigJson): BasicTrigger { | ||
return new BasicTrigger(this.mode, config, BasicCapability.CAPABILITY_ID, 'Trigger') | ||
} | ||
trigger(config: ConfigJson): BasicTrigger { | ||
return new BasicTrigger(this.mode, config, BasicCapability.CAPABILITY_ID, "Trigger"); | ||
} | ||
} | ||
|
||
/** | ||
* Trigger implementation for Trigger | ||
*/ | ||
class BasicTrigger implements Trigger<TriggerEvent, TriggerEvent> { | ||
constructor( | ||
public readonly mode: Mode, | ||
public readonly config: ConfigJson, | ||
private readonly _capabilityId: string, | ||
private readonly _method: string, | ||
) {} | ||
public readonly config: Config | ||
constructor( | ||
public readonly mode: Mode, | ||
config: Config | ConfigJson, | ||
private readonly _capabilityId: string, | ||
private readonly _method: string | ||
) { | ||
// biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages | ||
this.config = (config as any).$typeName ? config as Config : fromJson(ConfigSchema, config as ConfigJson) | ||
} | ||
|
||
capabilityId(): string { | ||
return this._capabilityId | ||
} | ||
capabilityId(): string { | ||
return this._capabilityId; | ||
} | ||
|
||
method(): string { | ||
return this._method | ||
} | ||
method(): string { | ||
return this._method; | ||
} | ||
|
||
outputSchema() { | ||
return TriggerEventSchema | ||
} | ||
outputSchema() { | ||
return TriggerEventSchema; | ||
} | ||
|
||
configAsAny(): Any { | ||
const configMessage = fromJson(ConfigSchema, this.config) | ||
return create(AnySchema, { | ||
typeUrl: getTypeUrl(ConfigSchema), | ||
value: toBinary(ConfigSchema, configMessage), | ||
}) | ||
} | ||
configAsAny(): Any { | ||
return create(AnySchema, { | ||
typeUrl: getTypeUrl(ConfigSchema), | ||
value: toBinary(ConfigSchema, this.config), | ||
}); | ||
} | ||
|
||
/** | ||
* Transform the raw trigger output - override this method if needed | ||
* Default implementation returns the raw output unchanged | ||
*/ | ||
adapt(rawOutput: TriggerEvent): TriggerEvent { | ||
return rawOutput | ||
} | ||
} | ||
/** | ||
* Transform the raw trigger output - override this method if needed | ||
* Default implementation returns the raw output unchanged | ||
*/ | ||
adapt(rawOutput: TriggerEvent): TriggerEvent { | ||
return rawOutput; | ||
} | ||
} |
105 changes: 57 additions & 48 deletions
105
src/generated-sdk/capabilities/internal/basicaction/v1/basicaction_sdk_gen.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,74 @@ | ||
import { fromBinary, toBinary, fromJson, create } from '@bufbuild/protobuf' | ||
import { Mode, type CapabilityResponse } from '@cre/generated/sdk/v1alpha/sdk_pb' | ||
import { callCapability } from '@cre/sdk/utils/capabilities/call-capability' | ||
import { CapabilityError } from '@cre/sdk/utils/capabilities/capability-error' | ||
import { getTypeUrl } from '@cre/sdk/utils/typeurl' | ||
import { fromBinary, toBinary, fromJson } from "@bufbuild/protobuf"; | ||
import { | ||
InputsSchema, | ||
OutputsSchema, | ||
type InputsJson, | ||
type Outputs, | ||
} from '@cre/generated/capabilities/internal/basicaction/v1/basic_action_pb' | ||
Mode, | ||
type CapabilityResponse, | ||
} from "@cre/generated/sdk/v1alpha/sdk_pb"; | ||
import { callCapability } from "@cre/sdk/utils/capabilities/call-capability"; | ||
import { CapabilityError } from "@cre/sdk/utils/capabilities/capability-error"; | ||
import { getTypeUrl } from "@cre/sdk/utils/typeurl"; | ||
import { | ||
InputsSchema, | ||
OutputsSchema, | ||
type Inputs, | ||
type InputsJson, | ||
type Outputs, | ||
} from "@cre/generated/capabilities/internal/basicaction/v1/basic_action_pb"; | ||
|
||
/** | ||
* BasicAction Capability | ||
* | ||
* | ||
* Capability ID: basic-test-action@1.0.0 | ||
* Default Mode: Mode.DON | ||
* Capability Name: basic-test-action | ||
* Capability Version: 1.0.0 | ||
*/ | ||
export class BasicActionCapability { | ||
/** The capability ID for this service */ | ||
static readonly CAPABILITY_ID = 'basic-test-action@1.0.0' | ||
|
||
/** The default execution mode for this capability */ | ||
static readonly DEFAULT_MODE = Mode.DON | ||
/** The capability ID for this service */ | ||
static readonly CAPABILITY_ID = "basic-test-action@1.0.0"; | ||
/** The default execution mode for this capability */ | ||
static readonly DEFAULT_MODE = Mode.DON; | ||
|
||
static readonly CAPABILITY_NAME = 'basic-test-action' | ||
static readonly CAPABILITY_VERSION = '1.0.0' | ||
static readonly CAPABILITY_NAME = "basic-test-action"; | ||
static readonly CAPABILITY_VERSION = "1.0.0"; | ||
|
||
constructor(private readonly mode: Mode = BasicActionCapability.DEFAULT_MODE) {} | ||
|
||
async performAction(input: InputsJson): Promise<Outputs> { | ||
const payload = { | ||
typeUrl: getTypeUrl(InputsSchema), | ||
value: toBinary(InputsSchema, fromJson(InputsSchema, input)), | ||
} | ||
const capabilityId = BasicActionCapability.CAPABILITY_ID | ||
constructor( | ||
private readonly mode: Mode = BasicActionCapability.DEFAULT_MODE | ||
) {} | ||
|
||
return callCapability({ | ||
capabilityId, | ||
method: 'PerformAction', | ||
mode: this.mode, | ||
payload, | ||
}).then((capabilityResponse: CapabilityResponse) => { | ||
if (capabilityResponse.response.case === 'error') { | ||
throw new CapabilityError(capabilityResponse.response.value, { | ||
capabilityId, | ||
method: 'PerformAction', | ||
mode: this.mode, | ||
}) | ||
} | ||
async performAction(input: Inputs | InputsJson): Promise<Outputs> { | ||
// biome-ignore lint/suspicious/noExplicitAny: Needed for runtime type checking of protocol buffer messages | ||
const value = (input as any).$typeName ? input as Inputs : fromJson(InputsSchema, input as InputsJson) | ||
const payload = { | ||
typeUrl: getTypeUrl(InputsSchema), | ||
value: toBinary(InputsSchema, value), | ||
}; | ||
const capabilityId = BasicActionCapability.CAPABILITY_ID; | ||
|
||
return callCapability({ | ||
capabilityId, | ||
method: "PerformAction", | ||
mode: this.mode, | ||
payload, | ||
}).then((capabilityResponse: CapabilityResponse) => { | ||
if (capabilityResponse.response.case === "error") { | ||
throw new CapabilityError(capabilityResponse.response.value, { | ||
capabilityId, | ||
method: "PerformAction", | ||
mode: this.mode, | ||
}); | ||
} | ||
|
||
if (capabilityResponse.response.case !== 'payload') { | ||
throw new CapabilityError('No payload in response', { | ||
capabilityId, | ||
method: 'PerformAction', | ||
mode: this.mode, | ||
}) | ||
} | ||
if (capabilityResponse.response.case !== "payload") { | ||
throw new CapabilityError("No payload in response", { | ||
capabilityId, | ||
method: "PerformAction", | ||
mode: this.mode, | ||
}); | ||
} | ||
|
||
return fromBinary(OutputsSchema, capabilityResponse.response.value.value) | ||
}) | ||
} | ||
return fromBinary(OutputsSchema, capabilityResponse.response.value.value); | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably shouldn't include this in the repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is temporary until the npm package is published.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have no idea why mine is so much smaller. I ran bun build:all. I wonder if there had been a debug build checked in by mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even in npm package I believe javy plugin needs to be included,
dist
is used by npm a lot to distribute artifacts, not sure what would be the alternative ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, so the dist folder would be published in the npm package but not checked into this repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeffrifwaldsmartcontract or @ernest-nowacki, anything blocking this PR? I want to build on it to clean up the runtime more :)