trellis 1.0.6 → 1.0.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/dist/ai/index.js +688 -0
- package/dist/cli/server.js +141 -27258
- package/dist/cli/tql.js +2889 -45710
- package/dist/graph/index.js +2248 -0
- package/dist/index.js +88 -12417
- package/dist/kernel/logic-middleware.js +179 -0
- package/dist/kernel/middleware.js +0 -0
- package/dist/kernel/operations.js +32 -0
- package/dist/kernel/schema-middleware.js +34 -0
- package/dist/kernel/security-middleware.js +53 -0
- package/dist/kernel/trellis-kernel.js +2239 -0
- package/dist/kernel/workspace.js +91 -0
- package/dist/persist/backend.js +0 -0
- package/dist/persist/sqlite-backend.js +123 -0
- package/dist/query/index.js +1643 -0
- package/dist/server/index.js +3309 -0
- package/dist/store/eav-store.js +323 -0
- package/dist/workflows/index.js +3160 -0
- package/package.json +9 -3
- package/.//out//windows-style.json +0 -602
- package/bun.lock +0 -350
- package/dist/cli/iroh.linux-x64-gnu-2y4tmrmh.node +0 -0
- package/dist/cli/iroh.linux-x64-musl-50ncx5bz.node +0 -0
- package/index.ts +0 -29
- package/run-server.sh +0 -5
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// src/kernel/workspace.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var PropertyTypeSchema = z.enum([
|
|
4
|
+
"title",
|
|
5
|
+
"rich_text",
|
|
6
|
+
"number",
|
|
7
|
+
"select",
|
|
8
|
+
"multi_select",
|
|
9
|
+
"status",
|
|
10
|
+
"date",
|
|
11
|
+
"people",
|
|
12
|
+
"files",
|
|
13
|
+
"checkbox",
|
|
14
|
+
"url",
|
|
15
|
+
"email",
|
|
16
|
+
"phone_number",
|
|
17
|
+
"relation",
|
|
18
|
+
"rollup",
|
|
19
|
+
"formula",
|
|
20
|
+
"ai_generated"
|
|
21
|
+
]);
|
|
22
|
+
var PropertyValueSpecificationSchema = z.object({
|
|
23
|
+
name: z.string(),
|
|
24
|
+
valueType: PropertyTypeSchema,
|
|
25
|
+
required: z.boolean().optional(),
|
|
26
|
+
description: z.string().optional(),
|
|
27
|
+
selectOptions: z.array(z.any()).optional(),
|
|
28
|
+
relation: z.object({
|
|
29
|
+
targetSchema: z.string().optional(),
|
|
30
|
+
cardinality: z.enum(["one", "many"]).optional(),
|
|
31
|
+
syncedProperty: z.string().optional()
|
|
32
|
+
}).optional(),
|
|
33
|
+
formula: z.string().optional(),
|
|
34
|
+
rollup: z.object({
|
|
35
|
+
relationProperty: z.string(),
|
|
36
|
+
targetProperty: z.string(),
|
|
37
|
+
aggregation: z.enum([
|
|
38
|
+
"count",
|
|
39
|
+
"sum",
|
|
40
|
+
"avg",
|
|
41
|
+
"min",
|
|
42
|
+
"max",
|
|
43
|
+
"median",
|
|
44
|
+
"mode"
|
|
45
|
+
])
|
|
46
|
+
}).optional(),
|
|
47
|
+
aiGenerated: z.object({
|
|
48
|
+
prompt: z.string(),
|
|
49
|
+
model: z.string().optional()
|
|
50
|
+
}).optional()
|
|
51
|
+
});
|
|
52
|
+
var SchemaDefinitionSchema = z.object({
|
|
53
|
+
"@id": z.string(),
|
|
54
|
+
"@type": z.literal("trellis:Schema"),
|
|
55
|
+
version: z.string(),
|
|
56
|
+
fields: z.array(PropertyValueSpecificationSchema)
|
|
57
|
+
});
|
|
58
|
+
var ProjectionDefinitionSchema = z.object({
|
|
59
|
+
"@id": z.string(),
|
|
60
|
+
"@type": z.literal("trellis:Projection"),
|
|
61
|
+
name: z.string(),
|
|
62
|
+
type: z.enum([
|
|
63
|
+
"card-grid",
|
|
64
|
+
"table",
|
|
65
|
+
"timeline",
|
|
66
|
+
"dashboard",
|
|
67
|
+
"kanban",
|
|
68
|
+
"graph"
|
|
69
|
+
]),
|
|
70
|
+
query: z.string(),
|
|
71
|
+
config: z.record(z.string(), z.any()).optional()
|
|
72
|
+
});
|
|
73
|
+
var WorkspaceConfigSchema = z.object({
|
|
74
|
+
workspace: z.object({
|
|
75
|
+
name: z.string().optional(),
|
|
76
|
+
description: z.string().optional(),
|
|
77
|
+
ontologies: z.record(z.string(), SchemaDefinitionSchema).optional(),
|
|
78
|
+
graph: z.object({
|
|
79
|
+
nodes: z.array(z.any()).optional(),
|
|
80
|
+
edges: z.array(z.any()).optional()
|
|
81
|
+
}).optional(),
|
|
82
|
+
projections: z.record(z.string(), ProjectionDefinitionSchema).optional()
|
|
83
|
+
})
|
|
84
|
+
});
|
|
85
|
+
export {
|
|
86
|
+
WorkspaceConfigSchema,
|
|
87
|
+
SchemaDefinitionSchema,
|
|
88
|
+
PropertyValueSpecificationSchema,
|
|
89
|
+
PropertyTypeSchema,
|
|
90
|
+
ProjectionDefinitionSchema
|
|
91
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// src/persist/sqlite-backend.ts
|
|
2
|
+
import { createRequire } from "module";
|
|
3
|
+
var require2 = createRequire(import.meta.url);
|
|
4
|
+
var encodeAtom = (v) => {
|
|
5
|
+
if (v instanceof Date)
|
|
6
|
+
return { $type: "date", value: v.toISOString() };
|
|
7
|
+
return v;
|
|
8
|
+
};
|
|
9
|
+
var decodeAtom = (v) => {
|
|
10
|
+
if (v && typeof v === "object" && "$type" in v && v.$type === "date" && typeof v.value === "string") {
|
|
11
|
+
return new Date(v.value);
|
|
12
|
+
}
|
|
13
|
+
return v;
|
|
14
|
+
};
|
|
15
|
+
var encodeOp = (op) => {
|
|
16
|
+
const encoded = { ...op };
|
|
17
|
+
if (encoded.facts) {
|
|
18
|
+
encoded.facts = encoded.facts.map((f) => ({
|
|
19
|
+
...f,
|
|
20
|
+
v: encodeAtom(f.v)
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
return encoded;
|
|
24
|
+
};
|
|
25
|
+
var decodeOp = (raw) => {
|
|
26
|
+
const decoded = { ...raw };
|
|
27
|
+
if (decoded.facts) {
|
|
28
|
+
decoded.facts = decoded.facts.map((f) => ({
|
|
29
|
+
...f,
|
|
30
|
+
v: decodeAtom(f.v)
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
return decoded;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
class SqliteKernelBackend {
|
|
37
|
+
opts;
|
|
38
|
+
db;
|
|
39
|
+
constructor(opts) {
|
|
40
|
+
this.opts = opts;
|
|
41
|
+
const mod = require2(["bun", "sqlite"].join(":"));
|
|
42
|
+
const DatabaseCtor = mod?.Database;
|
|
43
|
+
if (!DatabaseCtor) {
|
|
44
|
+
throw new Error("bun:sqlite is not available in this runtime");
|
|
45
|
+
}
|
|
46
|
+
this.db = new DatabaseCtor(opts.filename);
|
|
47
|
+
}
|
|
48
|
+
init() {
|
|
49
|
+
this.db.exec(`
|
|
50
|
+
PRAGMA journal_mode = WAL;
|
|
51
|
+
CREATE TABLE IF NOT EXISTS ops (
|
|
52
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
53
|
+
hash TEXT NOT NULL UNIQUE,
|
|
54
|
+
ts INTEGER NOT NULL,
|
|
55
|
+
kind TEXT NOT NULL,
|
|
56
|
+
payload TEXT NOT NULL
|
|
57
|
+
);
|
|
58
|
+
CREATE INDEX IF NOT EXISTS idx_ops_hash ON ops(hash);
|
|
59
|
+
|
|
60
|
+
CREATE TABLE IF NOT EXISTS snapshots (
|
|
61
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
62
|
+
last_op_hash TEXT NOT NULL,
|
|
63
|
+
ts INTEGER NOT NULL,
|
|
64
|
+
data TEXT NOT NULL
|
|
65
|
+
);
|
|
66
|
+
CREATE INDEX IF NOT EXISTS idx_snapshots_ts ON snapshots(ts);
|
|
67
|
+
`);
|
|
68
|
+
}
|
|
69
|
+
append(op) {
|
|
70
|
+
const stmt = this.db.prepare("INSERT INTO ops (hash, ts, kind, payload) VALUES (?, ?, ?, ?)");
|
|
71
|
+
stmt.run(op.hash, new Date(op.timestamp).getTime(), op.kind, JSON.stringify(encodeOp(op)));
|
|
72
|
+
}
|
|
73
|
+
readAll() {
|
|
74
|
+
const rows = this.db.prepare("SELECT payload FROM ops ORDER BY id ASC").all();
|
|
75
|
+
return rows.map((r) => decodeOp(JSON.parse(r.payload)));
|
|
76
|
+
}
|
|
77
|
+
readUntil(hash) {
|
|
78
|
+
const target = this.db.prepare("SELECT id FROM ops WHERE hash = ?").get(hash);
|
|
79
|
+
if (!target) {
|
|
80
|
+
throw new Error(`Operation with hash ${hash} not found`);
|
|
81
|
+
}
|
|
82
|
+
const rows = this.db.prepare("SELECT payload FROM ops WHERE id <= ? ORDER BY id ASC").all(target.id);
|
|
83
|
+
return rows.map((r) => decodeOp(JSON.parse(r.payload)));
|
|
84
|
+
}
|
|
85
|
+
readAfter(hash) {
|
|
86
|
+
const target = this.db.prepare("SELECT id FROM ops WHERE hash = ?").get(hash);
|
|
87
|
+
if (!target) {
|
|
88
|
+
throw new Error(`Operation with hash ${hash} not found`);
|
|
89
|
+
}
|
|
90
|
+
const rows = this.db.prepare("SELECT payload FROM ops WHERE id > ? ORDER BY id ASC").all(target.id);
|
|
91
|
+
return rows.map((r) => decodeOp(JSON.parse(r.payload)));
|
|
92
|
+
}
|
|
93
|
+
readUntilTimestamp(isoTimestamp) {
|
|
94
|
+
const ts = new Date(isoTimestamp).getTime();
|
|
95
|
+
const rows = this.db.prepare("SELECT payload FROM ops WHERE ts <= ? ORDER BY id ASC").all(ts);
|
|
96
|
+
return rows.map((r) => decodeOp(JSON.parse(r.payload)));
|
|
97
|
+
}
|
|
98
|
+
getLastOp() {
|
|
99
|
+
const row = this.db.prepare("SELECT payload FROM ops ORDER BY id DESC LIMIT 1").get();
|
|
100
|
+
if (!row)
|
|
101
|
+
return;
|
|
102
|
+
return decodeOp(JSON.parse(row.payload));
|
|
103
|
+
}
|
|
104
|
+
saveSnapshot(lastOpHash, data) {
|
|
105
|
+
const stmt = this.db.prepare("INSERT INTO snapshots (last_op_hash, ts, data) VALUES (?, ?, ?)");
|
|
106
|
+
stmt.run(lastOpHash, Date.now(), JSON.stringify(data));
|
|
107
|
+
}
|
|
108
|
+
loadLatestSnapshot() {
|
|
109
|
+
const row = this.db.prepare("SELECT last_op_hash, data FROM snapshots ORDER BY ts DESC LIMIT 1").get();
|
|
110
|
+
if (!row)
|
|
111
|
+
return;
|
|
112
|
+
return {
|
|
113
|
+
lastOpHash: row.last_op_hash,
|
|
114
|
+
data: JSON.parse(row.data)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
close() {
|
|
118
|
+
this.db.close();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export {
|
|
122
|
+
SqliteKernelBackend
|
|
123
|
+
};
|