@renderinc/sdk 0.2.1 → 0.3.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.
Files changed (62) hide show
  1. package/dist/experimental/object/api.d.ts +2 -1
  2. package/dist/experimental/object/api.d.ts.map +1 -1
  3. package/dist/experimental/object/api.js +20 -3
  4. package/dist/experimental/object/client.d.ts +3 -1
  5. package/dist/experimental/object/client.d.ts.map +1 -1
  6. package/dist/experimental/object/client.js +47 -6
  7. package/dist/experimental/object/index.d.ts +1 -1
  8. package/dist/experimental/object/index.d.ts.map +1 -1
  9. package/dist/experimental/object/types.d.ts +17 -0
  10. package/dist/experimental/object/types.d.ts.map +1 -1
  11. package/dist/generated/schema.d.ts +167 -28
  12. package/dist/generated/schema.d.ts.map +1 -1
  13. package/dist/workflows/uds.d.ts.map +1 -1
  14. package/dist/workflows/uds.js +3 -2
  15. package/package.json +4 -1
  16. package/CHANGELOG.md +0 -33
  17. package/biome.json +0 -84
  18. package/examples/client/main.ts +0 -42
  19. package/examples/client/package-lock.json +0 -601
  20. package/examples/client/package.json +0 -16
  21. package/examples/client/tsconfig.json +0 -17
  22. package/examples/task/main.ts +0 -90
  23. package/examples/task/package-lock.json +0 -584
  24. package/examples/task/package.json +0 -16
  25. package/examples/task/tsconfig.json +0 -17
  26. package/src/errors.test.ts +0 -75
  27. package/src/errors.ts +0 -73
  28. package/src/experimental/experimental.ts +0 -56
  29. package/src/experimental/index.ts +0 -24
  30. package/src/experimental/object/api.ts +0 -91
  31. package/src/experimental/object/client.test.ts +0 -138
  32. package/src/experimental/object/client.ts +0 -317
  33. package/src/experimental/object/index.ts +0 -22
  34. package/src/experimental/object/types.test.ts +0 -87
  35. package/src/experimental/object/types.ts +0 -131
  36. package/src/generated/schema.ts +0 -12937
  37. package/src/index.ts +0 -7
  38. package/src/render.ts +0 -35
  39. package/src/utils/create-api-client.ts +0 -13
  40. package/src/utils/get-base-url.test.ts +0 -58
  41. package/src/utils/get-base-url.ts +0 -16
  42. package/src/version.ts +0 -37
  43. package/src/workflows/client/client.test.ts +0 -68
  44. package/src/workflows/client/client.ts +0 -142
  45. package/src/workflows/client/create-client.ts +0 -17
  46. package/src/workflows/client/index.ts +0 -3
  47. package/src/workflows/client/sse.ts +0 -95
  48. package/src/workflows/client/types.ts +0 -56
  49. package/src/workflows/executor.ts +0 -124
  50. package/src/workflows/index.ts +0 -7
  51. package/src/workflows/registry.test.ts +0 -76
  52. package/src/workflows/registry.ts +0 -88
  53. package/src/workflows/runner.ts +0 -38
  54. package/src/workflows/schema.ts +0 -348
  55. package/src/workflows/task.ts +0 -117
  56. package/src/workflows/types.test.ts +0 -52
  57. package/src/workflows/types.ts +0 -89
  58. package/src/workflows/uds.ts +0 -139
  59. package/test-types.ts +0 -14
  60. package/tsconfig.build.json +0 -4
  61. package/tsconfig.json +0 -23
  62. package/vitest.config.ts +0 -8
@@ -1,52 +0,0 @@
1
- import type { TaskContext, TaskFunction, TaskResult } from "./types.js";
2
-
3
- describe("TaskFunction type", () => {
4
- it("accepts typed args and returns typed result", () => {
5
- expectTypeOf<TaskFunction<[string, number], boolean>>().toExtend<
6
- (a: string, b: number) => boolean | Promise<boolean>
7
- >();
8
- });
9
-
10
- it("defaults to any[] args and any result", () => {
11
- expectTypeOf<TaskFunction>().toExtend<(...args: any[]) => any>();
12
- });
13
-
14
- it("allows async return type", () => {
15
- const asyncFn: TaskFunction<[string], number> = async (s) => s.length;
16
- expectTypeOf(asyncFn).returns.toExtend<number | Promise<number>>();
17
- });
18
-
19
- it("allows sync return type", () => {
20
- const syncFn: TaskFunction<[string], number> = (s) => s.length;
21
- expectTypeOf(syncFn).returns.toExtend<number | Promise<number>>();
22
- });
23
- });
24
-
25
- describe("TaskResult type", () => {
26
- it("get() returns Promise<T>", () => {
27
- expectTypeOf<TaskResult<string>>().toHaveProperty("get");
28
- expectTypeOf<TaskResult<string>["get"]>().returns.toEqualTypeOf<Promise<string>>();
29
- });
30
-
31
- it("preserves generic parameter", () => {
32
- type NumberResult = TaskResult<number>;
33
- type StringResult = TaskResult<string>;
34
- expectTypeOf<NumberResult["get"]>().returns.toEqualTypeOf<Promise<number>>();
35
- expectTypeOf<StringResult["get"]>().returns.toEqualTypeOf<Promise<string>>();
36
- });
37
- });
38
-
39
- describe("TaskContext type", () => {
40
- it("has executeTask method", () => {
41
- expectTypeOf<TaskContext>().toHaveProperty("executeTask");
42
- });
43
-
44
- it("executeTask is callable", () => {
45
- type ExecuteTask = TaskContext["executeTask"];
46
- expectTypeOf<ExecuteTask>().toBeCallableWith(
47
- {} as TaskFunction<[string], number>,
48
- "taskName",
49
- "arg",
50
- );
51
- });
52
- });
@@ -1,89 +0,0 @@
1
- import type { components } from "./schema.js";
2
-
3
- /**
4
- * Task function signature
5
- */
6
- export type TaskFunction<TArgs extends any[] = any[], TResult = any> = (
7
- ...args: TArgs
8
- ) => TResult | Promise<TResult>;
9
-
10
- export type TaskOptions = components["schemas"]["TaskOptions"];
11
-
12
- /**
13
- * Task metadata
14
- */
15
- export interface TaskMetadata {
16
- name: string;
17
- func: TaskFunction;
18
- options?: TaskOptions;
19
- }
20
-
21
- /**
22
- * Task context for executing subtasks
23
- */
24
- export interface TaskContext {
25
- executeTask<TArgs extends any[], TResult>(
26
- task: TaskFunction<TArgs, TResult>,
27
- taskName: string,
28
- ...args: TArgs
29
- ): TaskResult<TResult>;
30
- }
31
-
32
- /**
33
- * Result of a task execution
34
- */
35
- export interface TaskResult<T> {
36
- get(): Promise<T>;
37
- }
38
-
39
- /**
40
- * Task input from the workflow system
41
- */
42
- export interface TaskInput {
43
- task_name: string;
44
- input: any[];
45
- }
46
-
47
- /**
48
- * Task callback request/response types
49
- */
50
-
51
- export type CallbackRequest = components["schemas"]["CallbackRequest"];
52
-
53
- export type GetInputResponse = components["schemas"]["InputResponse"];
54
-
55
- export type RunSubtaskRequest = components["schemas"]["RunSubtaskRequest"];
56
-
57
- export type RunSubtaskResponse = components["schemas"]["RunSubtaskResponse"];
58
-
59
- export type GetSubtaskResultRequest = components["schemas"]["SubtaskResultRequest"];
60
-
61
- export type GetSubtaskResultResponse = components["schemas"]["SubtaskResultResponse"];
62
-
63
- export type RegisterTasksRequest = components["schemas"]["Tasks"];
64
-
65
- /**
66
- * Retry configuration for task execution
67
- */
68
- export interface Retry {
69
- maxRetries: number;
70
- waitDurationMs: number;
71
- backoffScaling?: number; // default 1.5
72
- }
73
-
74
- /**
75
- * Task execution options
76
- */
77
- export interface RegisterTaskOptions {
78
- retry?: Retry;
79
- timeoutSeconds?: number;
80
- /**
81
- * Resource plan for task execution.
82
- * Common plans include:
83
- * - "starter": 0.5 CPU, 512MB memory
84
- * - "standard": 1 CPU, 2GB memory (default)
85
- * - "pro": 2 CPU, 4GB memory
86
- */
87
- plan?: string;
88
- name: string;
89
- }
@@ -1,139 +0,0 @@
1
- import http from "node:http";
2
- import { getUserAgent } from "../version.js";
3
-
4
- import type {
5
- CallbackRequest,
6
- GetInputResponse,
7
- GetSubtaskResultRequest,
8
- GetSubtaskResultResponse,
9
- RegisterTasksRequest,
10
- RunSubtaskRequest,
11
- RunSubtaskResponse,
12
- TaskMetadata,
13
- } from "./types.js";
14
-
15
- /**
16
- * Unix Domain Socket client for communicating with the workflow system
17
- */
18
- export class UDSClient {
19
- constructor(private readonly socketPath: string) {}
20
-
21
- /**
22
- * Get task input and name
23
- */
24
- async getInput(): Promise<GetInputResponse> {
25
- return this.request<GetInputResponse>("/input", "GET");
26
- }
27
-
28
- private buildCallbackBody(results?: any, error?: string): CallbackRequest {
29
- if (results !== undefined) {
30
- const resultsArray = [results];
31
- const output = Buffer.from(JSON.stringify(resultsArray)).toString("base64");
32
- return {
33
- complete: {
34
- output,
35
- },
36
- };
37
- }
38
-
39
- if (error === undefined) {
40
- throw new Error("Either results or error must be provided");
41
- }
42
-
43
- return {
44
- error: {
45
- details: error,
46
- },
47
- };
48
- }
49
-
50
- /**
51
- * Send task result or error
52
- */
53
- async sendCallback(results?: any, error?: string): Promise<void> {
54
- await this.request<void>("/callback", "POST", this.buildCallbackBody(results, error));
55
- }
56
-
57
- /**
58
- * Run a subtask
59
- */
60
- async runSubtask(taskName: string, input: any[]): Promise<string> {
61
- const inputBase64 = Buffer.from(JSON.stringify(input)).toString("base64");
62
- const body: RunSubtaskRequest = {
63
- task_name: taskName,
64
- input: inputBase64,
65
- };
66
- const response = await this.request<RunSubtaskResponse>("/run-subtask", "POST", body);
67
- return response.task_run_id;
68
- }
69
-
70
- /**
71
- * Get subtask result
72
- */
73
- async getSubtaskResult(subtaskId: string): Promise<GetSubtaskResultResponse> {
74
- const body: GetSubtaskResultRequest = {
75
- task_run_id: subtaskId,
76
- };
77
- return this.request<GetSubtaskResultResponse>("/get-subtask-result", "POST", body);
78
- }
79
-
80
- /**
81
- * Register tasks with the workflow system
82
- */
83
- async registerTasks(tasks: TaskMetadata[]): Promise<void> {
84
- const body: RegisterTasksRequest = {
85
- tasks: tasks.map((task) => ({
86
- name: task.name,
87
- options: task.options,
88
- })),
89
- };
90
- await this.request<void>("/register-tasks", "POST", body);
91
- }
92
-
93
- /**
94
- * Make a request to the Unix socket
95
- */
96
- private async request<T>(path: string, method: string, body?: any): Promise<T> {
97
- return new Promise((resolve, reject) => {
98
- const req = http.request(
99
- {
100
- socketPath: this.socketPath,
101
- path: path,
102
- method: method,
103
- headers: {
104
- "Content-Length": body ? JSON.stringify(body).length : 0,
105
- "Content-Type": "application/json",
106
- "User-Agent": getUserAgent(),
107
- },
108
- },
109
- async (res) => {
110
- const chunks: Buffer[] = [];
111
- for await (const chunk of res) chunks.push(chunk);
112
- const responseBody = Buffer.concat(chunks).toString();
113
-
114
- if (res.statusCode && res.statusCode >= 400) {
115
- reject(new Error(`HTTP ${res.statusCode}: ${responseBody}`));
116
- return;
117
- }
118
-
119
- if (responseBody.length === 0) {
120
- resolve(undefined as T);
121
- return;
122
- }
123
-
124
- try {
125
- resolve(JSON.parse(responseBody));
126
- } catch (error) {
127
- reject(error);
128
- }
129
- },
130
- );
131
- req.on("error", (error) => {
132
- reject(error);
133
- });
134
-
135
- // Write the body to the request
136
- req.end(body ? JSON.stringify(body) : "");
137
- });
138
- }
139
- }
package/test-types.ts DELETED
@@ -1,14 +0,0 @@
1
- import { Render } from "./src";
2
-
3
- export async function test() {
4
- const render = new Render({
5
- baseUrl: "https://api.localhost.render.com:8443",
6
- token: "test",
7
- });
8
-
9
- const taskRun = await render.workflows.runTask("workflow-sdk/greet", ["Ruben"]);
10
-
11
- // This should show the type
12
- const taskRunType = typeof taskRun;
13
- console.log(taskRunType);
14
- }
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "exclude": ["node_modules", "dist", "**/*.test.ts"]
4
- }
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "NodeNext",
5
- "lib": ["ES2020"],
6
- "declaration": true,
7
- "declarationMap": true,
8
- "outDir": "./dist",
9
- "rootDir": "./src",
10
- "removeComments": true,
11
- "strict": true,
12
- "esModuleInterop": true,
13
- "skipLibCheck": true,
14
- "forceConsistentCasingInFileNames": true,
15
- "moduleResolution": "NodeNext",
16
- "resolveJsonModule": true,
17
- "experimentalDecorators": true,
18
- "emitDecoratorMetadata": true,
19
- "types": ["node", "vitest/globals"]
20
- },
21
- "include": ["src/**/*"],
22
- "exclude": ["node_modules", "dist"]
23
- }
package/vitest.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
-
3
- export default defineConfig({
4
- test: {
5
- include: ["src/**/*.test.ts"],
6
- globals: true,
7
- },
8
- });