@tailor-platform/sdk 2.11.0 → 2.13.0
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/CHANGELOG.md +36 -0
- package/dist/application-BFTkaW6X.mjs +1 -0
- package/dist/{application-CcrP-v7z.mjs → application-D3HlhR3i.mjs} +2 -2
- package/dist/{application-CcrP-v7z.mjs.map → application-D3HlhR3i.mjs.map} +1 -1
- package/dist/cli/commands/generate/seed/bundler.d.mts +2 -2
- package/dist/cli/commands/tailordb/migrate/bundler.d.mts +1 -1
- package/dist/cli/commands/workspace/user/remove.d.mts +1 -1
- package/dist/cli/commands/workspace/user/update.d.mts +1 -1
- package/dist/cli/lib.mjs +1 -1
- package/dist/cli/main.mjs +41 -42
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/shared/script-executor.d.mts +2 -2
- package/dist/completion/zsh-worker.zsh +32 -2
- package/dist/kysely-type-B-BOlXH7.mjs +43 -0
- package/dist/kysely-type-B-BOlXH7.mjs.map +1 -0
- package/dist/plugin/builtin/kysely-type/index.mjs +1 -1
- package/dist/{register-ts-hook-YqgUg8P7.mjs → register-ts-hook-CoZS-8Mx.mjs} +14 -14
- package/dist/register-ts-hook-CoZS-8Mx.mjs.map +1 -0
- package/dist/seed-CMkupmX8.mjs.map +1 -1
- package/dist/service_pb-CFVlGYdr.mjs +1 -0
- package/dist/{service_pb-BNxUPfP3.mjs → service_pb-CxHztLk1.mjs} +2 -2
- package/dist/{service_pb-BNxUPfP3.mjs.map → service_pb-CxHztLk1.mjs.map} +1 -1
- package/dist/tailor-proto/src/tailor/v1/auth_resource_pb.d.mts +10 -0
- package/dist/workflow-Cs9ISw6j.mjs.map +1 -1
- package/dist/workspace_resource_pb-u9bj6p3i.mjs +2 -0
- package/dist/workspace_resource_pb-u9bj6p3i.mjs.map +1 -0
- package/docs/cli/user.md +84 -21
- package/docs/cli-reference.md +1 -0
- package/package.json +6 -6
- package/dist/application-B4tCGHiQ.mjs +0 -1
- package/dist/kysely-type-CmvAz1Xj.mjs +0 -43
- package/dist/kysely-type-CmvAz1Xj.mjs.map +0 -1
- package/dist/register-ts-hook-YqgUg8P7.mjs.map +0 -1
- package/dist/service_pb-D-xFu9Ub.mjs +0 -1
- package/dist/workspace_resource_pb-B7S-zx4Z.mjs +0 -2
- package/dist/workspace_resource_pb-B7S-zx4Z.mjs.map +0 -1
package/docs/cli/user.md
CHANGED
|
@@ -66,9 +66,28 @@ See [Global Options](../cli-reference.md#global-options) for options available t
|
|
|
66
66
|
|
|
67
67
|
**Commands**
|
|
68
68
|
|
|
69
|
-
| Command
|
|
70
|
-
|
|
|
71
|
-
| [`auth
|
|
69
|
+
| Command | Description |
|
|
70
|
+
| ----------------------------- | ------------------------------------------------------------------------------------- |
|
|
71
|
+
| [`auth status`](#auth-status) | Show the active Tailor Platform authentication status without printing tokens. |
|
|
72
|
+
| [`auth token`](#auth-token) | Print a valid Tailor Platform access token to stdout, refreshing it first if expired. |
|
|
73
|
+
|
|
74
|
+
### auth status
|
|
75
|
+
|
|
76
|
+
Show the active Tailor Platform authentication status without printing tokens.
|
|
77
|
+
|
|
78
|
+
**Usage**
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
tailor auth status [options]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Options**
|
|
85
|
+
|
|
86
|
+
| Option | Alias | Description | Required | Default | Env |
|
|
87
|
+
| --------------------- | ----- | ----------------- | -------- | ------- | ------------------------- |
|
|
88
|
+
| `--profile <PROFILE>` | `-p` | Workspace profile | No | - | `TAILOR_PLATFORM_PROFILE` |
|
|
89
|
+
|
|
90
|
+
See [Global Options](../cli-reference.md#global-options) for options available to all commands.
|
|
72
91
|
|
|
73
92
|
### auth token
|
|
74
93
|
|
|
@@ -116,9 +135,15 @@ Show current user.
|
|
|
116
135
|
**Usage**
|
|
117
136
|
|
|
118
137
|
```
|
|
119
|
-
tailor user current
|
|
138
|
+
tailor user current [options]
|
|
120
139
|
```
|
|
121
140
|
|
|
141
|
+
**Options**
|
|
142
|
+
|
|
143
|
+
| Option | Alias | Description | Required | Default | Env |
|
|
144
|
+
| --------------------- | ----- | ----------------- | -------- | ------- | ------------------------- |
|
|
145
|
+
| `--profile <PROFILE>` | `-p` | Workspace profile | No | - | `TAILOR_PLATFORM_PROFILE` |
|
|
146
|
+
|
|
122
147
|
See [Global Options](../cli-reference.md#global-options) for options available to all commands.
|
|
123
148
|
|
|
124
149
|
### user list
|
|
@@ -128,9 +153,15 @@ List all users.
|
|
|
128
153
|
**Usage**
|
|
129
154
|
|
|
130
155
|
```
|
|
131
|
-
tailor user list
|
|
156
|
+
tailor user list [options]
|
|
132
157
|
```
|
|
133
158
|
|
|
159
|
+
**Options**
|
|
160
|
+
|
|
161
|
+
| Option | Alias | Description | Required | Default | Env |
|
|
162
|
+
| --------------------- | ----- | ----------------- | -------- | ------- | ------------------------- |
|
|
163
|
+
| `--profile <PROFILE>` | `-p` | Workspace profile | No | - | `TAILOR_PLATFORM_PROFILE` |
|
|
164
|
+
|
|
134
165
|
See [Global Options](../cli-reference.md#global-options) for options available to all commands.
|
|
135
166
|
|
|
136
167
|
### user pat
|
|
@@ -172,9 +203,10 @@ tailor user pat create [options] <name>
|
|
|
172
203
|
|
|
173
204
|
**Options**
|
|
174
205
|
|
|
175
|
-
| Option
|
|
176
|
-
|
|
|
177
|
-
| `--write`
|
|
206
|
+
| Option | Alias | Description | Required | Default | Env |
|
|
207
|
+
| --------------------- | ----- | ------------------------------------------- | -------- | ------- | ------------------------- |
|
|
208
|
+
| `--write` | `-W` | Grant write permission (default: read-only) | No | `false` | - |
|
|
209
|
+
| `--profile <PROFILE>` | `-p` | Workspace profile | No | - | `TAILOR_PLATFORM_PROFILE` |
|
|
178
210
|
|
|
179
211
|
See [Global Options](../cli-reference.md#global-options) for options available to all commands.
|
|
180
212
|
|
|
@@ -185,7 +217,7 @@ Delete a personal access token.
|
|
|
185
217
|
**Usage**
|
|
186
218
|
|
|
187
219
|
```
|
|
188
|
-
tailor user pat delete <name>
|
|
220
|
+
tailor user pat delete [options] <name>
|
|
189
221
|
```
|
|
190
222
|
|
|
191
223
|
**Arguments**
|
|
@@ -194,6 +226,12 @@ tailor user pat delete <name>
|
|
|
194
226
|
| -------- | ----------- | -------- |
|
|
195
227
|
| `name` | Token name | Yes |
|
|
196
228
|
|
|
229
|
+
**Options**
|
|
230
|
+
|
|
231
|
+
| Option | Alias | Description | Required | Default | Env |
|
|
232
|
+
| --------------------- | ----- | ----------------- | -------- | ------- | ------------------------- |
|
|
233
|
+
| `--profile <PROFILE>` | `-p` | Workspace profile | No | - | `TAILOR_PLATFORM_PROFILE` |
|
|
234
|
+
|
|
197
235
|
See [Global Options](../cli-reference.md#global-options) for options available to all commands.
|
|
198
236
|
|
|
199
237
|
#### user pat list
|
|
@@ -208,10 +246,11 @@ tailor user pat list [options]
|
|
|
208
246
|
|
|
209
247
|
**Options**
|
|
210
248
|
|
|
211
|
-
| Option
|
|
212
|
-
|
|
|
213
|
-
| `--order <ORDER>`
|
|
214
|
-
| `--limit <LIMIT>`
|
|
249
|
+
| Option | Alias | Description | Required | Default | Env |
|
|
250
|
+
| --------------------- | ----- | -------------------------------------------------------- | -------- | -------- | ------------------------- |
|
|
251
|
+
| `--order <ORDER>` | - | Sort order (asc or desc) | No | `"desc"` | - |
|
|
252
|
+
| `--limit <LIMIT>` | `-l` | Maximum number of items to return (0 or omit: unlimited) | No | - | - |
|
|
253
|
+
| `--profile <PROFILE>` | `-p` | Workspace profile | No | - | `TAILOR_PLATFORM_PROFILE` |
|
|
215
254
|
|
|
216
255
|
See [Global Options](../cli-reference.md#global-options) for options available to all commands.
|
|
217
256
|
|
|
@@ -233,9 +272,10 @@ tailor user pat update [options] <name>
|
|
|
233
272
|
|
|
234
273
|
**Options**
|
|
235
274
|
|
|
236
|
-
| Option
|
|
237
|
-
|
|
|
238
|
-
| `--write`
|
|
275
|
+
| Option | Alias | Description | Required | Default | Env |
|
|
276
|
+
| --------------------- | ----- | ---------------------------------------------------------- | -------- | ------- | ------------------------- |
|
|
277
|
+
| `--write` | `-W` | Grant write permission (if not specified, keeps read-only) | No | `false` | - |
|
|
278
|
+
| `--profile <PROFILE>` | `-p` | Workspace profile | No | - | `TAILOR_PLATFORM_PROFILE` |
|
|
239
279
|
|
|
240
280
|
See [Global Options](../cli-reference.md#global-options) for options available to all commands.
|
|
241
281
|
|
|
@@ -246,7 +286,7 @@ Set current user.
|
|
|
246
286
|
**Usage**
|
|
247
287
|
|
|
248
288
|
```
|
|
249
|
-
tailor user switch <user>
|
|
289
|
+
tailor user switch [options] <user>
|
|
250
290
|
```
|
|
251
291
|
|
|
252
292
|
**Arguments**
|
|
@@ -255,22 +295,45 @@ tailor user switch <user>
|
|
|
255
295
|
| -------- | -------------------------------------------- | -------- |
|
|
256
296
|
| `user` | User email address or machine user client ID | Yes |
|
|
257
297
|
|
|
298
|
+
**Options**
|
|
299
|
+
|
|
300
|
+
| Option | Alias | Description | Required | Default | Env |
|
|
301
|
+
| --------------------- | ----- | ----------------- | -------- | ------- | ------------------------- |
|
|
302
|
+
| `--profile <PROFILE>` | `-p` | Workspace profile | No | - | `TAILOR_PLATFORM_PROFILE` |
|
|
303
|
+
|
|
258
304
|
See [Global Options](../cli-reference.md#global-options) for options available to all commands.
|
|
259
305
|
When no subcommand is provided, defaults to `list`.
|
|
260
306
|
|
|
261
307
|
**Output (default):**
|
|
262
308
|
|
|
263
309
|
```
|
|
264
|
-
|
|
265
|
-
|
|
310
|
+
┌──────────────┬────────────┬──────────────┬──────────────┐
|
|
311
|
+
│ name │ scopes │ createdAt │ lastUsedAt │
|
|
312
|
+
├──────────────┼────────────┼──────────────┼──────────────┤
|
|
313
|
+
│ token-name-1 │ read/write │ 8 months ago │ 6 months ago │
|
|
314
|
+
│ token-name-2 │ read │ 8 months ago │ never │
|
|
315
|
+
└──────────────┴────────────┴──────────────┴──────────────┘
|
|
266
316
|
```
|
|
267
317
|
|
|
318
|
+
`lastUsedAt` reads `never` until the token has been used to authenticate, and is
|
|
319
|
+
updated at most once per hour.
|
|
320
|
+
|
|
268
321
|
**Output (`-j, --json`):**
|
|
269
322
|
|
|
270
323
|
```json
|
|
271
324
|
[
|
|
272
|
-
{
|
|
273
|
-
|
|
325
|
+
{
|
|
326
|
+
"name": "token-name-1",
|
|
327
|
+
"scopes": ["read", "write"],
|
|
328
|
+
"createdAt": "2026-01-02T03:04:05.000Z",
|
|
329
|
+
"lastUsedAt": "2026-03-04T05:06:07.000Z"
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
"name": "token-name-2",
|
|
333
|
+
"scopes": ["read"],
|
|
334
|
+
"createdAt": "2026-01-02T03:04:05.000Z",
|
|
335
|
+
"lastUsedAt": null
|
|
336
|
+
}
|
|
274
337
|
]
|
|
275
338
|
```
|
|
276
339
|
|
package/docs/cli-reference.md
CHANGED
|
@@ -231,6 +231,7 @@ Commands for authentication and user management.
|
|
|
231
231
|
| [login](./cli/user.md#login) | Login to Tailor Platform. |
|
|
232
232
|
| [logout](./cli/user.md#logout) | Logout from Tailor Platform. |
|
|
233
233
|
| [auth](./cli/user.md#auth) | Authentication helpers for scripts and plugins. |
|
|
234
|
+
| [auth status](./cli/user.md#auth-status) | Show the active Tailor Platform authentication status without printing tokens. |
|
|
234
235
|
| [auth token](./cli/user.md#auth-token) | Print a valid Tailor Platform access token to stdout, refreshing it first if expired. |
|
|
235
236
|
| [user](./cli/user.md#user) | Manage Tailor Platform users. |
|
|
236
237
|
| [user current](./cli/user.md#user-current) | Show current user. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tailor-platform/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.0",
|
|
4
4
|
"description": "Tailor Platform SDK - The SDK to work with Tailor Platform",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -184,9 +184,9 @@
|
|
|
184
184
|
"inflection": "3.0.2",
|
|
185
185
|
"kysely": "0.29.5",
|
|
186
186
|
"mime-types": "3.0.2",
|
|
187
|
-
"open": "11.0.
|
|
187
|
+
"open": "11.0.2",
|
|
188
188
|
"oxc-parser": "0.147.0",
|
|
189
|
-
"p-limit": "7.3.
|
|
189
|
+
"p-limit": "7.3.2",
|
|
190
190
|
"pathe": "2.0.3",
|
|
191
191
|
"pgsql-ast-parser": "12.0.2",
|
|
192
192
|
"pkg-types": "2.3.1",
|
|
@@ -196,9 +196,9 @@
|
|
|
196
196
|
"sql-highlight": "6.1.0",
|
|
197
197
|
"std-env": "4.2.0",
|
|
198
198
|
"ts-cron-validator": "1.1.5",
|
|
199
|
-
"type-fest": "5.
|
|
199
|
+
"type-fest": "5.9.0",
|
|
200
200
|
"xdg-basedir": "5.1.0",
|
|
201
|
-
"zod": "4.4
|
|
201
|
+
"zod": "4.5.4"
|
|
202
202
|
},
|
|
203
203
|
"devDependencies": {
|
|
204
204
|
"@opentelemetry/sdk-trace-base": "2.10.0",
|
|
@@ -209,7 +209,7 @@
|
|
|
209
209
|
"@types/semver": "7.8.0",
|
|
210
210
|
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
211
211
|
"@vitest/coverage-v8": "4.1.11",
|
|
212
|
-
"eslint-plugin-zod": "4.
|
|
212
|
+
"eslint-plugin-zod": "4.12.0",
|
|
213
213
|
"oxfmt": "0.65.0",
|
|
214
214
|
"oxlint": "1.80.0",
|
|
215
215
|
"oxlint-tsgolint": "7.0.2001",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,t}from"./application-CcrP-v7z.mjs";export{t as defineApplication,e as generatePluginFilesIfNeeded};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./multiline-EyzjEwn9.mjs";import{n as t,t as n}from"./field-column-type-QMtF6lUp.mjs";function getEnumType(e){let t=e.allowedValues;return t&&Array.isArray(t)?t.map(e=>`"${typeof e==`string`?e:e.value}"`).join(` | `):`string`}function getNestedType(e){let t=e.fields;if(!t||typeof t!=`object`)return{type:`string`,usedUtilityTypes:{Timestamp:!1,Serial:!1}};let n=Object.entries(t).map(([e,t])=>{let n=generateFieldType(t);return{fieldType:`${e}${t.required===!0?``:`?`}: ${n.type}`,usedUtilityTypes:n.usedUtilityTypes}}),r=n.reduce((e,t)=>({Timestamp:e.Timestamp||t.usedUtilityTypes.Timestamp,Serial:e.Serial||t.usedUtilityTypes.Serial}),{Timestamp:!1,Serial:!1}),i=n.map(e=>e.fieldType),a=`{\n ${i.join(`;
|
|
2
|
-
`)}${i.length>0?`;`:``}\n}`,o=Object.values(t).some(e=>e.required!==!0),s=Object.values(t).some(e=>e.hooks?.create||e.default!==void 0||e.optionalOnCreate===!0);return r.Timestamp||o||s?{type:`ObjectColumnType<${a}>`,usedUtilityTypes:r}:{type:a,usedUtilityTypes:r}}function getBaseType(e){let n=e.type,r={Timestamp:!1,Serial:!1};if(n===`enum`)return{type:getEnumType(e),usedUtilityTypes:r};if(n===`nested`)return getNestedType(e);let i=t(n);return r.Timestamp=i===`Timestamp`,{type:i,usedUtilityTypes:r}}function generateFieldType(e){let t=getBaseType(e),r={...t.usedUtilityTypes},i=e.array===!0,a=e.required!==!0,o=n.has(t.type),s=t.type;return i&&(s=o||s.startsWith(`ObjectColumnType<`)?`ArrayColumnType<${t.type}>`:e.type===`enum`?`(${t.type})[]`:`${t.type}[]`),a&&(s=`${s} | null`),e.serial&&(r.Serial=!0,s=`Serial<${s}>`),(e.hooks?.create||e.default!==void 0||e.optionalOnCreate===!0)&&(s=`Generated<${s}>`),{type:s,usedUtilityTypes:r}}function generateTableInterface(t,n){let r=Object.entries(n).filter(([e])=>e!==`id`).map(([e,t])=>({fieldName:e,...generateFieldType(t)})),i=[`id: Generated<string>;`,...r.map(e=>`${e.fieldName}: ${e.type};`)],a=r.reduce((e,t)=>({Timestamp:e.Timestamp||t.usedUtilityTypes.Timestamp,Serial:e.Serial||t.usedUtilityTypes.Serial}),{Timestamp:!1,Serial:!1});return{typeDef:e`
|
|
3
|
-
${t}: {
|
|
4
|
-
${i.join(`
|
|
5
|
-
`)}
|
|
6
|
-
}
|
|
7
|
-
`,usedUtilityTypes:a}}function processKyselyFields(e,t){let n=generateTableInterface(e,t);return{name:e,typeDef:n.typeDef,usedUtilityTypes:n.usedUtilityTypes}}async function processKyselyType(e){return processKyselyFields(e.name,Object.fromEntries(Object.entries(e.fields).map(([e,t])=>[e,t.config])))}function generateUnifiedKyselyTypes(t){if(t.length===0)return``;let n=t.reduce((e,t)=>({Timestamp:e.Timestamp||t.usedUtilityTypes.Timestamp,Serial:e.Serial||t.usedUtilityTypes.Serial}),{Timestamp:!1,Serial:!1}),r=[`type Generated`];return n.Timestamp&&r.push(`type Timestamp`),t.some(e=>e.types.some(e=>e.typeDef.includes(`ObjectColumnType<`)))&&r.push(`type ObjectColumnType`),t.some(e=>e.types.some(e=>e.typeDef.includes(`ArrayColumnType<`)))&&r.push(`type ArrayColumnType`),n.Serial&&r.push(`type Serial`),[e`
|
|
8
|
-
import {
|
|
9
|
-
createGetDB,
|
|
10
|
-
${r.join(`,
|
|
11
|
-
`)},
|
|
12
|
-
type NamespaceDB,
|
|
13
|
-
type NamespaceInsertable,
|
|
14
|
-
type NamespaceSelectable,
|
|
15
|
-
type NamespaceTable,
|
|
16
|
-
type NamespaceTableName,
|
|
17
|
-
type NamespaceTransaction,
|
|
18
|
-
type NamespaceUpdateable,
|
|
19
|
-
} from "@tailor-platform/sdk/kysely";
|
|
20
|
-
`,`export interface Namespace {\n${t.map(({namespace:e,types:t})=>` "${e}": {\n${t.map(e=>e.typeDef.split(`
|
|
21
|
-
`).map(e=>e.trim()?` ${e}`:``).join(`
|
|
22
|
-
`)).join(`
|
|
23
|
-
|
|
24
|
-
`)}\n }`).join(`,
|
|
25
|
-
`)}\n}`,e`
|
|
26
|
-
export const getDB = createGetDB<Namespace>();
|
|
27
|
-
|
|
28
|
-
export type DB<N extends keyof Namespace = keyof Namespace> = NamespaceDB<Namespace, N>;
|
|
29
|
-
`,e`
|
|
30
|
-
export type Transaction<K extends keyof Namespace | DB = keyof Namespace> =
|
|
31
|
-
NamespaceTransaction<Namespace, K>;
|
|
32
|
-
|
|
33
|
-
type TableName = NamespaceTableName<Namespace>;
|
|
34
|
-
export type Table<T extends TableName> = NamespaceTable<Namespace, T>;
|
|
35
|
-
|
|
36
|
-
export type Insertable<T extends TableName> = NamespaceInsertable<Namespace, T>;
|
|
37
|
-
export type Selectable<T extends TableName> = NamespaceSelectable<Namespace, T>;
|
|
38
|
-
export type Updateable<T extends TableName> = NamespaceUpdateable<Namespace, T>;
|
|
39
|
-
`].join(`
|
|
40
|
-
|
|
41
|
-
`)+`
|
|
42
|
-
`}const r=`@tailor-platform/kysely-type`,i=`./generated/tailordb.ts`;function kyselyTypePlugin(e){return{id:r,description:`Generates Kysely type definitions for TailorDB tables`,pluginConfig:e,async onTailorDBReady(e){let t=[];for(let n of e.tailordb){let e=[];for(let t of Object.values(n.tables)){let n=await processKyselyType(t);e.push(n)}if(e.length===0)continue;let r=e.reduce((e,t)=>({Timestamp:e.Timestamp||t.usedUtilityTypes.Timestamp,Serial:e.Serial||t.usedUtilityTypes.Serial}),{Timestamp:!1,Serial:!1});t.push({namespace:n.namespace,types:e,usedUtilityTypes:r})}let n=[];if(t.length>0){let r=generateUnifiedKyselyTypes(t);n.push({path:e.pluginConfig.distPath,content:r})}return{files:n}}}}export{processKyselyFields as a,generateUnifiedKyselyTypes as i,r as n,kyselyTypePlugin as r,i as t};
|
|
43
|
-
//# sourceMappingURL=kysely-type-CmvAz1Xj.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kysely-type-CmvAz1Xj.mjs","names":[],"sources":["../src/plugin/builtin/kysely-type/type-processor.ts","../src/plugin/builtin/kysely-type/index.ts"],"sourcesContent":["import { COLUMN_TYPE_ALIASES, mapFieldTypeToColumnType } from \"#/utils/field-column-type\";\nimport multiline from \"#/utils/multiline\";\nimport {\n type KyselyFieldConfig,\n type KyselyNamespaceMetadata,\n type KyselyTypeMetadata,\n} from \"./types\";\nimport type { TailorDBType } from \"#/parser/service/tailordb/types\";\n\ntype UsedUtilityTypes = { Timestamp: boolean; Serial: boolean };\n\ntype FieldTypeResult = {\n type: string;\n usedUtilityTypes: UsedUtilityTypes;\n};\n\n/**\n * Get the enum type definition.\n * @param fieldConfig - The field configuration\n * @returns The enum type as a string union\n */\nfunction getEnumType(fieldConfig: KyselyFieldConfig): string {\n const allowedValues = fieldConfig.allowedValues;\n\n if (allowedValues && Array.isArray(allowedValues)) {\n return allowedValues\n .map((v: string | { value: string }) => {\n const value = typeof v === \"string\" ? v : v.value;\n return `\"${value}\"`;\n })\n .join(\" | \");\n }\n return \"string\";\n}\n\n/**\n * Get the nested object type definition.\n * @param fieldConfig - The field configuration\n * @returns The nested type with used utility types\n */\nfunction getNestedType(fieldConfig: KyselyFieldConfig): FieldTypeResult {\n const fields = fieldConfig.fields;\n if (!fields || typeof fields !== \"object\") {\n return {\n type: \"string\",\n usedUtilityTypes: { Timestamp: false, Serial: false },\n };\n }\n\n const fieldResults = Object.entries(fields).map(([fieldName, config]) => {\n const result = generateFieldType(config);\n const optional = config.required !== true ? \"?\" : \"\";\n return {\n fieldType: `${fieldName}${optional}: ${result.type}`,\n usedUtilityTypes: result.usedUtilityTypes,\n };\n });\n\n const aggregatedUtilityTypes = fieldResults.reduce(\n (acc, result) => ({\n Timestamp: acc.Timestamp || result.usedUtilityTypes.Timestamp,\n Serial: acc.Serial || result.usedUtilityTypes.Serial,\n }),\n { Timestamp: false, Serial: false },\n );\n\n const fieldTypes = fieldResults.map((r) => r.fieldType);\n const obj = `{\\n ${fieldTypes.join(\";\\n \")}${fieldTypes.length > 0 ? \";\" : \"\"}\\n}`;\n\n const hasOptionalFields = Object.values(fields).some((config) => config.required !== true);\n const hasGeneratedFields = Object.values(fields).some(\n (config) =>\n config.hooks?.create || config.default !== undefined || config.optionalOnCreate === true,\n );\n if (aggregatedUtilityTypes.Timestamp || hasOptionalFields || hasGeneratedFields) {\n return { type: `ObjectColumnType<${obj}>`, usedUtilityTypes: aggregatedUtilityTypes };\n }\n return { type: obj, usedUtilityTypes: aggregatedUtilityTypes };\n}\n\n/**\n * Get the base Kysely type for a field (without array/null modifiers).\n * @param fieldConfig - The field configuration\n * @returns The base type with used utility types\n */\nfunction getBaseType(fieldConfig: KyselyFieldConfig): FieldTypeResult {\n const fieldType = fieldConfig.type;\n const usedUtilityTypes = { Timestamp: false, Serial: false };\n\n if (fieldType === \"enum\") {\n return { type: getEnumType(fieldConfig), usedUtilityTypes };\n }\n if (fieldType === \"nested\") {\n return getNestedType(fieldConfig);\n }\n\n const type = mapFieldTypeToColumnType(fieldType);\n usedUtilityTypes.Timestamp = type === \"Timestamp\";\n\n return { type, usedUtilityTypes };\n}\n\n/**\n * Generate the complete field type including array and null modifiers.\n * @param fieldConfig - The field configuration\n * @returns The complete field type with used utility types\n */\nfunction generateFieldType(fieldConfig: KyselyFieldConfig): FieldTypeResult {\n const baseTypeResult = getBaseType(fieldConfig);\n const usedUtilityTypes = { ...baseTypeResult.usedUtilityTypes };\n\n const isArray = fieldConfig.array === true;\n const isNullable = fieldConfig.required !== true;\n\n // A ColumnType-shaped alias and ObjectColumnType cannot be wrapped with [] for\n // arrays, because Kysely only resolves ColumnType at the top-level table\n // property. Use ArrayColumnType to keep the ColumnType at the top level.\n const isColumnTypeBase = COLUMN_TYPE_ALIASES.has(baseTypeResult.type);\n\n let finalType = baseTypeResult.type;\n if (isArray) {\n if (isColumnTypeBase || finalType.startsWith(\"ObjectColumnType<\")) {\n finalType = `ArrayColumnType<${baseTypeResult.type}>`;\n } else {\n const needsParens = fieldConfig.type === \"enum\";\n finalType = needsParens ? `(${baseTypeResult.type})[]` : `${baseTypeResult.type}[]`;\n }\n }\n if (isNullable) {\n finalType = `${finalType} | null`;\n }\n\n if (fieldConfig.serial) {\n usedUtilityTypes.Serial = true;\n finalType = `Serial<${finalType}>`;\n }\n if (\n fieldConfig.hooks?.create ||\n fieldConfig.default !== undefined ||\n fieldConfig.optionalOnCreate === true\n ) {\n finalType = `Generated<${finalType}>`;\n }\n\n return { type: finalType, usedUtilityTypes };\n}\n\n/**\n * Generate the table interface.\n * @param name - Table name\n * @param fields - Field configurations keyed by field name\n * @returns The type definition and used utility types\n */\nfunction generateTableInterface(\n name: string,\n fields: Record<string, KyselyFieldConfig>,\n): {\n typeDef: string;\n usedUtilityTypes: UsedUtilityTypes;\n} {\n const fieldEntries = Object.entries(fields).filter(([fieldName]) => fieldName !== \"id\");\n\n const fieldResults = fieldEntries.map(([fieldName, fieldConfig]) => ({\n fieldName,\n ...generateFieldType(fieldConfig),\n }));\n\n const fieldLines = [\n \"id: Generated<string>;\",\n ...fieldResults.map((result) => `${result.fieldName}: ${result.type};`),\n ];\n\n const aggregatedUtilityTypes = fieldResults.reduce(\n (acc, result) => ({\n Timestamp: acc.Timestamp || result.usedUtilityTypes.Timestamp,\n\n Serial: acc.Serial || result.usedUtilityTypes.Serial,\n }),\n { Timestamp: false, Serial: false },\n );\n\n const typeDef = multiline /* ts */ `\n ${name}: {\n ${fieldLines.join(\"\\n\")}\n }\n `;\n\n return { typeDef, usedUtilityTypes: aggregatedUtilityTypes };\n}\n\n/**\n * Generate KyselyTypeMetadata from field configurations.\n * @param name - Table name\n * @param fields - Field configurations keyed by field name\n * @returns Generated Kysely type metadata\n */\nexport function processKyselyFields(\n name: string,\n fields: Record<string, KyselyFieldConfig>,\n): KyselyTypeMetadata {\n const result = generateTableInterface(name, fields);\n\n return {\n name,\n typeDef: result.typeDef,\n usedUtilityTypes: result.usedUtilityTypes,\n };\n}\n\n/**\n * Convert a TailorDBType into KyselyTypeMetadata.\n * @param type - Parsed TailorDB table\n * @returns Generated Kysely type metadata\n */\nexport async function processKyselyType(type: TailorDBType): Promise<KyselyTypeMetadata> {\n return processKyselyFields(\n type.name,\n Object.fromEntries(\n Object.entries(type.fields).map(([fieldName, parsedField]) => [\n fieldName,\n parsedField.config,\n ]),\n ),\n );\n}\n\n/**\n * Generate unified types file from multiple namespaces.\n * @param namespaceData - Namespace metadata\n * @returns Generated types file contents\n */\nexport function generateUnifiedKyselyTypes(namespaceData: KyselyNamespaceMetadata[]): string {\n if (namespaceData.length === 0) {\n return \"\";\n }\n\n // Aggregate used utility types from all namespaces\n const globalUsedUtilityTypes = namespaceData.reduce(\n (acc, ns) => ({\n Timestamp: acc.Timestamp || ns.usedUtilityTypes.Timestamp,\n Serial: acc.Serial || ns.usedUtilityTypes.Serial,\n }),\n { Timestamp: false, Serial: false },\n );\n\n const utilityTypeImports: string[] = [\"type Generated\"];\n if (globalUsedUtilityTypes.Timestamp) {\n utilityTypeImports.push(\"type Timestamp\");\n }\n const hasObjectColumnType = namespaceData.some((ns) =>\n ns.types.some((t) => t.typeDef.includes(\"ObjectColumnType<\")),\n );\n if (hasObjectColumnType) {\n utilityTypeImports.push(\"type ObjectColumnType\");\n }\n const hasArrayColumnType = namespaceData.some((ns) =>\n ns.types.some((t) => t.typeDef.includes(\"ArrayColumnType<\")),\n );\n if (hasArrayColumnType) {\n utilityTypeImports.push(\"type ArrayColumnType\");\n }\n if (globalUsedUtilityTypes.Serial) {\n utilityTypeImports.push(\"type Serial\");\n }\n\n const importsSection = multiline /* ts */ `\n import {\n createGetDB,\n ${utilityTypeImports.join(\",\\n\")},\n type NamespaceDB,\n type NamespaceInsertable,\n type NamespaceSelectable,\n type NamespaceTable,\n type NamespaceTableName,\n type NamespaceTransaction,\n type NamespaceUpdateable,\n } from \"@tailor-platform/sdk/kysely\";\n `;\n\n // Generate Namespace interface with multiple namespaces\n const namespaceInterfaces = namespaceData\n .map(({ namespace, types }) => {\n const typeDefsWithIndent = types\n .map((type) => {\n return type.typeDef\n .split(\"\\n\")\n .map((line) => (line.trim() ? ` ${line}` : \"\"))\n .join(\"\\n\");\n })\n .join(\"\\n\\n\");\n\n return ` \"${namespace}\": {\\n${typeDefsWithIndent}\\n }`;\n })\n .join(\",\\n\");\n\n const namespaceInterface = `export interface Namespace {\\n${namespaceInterfaces}\\n}`;\n\n const getDBFunction = multiline /* ts */ `\n export const getDB = createGetDB<Namespace>();\n\n export type DB<N extends keyof Namespace = keyof Namespace> = NamespaceDB<Namespace, N>;\n `;\n\n const utilityTypeExports = multiline /* ts */ `\n export type Transaction<K extends keyof Namespace | DB = keyof Namespace> =\n NamespaceTransaction<Namespace, K>;\n\n type TableName = NamespaceTableName<Namespace>;\n export type Table<T extends TableName> = NamespaceTable<Namespace, T>;\n\n export type Insertable<T extends TableName> = NamespaceInsertable<Namespace, T>;\n export type Selectable<T extends TableName> = NamespaceSelectable<Namespace, T>;\n export type Updateable<T extends TableName> = NamespaceUpdateable<Namespace, T>;\n `;\n\n return (\n [importsSection, namespaceInterface, getDBFunction, utilityTypeExports].join(\"\\n\\n\") + \"\\n\"\n );\n}\n","import { processKyselyType, generateUnifiedKyselyTypes } from \"./type-processor\";\nimport type { Plugin, GeneratorResult, TailorDBReadyContext } from \"#/plugin/types\";\nimport type { KyselyTypeMetadata, KyselyNamespaceMetadata } from \"./types\";\n\n/** Unique identifier for the Kysely type generator plugin. */\nexport const KyselyGeneratorID = \"@tailor-platform/kysely-type\";\n\ntype KyselyTypePluginOptions = {\n distPath: string;\n};\n\n// Register this plugin's config type under its own id, via the package's\n// real public specifier, so callers can resolve it type-safely from a\n// `Plugin[]` array (see plugin/get-plugin-config.ts's resolvePluginConfig)\n// without importing KyselyTypePluginOptions, which stays unexported.\ndeclare module \"@tailor-platform/sdk/plugin\" {\n interface PluginConfigRegistry {\n \"@tailor-platform/kysely-type\": KyselyTypePluginOptions;\n }\n}\n\n/** Conventional output path used when `kyselyTypePlugin` has no `distPath` configured. */\nexport const DEFAULT_KYSELY_TYPES_DIST_PATH = \"./generated/tailordb.ts\";\n\n/**\n * Plugin that generates Kysely type definitions for TailorDB tables.\n * @param options - Plugin options\n * @param options.distPath - Output file path for generated types\n * @returns Plugin instance with onTailorDBReady hook\n */\nexport function kyselyTypePlugin(\n options: KyselyTypePluginOptions,\n): Plugin<unknown, KyselyTypePluginOptions> {\n return {\n id: KyselyGeneratorID,\n description: \"Generates Kysely type definitions for TailorDB tables\",\n pluginConfig: options,\n\n async onTailorDBReady(\n ctx: TailorDBReadyContext<KyselyTypePluginOptions>,\n ): Promise<GeneratorResult> {\n const allNamespaceData: KyselyNamespaceMetadata[] = [];\n\n for (const ns of ctx.tailordb) {\n const typeMetadataList: KyselyTypeMetadata[] = [];\n\n for (const type of Object.values(ns.tables)) {\n const metadata = await processKyselyType(type);\n typeMetadataList.push(metadata);\n }\n\n if (typeMetadataList.length === 0) continue;\n\n const usedUtilityTypes = typeMetadataList.reduce(\n (acc, type) => ({\n Timestamp: acc.Timestamp || type.usedUtilityTypes.Timestamp,\n Serial: acc.Serial || type.usedUtilityTypes.Serial,\n }),\n { Timestamp: false, Serial: false },\n );\n\n allNamespaceData.push({\n namespace: ns.namespace,\n types: typeMetadataList,\n usedUtilityTypes,\n });\n }\n\n const files: GeneratorResult[\"files\"] = [];\n if (allNamespaceData.length > 0) {\n const content = generateUnifiedKyselyTypes(allNamespaceData);\n files.push({\n path: ctx.pluginConfig.distPath,\n content,\n });\n }\n\n return { files };\n },\n };\n}\n"],"mappings":"yGAqBA,SAAS,YAAY,EAAwC,CAC3D,IAAM,EAAgB,EAAY,cAUlC,OARI,GAAiB,MAAM,QAAQ,CAAa,EACvC,EACJ,IAAK,GAEG,IADO,OAAO,GAAM,SAAW,EAAI,EAAE,MAC3B,EAClB,CAAC,CACD,KAAK,KAAK,EAER,QACT,CAOA,SAAS,cAAc,EAAiD,CACtE,IAAM,EAAS,EAAY,OAC3B,GAAI,CAAC,GAAU,OAAO,GAAW,SAC/B,MAAO,CACL,KAAM,SACN,iBAAkB,CAAE,UAAW,GAAO,OAAQ,EAAM,CACtD,EAGF,IAAM,EAAe,OAAO,QAAQ,CAAM,CAAC,CAAC,KAAK,CAAC,EAAW,KAAY,CACvE,IAAM,EAAS,kBAAkB,CAAM,EAEvC,MAAO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