@treeseed/sdk 0.6.15 → 0.6.17

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 (47) hide show
  1. package/dist/db/d1.d.ts +3493 -0
  2. package/dist/db/d1.js +8 -0
  3. package/dist/db/index.d.ts +2 -0
  4. package/dist/db/index.js +2 -0
  5. package/dist/db/node-sqlite.d.ts +3544 -0
  6. package/dist/db/node-sqlite.js +119 -0
  7. package/dist/db/schema.d.ts +6272 -0
  8. package/dist/db/schema.js +231 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +1 -0
  11. package/dist/operations/providers/default.js +1 -0
  12. package/dist/operations/services/commit-message-provider.d.ts +33 -1
  13. package/dist/operations/services/commit-message-provider.js +228 -51
  14. package/dist/operations/services/config-runtime.js +0 -1
  15. package/dist/operations/services/deploy.d.ts +19 -5
  16. package/dist/operations/services/deploy.js +75 -36
  17. package/dist/operations/services/github-actions-verification.d.ts +123 -0
  18. package/dist/operations/services/github-actions-verification.js +440 -0
  19. package/dist/operations/services/mailpit-runtime.d.ts +5 -0
  20. package/dist/operations/services/mailpit-runtime.js +2 -2
  21. package/dist/operations/services/repository-save-orchestrator.js +64 -8
  22. package/dist/operations/services/runtime-tools.d.ts +6 -0
  23. package/dist/operations/services/runtime-tools.js +11 -0
  24. package/dist/operations-registry.js +1 -0
  25. package/dist/platform/contracts.d.ts +6 -0
  26. package/dist/platform/deploy-config.js +17 -0
  27. package/dist/reconcile/builtin-adapters.js +2 -16
  28. package/dist/reconcile/contracts.d.ts +1 -1
  29. package/dist/reconcile/desired-state.d.ts +6 -0
  30. package/dist/reconcile/desired-state.js +1 -13
  31. package/dist/reconcile/engine.d.ts +12 -0
  32. package/dist/reconcile/state.js +2 -1
  33. package/dist/reconcile/units.js +0 -1
  34. package/dist/scripts/tenant-d1-migrate-local.js +5 -2
  35. package/dist/scripts/tenant-destroy.js +3 -1
  36. package/dist/sdk.js +2 -6
  37. package/dist/types/cloudflare.d.ts +0 -1
  38. package/dist/workflow/operations.d.ts +2 -1
  39. package/dist/workflow/operations.js +115 -35
  40. package/dist/workflow-support.d.ts +1 -0
  41. package/dist/workflow-support.js +6 -0
  42. package/dist/workflow.d.ts +24 -2
  43. package/dist/workflow.js +6 -0
  44. package/package.json +19 -5
  45. package/templates/github/deploy.workflow.yml +4 -0
  46. package/dist/wrangler-d1.d.ts +0 -25
  47. package/dist/wrangler-d1.js +0 -89
@@ -0,0 +1,119 @@
1
+ import { mkdirSync } from "node:fs";
2
+ import { dirname, resolve } from "node:path";
3
+ import { DatabaseSync } from "node:sqlite";
4
+ import { drizzle } from "drizzle-orm/sqlite-proxy";
5
+ import { treeseedSchema } from "./schema.js";
6
+ function isDirectoryLike(path) {
7
+ return !/\.(sqlite|sqlite3|db)$/iu.test(path);
8
+ }
9
+ function resolveTreeseedSqlitePath(input) {
10
+ const base = input?.trim() || ".treeseed/generated/environments/local/site-data.sqlite";
11
+ return isDirectoryLike(base) ? resolve(base, "site-data.sqlite") : resolve(base);
12
+ }
13
+ function toD1Result(result, rows = []) {
14
+ const changes = Number(result?.changes ?? 0);
15
+ return {
16
+ success: true,
17
+ results: rows,
18
+ meta: {
19
+ duration: 0,
20
+ size_after: 0,
21
+ rows_read: rows.length,
22
+ rows_written: changes,
23
+ last_row_id: Number(result?.lastInsertRowid ?? 0),
24
+ changed_db: changes > 0,
25
+ changes
26
+ }
27
+ };
28
+ }
29
+ class NodeSqliteD1PreparedStatement {
30
+ constructor(client, query) {
31
+ this.client = client;
32
+ this.query = query;
33
+ }
34
+ client;
35
+ query;
36
+ bindings = [];
37
+ bind(...values) {
38
+ this.bindings = values;
39
+ return this;
40
+ }
41
+ async run() {
42
+ const statement = this.client.prepare(this.query);
43
+ return toD1Result(statement.run(...this.bindings));
44
+ }
45
+ async all() {
46
+ const statement = this.client.prepare(this.query);
47
+ const rows = statement.all(...this.bindings);
48
+ return toD1Result(void 0, rows);
49
+ }
50
+ async first() {
51
+ const statement = this.client.prepare(this.query);
52
+ return statement.get(...this.bindings) ?? null;
53
+ }
54
+ async raw() {
55
+ const { results } = await this.all();
56
+ return results.map((entry) => Object.values(entry));
57
+ }
58
+ }
59
+ class NodeSqliteD1Database {
60
+ client;
61
+ path;
62
+ constructor(path) {
63
+ this.path = resolveTreeseedSqlitePath(path);
64
+ mkdirSync(dirname(this.path), { recursive: true });
65
+ this.client = new DatabaseSync(this.path);
66
+ this.client.exec("PRAGMA foreign_keys = ON;");
67
+ this.client.exec("PRAGMA journal_mode = WAL;");
68
+ }
69
+ prepare(query) {
70
+ return new NodeSqliteD1PreparedStatement(this.client, query);
71
+ }
72
+ async exec(query) {
73
+ this.client.exec(query);
74
+ return toD1Result(void 0);
75
+ }
76
+ async batch(statements) {
77
+ const results = [];
78
+ this.client.exec("BEGIN");
79
+ try {
80
+ for (const statement of statements) {
81
+ results.push(await statement.run());
82
+ }
83
+ this.client.exec("COMMIT");
84
+ return results;
85
+ } catch (error) {
86
+ this.client.exec("ROLLBACK");
87
+ throw error;
88
+ }
89
+ }
90
+ close() {
91
+ this.client.close();
92
+ }
93
+ }
94
+ function createTreeseedNodeSqliteDrizzle(path) {
95
+ const database = new NodeSqliteD1Database(path);
96
+ return {
97
+ d1: database,
98
+ db: drizzle(async (sql, params, method) => {
99
+ const statement = database.client.prepare(sql);
100
+ if (method === "run") {
101
+ statement.run(...params);
102
+ return { rows: [] };
103
+ }
104
+ if (method === "get") {
105
+ const row = statement.get(...params);
106
+ return { rows: row ? [row] : [] };
107
+ }
108
+ if (method === "values") {
109
+ return { rows: statement.all(...params).map((row) => Object.values(row)) };
110
+ }
111
+ return { rows: statement.all(...params) };
112
+ }, { schema: treeseedSchema })
113
+ };
114
+ }
115
+ export {
116
+ NodeSqliteD1Database,
117
+ createTreeseedNodeSqliteDrizzle,
118
+ resolveTreeseedSqlitePath
119
+ };