noot
This commit is contained in:
parent
01b0924a48
commit
7986b85d27
ts
Binary file not shown.
@ -39,6 +39,7 @@
|
||||
"pino-logfmt": "^0.1.1",
|
||||
"pino-pretty": "^13.0.0",
|
||||
"postgres": "^3.4.5",
|
||||
"superjson": "^2.2.2",
|
||||
"ts-markdown-builder": "^0.4.0",
|
||||
"why-is-node-running": "^3.2.2",
|
||||
"znv": "^0.4.0",
|
||||
|
@ -50,5 +50,4 @@ export const reply_to_interaction = async (props: {
|
||||
|
||||
return await bot.helpers.sendInteractionResponse(ref.id, ref.token,
|
||||
{ type, data }, { withResponse: options?.withResponse })
|
||||
|
||||
}
|
||||
|
61
ts/src/payload-converter/adapter.ts
Normal file
61
ts/src/payload-converter/adapter.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import {
|
||||
EncodingType,
|
||||
METADATA_ENCODING_KEY,
|
||||
Payload,
|
||||
PayloadConverterError,
|
||||
PayloadConverterWithEncoding,
|
||||
} from '@temporalio/common';
|
||||
import { decode, encode } from '@temporalio/common/lib/encoding';
|
||||
import { errorMessage } from '@temporalio/common/lib/type-helpers';
|
||||
import superjson from 'superjson';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts between values and [superjson](https://github.com/flightcontrolhq/superjson) Payloads.
|
||||
*/
|
||||
export class SuperJsonPayloadConverter implements PayloadConverterWithEncoding {
|
||||
// Use 'json/plain' so that Payloads are displayed in the UI
|
||||
public encodingType = 'json/plain' as EncodingType;
|
||||
|
||||
public toPayload(value: unknown): Payload | undefined {
|
||||
if (value === undefined) return undefined;
|
||||
let ejson;
|
||||
try {
|
||||
ejson = superjson.stringify(value);
|
||||
} catch (e) {
|
||||
throw new UnsupportedSuperJsonTypeError(
|
||||
`Can't run superjson.stringify on this value: ${value}. Either convert it (or its properties) to superjson-serializable values (see https://docs.meteor.com/api/ejson.html ), or create a custom data converter. superjson.stringify error message: ${
|
||||
errorMessage(
|
||||
e,
|
||||
)
|
||||
}`,
|
||||
e as Error,
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
metadata: {
|
||||
[METADATA_ENCODING_KEY]: encode('json/plain'),
|
||||
// Include an additional metadata field to indicate that this is an superjson payload
|
||||
format: encode('extended'),
|
||||
},
|
||||
data: encode(ejson),
|
||||
};
|
||||
}
|
||||
|
||||
public fromPayload<T>(content: Payload): T {
|
||||
return content.data ? superjson.parse<T>(decode(content.data)) : {} as T;
|
||||
}
|
||||
}
|
||||
|
||||
export class UnsupportedSuperJsonTypeError extends PayloadConverterError {
|
||||
public readonly name: string = 'UnsupportedJsonTypeError';
|
||||
|
||||
constructor(
|
||||
message: string | undefined,
|
||||
public readonly cause?: Error,
|
||||
) {
|
||||
super(message ?? undefined);
|
||||
}
|
||||
}
|
10
ts/src/payload-converter/index.ts
Normal file
10
ts/src/payload-converter/index.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import {
|
||||
CompositePayloadConverter,
|
||||
UndefinedPayloadConverter,
|
||||
} from '@temporalio/common';
|
||||
import { SuperJsonPayloadConverter } from './adapter';
|
||||
|
||||
export const payloadConverter = new CompositePayloadConverter(
|
||||
new UndefinedPayloadConverter(),
|
||||
new SuperJsonPayloadConverter(),
|
||||
);
|
@ -12,6 +12,9 @@ c.bind({
|
||||
const client = new Client({
|
||||
connection,
|
||||
namespace: config.TEMPORAL_NAMESPACE,
|
||||
dataConverter: {
|
||||
payloadConverterPath: require.resolve('../../payload-converter'),
|
||||
},
|
||||
});
|
||||
process.on('exit', () => {
|
||||
console.log('closing temporal client');
|
||||
|
37
ts/src/workflows/discord.ts
Normal file
37
ts/src/workflows/discord.ts
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
import { proxyActivities } from '@temporalio/workflow';
|
||||
import type * as activities from '#/activities';
|
||||
import { InteractionData, InteractionTypes } from 'discordeno';
|
||||
import { c } from '#/di';
|
||||
import { Bot } from '#/bot';
|
||||
|
||||
const { } = proxyActivities<typeof activities>({
|
||||
startToCloseTimeout: '1 minute',
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
interface HandleInteractionCreatePayload {
|
||||
ref: activities.InteractionRef
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const workflowHandleApplicationCommand = async (
|
||||
{ }: HandleInteractionCreatePayload,
|
||||
) => {
|
||||
const bot = await c.getAsync(Bot)
|
||||
|
||||
}
|
||||
|
||||
export const workflowHandleInteractionCreate = async (
|
||||
payload: HandleInteractionCreatePayload,
|
||||
) => {
|
||||
const {ref } = payload
|
||||
|
||||
if(ref.type === InteractionTypes.ApplicationCommand) {
|
||||
await workflowHandleApplicationCommand(payload)
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
* @file Automatically generated by barrelsby.
|
||||
*/
|
||||
|
||||
export * from "./discord";
|
||||
export * from "./guilds";
|
||||
export * from "./items";
|
||||
export * from "./players";
|
||||
|
26
ts/yarn.lock
26
ts/yarn.lock
@ -1355,6 +1355,7 @@ __metadata:
|
||||
pino-pretty: "npm:^13.0.0"
|
||||
postgres: "npm:^3.4.5"
|
||||
rollup: "npm:^4.34.8"
|
||||
superjson: "npm:^2.2.2"
|
||||
ts-markdown-builder: "npm:^0.4.0"
|
||||
typescript: "npm:5.7.3"
|
||||
why-is-node-running: "npm:^3.2.2"
|
||||
@ -1734,6 +1735,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"copy-anything@npm:^3.0.2":
|
||||
version: 3.0.5
|
||||
resolution: "copy-anything@npm:3.0.5"
|
||||
dependencies:
|
||||
is-what: "npm:^4.1.8"
|
||||
checksum: 10c0/01eadd500c7e1db71d32d95a3bfaaedcb839ef891c741f6305ab0461398056133de08f2d1bf4c392b364e7bdb7ce498513896e137a7a183ac2516b065c28a4fe
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"cross-spawn@npm:^7.0.6":
|
||||
version: 7.0.6
|
||||
resolution: "cross-spawn@npm:7.0.6"
|
||||
@ -2575,6 +2585,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"is-what@npm:^4.1.8":
|
||||
version: 4.1.16
|
||||
resolution: "is-what@npm:4.1.16"
|
||||
checksum: 10c0/611f1947776826dcf85b57cfb7bd3b3ea6f4b94a9c2f551d4a53f653cf0cb9d1e6518846648256d46ee6c91d114b6d09d2ac8a07306f7430c5900f87466aae5b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"isarray@npm:^2.0.5":
|
||||
version: 2.0.5
|
||||
resolution: "isarray@npm:2.0.5"
|
||||
@ -3959,6 +3976,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"superjson@npm:^2.2.2":
|
||||
version: 2.2.2
|
||||
resolution: "superjson@npm:2.2.2"
|
||||
dependencies:
|
||||
copy-anything: "npm:^3.0.2"
|
||||
checksum: 10c0/aa49ebe6653e963020bc6a1ed416d267dfda84cfcc3cbd3beffd75b72e44eb9df7327215f3e3e77528f6e19ad8895b16a4964fdcd56d1799d14350db8c92afbc
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"supports-color@npm:^5.3.0":
|
||||
version: 5.5.0
|
||||
resolution: "supports-color@npm:5.5.0"
|
||||
|
Loading…
Reference in New Issue
Block a user