theokit 0.75.1 → 0.76.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.
- package/README.md +88 -1
- package/dist/{actions-virtual-module-MIQPBAZW.js → actions-virtual-module-52O6HJZT.js} +11 -9
- package/dist/actions-virtual-module-52O6HJZT.js.map +1 -0
- package/dist/{actions-virtual-module-QEI6QPK4.js → actions-virtual-module-HS4W7HQU.js} +6 -5
- package/dist/{actions-virtual-module-QEI6QPK4.js.map → actions-virtual-module-HS4W7HQU.js.map} +1 -1
- package/dist/adapters/agent-mount.js +9 -7
- package/dist/{agent-N4OV5MDY.js → agent-HCK5RHH7.js} +4 -3
- package/dist/{app-typed-client-CHSITA46.js → app-typed-client-BWITJLJA.js} +6 -5
- package/dist/{app-typed-client-CHSITA46.js.map → app-typed-client-BWITJLJA.js.map} +1 -1
- package/dist/{app-typed-client-XQJXF646.js → app-typed-client-CJCOALMM.js} +11 -9
- package/dist/app-typed-client-CJCOALMM.js.map +1 -0
- package/dist/{aws-lambda-K5Y6XS5V.js → aws-lambda-XT7ZDJ6B.js} +3 -3
- package/dist/{build-GNKTCEES.js → build-Y3CWTWP6.js} +24 -92
- package/dist/build-Y3CWTWP6.js.map +1 -0
- package/dist/{bun-VPXMWFBA.js → bun-PJLDELDT.js} +5 -5
- package/dist/{chunk-J2KYVTPD.js → chunk-2SGNODVJ.js} +30 -16
- package/dist/chunk-2SGNODVJ.js.map +1 -0
- package/dist/chunk-2SQ7YAU3.js +85 -0
- package/dist/chunk-2SQ7YAU3.js.map +1 -0
- package/dist/{chunk-SYIQV4UH.js → chunk-36ZACTF3.js} +5 -5
- package/dist/{chunk-RY6D4EXL.js → chunk-3GM4GACM.js} +25 -4
- package/dist/{chunk-RY6D4EXL.js.map → chunk-3GM4GACM.js.map} +1 -1
- package/dist/{chunk-EW5IG7GA.js → chunk-42TYMRBG.js} +1 -1
- package/dist/{chunk-EW5IG7GA.js.map → chunk-42TYMRBG.js.map} +1 -1
- package/dist/{chunk-BINRCILF.js → chunk-4JRXZTVQ.js} +4 -13
- package/dist/chunk-4JRXZTVQ.js.map +1 -0
- package/dist/{chunk-R4AMIBZL.js → chunk-4XZOUS5G.js} +8 -8
- package/dist/chunk-4XZOUS5G.js.map +1 -0
- package/dist/{chunk-ICXXHV4V.js → chunk-54BIQFP4.js} +4 -13
- package/dist/chunk-54BIQFP4.js.map +1 -0
- package/dist/{chunk-VPK7ABMB.js → chunk-7MCEJVGV.js} +3 -3
- package/dist/{chunk-D7STTNQN.js → chunk-BXQCJJPT.js} +3 -3
- package/dist/{chunk-NX3P5MLH.js → chunk-C2BRSL4W.js} +50 -6
- package/dist/chunk-C2BRSL4W.js.map +1 -0
- package/dist/{chunk-E5QTCOKC.js → chunk-FEK25JUL.js} +88 -24
- package/dist/chunk-FEK25JUL.js.map +1 -0
- package/dist/{chunk-NLHAYGQQ.js → chunk-G3DDIEYE.js} +4 -2
- package/dist/chunk-G3DDIEYE.js.map +1 -0
- package/dist/chunk-IXXZBZF7.js +70 -0
- package/dist/chunk-IXXZBZF7.js.map +1 -0
- package/dist/{chunk-PVNMLZ5G.js → chunk-JO462JZM.js} +2 -2
- package/dist/chunk-LXV5IEBB.js +76 -0
- package/dist/chunk-LXV5IEBB.js.map +1 -0
- package/dist/{chunk-D2R5SJEL.js → chunk-MAJZ2L3A.js} +2 -2
- package/dist/{chunk-D2R5SJEL.js.map → chunk-MAJZ2L3A.js.map} +1 -1
- package/dist/chunk-NF7LXSXZ.js +19 -0
- package/dist/chunk-NF7LXSXZ.js.map +1 -0
- package/dist/chunk-OED37LE5.js +469 -0
- package/dist/chunk-OED37LE5.js.map +1 -0
- package/dist/{chunk-CLSYYO5F.js → chunk-OIYSUQM7.js} +2 -2
- package/dist/{chunk-2Z7TANA4.js → chunk-PVCXREGE.js} +6 -6
- package/dist/{chunk-EVKNHQWG.js → chunk-QBK6YYZA.js} +48 -5
- package/dist/chunk-QBK6YYZA.js.map +1 -0
- package/dist/{chunk-4X43VTST.js → chunk-TODO6J42.js} +1 -1
- package/dist/chunk-TODO6J42.js.map +1 -0
- package/dist/{chunk-ZDCCILMP.js → chunk-TQTEKNOL.js} +2 -69
- package/dist/chunk-TQTEKNOL.js.map +1 -0
- package/dist/{chunk-3MKRDJQ2.js → chunk-UQQQ3V43.js} +278 -75
- package/dist/chunk-UQQQ3V43.js.map +1 -0
- package/dist/{chunk-MX63AWEK.js → chunk-VXDTQO3S.js} +22 -6
- package/dist/{chunk-MX63AWEK.js.map → chunk-VXDTQO3S.js.map} +1 -1
- package/dist/{chunk-OZB2TKGJ.js → chunk-W2I6L4IJ.js} +2 -2
- package/dist/{chunk-UWV3B3RY.js → chunk-XDLFOATW.js} +5 -5
- package/dist/{chunk-RQKMY3JW.js → chunk-XI4FALFZ.js} +3 -3
- package/dist/chunk-XI4FALFZ.js.map +1 -0
- package/dist/{chunk-2FHNJ7LI.js → chunk-Z76QQR7I.js} +2 -2
- package/dist/chunk-ZICY2CD7.js +16 -0
- package/dist/chunk-ZICY2CD7.js.map +1 -0
- package/dist/chunk-ZN5H7CUR.js +24 -0
- package/dist/chunk-ZN5H7CUR.js.map +1 -0
- package/dist/{chunk-I5PDEWZZ.js → chunk-ZQJORKBM.js} +9 -3
- package/dist/chunk-ZQJORKBM.js.map +1 -0
- package/dist/cli/index.js +21 -15
- package/dist/cli/index.js.map +1 -1
- package/dist/{cloudflare-7EZQE4UV.js → cloudflare-F7KLBOU4.js} +6 -6
- package/dist/{config-support-HUZ4DXR7.js → config-support-2TER2BYD.js} +28 -21
- package/dist/config-support-2TER2BYD.js.map +1 -0
- package/dist/cron-lock-CfAvLApv.d.ts +36 -0
- package/dist/db-ZWDKD57T.js +86 -0
- package/dist/db-ZWDKD57T.js.map +1 -0
- package/dist/{deno-deploy-M5V3PYWU.js → deno-deploy-LJ5JQQVR.js} +5 -5
- package/dist/{dev-7PMNIIOF.js → dev-R2ZYHZV4.js} +60 -11
- package/dist/dev-R2ZYHZV4.js.map +1 -0
- package/dist/{engine-singleton-X4R7AZBJ.js → engine-singleton-BQ5QOMTC.js} +15 -9
- package/dist/{engine-singleton-X4R7AZBJ.js.map → engine-singleton-BQ5QOMTC.js.map} +1 -1
- package/dist/{generate-RW3NO3NR.js → generate-VXBSMUMW.js} +291 -85
- package/dist/generate-VXBSMUMW.js.map +1 -0
- package/dist/{index-CmkWlIDO.d.ts → index-DfsJ3Qhk.d.ts} +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +12 -10
- package/dist/index.js.map +1 -1
- package/dist/{info-6NAUW5XY.js → info-IPMW56PI.js} +4 -4
- package/dist/{internal-api-R7TTYMCY.js → internal-api-6RAOYIET.js} +6 -5
- package/dist/{internal-api-A5HA7TYF.js → internal-api-YGFPLQ4E.js} +14 -11
- package/dist/job-backend-WvUs5rO1.d.ts +119 -0
- package/dist/{load-config-CLFWJOXN.js → load-config-USRR4GXP.js} +4 -4
- package/dist/{mcp-3NRZAQKY.js → mcp-FBXEX45H.js} +5 -4
- package/dist/{mcp-3NRZAQKY.js.map → mcp-FBXEX45H.js.map} +1 -1
- package/dist/{netlify-NI4HYDKN.js → netlify-ZPQNREFH.js} +2 -2
- package/dist/{node-LORYECWI.js → node-3EV3CVWB.js} +2 -2
- package/dist/{observability-bootstrap-DOWRMADT.js → observability-bootstrap-DMJ7R6WA.js} +3 -3
- package/dist/{openapi-ZHKJB3XL.js → openapi-CA3E3LZH.js} +4 -4
- package/dist/{preview-SNS7VJWH.js → preview-DLIVPM7A.js} +3 -3
- package/dist/registry-3D2KR7UE.js +34 -0
- package/dist/{routes-SMNSI2ZX.js → routes-BJ7GGRCV.js} +4 -4
- package/dist/{schema-DJH3IOVR.js → schema-FBM2UH72.js} +3 -3
- package/dist/{schemas-2R2J64ZH.js → schemas-BUR6PWSA.js} +2 -2
- package/dist/server/agent/index.d.ts +1 -1
- package/dist/server/agent/index.js +2 -1
- package/dist/server/cost/index.d.ts +2 -2
- package/dist/server/cost/index.js +1 -1
- package/dist/server/cost/sqlite/index.d.ts +2 -2
- package/dist/server/cost/sqlite/index.js +1 -1
- package/dist/server/cron/index.d.ts +20 -7
- package/dist/server/cron/index.js +8 -2
- package/dist/server/http/index.d.ts +2 -2
- package/dist/server/http/index.js +9 -7
- package/dist/server/index.d.ts +19 -10
- package/dist/server/index.js +103 -41
- package/dist/server/index.js.map +1 -1
- package/dist/server/jobs/index.d.ts +85 -44
- package/dist/server/jobs/index.js +9 -2
- package/dist/server/observability/index.js +9 -8
- package/dist/server/storage/index.d.ts +6 -2
- package/dist/server/storage/index.js +5 -1
- package/dist/server/webhook/index.d.ts +4 -5
- package/dist/server/webhook/index.js +1 -1
- package/dist/{server-boundary-ZT6HN7ON.js → server-boundary-EKIGYL7B.js} +6 -5
- package/dist/{server-boundary-ZT6HN7ON.js.map → server-boundary-EKIGYL7B.js.map} +1 -1
- package/dist/{server-boundary-HYLYGFZY.js → server-boundary-IDWIB24L.js} +11 -9
- package/dist/server-boundary-IDWIB24L.js.map +1 -0
- package/dist/{start-L5TGWGLU.js → start-LNT5UVSY.js} +118 -185
- package/dist/start-LNT5UVSY.js.map +1 -0
- package/dist/{static-O2RZ5NLR.js → static-VNN4HYRN.js} +2 -2
- package/dist/{storage-manager-3O5PDO6O.js → storage-manager-3IUIEG2P.js} +49 -5
- package/dist/storage-manager-3IUIEG2P.js.map +1 -0
- package/dist/{storage-manager-BtG38jYl.d.ts → storage-manager-Clu2RBpH.d.ts} +15 -3
- package/dist/{storage-types-CFGPFIdB.d.ts → storage-types-ndO0ZZqH.d.ts} +2 -2
- package/dist/{theo-cloud-B4R7GCWK.js → theo-cloud-243SPOIA.js} +2 -2
- package/dist/{vercel-INHLOCSZ.js → vercel-EXKSZ2OQ.js} +5 -5
- package/dist/vite-plugin/index.js +12 -10
- package/dist/{vite-plugin-UXEXT7GX.js → vite-plugin-LE42ZIGV.js} +10 -9
- package/dist/{whatsapp-D_Fnl1LX.d.ts → whatsapp-4W2eK2ij.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/actions-virtual-module-MIQPBAZW.js.map +0 -1
- package/dist/app-typed-client-XQJXF646.js.map +0 -1
- package/dist/build-GNKTCEES.js.map +0 -1
- package/dist/chunk-3MKRDJQ2.js.map +0 -1
- package/dist/chunk-4X43VTST.js.map +0 -1
- package/dist/chunk-BINRCILF.js.map +0 -1
- package/dist/chunk-E5QTCOKC.js.map +0 -1
- package/dist/chunk-EVKNHQWG.js.map +0 -1
- package/dist/chunk-I5PDEWZZ.js.map +0 -1
- package/dist/chunk-ICXXHV4V.js.map +0 -1
- package/dist/chunk-IDEZ7FU2.js +0 -18
- package/dist/chunk-IDEZ7FU2.js.map +0 -1
- package/dist/chunk-J2KYVTPD.js.map +0 -1
- package/dist/chunk-NLHAYGQQ.js.map +0 -1
- package/dist/chunk-NX3P5MLH.js.map +0 -1
- package/dist/chunk-R4AMIBZL.js.map +0 -1
- package/dist/chunk-RQKMY3JW.js.map +0 -1
- package/dist/chunk-YCF3N4JS.js +0 -26
- package/dist/chunk-YCF3N4JS.js.map +0 -1
- package/dist/chunk-ZDCCILMP.js.map +0 -1
- package/dist/config-support-HUZ4DXR7.js.map +0 -1
- package/dist/db-IVVCQE5Z.js +0 -76
- package/dist/db-IVVCQE5Z.js.map +0 -1
- package/dist/dev-7PMNIIOF.js.map +0 -1
- package/dist/generate-RW3NO3NR.js.map +0 -1
- package/dist/job-backend-CgC8Xf33.d.ts +0 -68
- package/dist/registry-3SVWZVIJ.js +0 -34
- package/dist/server-boundary-HYLYGFZY.js.map +0 -1
- package/dist/start-L5TGWGLU.js.map +0 -1
- package/dist/storage-manager-3O5PDO6O.js.map +0 -1
- /package/dist/{agent-N4OV5MDY.js.map → agent-HCK5RHH7.js.map} +0 -0
- /package/dist/{aws-lambda-K5Y6XS5V.js.map → aws-lambda-XT7ZDJ6B.js.map} +0 -0
- /package/dist/{bun-VPXMWFBA.js.map → bun-PJLDELDT.js.map} +0 -0
- /package/dist/{chunk-SYIQV4UH.js.map → chunk-36ZACTF3.js.map} +0 -0
- /package/dist/{chunk-VPK7ABMB.js.map → chunk-7MCEJVGV.js.map} +0 -0
- /package/dist/{chunk-D7STTNQN.js.map → chunk-BXQCJJPT.js.map} +0 -0
- /package/dist/{chunk-PVNMLZ5G.js.map → chunk-JO462JZM.js.map} +0 -0
- /package/dist/{chunk-CLSYYO5F.js.map → chunk-OIYSUQM7.js.map} +0 -0
- /package/dist/{chunk-2Z7TANA4.js.map → chunk-PVCXREGE.js.map} +0 -0
- /package/dist/{chunk-OZB2TKGJ.js.map → chunk-W2I6L4IJ.js.map} +0 -0
- /package/dist/{chunk-UWV3B3RY.js.map → chunk-XDLFOATW.js.map} +0 -0
- /package/dist/{chunk-2FHNJ7LI.js.map → chunk-Z76QQR7I.js.map} +0 -0
- /package/dist/{cloudflare-7EZQE4UV.js.map → cloudflare-F7KLBOU4.js.map} +0 -0
- /package/dist/{deno-deploy-M5V3PYWU.js.map → deno-deploy-LJ5JQQVR.js.map} +0 -0
- /package/dist/{info-6NAUW5XY.js.map → info-IPMW56PI.js.map} +0 -0
- /package/dist/{internal-api-R7TTYMCY.js.map → internal-api-6RAOYIET.js.map} +0 -0
- /package/dist/{internal-api-A5HA7TYF.js.map → internal-api-YGFPLQ4E.js.map} +0 -0
- /package/dist/{load-config-CLFWJOXN.js.map → load-config-USRR4GXP.js.map} +0 -0
- /package/dist/{netlify-NI4HYDKN.js.map → netlify-ZPQNREFH.js.map} +0 -0
- /package/dist/{node-LORYECWI.js.map → node-3EV3CVWB.js.map} +0 -0
- /package/dist/{observability-bootstrap-DOWRMADT.js.map → observability-bootstrap-DMJ7R6WA.js.map} +0 -0
- /package/dist/{openapi-ZHKJB3XL.js.map → openapi-CA3E3LZH.js.map} +0 -0
- /package/dist/{preview-SNS7VJWH.js.map → preview-DLIVPM7A.js.map} +0 -0
- /package/dist/{registry-3SVWZVIJ.js.map → registry-3D2KR7UE.js.map} +0 -0
- /package/dist/{routes-SMNSI2ZX.js.map → routes-BJ7GGRCV.js.map} +0 -0
- /package/dist/{schema-DJH3IOVR.js.map → schema-FBM2UH72.js.map} +0 -0
- /package/dist/{schemas-2R2J64ZH.js.map → schemas-BUR6PWSA.js.map} +0 -0
- /package/dist/{static-O2RZ5NLR.js.map → static-VNN4HYRN.js.map} +0 -0
- /package/dist/{theo-cloud-B4R7GCWK.js.map → theo-cloud-243SPOIA.js.map} +0 -0
- /package/dist/{vercel-INHLOCSZ.js.map → vercel-EXKSZ2OQ.js.map} +0 -0
- /package/dist/{vite-plugin-UXEXT7GX.js.map → vite-plugin-LE42ZIGV.js.map} +0 -0
|
@@ -11,16 +11,16 @@ import {
|
|
|
11
11
|
import "./chunk-Z7CJHDLS.js";
|
|
12
12
|
import {
|
|
13
13
|
loadConfig
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-W2I6L4IJ.js";
|
|
15
15
|
import "./chunk-3QPVEJ7D.js";
|
|
16
16
|
import "./chunk-O5JZ6ROY.js";
|
|
17
|
-
import "./chunk-
|
|
17
|
+
import "./chunk-C2BRSL4W.js";
|
|
18
18
|
import "./chunk-L4V5V2TI.js";
|
|
19
|
-
import "./chunk-
|
|
19
|
+
import "./chunk-MAJZ2L3A.js";
|
|
20
20
|
|
|
21
21
|
// src/cli/commands/generate.ts
|
|
22
22
|
import { existsSync as existsSync2, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
23
|
-
import { resolve as resolve4, dirname as dirname3 } from "path";
|
|
23
|
+
import { posix, resolve as resolve4, dirname as dirname3 } from "path";
|
|
24
24
|
|
|
25
25
|
// src/cli/commands/generate-containment.ts
|
|
26
26
|
import { isAbsolute, relative, resolve, sep } from "path";
|
|
@@ -56,8 +56,8 @@ function undecidedPolicyDeclaration(routePath, what) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// src/cli/commands/generate-resource.ts
|
|
59
|
-
import {
|
|
60
|
-
import { resolve as resolve2
|
|
59
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
60
|
+
import { dirname, join, resolve as resolve2 } from "path";
|
|
61
61
|
var ALLOWED_FIELD_TYPES = /* @__PURE__ */ new Set(["string", "text", "number", "boolean"]);
|
|
62
62
|
var RESERVED_FIELDS = /* @__PURE__ */ new Set(["id", "createdAt", "created_at"]);
|
|
63
63
|
function parseResourceFields(args) {
|
|
@@ -84,21 +84,89 @@ function parseResourceFields(args) {
|
|
|
84
84
|
return {
|
|
85
85
|
name,
|
|
86
86
|
type: fieldType,
|
|
87
|
-
drizzleColumn: mapDrizzleColumn(name, fieldType),
|
|
88
87
|
zodType: mapZodType(fieldType)
|
|
89
88
|
};
|
|
90
89
|
});
|
|
91
90
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
91
|
+
var DIALECTS = {
|
|
92
|
+
sqlite: {
|
|
93
|
+
module: "drizzle-orm/sqlite-core",
|
|
94
|
+
dbIndexExample: [
|
|
95
|
+
`import Database from 'better-sqlite3'`,
|
|
96
|
+
`import { drizzle } from 'drizzle-orm/better-sqlite3'`,
|
|
97
|
+
`import * as schema from './schema.js'`,
|
|
98
|
+
`export const db = drizzle(new Database('data.db'), { schema })`
|
|
99
|
+
],
|
|
100
|
+
importPattern: /import\s*\{([^}]*)\}\s*from\s*['"]drizzle-orm\/sqlite-core['"]/,
|
|
101
|
+
table: "sqliteTable",
|
|
102
|
+
columns: ["integer", "text"],
|
|
103
|
+
idColumn: `integer('id').primaryKey({ autoIncrement: true })`,
|
|
104
|
+
createdAtColumn: [
|
|
105
|
+
`text('created_at')`,
|
|
106
|
+
` .notNull()`,
|
|
107
|
+
` .$defaultFn(() => new Date().toISOString().split('T')[0])`
|
|
108
|
+
],
|
|
109
|
+
column: (name, type) => {
|
|
110
|
+
switch (type) {
|
|
111
|
+
case "string":
|
|
112
|
+
case "text":
|
|
113
|
+
return `text('${name}').notNull()`;
|
|
114
|
+
case "number":
|
|
115
|
+
return `integer('${name}').notNull()`;
|
|
116
|
+
case "boolean":
|
|
117
|
+
return `integer('${name}', { mode: 'boolean' }).notNull().default(false)`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
postgresql: {
|
|
122
|
+
module: "drizzle-orm/pg-core",
|
|
123
|
+
dbIndexExample: [
|
|
124
|
+
`import pg from 'pg'`,
|
|
125
|
+
`import { drizzle } from 'drizzle-orm/node-postgres'`,
|
|
126
|
+
`import * as schema from './schema.js'`,
|
|
127
|
+
`const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })`,
|
|
128
|
+
`pool.on('error', (err) => console.warn('[pg] idle client error:', err.message))`,
|
|
129
|
+
`export const db = drizzle(pool, { schema })`
|
|
130
|
+
],
|
|
131
|
+
importPattern: /import\s*\{([^}]*)\}\s*from\s*['"]drizzle-orm\/pg-core['"]/,
|
|
132
|
+
table: "pgTable",
|
|
133
|
+
columns: ["boolean", "integer", "serial", "text", "timestamp"],
|
|
134
|
+
idColumn: `serial('id').primaryKey()`,
|
|
135
|
+
createdAtColumn: [`timestamp('created_at').notNull().defaultNow()`],
|
|
136
|
+
column: (name, type) => {
|
|
137
|
+
switch (type) {
|
|
138
|
+
case "string":
|
|
139
|
+
case "text":
|
|
140
|
+
return `text('${name}').notNull()`;
|
|
141
|
+
case "number":
|
|
142
|
+
return `integer('${name}').notNull()`;
|
|
143
|
+
case "boolean":
|
|
144
|
+
return `boolean('${name}').notNull().default(false)`;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
101
147
|
}
|
|
148
|
+
};
|
|
149
|
+
var DIALECT_ALIASES = {
|
|
150
|
+
sqlite: "sqlite",
|
|
151
|
+
turso: "sqlite",
|
|
152
|
+
postgresql: "postgresql"
|
|
153
|
+
};
|
|
154
|
+
var SCHEMA_IMPORT_DIALECTS = [
|
|
155
|
+
[/from ['"]drizzle-orm\/sqlite-core['"]/, "sqlite"],
|
|
156
|
+
[/from ['"]drizzle-orm\/pg-core['"]/, "postgresql"],
|
|
157
|
+
[/from ['"]drizzle-orm\/mysql-core['"]/, "mysql"],
|
|
158
|
+
[/from ['"]drizzle-orm\/singlestore-core['"]/, "singlestore"]
|
|
159
|
+
];
|
|
160
|
+
function detectDialect(cwd, schemaSource) {
|
|
161
|
+
const config = readIfPresent(resolve2(cwd, "drizzle.config.ts"));
|
|
162
|
+
if (config !== void 0) {
|
|
163
|
+
const declared = /dialect\s*:\s*['"]([a-z0-9-]+)['"]/.exec(config);
|
|
164
|
+
if (declared) return declared[1];
|
|
165
|
+
}
|
|
166
|
+
for (const [pattern, dialect] of SCHEMA_IMPORT_DIALECTS) {
|
|
167
|
+
if (pattern.test(schemaSource)) return dialect;
|
|
168
|
+
}
|
|
169
|
+
return "sqlite";
|
|
102
170
|
}
|
|
103
171
|
function mapZodType(type) {
|
|
104
172
|
switch (type) {
|
|
@@ -111,38 +179,71 @@ function mapZodType(type) {
|
|
|
111
179
|
return "z.boolean()";
|
|
112
180
|
}
|
|
113
181
|
}
|
|
114
|
-
function generateSchemaEntry(resourceName, fields) {
|
|
182
|
+
function generateSchemaEntry(resourceName, fields, dialect) {
|
|
183
|
+
const [createdAtFirst, ...createdAtRest] = dialect.createdAtColumn;
|
|
115
184
|
const cols = [
|
|
116
|
-
` id:
|
|
117
|
-
...fields.map((f) => ` ${f.name}: ${f.
|
|
118
|
-
` createdAt:
|
|
119
|
-
|
|
120
|
-
` .$defaultFn(() => new Date().toISOString().split('T')[0]),`
|
|
185
|
+
` id: ${dialect.idColumn},`,
|
|
186
|
+
...fields.map((f) => ` ${f.name}: ${dialect.column(f.name, f.type)},`),
|
|
187
|
+
` createdAt: ${createdAtFirst}`,
|
|
188
|
+
...createdAtRest
|
|
121
189
|
];
|
|
190
|
+
cols[cols.length - 1] += ",";
|
|
122
191
|
return [
|
|
123
192
|
``,
|
|
124
|
-
`export const ${resourceName} =
|
|
193
|
+
`export const ${resourceName} = ${dialect.table}('${resourceName}', {`,
|
|
125
194
|
...cols,
|
|
126
195
|
`})`,
|
|
127
196
|
``
|
|
128
197
|
].join("\n");
|
|
129
198
|
}
|
|
130
|
-
function
|
|
199
|
+
function withDialectImports(source, dialect) {
|
|
200
|
+
const needed = [dialect.table, ...dialect.columns];
|
|
201
|
+
const existing = dialect.importPattern.exec(source);
|
|
202
|
+
if (existing) {
|
|
203
|
+
const have = existing[1].split(",").map((n) => n.trim()).filter(Boolean);
|
|
204
|
+
const merged = [.../* @__PURE__ */ new Set([...have, ...needed])].sort((a, b) => a.localeCompare(b));
|
|
205
|
+
return source.replace(existing[0], `import { ${merged.join(", ")} } from '${dialect.module}'`);
|
|
206
|
+
}
|
|
207
|
+
return `import { ${[...needed].sort((a, b) => a.localeCompare(b)).join(", ")} } from '${dialect.module}'
|
|
208
|
+
${source}`;
|
|
209
|
+
}
|
|
210
|
+
var QUERIES = {
|
|
211
|
+
sqlite: {
|
|
212
|
+
async: false,
|
|
213
|
+
list: (t) => `db.select().from(${t}).all()`,
|
|
214
|
+
insert: (t) => `db.insert(${t}).values(body).returning().get()`,
|
|
215
|
+
findById: (t) => `db.select().from(${t}).where(eq(${t}.id, params.id)).get()`,
|
|
216
|
+
updateById: (t) => `db.update(${t}).set(body).where(eq(${t}.id, params.id)).returning().get()`,
|
|
217
|
+
deleteById: (t) => `db.delete(${t}).where(eq(${t}.id, params.id)).run()`
|
|
218
|
+
},
|
|
219
|
+
postgresql: {
|
|
220
|
+
async: true,
|
|
221
|
+
list: (t) => `await db.select().from(${t})`,
|
|
222
|
+
insert: (t) => `(await db.insert(${t}).values(body).returning())[0]`,
|
|
223
|
+
findById: (t) => `(await db.select().from(${t}).where(eq(${t}.id, params.id)))[0]`,
|
|
224
|
+
updateById: (t) => `(await db.update(${t}).set(body).where(eq(${t}.id, params.id)).returning())[0]`,
|
|
225
|
+
deleteById: (t) => `await db.delete(${t}).where(eq(${t}.id, params.id))`
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
function generateRouteIndex({
|
|
229
|
+
resourceName,
|
|
230
|
+
fields,
|
|
231
|
+
queries,
|
|
232
|
+
displayPath
|
|
233
|
+
}) {
|
|
131
234
|
const bodyFields = fields.map((f) => ` ${f.name}: ${f.zodType},`).join("\n");
|
|
235
|
+
const asyncKw = queries.async ? "async " : "";
|
|
132
236
|
return [
|
|
133
237
|
`import { route, type AccessDecision } from 'theokit/server/define'`,
|
|
134
238
|
`import { z } from 'zod'`,
|
|
135
239
|
`import { db } from '../../db/index.js'`,
|
|
136
240
|
`import { ${resourceName} } from '../../db/schema.js'`,
|
|
137
241
|
``,
|
|
138
|
-
...undecidedPolicyDeclaration(
|
|
139
|
-
`server/routes/${resourceName}/index.ts`,
|
|
140
|
-
"these methods read and write a table"
|
|
141
|
-
),
|
|
242
|
+
...undecidedPolicyDeclaration(displayPath, "these methods read and write a table"),
|
|
142
243
|
``,
|
|
143
244
|
`export const GET = route()`,
|
|
144
245
|
` .policy(${UNDECIDED_POLICY_IDENT})`,
|
|
145
|
-
` .handler(() =>
|
|
246
|
+
` .handler(${asyncKw}() => ${queries.list(resourceName)})`,
|
|
146
247
|
` .build()`,
|
|
147
248
|
``,
|
|
148
249
|
`export const POST = route()`,
|
|
@@ -153,16 +254,22 @@ function generateRouteIndex(resourceName, fields) {
|
|
|
153
254
|
` }),`,
|
|
154
255
|
` )`,
|
|
155
256
|
` .status(201)`,
|
|
156
|
-
` .handler(({ body }) => {`,
|
|
157
|
-
` const result =
|
|
257
|
+
` .handler(${asyncKw}({ body }) => {`,
|
|
258
|
+
` const result = ${queries.insert(resourceName)}`,
|
|
158
259
|
` return result`,
|
|
159
260
|
` })`,
|
|
160
261
|
` .build()`,
|
|
161
262
|
``
|
|
162
263
|
].join("\n");
|
|
163
264
|
}
|
|
164
|
-
function generateRouteId(
|
|
265
|
+
function generateRouteId({
|
|
266
|
+
resourceName,
|
|
267
|
+
fields,
|
|
268
|
+
queries,
|
|
269
|
+
displayPath
|
|
270
|
+
}) {
|
|
165
271
|
const updateFields = fields.map((f) => ` ${f.name}: ${f.zodType}.optional(),`).join("\n");
|
|
272
|
+
const asyncKw = queries.async ? "async " : "";
|
|
166
273
|
return [
|
|
167
274
|
`import { route, type AccessDecision } from 'theokit/server/define'`,
|
|
168
275
|
`import { z } from 'zod'`,
|
|
@@ -171,15 +278,15 @@ function generateRouteId(resourceName, fields) {
|
|
|
171
278
|
`import { eq } from 'drizzle-orm'`,
|
|
172
279
|
``,
|
|
173
280
|
...undecidedPolicyDeclaration(
|
|
174
|
-
|
|
281
|
+
displayPath,
|
|
175
282
|
"these methods read, update and delete rows of a table"
|
|
176
283
|
),
|
|
177
284
|
``,
|
|
178
285
|
`export const GET = route()`,
|
|
179
286
|
` .policy(${UNDECIDED_POLICY_IDENT})`,
|
|
180
287
|
` .params(z.object({ id: z.coerce.number() }))`,
|
|
181
|
-
` .handler(({ params }) => {`,
|
|
182
|
-
` const item =
|
|
288
|
+
` .handler(${asyncKw}({ params }) => {`,
|
|
289
|
+
` const item = ${queries.findById(resourceName)}`,
|
|
183
290
|
` if (!item) return new Response(JSON.stringify({ error: 'Not found' }), { status: 404 })`,
|
|
184
291
|
` return item`,
|
|
185
292
|
` })`,
|
|
@@ -193,8 +300,8 @@ function generateRouteId(resourceName, fields) {
|
|
|
193
300
|
updateFields,
|
|
194
301
|
` }),`,
|
|
195
302
|
` )`,
|
|
196
|
-
` .handler(({ params, body }) => {`,
|
|
197
|
-
` const result =
|
|
303
|
+
` .handler(${asyncKw}({ params, body }) => {`,
|
|
304
|
+
` const result = ${queries.updateById(resourceName)}`,
|
|
198
305
|
` if (!result) return new Response(JSON.stringify({ error: 'Not found' }), { status: 404 })`,
|
|
199
306
|
` return result`,
|
|
200
307
|
` })`,
|
|
@@ -204,25 +311,25 @@ function generateRouteId(resourceName, fields) {
|
|
|
204
311
|
` .policy(${UNDECIDED_POLICY_IDENT})`,
|
|
205
312
|
` .params(z.object({ id: z.coerce.number() }))`,
|
|
206
313
|
` .status(204)`,
|
|
207
|
-
` .handler(({ params }) => {`,
|
|
208
|
-
`
|
|
314
|
+
` .handler(${asyncKw}({ params }) => {`,
|
|
315
|
+
` ${queries.deleteById(resourceName)}`,
|
|
209
316
|
` })`,
|
|
210
317
|
` .build()`,
|
|
211
318
|
``
|
|
212
319
|
].join("\n");
|
|
213
320
|
}
|
|
214
|
-
function generateTestTemplate(resourceName) {
|
|
321
|
+
function generateTestTemplate(resourceName, serverDir) {
|
|
215
322
|
return [
|
|
216
323
|
`import { describe, it, expect } from 'vitest'`,
|
|
217
324
|
``,
|
|
218
325
|
`describe('${resourceName} API', () => {`,
|
|
219
326
|
` it('should have a schema defined', async () => {`,
|
|
220
|
-
` const schema = await import('
|
|
327
|
+
` const schema = await import('../${serverDir}/db/schema.js')`,
|
|
221
328
|
` expect(schema.${resourceName}).toBeDefined()`,
|
|
222
329
|
` })`,
|
|
223
330
|
``,
|
|
224
331
|
` it('should have route handlers', async () => {`,
|
|
225
|
-
` const index = await import('
|
|
332
|
+
` const index = await import('../${serverDir}/routes/${resourceName}/index.js')`,
|
|
226
333
|
` expect(index.GET).toBeDefined()`,
|
|
227
334
|
` expect(index.POST).toBeDefined()`,
|
|
228
335
|
` })`,
|
|
@@ -230,44 +337,93 @@ function generateTestTemplate(resourceName) {
|
|
|
230
337
|
``
|
|
231
338
|
].join("\n");
|
|
232
339
|
}
|
|
233
|
-
function
|
|
340
|
+
function readIfPresent(path) {
|
|
341
|
+
try {
|
|
342
|
+
return readFileSync(path, "utf-8");
|
|
343
|
+
} catch (err) {
|
|
344
|
+
if (err.code === "ENOENT") return void 0;
|
|
345
|
+
throw err;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
var DB_INDEX_FILES = ["index.ts", "index.tsx", "index.js"];
|
|
349
|
+
function createExclusive(path, content) {
|
|
350
|
+
try {
|
|
351
|
+
writeFileSync(path, content, { flag: "wx" });
|
|
352
|
+
return true;
|
|
353
|
+
} catch (err) {
|
|
354
|
+
if (err.code === "EEXIST") return false;
|
|
355
|
+
throw err;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function generateResource(cwd, name, fieldArgs, serverDir = "server") {
|
|
234
359
|
let fields;
|
|
235
360
|
try {
|
|
236
361
|
fields = parseResourceFields(fieldArgs);
|
|
237
362
|
} catch (err) {
|
|
238
363
|
return { status: "invalid_name", message: err instanceof Error ? err.message : String(err) };
|
|
239
364
|
}
|
|
240
|
-
const
|
|
241
|
-
const
|
|
242
|
-
const
|
|
365
|
+
const schemaRel = join(serverDir, "db", "schema.ts");
|
|
366
|
+
const routeDirRel = join(serverDir, "routes", name);
|
|
367
|
+
const schemaPath = resolve2(cwd, schemaRel);
|
|
368
|
+
const routeIndexPath = resolve2(cwd, routeDirRel, "index.ts");
|
|
369
|
+
const routeIdPath = resolve2(cwd, routeDirRel, "[id].ts");
|
|
243
370
|
const testPath = resolve2(cwd, `tests/${name}.test.ts`);
|
|
244
|
-
|
|
371
|
+
const existingSchema = readIfPresent(schemaPath);
|
|
372
|
+
if (existingSchema === void 0) {
|
|
245
373
|
return {
|
|
246
374
|
status: "not_a_project",
|
|
247
|
-
message:
|
|
375
|
+
message: `${schemaRel} not found. \`theokit generate resource\` appends the table to the Drizzle schema under the configured serverDir ("${serverDir}"); create it first.`
|
|
248
376
|
};
|
|
249
377
|
}
|
|
250
|
-
if (existsSync(routeIndexPath)) {
|
|
251
|
-
return { status: "already_exists", filePath: routeIndexPath, kind: "resource", name };
|
|
252
|
-
}
|
|
253
|
-
const existingSchema = readFileSync(schemaPath, "utf-8");
|
|
254
378
|
if (existingSchema.includes(`export const ${name} =`)) {
|
|
255
379
|
return {
|
|
256
380
|
status: "already_exists",
|
|
257
381
|
filePath: schemaPath,
|
|
258
382
|
kind: "resource",
|
|
259
383
|
name,
|
|
260
|
-
message: `Table "${name}" already exists in
|
|
384
|
+
message: `Table "${name}" already exists in ${schemaRel}`
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
const detected = detectDialect(cwd, existingSchema);
|
|
388
|
+
const dialectName = DIALECT_ALIASES[detected];
|
|
389
|
+
if (dialectName === void 0) {
|
|
390
|
+
return {
|
|
391
|
+
status: "invalid_config",
|
|
392
|
+
message: `\`theokit generate resource\` writes code for SQLite and PostgreSQL; this project uses "${detected}" (from drizzle.config.ts or the imports in ${schemaRel}). Nothing was written.`
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
const dialect = DIALECTS[dialectName];
|
|
396
|
+
const queries = QUERIES[dialectName];
|
|
397
|
+
const dbIndexRel = join(serverDir, "db", "index.ts");
|
|
398
|
+
if (!DB_INDEX_FILES.some((file) => existsSync(resolve2(cwd, serverDir, "db", file)))) {
|
|
399
|
+
const example = dialect.dbIndexExample.map((line) => " " + line).join("\n");
|
|
400
|
+
return {
|
|
401
|
+
status: "not_a_project",
|
|
402
|
+
message: `${dbIndexRel} not found. The routes \`theokit generate resource\` writes import \`db\` from it, so the build would fail to resolve it. Create it with \`export const db\`, for example (${dialectName}):
|
|
403
|
+
|
|
404
|
+
${example}
|
|
405
|
+
|
|
406
|
+
Nothing was written.`
|
|
261
407
|
};
|
|
262
408
|
}
|
|
263
|
-
appendFileSync(schemaPath, generateSchemaEntry(name, fields));
|
|
264
409
|
mkdirSync(dirname(routeIndexPath), { recursive: true });
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
410
|
+
const template = { resourceName: name, fields, queries };
|
|
411
|
+
if (!createExclusive(
|
|
412
|
+
routeIndexPath,
|
|
413
|
+
generateRouteIndex({ ...template, displayPath: join(routeDirRel, "index.ts") })
|
|
414
|
+
)) {
|
|
415
|
+
return { status: "already_exists", filePath: routeIndexPath, kind: "resource", name };
|
|
270
416
|
}
|
|
417
|
+
writeFileSync(
|
|
418
|
+
routeIdPath,
|
|
419
|
+
generateRouteId({ ...template, displayPath: join(routeDirRel, "[id].ts") })
|
|
420
|
+
);
|
|
421
|
+
writeFileSync(
|
|
422
|
+
schemaPath,
|
|
423
|
+
withDialectImports(existingSchema, dialect) + generateSchemaEntry(name, fields, dialect)
|
|
424
|
+
);
|
|
425
|
+
mkdirSync(dirname(testPath), { recursive: true });
|
|
426
|
+
createExclusive(testPath, generateTestTemplate(name, serverDir));
|
|
271
427
|
return { status: "created", filePath: routeIndexPath, kind: "resource", name };
|
|
272
428
|
}
|
|
273
429
|
|
|
@@ -437,15 +593,12 @@ function toCamelCase(name) {
|
|
|
437
593
|
const pascal = toPascalCase(name);
|
|
438
594
|
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
439
595
|
}
|
|
440
|
-
function generateRouteTemplate(name) {
|
|
596
|
+
function generateRouteTemplate(name, displayPath) {
|
|
441
597
|
return [
|
|
442
598
|
`import { route, type AccessDecision } from 'theokit/server'`,
|
|
443
599
|
`import { z } from 'zod'`,
|
|
444
600
|
``,
|
|
445
|
-
...undecidedPolicyDeclaration(
|
|
446
|
-
`server/routes/${name}.ts`,
|
|
447
|
-
"a stub today is a real handler tomorrow"
|
|
448
|
-
),
|
|
601
|
+
...undecidedPolicyDeclaration(displayPath, "a stub today is a real handler tomorrow"),
|
|
449
602
|
``,
|
|
450
603
|
`export const GET = route()`,
|
|
451
604
|
` .policy(${UNDECIDED_POLICY_IDENT})`,
|
|
@@ -488,13 +641,18 @@ function generateActionTemplate(name) {
|
|
|
488
641
|
``
|
|
489
642
|
].join("\n");
|
|
490
643
|
}
|
|
491
|
-
function generateAgentTemplate(name) {
|
|
644
|
+
function generateAgentTemplate(name, displayPath) {
|
|
492
645
|
return [
|
|
493
646
|
`import { AgentBuilder } from '@theokit/agents'`,
|
|
647
|
+
`import type { AccessDecision } from 'theokit/server'`,
|
|
494
648
|
`import { z } from 'zod'`,
|
|
495
649
|
``,
|
|
496
650
|
`// Zero-config: this file is auto-served at POST /api/agents/${name}.`,
|
|
497
651
|
`// Add tools with tool('name')...build() and chain them via .tool(...).`,
|
|
652
|
+
``,
|
|
653
|
+
...undecidedPolicyDeclaration(displayPath, "an agent endpoint runs a model on your key"),
|
|
654
|
+
`export const policy = ${UNDECIDED_POLICY_IDENT}`,
|
|
655
|
+
``,
|
|
498
656
|
`export default AgentBuilder.create()`,
|
|
499
657
|
` .input(z.object({ message: z.string() }))`,
|
|
500
658
|
` .model('openai/gpt-4o-mini')`,
|
|
@@ -610,31 +768,75 @@ function generateMemoryTemplate(_name) {
|
|
|
610
768
|
].join("\n");
|
|
611
769
|
}
|
|
612
770
|
var SINGLE_FILE_KINDS = {
|
|
613
|
-
// Agent-capability generators. These live UNDER `
|
|
614
|
-
// not standalone top-level concerns — and the folder-semantic scanner treats each as
|
|
615
|
-
// (never a phantom route).
|
|
616
|
-
workflow: {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
771
|
+
// Agent-capability generators. These live UNDER `agentsDir` — they are facets of the agent
|
|
772
|
+
// domain, not standalone top-level concerns — and the folder-semantic scanner treats each as
|
|
773
|
+
// composition (never a phantom route).
|
|
774
|
+
workflow: {
|
|
775
|
+
path: (name, { agentsDir }) => posix.join(agentsDir, "workflows", `${name}.ts`),
|
|
776
|
+
template: generateWorkflowTemplate
|
|
777
|
+
},
|
|
778
|
+
eval: {
|
|
779
|
+
path: (name, { agentsDir }) => posix.join(agentsDir, "evals", `${name}.ts`),
|
|
780
|
+
template: generateEvalTemplate
|
|
781
|
+
},
|
|
782
|
+
sandbox: {
|
|
783
|
+
path: (name, { agentsDir }) => posix.join(agentsDir, "sandbox", `${name}.ts`),
|
|
784
|
+
template: generateSandboxTemplate
|
|
785
|
+
},
|
|
786
|
+
memory: {
|
|
787
|
+
path: (name, { agentsDir }) => posix.join(agentsDir, "memory", `${name}.ts`),
|
|
788
|
+
template: generateMemoryTemplate
|
|
789
|
+
},
|
|
790
|
+
route: {
|
|
791
|
+
path: (name, { serverDir }) => posix.join(serverDir, "routes", `${name}.ts`),
|
|
792
|
+
template: generateRouteTemplate
|
|
793
|
+
},
|
|
794
|
+
action: {
|
|
795
|
+
path: (name, { serverDir }) => posix.join(serverDir, "actions", `${name}.ts`),
|
|
796
|
+
template: generateActionTemplate
|
|
797
|
+
},
|
|
798
|
+
page: {
|
|
799
|
+
path: (name, { appDir }) => posix.join(appDir, name, "page.tsx"),
|
|
800
|
+
template: generatePageTemplate
|
|
801
|
+
},
|
|
802
|
+
ws: {
|
|
803
|
+
path: (name, { serverDir }) => posix.join(serverDir, "ws", `${name}.ts`),
|
|
804
|
+
template: generateWsTemplate
|
|
805
|
+
},
|
|
624
806
|
controller: {
|
|
625
|
-
path: (name) =>
|
|
807
|
+
path: (name, { serverDir }) => posix.join(serverDir, "controllers", `${name}.controller.ts`),
|
|
626
808
|
template: generateControllerTemplate
|
|
627
809
|
},
|
|
628
|
-
agent
|
|
810
|
+
// `<agentsDir>/<name>.ts` is what the agent scanner serves at `/api/agents/<name>`, the URL the
|
|
811
|
+
// template promises. The old `server/agents/<name>.agent.ts` was outside `agentsDir` in both the
|
|
812
|
+
// flat and the scaffold layout, so the agent was never served.
|
|
813
|
+
agent: {
|
|
814
|
+
path: (name, { agentsDir }) => posix.join(agentsDir, `${name}.ts`),
|
|
815
|
+
template: generateAgentTemplate
|
|
816
|
+
},
|
|
629
817
|
toolbox: {
|
|
630
|
-
path: (name) =>
|
|
818
|
+
path: (name, { serverDir }) => posix.join(serverDir, "toolboxes", `${name}.tools.ts`),
|
|
631
819
|
template: generateToolboxTemplate
|
|
632
820
|
}
|
|
633
821
|
};
|
|
634
|
-
function
|
|
822
|
+
async function readLayout(cwd) {
|
|
823
|
+
try {
|
|
824
|
+
const { appDir, serverDir, agentsDir } = await loadConfig(cwd);
|
|
825
|
+
return { appDir, serverDir, agentsDir };
|
|
826
|
+
} catch (err) {
|
|
827
|
+
return {
|
|
828
|
+
status: "invalid_config",
|
|
829
|
+
message: `Cannot read ${resolve4(cwd, "theo.config.ts")}: ${err.message}`
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
async function resolveTemplate(cwd, kind, name) {
|
|
635
834
|
const spec = SINGLE_FILE_KINDS[kind];
|
|
636
835
|
if (spec === void 0) return null;
|
|
637
|
-
|
|
836
|
+
const layout = await readLayout(cwd);
|
|
837
|
+
if ("status" in layout) return layout;
|
|
838
|
+
const displayPath = spec.path(name, layout);
|
|
839
|
+
return { filePath: resolve4(cwd, displayPath), content: spec.template(name, displayPath) };
|
|
638
840
|
}
|
|
639
841
|
function generateActionTestTemplate(name) {
|
|
640
842
|
const camel = toCamelCase(name);
|
|
@@ -708,7 +910,7 @@ function refuseOptions({ cwd, type, name }) {
|
|
|
708
910
|
}
|
|
709
911
|
async function resolveTarget(cwd, type, name) {
|
|
710
912
|
if (type === "schedule") return resolveScheduleTarget(cwd, name);
|
|
711
|
-
const target = resolveTemplate(cwd, type, name);
|
|
913
|
+
const target = await resolveTemplate(cwd, type, name);
|
|
712
914
|
if (target === null) return { status: "invalid_kind", message: `Unknown type: ${type}` };
|
|
713
915
|
return target;
|
|
714
916
|
}
|
|
@@ -734,14 +936,18 @@ async function generate(opts) {
|
|
|
734
936
|
const { cwd, name } = opts;
|
|
735
937
|
const kind = opts.type;
|
|
736
938
|
if (kind === "resource") {
|
|
737
|
-
|
|
939
|
+
const layout = await readLayout(cwd);
|
|
940
|
+
if ("status" in layout) return layout;
|
|
941
|
+
return generateResource(cwd, name, opts.fields ?? [], layout.serverDir);
|
|
738
942
|
}
|
|
739
943
|
const resolved = await resolveTarget(cwd, kind, name);
|
|
740
944
|
if ("status" in resolved) return resolved;
|
|
741
945
|
return writeTarget(cwd, kind, name, resolved);
|
|
742
946
|
}
|
|
743
947
|
var CLI_REFUSALS = {
|
|
744
|
-
|
|
948
|
+
// The generator's own reason when it gave one: `generate resource` refuses a project that HAS a
|
|
949
|
+
// theo.config.ts when the schema file is missing, and the generic text blamed the config (#1022).
|
|
950
|
+
not_a_project: (result) => result.message ?? "Not a Theo project. Run this from a project root with theo.config.ts",
|
|
745
951
|
invalid_kind: (result) => result.message ?? "Invalid kind",
|
|
746
952
|
// `generate` returns invalid_name for a malformed name, a reserved name and a path that
|
|
747
953
|
// resolves outside the project; each message says which, so the CLI must not replace it.
|
|
@@ -767,4 +973,4 @@ export {
|
|
|
767
973
|
generate,
|
|
768
974
|
generateCommand
|
|
769
975
|
};
|
|
770
|
-
//# sourceMappingURL=generate-
|
|
976
|
+
//# sourceMappingURL=generate-VXBSMUMW.js.map
|