@decocms/runtime 0.28.0 → 1.0.0-alpha-candy.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.
Files changed (97) hide show
  1. package/package.json +11 -77
  2. package/scripts/generate-json-schema.ts +24 -0
  3. package/src/asset-server/dev-server-proxy.ts +16 -0
  4. package/src/asset-server/index.ts +44 -0
  5. package/src/bindings/README.md +1 -1
  6. package/src/bindings/binder.ts +2 -5
  7. package/src/bindings/channels.ts +1 -1
  8. package/src/bindings/index.ts +1 -32
  9. package/src/bindings/language-model/utils.ts +0 -91
  10. package/src/bindings.ts +30 -108
  11. package/src/client.ts +1 -145
  12. package/src/index.ts +46 -175
  13. package/src/mcp.ts +8 -165
  14. package/src/proxy.ts +3 -62
  15. package/src/state.ts +1 -30
  16. package/src/tools.ts +336 -0
  17. package/src/wrangler.ts +5 -5
  18. package/tsconfig.json +8 -0
  19. package/dist/admin.d.ts +0 -5
  20. package/dist/admin.js +0 -21
  21. package/dist/admin.js.map +0 -1
  22. package/dist/bindings/deconfig/index.d.ts +0 -12
  23. package/dist/bindings/deconfig/index.js +0 -10
  24. package/dist/bindings/deconfig/index.js.map +0 -1
  25. package/dist/bindings/index.d.ts +0 -2312
  26. package/dist/bindings/index.js +0 -135
  27. package/dist/bindings/index.js.map +0 -1
  28. package/dist/chunk-3AWMDSOH.js +0 -96
  29. package/dist/chunk-3AWMDSOH.js.map +0 -1
  30. package/dist/chunk-4XSQKJLU.js +0 -105
  31. package/dist/chunk-4XSQKJLU.js.map +0 -1
  32. package/dist/chunk-5EYZ2LVM.js +0 -158
  33. package/dist/chunk-5EYZ2LVM.js.map +0 -1
  34. package/dist/chunk-7ITSLORK.js +0 -128
  35. package/dist/chunk-7ITSLORK.js.map +0 -1
  36. package/dist/chunk-I7BWSAN6.js +0 -49
  37. package/dist/chunk-I7BWSAN6.js.map +0 -1
  38. package/dist/chunk-L4OT2YDO.js +0 -27
  39. package/dist/chunk-L4OT2YDO.js.map +0 -1
  40. package/dist/chunk-SHQSNOFL.js +0 -769
  41. package/dist/chunk-SHQSNOFL.js.map +0 -1
  42. package/dist/chunk-UHR3BLMF.js +0 -92
  43. package/dist/chunk-UHR3BLMF.js.map +0 -1
  44. package/dist/chunk-UIJGM3NV.js +0 -518
  45. package/dist/chunk-UIJGM3NV.js.map +0 -1
  46. package/dist/chunk-ZPUT6RN6.js +0 -32
  47. package/dist/chunk-ZPUT6RN6.js.map +0 -1
  48. package/dist/client.d.ts +0 -28
  49. package/dist/client.js +0 -5
  50. package/dist/client.js.map +0 -1
  51. package/dist/d1-store.d.ts +0 -9
  52. package/dist/d1-store.js +0 -4
  53. package/dist/d1-store.js.map +0 -1
  54. package/dist/drizzle.d.ts +0 -49
  55. package/dist/drizzle.js +0 -121
  56. package/dist/drizzle.js.map +0 -1
  57. package/dist/index-B7U9jXW4.d.ts +0 -530
  58. package/dist/index-uCMd27hU.d.ts +0 -471
  59. package/dist/index.d.ts +0 -10
  60. package/dist/index.js +0 -637
  61. package/dist/index.js.map +0 -1
  62. package/dist/mastra.d.ts +0 -10
  63. package/dist/mastra.js +0 -6
  64. package/dist/mastra.js.map +0 -1
  65. package/dist/mcp-DYmQ2RQf.d.ts +0 -105
  66. package/dist/mcp-client.d.ts +0 -232
  67. package/dist/mcp-client.js +0 -4
  68. package/dist/mcp-client.js.map +0 -1
  69. package/dist/proxy.d.ts +0 -11
  70. package/dist/proxy.js +0 -5
  71. package/dist/proxy.js.map +0 -1
  72. package/dist/resources.d.ts +0 -362
  73. package/dist/resources.js +0 -4
  74. package/dist/resources.js.map +0 -1
  75. package/dist/views.d.ts +0 -72
  76. package/dist/views.js +0 -4
  77. package/dist/views.js.map +0 -1
  78. package/src/admin.ts +0 -16
  79. package/src/auth.ts +0 -233
  80. package/src/bindings/deconfig/helpers.ts +0 -107
  81. package/src/bindings/deconfig/index.ts +0 -1
  82. package/src/bindings/deconfig/resources.ts +0 -659
  83. package/src/bindings/deconfig/types.ts +0 -106
  84. package/src/bindings/language-model/ai-sdk.ts +0 -87
  85. package/src/bindings/language-model/index.ts +0 -4
  86. package/src/bindings/resources/bindings.ts +0 -99
  87. package/src/bindings/resources/helpers.ts +0 -95
  88. package/src/bindings/resources/schemas.ts +0 -265
  89. package/src/bindings/views.ts +0 -14
  90. package/src/cf-imports.ts +0 -1
  91. package/src/d1-store.ts +0 -34
  92. package/src/deprecated.ts +0 -59
  93. package/src/drizzle.ts +0 -201
  94. package/src/mastra.ts +0 -898
  95. package/src/resources.ts +0 -168
  96. package/src/views.ts +0 -26
  97. package/src/workflow.ts +0 -193
package/src/d1-store.ts DELETED
@@ -1,34 +0,0 @@
1
- import {
2
- D1ClientConfig as MastraD1StoreConfig,
3
- D1Store as MastraD1Store,
4
- } from "@mastra/cloudflare-d1";
5
-
6
- export class D1Store extends MastraD1Store {
7
- constructor(private config: MastraD1StoreConfig) {
8
- super(config);
9
- }
10
-
11
- override async init() {
12
- await super.init();
13
-
14
- // Create indexes for better performance on frequently queried columns
15
- const indexQueries = [
16
- {
17
- sql: "CREATE INDEX IF NOT EXISTS idx_mastra_workflow_snapshot_created_at ON mastra_workflow_snapshot(createdAt)",
18
- params: [],
19
- },
20
- {
21
- sql: "CREATE INDEX IF NOT EXISTS idx_mastra_messages_created_at ON mastra_messages(createdAt)",
22
- params: [],
23
- },
24
- ];
25
-
26
- // Execute each index creation query
27
- for (const { sql, params } of indexQueries) {
28
- await this.config.client.query({
29
- sql,
30
- params,
31
- });
32
- }
33
- }
34
- }
package/src/deprecated.ts DELETED
@@ -1,59 +0,0 @@
1
- import type { RequestContext } from "./index.ts";
2
- import type { DurableObjectNamespace } from "@cloudflare/workers-types";
3
- import type { WorkspaceDB } from "./index.ts";
4
- import type { WorkflowDO } from "./workflow.ts";
5
- import type { z } from "zod/v3";
6
-
7
- // oxlint-disable-next-line no-explicit-any
8
- export interface DeprecatedEnv<TSchema extends z.ZodTypeAny = any> {
9
- /**
10
- * @deprecated Use DECO_REQUEST_CONTEXT instead
11
- */
12
- DECO_CHAT_REQUEST_CONTEXT: RequestContext<TSchema>;
13
- /**
14
- * @deprecated Use DECO_APP_NAME instead
15
- */
16
- DECO_CHAT_APP_NAME: string;
17
- /**
18
- * @deprecated Use DECO_APP_SLUG instead
19
- */
20
- DECO_CHAT_APP_SLUG: string;
21
- /**
22
- * @deprecated Use DECO_APP_ENTRYPOINT instead
23
- */
24
- DECO_CHAT_APP_ENTRYPOINT: string;
25
- /**
26
- * @deprecated Use DECO_API_URL instead
27
- */
28
- DECO_CHAT_API_URL?: string;
29
- /**
30
- * @deprecated Use DECO_WORKSPACE instead
31
- */
32
- DECO_CHAT_WORKSPACE: string;
33
- /**
34
- * @deprecated Use DECO_API_JWT_PUBLIC_KEY instead
35
- */
36
- DECO_CHAT_API_JWT_PUBLIC_KEY: string;
37
- /**
38
- * @deprecated Use DECO_APP_DEPLOYMENT_ID instead
39
- */
40
- DECO_CHAT_APP_DEPLOYMENT_ID: string;
41
- /**
42
- * @deprecated Use DECO_BINDINGS instead
43
- */
44
- DECO_CHAT_BINDINGS: string;
45
- /**
46
- * @deprecated Use DECO_API_TOKEN instead
47
- */
48
- DECO_CHAT_API_TOKEN: string;
49
- /**
50
- * @deprecated Use DECO_WORKFLOW_DO instead
51
- */
52
- DECO_CHAT_WORKFLOW_DO: DurableObjectNamespace<WorkflowDO>;
53
- /**
54
- * @deprecated Use DECO_WORKSPACE_DB instead
55
- */
56
- DECO_CHAT_WORKSPACE_DB: WorkspaceDB & {
57
- forContext: (ctx: RequestContext) => WorkspaceDB;
58
- };
59
- }
package/src/drizzle.ts DELETED
@@ -1,201 +0,0 @@
1
- import type { DrizzleConfig } from "drizzle-orm";
2
- import {
3
- drizzle as drizzleProxy,
4
- type SqliteRemoteDatabase,
5
- } from "drizzle-orm/sqlite-proxy";
6
- import { QueryResult } from "./mcp.ts";
7
- export * from "drizzle-orm/sqlite-core";
8
- export * as orm from "drizzle-orm";
9
- import { sql } from "drizzle-orm";
10
- import { DefaultEnv } from "./index.ts";
11
-
12
- const mapGetResult = ({ result: [page] }: { result: QueryResult[] }) => {
13
- return page.results ?? [];
14
- };
15
-
16
- const mapPostResult = ({ result }: { result: QueryResult[] }) => {
17
- return (
18
- result
19
- .map((page) => page.results ?? [])
20
- .flat()
21
- // @ts-expect-error - this is ok, result comes as unknown
22
- .map(Object.values)
23
- );
24
- };
25
-
26
- export function drizzle<
27
- TSchema extends Record<string, unknown> = Record<string, never>,
28
- >(
29
- { DECO_WORKSPACE_DB }: Pick<DefaultEnv, "DECO_WORKSPACE_DB">,
30
- config?: DrizzleConfig<TSchema>,
31
- ) {
32
- return drizzleProxy((sql, params, method) => {
33
- // https://orm.drizzle.team/docs/connect-drizzle-proxy says
34
- // Drizzle always waits for {rows: string[][]} or {rows: string[]} for the return value.
35
- // When the method is get, you should return a value as {rows: string[]}.
36
- // Otherwise, you should return {rows: string[][]}.
37
- const asRows = method === "get" ? mapGetResult : mapPostResult;
38
- return DECO_WORKSPACE_DB.query({
39
- sql,
40
- params,
41
- }).then((result) => ({ rows: asRows(result) }));
42
- }, config);
43
- }
44
-
45
- /**
46
- * The following code is a custom migration system tweaked
47
- * from the durable-sqlite original migrator.
48
- *
49
- * @see https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/durable-sqlite/migrator.ts
50
- *
51
- * It applies the migrations without transactions, as a workaround
52
- * while we don't have remote transactions support on the
53
- * workspace database durable object. Not ideal and we should
54
- * look into implementing some way of doing transactions soon.
55
- */
56
-
57
- export interface MigrationMeta {
58
- sql: string[];
59
- folderMillis: number;
60
- hash: string;
61
- bps: boolean;
62
- }
63
-
64
- export interface MigrationConfig {
65
- journal: {
66
- entries: { idx: number; when: number; tag: string; breakpoints: boolean }[];
67
- };
68
- migrations: Record<string, string>;
69
- debug?: boolean;
70
- }
71
-
72
- function readMigrationFiles({
73
- journal,
74
- migrations,
75
- }: MigrationConfig): MigrationMeta[] {
76
- const migrationQueries: MigrationMeta[] = [];
77
-
78
- for (const journalEntry of journal.entries) {
79
- const query =
80
- migrations[`m${journalEntry.idx.toString().padStart(4, "0")}`];
81
-
82
- if (!query) {
83
- throw new Error(`Missing migration: ${journalEntry.tag}`);
84
- }
85
-
86
- try {
87
- const result = query.split("--> statement-breakpoint").map((it) => {
88
- return it;
89
- });
90
-
91
- migrationQueries.push({
92
- sql: result,
93
- bps: journalEntry.breakpoints,
94
- folderMillis: journalEntry.when,
95
- hash: "",
96
- });
97
- } catch {
98
- throw new Error(`Failed to parse migration: ${journalEntry.tag}`);
99
- }
100
- }
101
-
102
- return migrationQueries;
103
- }
104
-
105
- export async function migrateWithoutTransaction(
106
- db: SqliteRemoteDatabase,
107
- config: MigrationConfig,
108
- ): Promise<void> {
109
- const debug = config.debug ?? false;
110
-
111
- if (debug) console.log("Migrating database");
112
- const migrations = readMigrationFiles(config);
113
- if (debug) console.log("Migrations", migrations);
114
-
115
- try {
116
- if (debug) console.log("Setting up migrations table");
117
- const migrationsTable = "__drizzle_migrations";
118
-
119
- // Create migrations table if it doesn't exist
120
- // Note: Changed from SERIAL to INTEGER PRIMARY KEY AUTOINCREMENT for SQLite compatibility
121
- const migrationTableCreate = sql`
122
- CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
123
- id INTEGER PRIMARY KEY AUTOINCREMENT,
124
- hash text NOT NULL,
125
- created_at numeric
126
- )
127
- `;
128
- await db.run(migrationTableCreate);
129
-
130
- // Get the last applied migration
131
- const dbMigrations = await db.values<[number, string, string]>(
132
- sql`SELECT id, hash, created_at FROM ${sql.identifier(
133
- migrationsTable,
134
- )} ORDER BY created_at DESC LIMIT 1`,
135
- );
136
-
137
- const lastDbMigration = dbMigrations[0] ?? undefined;
138
- if (debug) console.log("Last applied migration:", lastDbMigration);
139
-
140
- // Apply pending migrations sequentially (without transaction wrapper)
141
- for (const migration of migrations) {
142
- const hasNoMigrations =
143
- lastDbMigration === undefined || !lastDbMigration.length;
144
- if (
145
- hasNoMigrations ||
146
- Number(lastDbMigration[2])! < migration.folderMillis
147
- ) {
148
- if (debug) console.log(`Applying migration: ${migration.folderMillis}`);
149
-
150
- try {
151
- // Execute all statements in the migration
152
- for (const stmt of migration.sql) {
153
- if (stmt.trim()) {
154
- // Skip empty statements
155
- if (debug) {
156
- console.log("Executing:", stmt.substring(0, 100) + "...");
157
- }
158
- await db.run(sql.raw(stmt));
159
- }
160
- }
161
-
162
- // Record successful migration
163
- await db.run(
164
- sql`INSERT INTO ${sql.identifier(
165
- migrationsTable,
166
- )} ("hash", "created_at") VALUES(${migration.hash}, ${migration.folderMillis})`,
167
- );
168
-
169
- if (debug) {
170
- console.log(
171
- `✅ Migration ${migration.folderMillis} applied successfully`,
172
- );
173
- }
174
- } catch (migrationError: unknown) {
175
- console.error(
176
- `❌ Migration ${migration.folderMillis} failed:`,
177
- migrationError,
178
- );
179
- throw new Error(
180
- `Migration failed at ${migration.folderMillis}: ${
181
- migrationError instanceof Error
182
- ? migrationError.message
183
- : String(migrationError)
184
- }`,
185
- );
186
- }
187
- } else {
188
- if (debug) {
189
- console.log(
190
- `⏭️ Skipping already applied migration: ${migration.folderMillis}`,
191
- );
192
- }
193
- }
194
- }
195
-
196
- if (debug) console.log("✅ All migrations completed successfully");
197
- } catch (error: unknown) {
198
- console.error("❌ Migration process failed:", error);
199
- throw error;
200
- }
201
- }