@telorun/starlark 0.1.6 → 0.1.8
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/CHANGELOG.md +7 -0
- package/LICENSE +17 -0
- package/dist/script.d.ts +2 -2
- package/dist/script.js +7 -10
- package/package.json +7 -7
- package/src/script.ts +10 -13
package/CHANGELOG.md
CHANGED
package/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# SUSTAINABLE USE LICENSE (Fair-code)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DiglyAI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, and distribute the Software for any purpose—including commercial purposes—subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
1. ANTI-COMPETITION RESTRICTION: The Software may not be provided to third parties as a managed service, commercial SaaS (Software-as-a-Service), PaaS (Platform-as-a-Service), BaaS (Backend-as-a-Service), or similar offering where the primary value provided to the user is the functionality of the Software itself, without a separate commercial license from the copyright holder.
|
|
8
|
+
|
|
9
|
+
2. PERMITTED COMMERCIAL USE: You are free to use the Software to build, host, and monetize your own commercial applications, products, and services, provided such use does not violate Clause 1.
|
|
10
|
+
|
|
11
|
+
3. ATTRIBUTION: This copyright notice and license must be included in all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
4. CONTRIBUTIONS: Contributions to the Software are welcome and encouraged. By contributing, you agree that your contributions may be incorporated into the Software and distributed under this license.
|
|
14
|
+
|
|
15
|
+
5. DISCLAIMER: The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.
|
|
16
|
+
|
|
17
|
+
For commercial licensing, managed hosting exemptions, or enterprise inquiries, please contact DiglyAI.
|
package/dist/script.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ declare global {
|
|
|
4
4
|
}
|
|
5
5
|
type StarlarkScriptResource = RuntimeResource & {
|
|
6
6
|
code?: string;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
inputType?: string | Record<string, any>;
|
|
8
|
+
outputType?: string | Record<string, any>;
|
|
9
9
|
};
|
|
10
10
|
export declare function register(ctx: ControllerContext): Promise<void>;
|
|
11
11
|
export declare function create(resource: StarlarkScriptResource, ctx: ResourceContext): Promise<ResourceInstance>;
|
package/dist/script.js
CHANGED
|
@@ -17,21 +17,20 @@ export async function register(ctx) {
|
|
|
17
17
|
class StarlarkScript {
|
|
18
18
|
ctx;
|
|
19
19
|
manifest;
|
|
20
|
-
name;
|
|
21
20
|
code;
|
|
21
|
+
inputValidator;
|
|
22
|
+
outputValidator;
|
|
22
23
|
constructor(ctx, manifest) {
|
|
23
24
|
this.ctx = ctx;
|
|
24
25
|
this.manifest = manifest;
|
|
25
|
-
this.name = manifest.metadata.name;
|
|
26
26
|
this.code = manifest.code || "";
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// Starlark code is compiled on-demand during execution
|
|
27
|
+
this.inputValidator = ctx.createTypeValidator(manifest.inputType);
|
|
28
|
+
this.outputValidator = ctx.createTypeValidator(manifest.outputType);
|
|
30
29
|
}
|
|
31
30
|
async invoke(input) {
|
|
32
|
-
this.
|
|
31
|
+
this.inputValidator.validate(input);
|
|
33
32
|
const result = await executeStarlark(this.code, input);
|
|
34
|
-
this.
|
|
33
|
+
this.outputValidator.validate(result);
|
|
35
34
|
return result;
|
|
36
35
|
}
|
|
37
36
|
}
|
|
@@ -40,9 +39,7 @@ export async function create(resource, ctx) {
|
|
|
40
39
|
if (!resource.code) {
|
|
41
40
|
throw new Error(`StarlarkScript "${name}" is missing code`);
|
|
42
41
|
}
|
|
43
|
-
|
|
44
|
-
await instance.init();
|
|
45
|
-
return instance;
|
|
42
|
+
return new StarlarkScript(ctx, resource);
|
|
46
43
|
}
|
|
47
44
|
async function executeStarlark(code, input) {
|
|
48
45
|
try {
|
package/package.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telorun/starlark",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"build": "tsc -p tsconfig.lib.json"
|
|
7
|
-
},
|
|
8
5
|
"exports": {
|
|
9
6
|
"./script": {
|
|
10
7
|
"bun": "./src/script.ts",
|
|
@@ -13,12 +10,15 @@
|
|
|
13
10
|
}
|
|
14
11
|
},
|
|
15
12
|
"dependencies": {
|
|
16
|
-
"@telorun/sdk": "workspace:*",
|
|
17
13
|
"ajv": "^8.17.1",
|
|
18
|
-
"starlark-webasm": "^1.0.3"
|
|
14
|
+
"starlark-webasm": "^1.0.3",
|
|
15
|
+
"@telorun/sdk": "0.2.7"
|
|
19
16
|
},
|
|
20
17
|
"devDependencies": {
|
|
21
18
|
"@types/node": "^20.0.0",
|
|
22
19
|
"typescript": "^5.0.0"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc -p tsconfig.lib.json"
|
|
23
23
|
}
|
|
24
|
-
}
|
|
24
|
+
}
|
package/src/script.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ControllerContext,
|
|
3
|
+
DataValidator,
|
|
3
4
|
ResourceContext,
|
|
4
5
|
ResourceInstance,
|
|
5
6
|
ResourceManifest,
|
|
@@ -13,8 +14,8 @@ declare global {
|
|
|
13
14
|
|
|
14
15
|
type StarlarkScriptResource = RuntimeResource & {
|
|
15
16
|
code?: string;
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
inputType?: string | Record<string, any>;
|
|
18
|
+
outputType?: string | Record<string, any>;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
let initialized = false;
|
|
@@ -33,25 +34,23 @@ export async function register(ctx: ControllerContext): Promise<void> {
|
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
class StarlarkScript implements ResourceInstance {
|
|
36
|
-
private name: string;
|
|
37
37
|
private code: string;
|
|
38
|
+
private inputValidator: DataValidator;
|
|
39
|
+
private outputValidator: DataValidator;
|
|
38
40
|
|
|
39
41
|
constructor(
|
|
40
42
|
readonly ctx: ResourceContext,
|
|
41
43
|
readonly manifest: ResourceManifest,
|
|
42
44
|
) {
|
|
43
|
-
this.name = manifest.metadata.name;
|
|
44
45
|
this.code = manifest.code || "";
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
async init(): Promise<void> {
|
|
48
|
-
// Starlark code is compiled on-demand during execution
|
|
46
|
+
this.inputValidator = ctx.createTypeValidator(manifest.inputType);
|
|
47
|
+
this.outputValidator = ctx.createTypeValidator(manifest.outputType);
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
async invoke(input: Record<string, any>): Promise<any> {
|
|
52
|
-
this.
|
|
51
|
+
this.inputValidator.validate(input);
|
|
53
52
|
const result = await executeStarlark(this.code, input);
|
|
54
|
-
this.
|
|
53
|
+
this.outputValidator.validate(result);
|
|
55
54
|
return result;
|
|
56
55
|
}
|
|
57
56
|
}
|
|
@@ -65,9 +64,7 @@ export async function create(
|
|
|
65
64
|
throw new Error(`StarlarkScript "${name}" is missing code`);
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
await instance.init();
|
|
70
|
-
return instance;
|
|
67
|
+
return new StarlarkScript(ctx, resource);
|
|
71
68
|
}
|
|
72
69
|
|
|
73
70
|
async function executeStarlark(code: string, input: any): Promise<any> {
|