@telorun/sdk 0.1.0 → 0.1.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
@@ -12,7 +12,8 @@
12
12
  }
13
13
  },
14
14
  "files": [
15
- "dist"
15
+ "dist/**",
16
+ "src/**"
16
17
  ],
17
18
  "devDependencies": {
18
19
  "@types/node": "^20.0.0",
@@ -0,0 +1,21 @@
1
+ import { RuntimeEvent } from './runtime-event.js';
2
+
3
+ export interface ControllerContext {
4
+ on(
5
+ event: string,
6
+ handler: (event: RuntimeEvent) => void | Promise<void>,
7
+ ): void;
8
+ once(
9
+ event: string,
10
+ handler: (event: RuntimeEvent) => void | Promise<void>,
11
+ ): void;
12
+ off(
13
+ event: string,
14
+ handler: (event: RuntimeEvent) => void | Promise<void>,
15
+ ): void;
16
+ emit(event: string, payload?: any, metadata?: Record<string, any>): void;
17
+ acquireHold(reason?: string): () => void;
18
+ requestExit(code: number): void;
19
+ evaluateCel(expression: string, context: Record<string, any>): unknown;
20
+ expandValue(value: any, context: Record<string, any>): any;
21
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from './controller-context.js';
2
+ export * from './resource-context.js';
3
+ export * from './resource-instance.js';
4
+ export * from './resource-manifest.js';
5
+ export * from './runtime-error.js';
6
+ export * from './runtime-event.js';
7
+ export * from './runtime-resource.js';
8
+
@@ -0,0 +1,34 @@
1
+ import { ControllerContext } from "./controller-context.js";
2
+ import { RuntimeResource } from "./runtime-resource.js";
3
+
4
+ export interface DataValidator {
5
+ validate(data: any): void;
6
+ isValid(data: any): boolean;
7
+ }
8
+
9
+ export class NoopValidator implements DataValidator {
10
+ isValid() {
11
+ return true;
12
+ }
13
+
14
+ validate() {
15
+ // noop
16
+ }
17
+ }
18
+
19
+ export interface ResourceContext extends ControllerContext {
20
+ acquireHold(reason?: string): () => void;
21
+ emitEvent(event: string, payload?: any): Promise<void>;
22
+ invoke(kind: string, name: string, ...args: any[]): Promise<any>;
23
+ getResources(kind: string): RuntimeResource[];
24
+ getResourcesByName(kind: string, name: string): RuntimeResource | null;
25
+ registerManifest(resource: any): void;
26
+ validateSchema(value: any, schema: any): void;
27
+ createSchemaValidator(schema: any): DataValidator;
28
+ registerController(
29
+ moduleName: string,
30
+ resourceKind: string,
31
+ controllerInstance: any,
32
+ ): Promise<void>;
33
+ registerDefinition(definition: any): void;
34
+ }
@@ -0,0 +1,15 @@
1
+ import { ResourceContext } from "./resource-context.js";
2
+
3
+ export type ResourceInstance = {
4
+ init?(ctx?: ResourceContext): Promise<void>;
5
+ run?(): void | Promise<void>;
6
+ invoke?(input: any): any | Promise<any>;
7
+ teardown?(): void | Promise<void>;
8
+
9
+ /**
10
+ * Optional method for debugging/snapshots
11
+ * Called when taking runtime state snapshots
12
+ * Should return serializable state data specific to this resource
13
+ */
14
+ snapshot?(): Record<string, any> | Promise<Record<string, any>>;
15
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Type for resource manifest defined in YAML files
3
+ */
4
+ export interface ResourceManifest {
5
+ kind: string;
6
+ metadata: {
7
+ name: string;
8
+ module: string;
9
+ [key: string]: any;
10
+ };
11
+ [key: string]: any;
12
+ }
@@ -0,0 +1,8 @@
1
+ export type RuntimeErrorCode =
2
+ | 'ERR_RESOURCE_NOT_FOUND'
3
+ | 'ERR_CONTROLLER_NOT_FOUND'
4
+ | 'ERR_CONTROLLER_INVALID'
5
+ | 'ERR_RESOURCE_NOT_INVOKABLE'
6
+ | 'ERR_DUPLICATE_RESOURCE'
7
+ | 'ERR_EXECUTION_FAILED'
8
+ | 'ERR_INVALID_VALUE';
@@ -0,0 +1,5 @@
1
+ export type RuntimeEvent = {
2
+ name: string;
3
+ payload?: any;
4
+ metadata?: Record<string, any>;
5
+ };
@@ -0,0 +1,8 @@
1
+ export interface RuntimeResource {
2
+ kind: string;
3
+ metadata: {
4
+ name: string;
5
+ module: string;
6
+ [key: string]: any;
7
+ };
8
+ }