@meetploy/emulator 1.26.1 → 1.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundler/bundler.d.ts +1 -1
- package/dist/bundler/bundler.js +15 -317
- package/dist/bundler/bundler.js.map +1 -1
- package/dist/dashboard-dist/assets/{main-DZM02c9l.js → main-B2W_MQ7P.js} +57 -57
- package/dist/dashboard-dist/assets/main-oM9iTzuI.css +1 -0
- package/dist/dashboard-dist/index.html +2 -2
- package/dist/dev-dashboard.js +9 -1
- package/dist/dev-dashboard.js.map +1 -1
- package/dist/runtime/ai-runtime.d.ts +1 -1
- package/dist/runtime/ai-runtime.js +1 -157
- package/dist/runtime/ai-runtime.js.map +1 -1
- package/dist/runtime/fs-runtime.d.ts +1 -1
- package/dist/runtime/fs-runtime.js +1 -111
- package/dist/runtime/fs-runtime.js.map +1 -1
- package/dist/runtime/queue-runtime.d.ts +1 -1
- package/dist/runtime/queue-runtime.js +1 -59
- package/dist/runtime/queue-runtime.js.map +1 -1
- package/dist/runtime/state-runtime.d.ts +1 -1
- package/dist/runtime/state-runtime.js +1 -283
- package/dist/runtime/state-runtime.js.map +1 -1
- package/dist/runtime/timer-runtime.d.ts +1 -1
- package/dist/runtime/timer-runtime.js +1 -59
- package/dist/runtime/timer-runtime.js.map +1 -1
- package/dist/runtime/workflow-runtime.d.ts +1 -1
- package/dist/runtime/workflow-runtime.js +1 -266
- package/dist/runtime/workflow-runtime.js.map +1 -1
- package/dist/utils/sqlite.js +2 -86
- package/dist/utils/sqlite.js.map +1 -1
- package/package.json +1 -1
- package/dist/dashboard-dist/assets/main-C8ubpaTn.css +0 -1
|
@@ -1,60 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
interface QueueSendResult {
|
|
3
|
-
success: boolean;
|
|
4
|
-
messageId?: string;
|
|
5
|
-
error?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface QueueBatchSendResult {
|
|
9
|
-
success: boolean;
|
|
10
|
-
messageIds?: string[];
|
|
11
|
-
error?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface Queue<T = unknown> {
|
|
15
|
-
send: (payload: T, options?: { delaySeconds?: number }) => Promise<QueueSendResult>;
|
|
16
|
-
sendBatch: (messages: Array<{ payload: T; delaySeconds?: number }>) => Promise<QueueBatchSendResult>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function initializeQueue<T = unknown>(queueName: string, serviceUrl: string): Queue<T> {
|
|
20
|
-
return {
|
|
21
|
-
async send(payload: T, options?: { delaySeconds?: number }): Promise<QueueSendResult> {
|
|
22
|
-
const response = await fetch(serviceUrl + "/queue/send", {
|
|
23
|
-
method: "POST",
|
|
24
|
-
headers: { "Content-Type": "application/json" },
|
|
25
|
-
body: JSON.stringify({
|
|
26
|
-
queueName,
|
|
27
|
-
payload,
|
|
28
|
-
delaySeconds: options?.delaySeconds,
|
|
29
|
-
}),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
if (!response.ok) {
|
|
33
|
-
const errorText = await response.text();
|
|
34
|
-
return { success: false, error: "Queue send failed: " + errorText };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return await response.json();
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
async sendBatch(messages: Array<{ payload: T; delaySeconds?: number }>): Promise<QueueBatchSendResult> {
|
|
41
|
-
const response = await fetch(serviceUrl + "/queue/batch-send", {
|
|
42
|
-
method: "POST",
|
|
43
|
-
headers: { "Content-Type": "application/json" },
|
|
44
|
-
body: JSON.stringify({
|
|
45
|
-
queueName,
|
|
46
|
-
messages,
|
|
47
|
-
}),
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
if (!response.ok) {
|
|
51
|
-
const errorText = await response.text();
|
|
52
|
-
return { success: false, error: "Queue batch send failed: " + errorText };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return await response.json();
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
`;
|
|
1
|
+
export { QUEUE_RUNTIME_CODE } from "@meetploy/shared";
|
|
60
2
|
//# sourceMappingURL=queue-runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue-runtime.js","sourceRoot":"","sources":["../../src/runtime/queue-runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"queue-runtime.js","sourceRoot":"","sources":["../../src/runtime/queue-runtime.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const STATE_RUNTIME_CODE = "\ninterface StateUpdateDoc {\n $set?: Record<string, unknown>;\n $unset?: Record<string, unknown>;\n $inc?: Record<string, number>;\n $push?: Record<string, unknown>;\n $pop?: Record<string, 1 | -1>;\n}\n\ninterface KVNamespaceListOptions {\n prefix?: string;\n limit?: number;\n cursor?: string;\n}\n\ninterface KVNamespacePutOptions {\n expiration?: number;\n expirationTtl?: number;\n metadata?: unknown;\n}\n\ninterface KVNamespaceGetMethodOptions {\n type?: \"text\" | \"json\" | \"arrayBuffer\" | \"stream\";\n cacheTtl?: number;\n}\n\ninterface StateBinding {\n get(key: string, type?: \"text\" | KVNamespaceGetMethodOptions): Promise<string | null>;\n get<T = unknown>(key: string, type: \"json\" | (KVNamespaceGetMethodOptions & { type: \"json\" })): Promise<T | null>;\n get(key: string, type: \"arrayBuffer\" | (KVNamespaceGetMethodOptions & { type: \"arrayBuffer\" })): Promise<ArrayBuffer | null>;\n get(key: string, type: \"stream\" | (KVNamespaceGetMethodOptions & { type: \"stream\" })): Promise<ReadableStream | null>;\n get(keys: string[], type?: \"text\" | KVNamespaceGetMethodOptions): Promise<Map<string, string | null>>;\n get<T = unknown>(keys: string[], type: \"json\" | (KVNamespaceGetMethodOptions & { type: \"json\" })): Promise<Map<string, T | null>>;\n get(keys: string[], type: \"arrayBuffer\" | (KVNamespaceGetMethodOptions & { type: \"arrayBuffer\" })): Promise<Map<string, ArrayBuffer | null>>;\n get(keys: string[], type: \"stream\" | (KVNamespaceGetMethodOptions & { type: \"stream\" })): Promise<Map<string, ReadableStream | null>>;\n getWithMetadata(key: string, type?: \"text\" | KVNamespaceGetMethodOptions): Promise<{ value: string | null; metadata: unknown | null }>;\n getWithMetadata<T = unknown>(key: string, type: \"json\" | (KVNamespaceGetMethodOptions & { type: \"json\" })): Promise<{ value: T | null; metadata: unknown | null }>;\n getWithMetadata(key: string, type: \"arrayBuffer\" | (KVNamespaceGetMethodOptions & { type: \"arrayBuffer\" })): Promise<{ value: ArrayBuffer | null; metadata: unknown | null }>;\n getWithMetadata(key: string, type: \"stream\" | (KVNamespaceGetMethodOptions & { type: \"stream\" })): Promise<{ value: ReadableStream | null; metadata: unknown | null }>;\n put: (key: string, value: string | ArrayBuffer | ArrayBufferView | ReadableStream, options?: KVNamespacePutOptions) => Promise<void>;\n set: (key: string, value: string) => Promise<void>;\n delete: (key: string) => Promise<void>;\n list: (options?: KVNamespaceListOptions) => Promise<{ keys: Array<{ name: string; expiration?: number; metadata?: unknown }>; list_complete: boolean; cursor?: string }>;\n update: (key: string, update: StateUpdateDoc) => Promise<void>;\n}\n\ninterface EncodedStateValue {\n value: string;\n encoding: \"text\" | \"base64\";\n}\n\nfunction getErrorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\nfunction createStateRequestError(action: string, endpoint: string, error: unknown): Error {\n const message = \"State \" + action + \" failed while calling \" + endpoint + \": \" + getErrorMessage(error);\n if (error instanceof Error) {\n return new Error(message, { cause: error });\n }\n return new Error(message);\n}\n\nasync function requestState(action: string, serviceUrl: string, payload: Record<string, unknown>): Promise<Response> {\n const endpoint = serviceUrl + \"/state/\" + action;\n let response: Response;\n\n try {\n response = await fetch(endpoint, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(payload),\n });\n } catch (error) {\n throw createStateRequestError(action, endpoint, error);\n }\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\n \"State \" + action + \" failed (status \" + response.status + \" \" + response.statusText + \") from \" + endpoint + \": \" + (errorText || \"empty response body\"),\n );\n }\n\n return response;\n}\n\nfunction createStreamFromArrayBuffer(buffer: ArrayBuffer): ReadableStream {\n return new ReadableStream({\n start(controller) {\n controller.enqueue(new Uint8Array(buffer));\n controller.close();\n },\n });\n}\n\nfunction base64Encode(bytes: Uint8Array): string {\n let binary = \"\";\n for (let index = 0; index < bytes.length; index += 0x8000) {\n binary += String.fromCharCode(...bytes.subarray(index, index + 0x8000));\n }\n return btoa(binary);\n}\n\nfunction base64Decode(value: string): Uint8Array {\n const binary = atob(value);\n const bytes = new Uint8Array(binary.length);\n for (let index = 0; index < binary.length; index++) {\n bytes[index] = binary.charCodeAt(index);\n }\n return bytes;\n}\n\nasync function encodeStateValue(value: string | ArrayBuffer | ArrayBufferView | ReadableStream): Promise<EncodedStateValue> {\n if (typeof value === \"string\") {\n return { value, encoding: \"text\" };\n }\n\n if (value instanceof ArrayBuffer) {\n return { value: base64Encode(new Uint8Array(value)), encoding: \"base64\" };\n }\n\n if (ArrayBuffer.isView(value)) {\n return {\n value: base64Encode(new Uint8Array(value.buffer, value.byteOffset, value.byteLength)),\n encoding: \"base64\",\n };\n }\n\n const reader = value.getReader();\n const chunks: Uint8Array[] = [];\n let totalLength = 0;\n\n while (true) {\n const result = await reader.read();\n if (result.done) {\n break;\n }\n\n const chunk = result.value instanceof Uint8Array ? result.value : new Uint8Array(result.value);\n chunks.push(chunk);\n totalLength += chunk.byteLength;\n }\n\n const merged = new Uint8Array(totalLength);\n let offset = 0;\n for (const chunk of chunks) {\n merged.set(chunk, offset);\n offset += chunk.byteLength;\n }\n\n return { value: base64Encode(merged), encoding: \"base64\" };\n}\n\nfunction decodeStateValue(\n storedValue: string | null,\n encoding: string,\n type: \"text\" | \"json\" | \"arrayBuffer\" | \"stream\"\n): unknown | null {\n if (storedValue === null) {\n return null;\n }\n\n const bytes = encoding === \"base64\" ? base64Decode(storedValue) : new TextEncoder().encode(storedValue);\n\n if (type === \"arrayBuffer\") {\n return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);\n }\n\n if (type === \"stream\") {\n return createStreamFromArrayBuffer(bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength));\n }\n\n const text = encoding === \"base64\" ? new TextDecoder().decode(bytes) : storedValue;\n if (type === \"json\") {\n return JSON.parse(text);\n }\n\n return text;\n}\n\nfunction resolveExpiration(options?: KVNamespacePutOptions): number | null {\n if (!options) {\n return null;\n }\n\n if (options.expiration !== undefined && options.expirationTtl !== undefined) {\n throw new Error(\"KV put failed: specify either expiration or expirationTtl, not both\");\n }\n\n if (options.expiration !== undefined) {\n return options.expiration;\n }\n\n if (options.expirationTtl !== undefined) {\n return Math.floor(Date.now() / 1000) + options.expirationTtl;\n }\n\n return null;\n}\n\nfunction resolveGetType(options?: \"text\" | \"json\" | \"arrayBuffer\" | \"stream\" | KVNamespaceGetMethodOptions): \"text\" | \"json\" | \"arrayBuffer\" | \"stream\" {\n if (!options) {\n return \"text\";\n }\n\n if (typeof options === \"string\") {\n return options;\n }\n\n return options.type ?? \"text\";\n}\n\nexport function initializeState(stateName: string, serviceUrl: string): StateBinding {\n return {\n async get(keyOrKeys: string | string[], options?: \"text\" | \"json\" | \"arrayBuffer\" | \"stream\" | KVNamespaceGetMethodOptions): Promise<unknown> {\n const type = resolveGetType(options);\n if (Array.isArray(keyOrKeys)) {\n const entries = await Promise.all(\n keyOrKeys.map(async (key) => {\n const value = await this.get(key, type);\n return [key, value] as const;\n }),\n );\n return new Map(entries);\n }\n\n const response = await requestState(\"get\", serviceUrl, { stateName, key: keyOrKeys });\n const result = await response.json();\n return decodeStateValue(result.value ?? null, result.encoding ?? \"text\", type);\n },\n\n async getWithMetadata(key: string, options?: \"text\" | \"json\" | \"arrayBuffer\" | \"stream\" | KVNamespaceGetMethodOptions): Promise<{ value: unknown | null; metadata: unknown | null }> {\n const type = resolveGetType(options);\n const response = await requestState(\"get-with-metadata\", serviceUrl, { stateName, key });\n const result = await response.json();\n return {\n value: decodeStateValue(result.value ?? null, result.encoding ?? \"text\", type),\n metadata: result.metadata ?? null,\n };\n },\n\n async put(key: string, value: string | ArrayBuffer | ArrayBufferView | ReadableStream, options?: KVNamespacePutOptions): Promise<void> {\n const encoded = await encodeStateValue(value);\n await requestState(\"set\", serviceUrl, {\n stateName,\n key,\n value: encoded.value,\n encoding: encoded.encoding,\n metadata: options?.metadata ?? null,\n expiration: resolveExpiration(options),\n });\n },\n\n async set(key: string, value: string): Promise<void> {\n await this.put(key, value);\n },\n\n async delete(key: string): Promise<void> {\n await requestState(\"delete\", serviceUrl, { stateName, key });\n },\n\n async list(options?: KVNamespaceListOptions): Promise<{ keys: Array<{ name: string; expiration?: number; metadata?: unknown }>; list_complete: boolean; cursor?: string }> {\n const response = await requestState(\"list\", serviceUrl, {\n stateName,\n prefix: options?.prefix,\n limit: options?.limit,\n cursor: options?.cursor,\n });\n const result = await response.json();\n return {\n keys: result.keys,\n list_complete: result.list_complete,\n cursor: result.cursor || undefined,\n };\n },\n\n async update(key: string, update: StateUpdateDoc): Promise<void> {\n await requestState(\"update\", serviceUrl, { stateName, key, update });\n },\n };\n}\n";
|
|
1
|
+
export { STATE_RUNTIME_CODE } from "@meetploy/shared";
|
|
@@ -1,284 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
interface StateUpdateDoc {
|
|
3
|
-
$set?: Record<string, unknown>;
|
|
4
|
-
$unset?: Record<string, unknown>;
|
|
5
|
-
$inc?: Record<string, number>;
|
|
6
|
-
$push?: Record<string, unknown>;
|
|
7
|
-
$pop?: Record<string, 1 | -1>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface KVNamespaceListOptions {
|
|
11
|
-
prefix?: string;
|
|
12
|
-
limit?: number;
|
|
13
|
-
cursor?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface KVNamespacePutOptions {
|
|
17
|
-
expiration?: number;
|
|
18
|
-
expirationTtl?: number;
|
|
19
|
-
metadata?: unknown;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface KVNamespaceGetMethodOptions {
|
|
23
|
-
type?: "text" | "json" | "arrayBuffer" | "stream";
|
|
24
|
-
cacheTtl?: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface StateBinding {
|
|
28
|
-
get(key: string, type?: "text" | KVNamespaceGetMethodOptions): Promise<string | null>;
|
|
29
|
-
get<T = unknown>(key: string, type: "json" | (KVNamespaceGetMethodOptions & { type: "json" })): Promise<T | null>;
|
|
30
|
-
get(key: string, type: "arrayBuffer" | (KVNamespaceGetMethodOptions & { type: "arrayBuffer" })): Promise<ArrayBuffer | null>;
|
|
31
|
-
get(key: string, type: "stream" | (KVNamespaceGetMethodOptions & { type: "stream" })): Promise<ReadableStream | null>;
|
|
32
|
-
get(keys: string[], type?: "text" | KVNamespaceGetMethodOptions): Promise<Map<string, string | null>>;
|
|
33
|
-
get<T = unknown>(keys: string[], type: "json" | (KVNamespaceGetMethodOptions & { type: "json" })): Promise<Map<string, T | null>>;
|
|
34
|
-
get(keys: string[], type: "arrayBuffer" | (KVNamespaceGetMethodOptions & { type: "arrayBuffer" })): Promise<Map<string, ArrayBuffer | null>>;
|
|
35
|
-
get(keys: string[], type: "stream" | (KVNamespaceGetMethodOptions & { type: "stream" })): Promise<Map<string, ReadableStream | null>>;
|
|
36
|
-
getWithMetadata(key: string, type?: "text" | KVNamespaceGetMethodOptions): Promise<{ value: string | null; metadata: unknown | null }>;
|
|
37
|
-
getWithMetadata<T = unknown>(key: string, type: "json" | (KVNamespaceGetMethodOptions & { type: "json" })): Promise<{ value: T | null; metadata: unknown | null }>;
|
|
38
|
-
getWithMetadata(key: string, type: "arrayBuffer" | (KVNamespaceGetMethodOptions & { type: "arrayBuffer" })): Promise<{ value: ArrayBuffer | null; metadata: unknown | null }>;
|
|
39
|
-
getWithMetadata(key: string, type: "stream" | (KVNamespaceGetMethodOptions & { type: "stream" })): Promise<{ value: ReadableStream | null; metadata: unknown | null }>;
|
|
40
|
-
put: (key: string, value: string | ArrayBuffer | ArrayBufferView | ReadableStream, options?: KVNamespacePutOptions) => Promise<void>;
|
|
41
|
-
set: (key: string, value: string) => Promise<void>;
|
|
42
|
-
delete: (key: string) => Promise<void>;
|
|
43
|
-
list: (options?: KVNamespaceListOptions) => Promise<{ keys: Array<{ name: string; expiration?: number; metadata?: unknown }>; list_complete: boolean; cursor?: string }>;
|
|
44
|
-
update: (key: string, update: StateUpdateDoc) => Promise<void>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface EncodedStateValue {
|
|
48
|
-
value: string;
|
|
49
|
-
encoding: "text" | "base64";
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function getErrorMessage(error: unknown): string {
|
|
53
|
-
return error instanceof Error ? error.message : String(error);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function createStateRequestError(action: string, endpoint: string, error: unknown): Error {
|
|
57
|
-
const message = "State " + action + " failed while calling " + endpoint + ": " + getErrorMessage(error);
|
|
58
|
-
if (error instanceof Error) {
|
|
59
|
-
return new Error(message, { cause: error });
|
|
60
|
-
}
|
|
61
|
-
return new Error(message);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function requestState(action: string, serviceUrl: string, payload: Record<string, unknown>): Promise<Response> {
|
|
65
|
-
const endpoint = serviceUrl + "/state/" + action;
|
|
66
|
-
let response: Response;
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
response = await fetch(endpoint, {
|
|
70
|
-
method: "POST",
|
|
71
|
-
headers: { "Content-Type": "application/json" },
|
|
72
|
-
body: JSON.stringify(payload),
|
|
73
|
-
});
|
|
74
|
-
} catch (error) {
|
|
75
|
-
throw createStateRequestError(action, endpoint, error);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (!response.ok) {
|
|
79
|
-
const errorText = await response.text();
|
|
80
|
-
throw new Error(
|
|
81
|
-
"State " + action + " failed (status " + response.status + " " + response.statusText + ") from " + endpoint + ": " + (errorText || "empty response body"),
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return response;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function createStreamFromArrayBuffer(buffer: ArrayBuffer): ReadableStream {
|
|
89
|
-
return new ReadableStream({
|
|
90
|
-
start(controller) {
|
|
91
|
-
controller.enqueue(new Uint8Array(buffer));
|
|
92
|
-
controller.close();
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function base64Encode(bytes: Uint8Array): string {
|
|
98
|
-
let binary = "";
|
|
99
|
-
for (let index = 0; index < bytes.length; index += 0x8000) {
|
|
100
|
-
binary += String.fromCharCode(...bytes.subarray(index, index + 0x8000));
|
|
101
|
-
}
|
|
102
|
-
return btoa(binary);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function base64Decode(value: string): Uint8Array {
|
|
106
|
-
const binary = atob(value);
|
|
107
|
-
const bytes = new Uint8Array(binary.length);
|
|
108
|
-
for (let index = 0; index < binary.length; index++) {
|
|
109
|
-
bytes[index] = binary.charCodeAt(index);
|
|
110
|
-
}
|
|
111
|
-
return bytes;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async function encodeStateValue(value: string | ArrayBuffer | ArrayBufferView | ReadableStream): Promise<EncodedStateValue> {
|
|
115
|
-
if (typeof value === "string") {
|
|
116
|
-
return { value, encoding: "text" };
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (value instanceof ArrayBuffer) {
|
|
120
|
-
return { value: base64Encode(new Uint8Array(value)), encoding: "base64" };
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (ArrayBuffer.isView(value)) {
|
|
124
|
-
return {
|
|
125
|
-
value: base64Encode(new Uint8Array(value.buffer, value.byteOffset, value.byteLength)),
|
|
126
|
-
encoding: "base64",
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const reader = value.getReader();
|
|
131
|
-
const chunks: Uint8Array[] = [];
|
|
132
|
-
let totalLength = 0;
|
|
133
|
-
|
|
134
|
-
while (true) {
|
|
135
|
-
const result = await reader.read();
|
|
136
|
-
if (result.done) {
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const chunk = result.value instanceof Uint8Array ? result.value : new Uint8Array(result.value);
|
|
141
|
-
chunks.push(chunk);
|
|
142
|
-
totalLength += chunk.byteLength;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const merged = new Uint8Array(totalLength);
|
|
146
|
-
let offset = 0;
|
|
147
|
-
for (const chunk of chunks) {
|
|
148
|
-
merged.set(chunk, offset);
|
|
149
|
-
offset += chunk.byteLength;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return { value: base64Encode(merged), encoding: "base64" };
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function decodeStateValue(
|
|
156
|
-
storedValue: string | null,
|
|
157
|
-
encoding: string,
|
|
158
|
-
type: "text" | "json" | "arrayBuffer" | "stream"
|
|
159
|
-
): unknown | null {
|
|
160
|
-
if (storedValue === null) {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const bytes = encoding === "base64" ? base64Decode(storedValue) : new TextEncoder().encode(storedValue);
|
|
165
|
-
|
|
166
|
-
if (type === "arrayBuffer") {
|
|
167
|
-
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (type === "stream") {
|
|
171
|
-
return createStreamFromArrayBuffer(bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength));
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const text = encoding === "base64" ? new TextDecoder().decode(bytes) : storedValue;
|
|
175
|
-
if (type === "json") {
|
|
176
|
-
return JSON.parse(text);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return text;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function resolveExpiration(options?: KVNamespacePutOptions): number | null {
|
|
183
|
-
if (!options) {
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (options.expiration !== undefined && options.expirationTtl !== undefined) {
|
|
188
|
-
throw new Error("KV put failed: specify either expiration or expirationTtl, not both");
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (options.expiration !== undefined) {
|
|
192
|
-
return options.expiration;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (options.expirationTtl !== undefined) {
|
|
196
|
-
return Math.floor(Date.now() / 1000) + options.expirationTtl;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function resolveGetType(options?: "text" | "json" | "arrayBuffer" | "stream" | KVNamespaceGetMethodOptions): "text" | "json" | "arrayBuffer" | "stream" {
|
|
203
|
-
if (!options) {
|
|
204
|
-
return "text";
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (typeof options === "string") {
|
|
208
|
-
return options;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return options.type ?? "text";
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export function initializeState(stateName: string, serviceUrl: string): StateBinding {
|
|
215
|
-
return {
|
|
216
|
-
async get(keyOrKeys: string | string[], options?: "text" | "json" | "arrayBuffer" | "stream" | KVNamespaceGetMethodOptions): Promise<unknown> {
|
|
217
|
-
const type = resolveGetType(options);
|
|
218
|
-
if (Array.isArray(keyOrKeys)) {
|
|
219
|
-
const entries = await Promise.all(
|
|
220
|
-
keyOrKeys.map(async (key) => {
|
|
221
|
-
const value = await this.get(key, type);
|
|
222
|
-
return [key, value] as const;
|
|
223
|
-
}),
|
|
224
|
-
);
|
|
225
|
-
return new Map(entries);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const response = await requestState("get", serviceUrl, { stateName, key: keyOrKeys });
|
|
229
|
-
const result = await response.json();
|
|
230
|
-
return decodeStateValue(result.value ?? null, result.encoding ?? "text", type);
|
|
231
|
-
},
|
|
232
|
-
|
|
233
|
-
async getWithMetadata(key: string, options?: "text" | "json" | "arrayBuffer" | "stream" | KVNamespaceGetMethodOptions): Promise<{ value: unknown | null; metadata: unknown | null }> {
|
|
234
|
-
const type = resolveGetType(options);
|
|
235
|
-
const response = await requestState("get-with-metadata", serviceUrl, { stateName, key });
|
|
236
|
-
const result = await response.json();
|
|
237
|
-
return {
|
|
238
|
-
value: decodeStateValue(result.value ?? null, result.encoding ?? "text", type),
|
|
239
|
-
metadata: result.metadata ?? null,
|
|
240
|
-
};
|
|
241
|
-
},
|
|
242
|
-
|
|
243
|
-
async put(key: string, value: string | ArrayBuffer | ArrayBufferView | ReadableStream, options?: KVNamespacePutOptions): Promise<void> {
|
|
244
|
-
const encoded = await encodeStateValue(value);
|
|
245
|
-
await requestState("set", serviceUrl, {
|
|
246
|
-
stateName,
|
|
247
|
-
key,
|
|
248
|
-
value: encoded.value,
|
|
249
|
-
encoding: encoded.encoding,
|
|
250
|
-
metadata: options?.metadata ?? null,
|
|
251
|
-
expiration: resolveExpiration(options),
|
|
252
|
-
});
|
|
253
|
-
},
|
|
254
|
-
|
|
255
|
-
async set(key: string, value: string): Promise<void> {
|
|
256
|
-
await this.put(key, value);
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
async delete(key: string): Promise<void> {
|
|
260
|
-
await requestState("delete", serviceUrl, { stateName, key });
|
|
261
|
-
},
|
|
262
|
-
|
|
263
|
-
async list(options?: KVNamespaceListOptions): Promise<{ keys: Array<{ name: string; expiration?: number; metadata?: unknown }>; list_complete: boolean; cursor?: string }> {
|
|
264
|
-
const response = await requestState("list", serviceUrl, {
|
|
265
|
-
stateName,
|
|
266
|
-
prefix: options?.prefix,
|
|
267
|
-
limit: options?.limit,
|
|
268
|
-
cursor: options?.cursor,
|
|
269
|
-
});
|
|
270
|
-
const result = await response.json();
|
|
271
|
-
return {
|
|
272
|
-
keys: result.keys,
|
|
273
|
-
list_complete: result.list_complete,
|
|
274
|
-
cursor: result.cursor || undefined,
|
|
275
|
-
};
|
|
276
|
-
},
|
|
277
|
-
|
|
278
|
-
async update(key: string, update: StateUpdateDoc): Promise<void> {
|
|
279
|
-
await requestState("update", serviceUrl, { stateName, key, update });
|
|
280
|
-
},
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
`;
|
|
1
|
+
export { STATE_RUNTIME_CODE } from "@meetploy/shared";
|
|
284
2
|
//# sourceMappingURL=state-runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-runtime.js","sourceRoot":"","sources":["../../src/runtime/state-runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"state-runtime.js","sourceRoot":"","sources":["../../src/runtime/state-runtime.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { TIMER_RUNTIME_CODE } from "@meetploy/shared";
|
|
@@ -1,60 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export function initializeTimer(timerName, serviceUrl) {
|
|
3
|
-
function parseOptions(options) {
|
|
4
|
-
if (options === undefined || options === null) {
|
|
5
|
-
return { payload: undefined, intervalMs: undefined };
|
|
6
|
-
}
|
|
7
|
-
if (typeof options === "object" && options !== null && ("payload" in options || "intervalMs" in options)) {
|
|
8
|
-
return { payload: options.payload, intervalMs: options.intervalMs };
|
|
9
|
-
}
|
|
10
|
-
return { payload: options, intervalMs: undefined };
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return {
|
|
14
|
-
async set(id, scheduledTime, options) {
|
|
15
|
-
const ts = typeof scheduledTime === "number" ? scheduledTime : scheduledTime.getTime();
|
|
16
|
-
const { payload, intervalMs } = parseOptions(options);
|
|
17
|
-
const response = await fetch(serviceUrl + "/timer/set", {
|
|
18
|
-
method: "POST",
|
|
19
|
-
headers: { "Content-Type": "application/json" },
|
|
20
|
-
body: JSON.stringify({ timerName, id, scheduledTime: ts, payload, intervalMs }),
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
if (!response.ok) {
|
|
24
|
-
const errorText = await response.text();
|
|
25
|
-
throw new Error("Timer set failed: " + errorText);
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
async get(id) {
|
|
30
|
-
const response = await fetch(serviceUrl + "/timer/get", {
|
|
31
|
-
method: "POST",
|
|
32
|
-
headers: { "Content-Type": "application/json" },
|
|
33
|
-
body: JSON.stringify({ timerName, id }),
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
if (!response.ok) {
|
|
37
|
-
const errorText = await response.text();
|
|
38
|
-
throw new Error("Timer get failed: " + errorText);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const result = await response.json();
|
|
42
|
-
return result.timer ?? null;
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
async delete(id) {
|
|
46
|
-
const response = await fetch(serviceUrl + "/timer/delete", {
|
|
47
|
-
method: "POST",
|
|
48
|
-
headers: { "Content-Type": "application/json" },
|
|
49
|
-
body: JSON.stringify({ timerName, id }),
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
if (!response.ok) {
|
|
53
|
-
const errorText = await response.text();
|
|
54
|
-
throw new Error("Timer delete failed: " + errorText);
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
`;
|
|
1
|
+
export { TIMER_RUNTIME_CODE } from "@meetploy/shared";
|
|
60
2
|
//# sourceMappingURL=timer-runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timer-runtime.js","sourceRoot":"","sources":["../../src/runtime/timer-runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"timer-runtime.js","sourceRoot":"","sources":["../../src/runtime/timer-runtime.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { WORKFLOW_RUNTIME_CODE } from "@meetploy/shared";
|