Skip to content

Commit 93f722d

Browse files
committed
wip
1 parent cfa1dec commit 93f722d

File tree

4 files changed

+59
-20
lines changed

4 files changed

+59
-20
lines changed

examples/package.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env -S npx ts-node --transpileOnly
22

3-
import { Substrate, Box, Package, sb } from "substrate";
3+
import { Substrate, Box, Module, sb } from "substrate";
44

55
async function main() {
66
const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"];
@@ -17,38 +17,44 @@ async function main() {
1717
const y = sb.input({ type: "string" });
1818
const z = sb.input({ type: "object", properties: {} });
1919

20-
const a = new Box({ value: { a: x, z: z, liam: [x, x, x] } }, { id: "BoxA" });
20+
const a = new Box({ value: { a: x, z: z, liam: [x, x, x] } }, { id: "A" });
2121
const b = new Box(
2222
{ value: { b: sb.interpolate`x=${a.future.value.get("a")}, y=${y}` } },
23-
{ id: "BoxB" },
23+
{ id: "B" },
2424
);
2525

26-
const packageable = substrate.createPackageable([a, b], { x, y, z });
27-
// console.log("packageable", JSON.stringify(packageable, null, 2));
28-
29-
const p = new Package(
26+
// const publication = await substrate.module.publish({
27+
// name: "my reusable graph",
28+
// nodes: [a, b],
29+
// inputs: { x, y, z },
30+
// });
31+
32+
const p = new Module(
3033
{
31-
package_json: packageable.toJSON(),
34+
json: substrate.module.serialize({
35+
nodes: [a, b],
36+
inputs: { x, y, z },
37+
}),
3238
inputs: {
39+
// when commented will use "hello" because it is defined as the default above
3340
// x: "xxx",
3441
y: "yyy",
3542
z: {
36-
// string: "hi",
37-
// obj: { a: 123 },
3843
arr: ["123"],
3944
},
4045
},
41-
}, { id: "Package" }
46+
},
47+
{ id: "Module" },
4248
);
4349

4450
const c = new Box(
4551
{
4652
value: {
47-
"1": p.future.get("BoxB.value.b"),
48-
"2": p.future.get("BoxA.value.z.arr[0]"),
53+
"1": p.future.get("A.value.z.arr[0]"),
54+
"2": p.future.get("B.value.b"),
4955
},
5056
},
51-
{ id: "BoxC" },
57+
{ id: "C" },
5258
);
5359

5460
const res = await substrate.run(p, c);

src/Package.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,35 @@ export function packager(substrate: Substrate) {
6666
};
6767
}
6868

69-
type PackageIn = {
70-
package_json: any;
71-
inputs: Record<string, any>;
72-
};
69+
type PackageIn =
70+
| {
71+
package_json: any;
72+
inputs: Record<string, any>;
73+
}
74+
| {
75+
module_json: any;
76+
inputs: Record<string, any>;
77+
}
78+
| {
79+
id: any;
80+
inputs: Record<string, any>;
81+
}
82+
| {
83+
uri: any;
84+
inputs: Record<string, any>;
85+
}
86+
| {
87+
json: any;
88+
89+
inputs: Record<string, any>;
90+
};
7391

7492
export class Package extends Node {
7593
constructor(args: PackageIn, options?: Options) {
76-
super(args, options);
94+
// @ts-ignore
95+
let myargs = { package_json: args.json || args.package_json || args.module_json, inputs: args.inputs };
96+
97+
super(myargs, options);
7798
this.node = "Package";
7899
}
79100
}

src/Substrate.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,16 @@ export class Substrate {
294294

295295
return headers;
296296
}
297+
298+
module = {
299+
serialize: ({ nodes, inputs }: { nodes: Node[], inputs: any }) => {
300+
let p = packager(this);
301+
return p(nodes, inputs).toJSON();
302+
},
303+
304+
publish: async (publishable: any) => {
305+
console.log("not implemented yet");
306+
return publishable;
307+
}
308+
}
297309
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export {
5151
DeleteVectors,
5252
} from "substrate/Nodes";
5353

54-
export { Package } from "substrate/Package";
54+
export { Package, Package as Module } from "substrate/Package";
5555

5656
export { sb } from "substrate/sb";
5757
export { Substrate };

0 commit comments

Comments
 (0)