appos 0.2.1 → 0.2.3-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.
Files changed (232) hide show
  1. package/dist/bin/auth-schema-7KeUwlcd.mjs +2 -0
  2. package/dist/bin/concurrently.mjs +2 -0
  3. package/dist/bin/event-v2sCJkNd.mjs +2 -0
  4. package/dist/bin/extract-blob-metadata-TqNd9w-6.mjs +2 -0
  5. package/dist/bin/generate-image-variant-D8H9FxgD.mjs +2 -0
  6. package/dist/bin/generate-preview-5jLZLX6I.mjs +2 -0
  7. package/dist/bin/main.mjs +362 -0
  8. package/dist/bin/purge-attachment-CMlJMNOk.mjs +2 -0
  9. package/dist/bin/purge-audit-logs-hd6q6vnR.mjs +2 -0
  10. package/dist/bin/purge-unattached-blobs-BYv5b9R9.mjs +2 -0
  11. package/dist/bin/track-db-changes-q0Vl7Htm.mjs +2 -0
  12. package/dist/bin/vite.mjs +2 -0
  13. package/dist/bin/vitest.mjs +2 -0
  14. package/dist/bin/workflow-BagSlsMp.mjs +2 -0
  15. package/dist/bin/youch-handler-Jj6i1XIT.mjs +2 -0
  16. package/dist/exports/api/_virtual/rolldown_runtime.mjs +1 -0
  17. package/dist/exports/api/app-context.d.mts +115 -0
  18. package/dist/exports/api/app-context.mjs +1 -0
  19. package/dist/exports/api/auth-schema.d.mts +4248 -0
  20. package/dist/exports/api/auth-schema.mjs +1 -0
  21. package/dist/exports/api/auth.d.mts +398 -0
  22. package/dist/exports/api/auth.mjs +1 -0
  23. package/dist/exports/api/cache.d.mts +44 -0
  24. package/dist/exports/api/cache.mjs +1 -0
  25. package/dist/exports/api/config.d.mts +28 -0
  26. package/dist/exports/api/config.mjs +1 -0
  27. package/dist/exports/api/container.d.mts +210 -0
  28. package/dist/exports/api/container.mjs +1 -0
  29. package/dist/exports/api/database.d.mts +99 -0
  30. package/dist/exports/api/database.mjs +1 -0
  31. package/dist/exports/api/event.d.mts +235 -0
  32. package/dist/exports/api/event.mjs +1 -0
  33. package/dist/exports/api/i18n.d.mts +34 -0
  34. package/dist/exports/api/i18n.mjs +1 -0
  35. package/dist/exports/api/index.d.mts +21 -0
  36. package/dist/exports/api/index.mjs +1 -0
  37. package/dist/exports/api/logger.d.mts +21 -0
  38. package/dist/exports/api/logger.mjs +1 -0
  39. package/dist/exports/api/mailer.d.mts +70 -0
  40. package/dist/exports/api/mailer.mjs +1 -0
  41. package/dist/exports/api/middleware/request-logger.d.mts +24 -0
  42. package/dist/exports/api/middleware.d.mts +39 -0
  43. package/dist/exports/api/middleware.mjs +1 -0
  44. package/dist/exports/api/node_modules/.bun/change-case@5.4.4/node_modules/change-case/dist/index.mjs +1 -0
  45. package/dist/exports/api/openapi.d.mts +271 -0
  46. package/dist/exports/api/openapi.mjs +1 -0
  47. package/dist/exports/api/orm.d.mts +13 -0
  48. package/dist/exports/api/orm.mjs +1 -0
  49. package/dist/exports/api/otel.d.mts +40 -0
  50. package/dist/exports/api/otel.mjs +1 -0
  51. package/dist/exports/api/packages/appos/src/constants.mjs +1 -0
  52. package/dist/exports/api/packages/appos/src/instrumentation.d.mts +7 -0
  53. package/dist/exports/api/packages/appos/src/instrumentation.mjs +1 -0
  54. package/dist/exports/api/packages/appos/src/web/auth.mjs +1 -0
  55. package/dist/exports/api/redis.d.mts +34 -0
  56. package/dist/exports/api/redis.mjs +1 -0
  57. package/dist/exports/api/storage-schema.d.mts +707 -0
  58. package/dist/exports/api/storage-schema.mjs +1 -0
  59. package/dist/exports/api/storage.d.mts +506 -0
  60. package/dist/exports/api/storage.mjs +1 -0
  61. package/dist/exports/api/workflow.d.mts +250 -0
  62. package/dist/exports/api/workflow.mjs +1 -0
  63. package/dist/exports/api/workflows/_virtual/rolldown_runtime.mjs +1 -0
  64. package/dist/exports/api/workflows/auth-schema.mjs +1 -0
  65. package/dist/exports/api/workflows/auth.d.mts +375 -0
  66. package/dist/exports/api/workflows/cache.d.mts +44 -0
  67. package/dist/exports/api/workflows/config.d.mts +18 -0
  68. package/dist/exports/api/workflows/container.d.mts +167 -0
  69. package/dist/exports/api/workflows/database.d.mts +46 -0
  70. package/dist/exports/api/workflows/event.d.mts +68 -0
  71. package/dist/exports/api/workflows/event.mjs +1 -0
  72. package/dist/exports/api/workflows/extract-blob-metadata.mjs +1 -0
  73. package/dist/exports/api/workflows/generate-image-variant.d.mts +63 -0
  74. package/dist/exports/api/workflows/generate-image-variant.mjs +1 -0
  75. package/dist/exports/api/workflows/generate-preview.mjs +1 -0
  76. package/dist/exports/api/workflows/index.d.mts +2 -0
  77. package/dist/exports/api/workflows/index.mjs +1 -0
  78. package/dist/exports/api/workflows/logger.d.mts +21 -0
  79. package/dist/exports/api/workflows/mailer.d.mts +70 -0
  80. package/dist/exports/api/workflows/orm.d.mts +13 -0
  81. package/dist/exports/api/workflows/purge-attachment.mjs +1 -0
  82. package/dist/exports/api/workflows/purge-audit-logs.mjs +1 -0
  83. package/dist/exports/api/workflows/purge-unattached-blobs.mjs +1 -0
  84. package/dist/exports/api/workflows/redis.mjs +1 -0
  85. package/dist/exports/api/workflows/storage-schema.d.mts +699 -0
  86. package/dist/exports/api/workflows/storage.d.mts +396 -0
  87. package/dist/exports/api/workflows/track-db-changes.d.mts +72 -0
  88. package/dist/exports/api/workflows/track-db-changes.mjs +1 -0
  89. package/dist/exports/api/workflows/workflow.d.mts +24 -0
  90. package/dist/exports/api/workflows/workflow.mjs +1 -0
  91. package/dist/exports/cli/_virtual/rolldown_runtime.mjs +1 -0
  92. package/dist/exports/cli/api/auth-schema.mjs +1 -0
  93. package/dist/exports/cli/api/auth.d.mts +375 -0
  94. package/dist/exports/cli/api/cache.d.mts +44 -0
  95. package/dist/exports/cli/api/config.d.mts +18 -0
  96. package/dist/exports/cli/api/container.d.mts +167 -0
  97. package/dist/exports/cli/api/database.d.mts +46 -0
  98. package/dist/exports/cli/api/event.d.mts +68 -0
  99. package/dist/exports/cli/api/event.mjs +1 -0
  100. package/dist/exports/cli/api/logger.d.mts +21 -0
  101. package/dist/exports/cli/api/mailer.d.mts +70 -0
  102. package/dist/exports/cli/api/orm.d.mts +13 -0
  103. package/dist/exports/cli/api/redis.mjs +1 -0
  104. package/dist/exports/cli/api/storage-schema.d.mts +699 -0
  105. package/dist/exports/cli/api/storage.d.mts +396 -0
  106. package/dist/exports/cli/api/workflow.d.mts +2 -0
  107. package/dist/exports/cli/api/workflow.mjs +1 -0
  108. package/dist/exports/cli/api/workflows/extract-blob-metadata.mjs +1 -0
  109. package/dist/exports/cli/api/workflows/generate-image-variant.d.mts +63 -0
  110. package/dist/exports/cli/api/workflows/generate-image-variant.mjs +1 -0
  111. package/dist/exports/cli/api/workflows/generate-preview.mjs +1 -0
  112. package/dist/exports/cli/api/workflows/purge-attachment.mjs +1 -0
  113. package/dist/exports/cli/api/workflows/purge-audit-logs.mjs +1 -0
  114. package/dist/exports/cli/api/workflows/purge-unattached-blobs.mjs +1 -0
  115. package/dist/exports/cli/api/workflows/track-db-changes.mjs +1 -0
  116. package/dist/exports/cli/command.d.mts +54 -0
  117. package/dist/exports/cli/command.mjs +1 -0
  118. package/dist/exports/cli/context.d.mts +170 -0
  119. package/dist/exports/cli/index.d.mts +3 -0
  120. package/dist/exports/cli/index.mjs +1 -0
  121. package/dist/exports/devtools/index.d.ts +3 -0
  122. package/dist/exports/devtools/index.js +1 -0
  123. package/dist/exports/instrumentation.d.mts +1 -0
  124. package/dist/exports/instrumentation.mjs +1 -0
  125. package/dist/exports/tests/_virtual/rolldown_runtime.mjs +1 -0
  126. package/dist/exports/tests/api.d.mts +86 -0
  127. package/dist/exports/tests/api.mjs +1 -0
  128. package/dist/exports/tests/mock.d.mts +1 -0
  129. package/dist/exports/tests/mock.mjs +1 -0
  130. package/dist/exports/tests/node_modules/.bun/change-case@5.4.4/node_modules/change-case/dist/index.mjs +1 -0
  131. package/dist/exports/tests/node_modules/.bun/rate-limit-redis@4.3.1_f1fa5524233c9c60/node_modules/rate-limit-redis/dist/index.mjs +25 -0
  132. package/dist/exports/tests/packages/appos/src/api/app-context.d.mts +115 -0
  133. package/dist/exports/tests/packages/appos/src/api/auth-schema.d.mts +4248 -0
  134. package/dist/exports/tests/packages/appos/src/api/auth-schema.mjs +1 -0
  135. package/dist/exports/tests/packages/appos/src/api/auth.d.mts +398 -0
  136. package/dist/exports/tests/packages/appos/src/api/cache.d.mts +44 -0
  137. package/dist/exports/tests/packages/appos/src/api/config.d.mts +28 -0
  138. package/dist/exports/tests/packages/appos/src/api/container.d.mts +210 -0
  139. package/dist/exports/tests/packages/appos/src/api/database.d.mts +99 -0
  140. package/dist/exports/tests/packages/appos/src/api/database.mjs +1 -0
  141. package/dist/exports/tests/packages/appos/src/api/event.d.mts +235 -0
  142. package/dist/exports/tests/packages/appos/src/api/event.mjs +1 -0
  143. package/dist/exports/tests/packages/appos/src/api/i18n.d.mts +34 -0
  144. package/dist/exports/tests/packages/appos/src/api/index.d.mts +27 -0
  145. package/dist/exports/tests/packages/appos/src/api/logger.d.mts +21 -0
  146. package/dist/exports/tests/packages/appos/src/api/mailer.d.mts +70 -0
  147. package/dist/exports/tests/packages/appos/src/api/middleware/error-handler.mjs +1 -0
  148. package/dist/exports/tests/packages/appos/src/api/middleware/health.mjs +1 -0
  149. package/dist/exports/tests/packages/appos/src/api/middleware/i18n.mjs +1 -0
  150. package/dist/exports/tests/packages/appos/src/api/middleware/request-logger.d.mts +24 -0
  151. package/dist/exports/tests/packages/appos/src/api/middleware/request-logger.mjs +1 -0
  152. package/dist/exports/tests/packages/appos/src/api/middleware/shutdown.mjs +1 -0
  153. package/dist/exports/tests/packages/appos/src/api/middleware/timeout.mjs +1 -0
  154. package/dist/exports/tests/packages/appos/src/api/middleware/youch-handler.mjs +1 -0
  155. package/dist/exports/tests/packages/appos/src/api/middleware.d.mts +39 -0
  156. package/dist/exports/tests/packages/appos/src/api/middleware.mjs +1 -0
  157. package/dist/exports/tests/packages/appos/src/api/openapi.d.mts +271 -0
  158. package/dist/exports/tests/packages/appos/src/api/orm.d.mts +13 -0
  159. package/dist/exports/tests/packages/appos/src/api/otel.d.mts +40 -0
  160. package/dist/exports/tests/packages/appos/src/api/redis.d.mts +34 -0
  161. package/dist/exports/tests/packages/appos/src/api/redis.mjs +1 -0
  162. package/dist/exports/tests/packages/appos/src/api/server.mjs +1 -0
  163. package/dist/exports/tests/packages/appos/src/api/storage-schema.d.mts +707 -0
  164. package/dist/exports/tests/packages/appos/src/api/storage.d.mts +506 -0
  165. package/dist/exports/tests/packages/appos/src/api/workflow.d.mts +250 -0
  166. package/dist/exports/tests/packages/appos/src/api/workflow.mjs +1 -0
  167. package/dist/exports/tests/packages/appos/src/api/workflows/extract-blob-metadata.mjs +1 -0
  168. package/dist/exports/tests/packages/appos/src/api/workflows/generate-image-variant.d.mts +99 -0
  169. package/dist/exports/tests/packages/appos/src/api/workflows/generate-image-variant.mjs +1 -0
  170. package/dist/exports/tests/packages/appos/src/api/workflows/generate-preview.mjs +1 -0
  171. package/dist/exports/tests/packages/appos/src/api/workflows/purge-attachment.mjs +1 -0
  172. package/dist/exports/tests/packages/appos/src/api/workflows/purge-audit-logs.mjs +1 -0
  173. package/dist/exports/tests/packages/appos/src/api/workflows/purge-unattached-blobs.mjs +1 -0
  174. package/dist/exports/tests/packages/appos/src/api/workflows/track-db-changes.mjs +1 -0
  175. package/dist/exports/tests/packages/appos/src/constants.mjs +1 -0
  176. package/dist/exports/tests/packages/appos/src/instrumentation.d.mts +7 -0
  177. package/dist/exports/tests/packages/appos/src/instrumentation.mjs +1 -0
  178. package/dist/exports/tests/react.d.mts +2 -0
  179. package/dist/exports/tests/react.mjs +1 -0
  180. package/dist/exports/tests/setup.d.mts +1 -0
  181. package/dist/exports/tests/setup.mjs +1 -0
  182. package/dist/exports/vendors/date.js +1 -0
  183. package/dist/exports/vendors/toolkit.js +1 -0
  184. package/dist/exports/vendors/zod.d.ts +1 -0
  185. package/dist/exports/vendors/zod.js +1 -0
  186. package/dist/exports/vite/index.d.mts +19 -0
  187. package/dist/exports/vite/index.mjs +1 -0
  188. package/dist/exports/vitest/config.d.mts +1 -0
  189. package/dist/exports/vitest/config.mjs +1 -0
  190. package/dist/exports/vitest/globals.d.mts +1 -0
  191. package/dist/exports/vitest/globals.mjs +1 -0
  192. package/dist/exports/vitest/index.d.mts +1 -0
  193. package/dist/exports/vitest/index.mjs +1 -0
  194. package/dist/exports/web/api/auth.d.ts +125 -0
  195. package/dist/exports/web/api/database.d.ts +4 -0
  196. package/dist/exports/web/api/logger.d.ts +1 -0
  197. package/dist/exports/web/auth.d.ts +2388 -0
  198. package/dist/exports/web/auth.js +1 -0
  199. package/dist/exports/web/i18n.d.ts +42 -0
  200. package/dist/exports/web/i18n.js +1 -0
  201. package/dist/exports/web/index.d.ts +6 -0
  202. package/dist/exports/web/index.js +1 -0
  203. package/package.json +138 -98
  204. package/build/bin/main.mjs +0 -2
  205. package/build/exports/cli/index.d.mts +0 -325
  206. package/build/exports/cli/index.mjs +0 -1
  207. package/build/exports/instrumentation/execAsync-DaIUcs6_.mjs +0 -1
  208. package/build/exports/instrumentation/getMachineId-bsd-bB6ipDhm.mjs +0 -1
  209. package/build/exports/instrumentation/getMachineId-darwin-D1Bx5aCe.mjs +0 -2
  210. package/build/exports/instrumentation/getMachineId-linux-D_R9Tla0.mjs +0 -1
  211. package/build/exports/instrumentation/getMachineId-unsupported-BZKPE_Ev.mjs +0 -1
  212. package/build/exports/instrumentation/getMachineId-win-CmPvIqHL.mjs +0 -1
  213. package/build/exports/instrumentation/instrumentation.d.mts +0 -1
  214. package/build/exports/instrumentation/instrumentation.mjs +0 -80
  215. package/build/exports/server/index.d.mts +0 -327
  216. package/build/exports/server/index.mjs +0 -219
  217. package/build/exports/server/react-gPO8Jsy-.mjs +0 -13
  218. package/build/exports/server/server.node-D_9RYjm9.mjs +0 -210
  219. package/build/exports/store/index.d.mts +0 -58
  220. package/build/exports/store/index.mjs +0 -15
  221. package/build/exports/support/datetime.js +0 -1
  222. package/build/exports/support/utils.js +0 -1
  223. package/build/exports/support/zod.d.ts +0 -2
  224. package/build/exports/support/zod.js +0 -23
  225. package/build/exports/test/dist-DAsoCGWk.mjs +0 -348
  226. package/build/exports/test/index.d.mts +0 -3
  227. package/build/exports/test/index.mjs +0 -1
  228. package/build/exports/test/magic-string.es-BWgiB2kd.mjs +0 -14
  229. package/build/exports/test/setup.d.mts +0 -1
  230. package/build/exports/test/setup.mjs +0 -329
  231. /package/{build/exports/support/datetime.d.ts → dist/exports/vendors/date.d.ts} +0 -0
  232. /package/{build/exports/support/utils.d.ts → dist/exports/vendors/toolkit.d.ts} +0 -0
@@ -0,0 +1,396 @@
1
+ import { StorageBlob, StorageRelationsConfig, StorageTables } from "./storage-schema.mjs";
2
+ import { ImageTransformations, transformationsSchema } from "./generate-image-variant.mjs";
3
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
4
+ import { Pool } from "pg";
5
+ import { DriveManager } from "flydrive";
6
+ import { FSDriverOptions } from "flydrive/drivers/fs/types";
7
+ import { S3DriverOptions } from "flydrive/drivers/s3/types";
8
+
9
+ //#region src/api/storage.d.ts
10
+
11
+ /**
12
+ * Database type with storage schema and relations.
13
+ */
14
+ type DatabaseWithStorage = NodePgDatabase<StorageTables, StorageRelationsConfig> & {
15
+ $client: Pool;
16
+ };
17
+ /**
18
+ * Type of the storage service instance.
19
+ */
20
+ type Storage<TDisks extends Record<string, FSDriverOptions | S3DriverOptions> = Record<string, FSDriverOptions | S3DriverOptions>, TTableNames extends string = string, TAttachments extends Partial<Record<TTableNames, readonly string[]>> = Record<never, never>> = StorageService<Extract<keyof TDisks, string>, TTableNames, TAttachments>;
21
+ /**
22
+ * Helper type to extract attachment name for a specific table.
23
+ */
24
+ type AttachmentName<TAttachments extends Partial<Record<string, readonly string[]>>, TTable extends string> = TTable extends keyof TAttachments ? TAttachments[TTable] extends readonly (infer N)[] ? N : string : string;
25
+ /**
26
+ * Storage service for blob operations.
27
+ *
28
+ * This service uses a dual-drive architecture when configured:
29
+ * - `drive`: For actual file operations (upload, delete, read) using internal endpoints
30
+ * - `signedUrlDrive`: For generating browser-accessible signed URLs with public endpoints
31
+ *
32
+ * This allows containers to use fast internal network for operations while
33
+ * generating URLs that work in end-user browsers.
34
+ *
35
+ * @template TDiskNames - Union of disk names (e.g., "private" | "public")
36
+ * @template TTableNames - Union of table names for type-safe attachment methods
37
+ * @template TAttachments - Mapping of table names to valid attachment names
38
+ */
39
+ declare class StorageService<TDiskNames extends string = string, TTableNames extends string = string, TAttachments extends Partial<Record<TTableNames, readonly string[]>> = Record<never, never>> {
40
+ /**
41
+ * The drive manager for file operations.
42
+ */
43
+ readonly drive: DriveManager<any>;
44
+ /**
45
+ * The database instance with storage schema and relations.
46
+ */
47
+ readonly db: DatabaseWithStorage;
48
+ /**
49
+ * The default disk name.
50
+ */
51
+ readonly defaultDisk: TDiskNames;
52
+ /**
53
+ * Cron expression for unattached blob purge schedule.
54
+ *
55
+ * @default "0 0 * * *"
56
+ */
57
+ readonly purgeCron?: string;
58
+ /**
59
+ * Secret key for signing blob IDs.
60
+ */
61
+ readonly secret?: string;
62
+ /**
63
+ * Drive manager for generating signed URLs (public endpoint).
64
+ */
65
+ readonly signedUrlDrive: DriveManager<any>;
66
+ constructor(drive: DriveManager<any>, db: DatabaseWithStorage, defaultDisk: TDiskNames, signedUrlDrive: DriveManager<any>, purgeCron?: string, secret?: string);
67
+ /**
68
+ * Create a blob record and upload file.
69
+ */
70
+ createBlob(file: Buffer | Uint8Array, options: {
71
+ filename: string;
72
+ contentType?: string;
73
+ metadata?: Record<string, any>;
74
+ serviceName?: TDiskNames;
75
+ prefix?: string;
76
+ }): Promise<StorageBlob>;
77
+ /**
78
+ * Get blob by ID.
79
+ */
80
+ getBlob(id: string): Promise<StorageBlob | null>;
81
+ /**
82
+ * Download blob content.
83
+ */
84
+ downloadBlob(id: string): Promise<Buffer | null>;
85
+ /**
86
+ * Delete blob and its content.
87
+ */
88
+ deleteBlob(id: string): Promise<boolean>;
89
+ /**
90
+ * Get signed URL for blob. If blob is on public service, returns permanent
91
+ * URL instead.
92
+ */
93
+ getSignedUrl(id: string, options?: {
94
+ expiresIn?: number;
95
+ disposition?: "inline" | "attachment";
96
+ filename?: string;
97
+ }): Promise<string | null>;
98
+ /**
99
+ * Get permanent public URL (no expiration).
100
+ * Works for blobs on public storage service.
101
+ */
102
+ getPublicUrl(id: string): Promise<string | null>;
103
+ /**
104
+ * Create attachment between a record and blob.
105
+ *
106
+ * @param recordType - The table name (e.g., 'users')
107
+ * @param recordId - The record ID
108
+ * @param blobId - The blob ID to attach
109
+ * @param name - The attachment name (e.g., 'avatar')
110
+ * @param replaceExisting - If true, replaces existing attachment with same name (for one-to-one)
111
+ */
112
+ createAttachment(recordType: string, recordId: string, blobId: string, name: string, replaceExisting?: boolean): Promise<{
113
+ id: string;
114
+ createdAt: string;
115
+ name: string;
116
+ recordType: string;
117
+ recordId: string;
118
+ blobId: string;
119
+ }>;
120
+ /**
121
+ * Get attachments for a record with their associated blobs.
122
+ */
123
+ getAttachments(recordType: string, recordId: string, name?: string): Promise<{
124
+ id: string;
125
+ createdAt: string;
126
+ name: string;
127
+ recordType: string;
128
+ recordId: string;
129
+ blobId: string;
130
+ blob: {
131
+ metadata: unknown;
132
+ id: string;
133
+ key: string;
134
+ filename: string;
135
+ contentType: string | null;
136
+ serviceName: string;
137
+ byteSize: number;
138
+ checksum: string | null;
139
+ createdAt: string;
140
+ } | null;
141
+ }[]>;
142
+ /**
143
+ * Get attachments by their IDs with associated blobs.
144
+ *
145
+ * @param attachmentIds - Array of attachment IDs to fetch.
146
+ */
147
+ getAttachmentsByIds(attachmentIds: string[]): Promise<{
148
+ id: string;
149
+ createdAt: string;
150
+ name: string;
151
+ recordType: string;
152
+ recordId: string;
153
+ blobId: string;
154
+ blob: {
155
+ metadata: unknown;
156
+ id: string;
157
+ key: string;
158
+ filename: string;
159
+ contentType: string | null;
160
+ serviceName: string;
161
+ byteSize: number;
162
+ checksum: string | null;
163
+ createdAt: string;
164
+ } | null;
165
+ }[]>;
166
+ /**
167
+ * Delete a single attachment by ID.
168
+ */
169
+ deleteAttachment(attachmentId: string): Promise<boolean>;
170
+ /**
171
+ * Delete attachments for a record (without deleting the blobs).
172
+ */
173
+ deleteAttachments(recordType: string, recordId: string, name?: string): Promise<number>;
174
+ /**
175
+ * Get direct upload credentials (for S3). Also creates a pending blob record
176
+ * that will be finalized after upload.
177
+ */
178
+ getDirectUploadUrl(options: {
179
+ contentType?: string;
180
+ expiresIn?: number;
181
+ filename: string;
182
+ metadata?: Record<string, any>;
183
+ serviceName?: TDiskNames;
184
+ }): Promise<{
185
+ blobId: string;
186
+ headers?: Record<string, string>;
187
+ key: string;
188
+ url: string;
189
+ } | null>;
190
+ /**
191
+ * Finalize a direct upload by updating blob metadata. Call this after the
192
+ * client has uploaded to S3.
193
+ */
194
+ finalizeDirectUpload(blobId: string, actualSize: number): Promise<void>;
195
+ /**
196
+ * Update blob metadata (for automatic extraction).
197
+ */
198
+ updateBlobMetadata(blobId: string, metadata: Record<string, any>): Promise<void>;
199
+ /**
200
+ * Get existing variant or return null.
201
+ */
202
+ getVariant(blobId: string, transformations: ImageTransformations): Promise<StorageBlob | null>;
203
+ /**
204
+ * Create variant blob and record.
205
+ */
206
+ createVariant(blobId: string, transformations: ImageTransformations, variantBuffer: Buffer): Promise<StorageBlob>;
207
+ /**
208
+ * Get blobs that have no attachments (orphaned). Useful for cleanup jobs.
209
+ */
210
+ getUnattachedBlobs(options?: {
211
+ olderThan?: string;
212
+ limit?: number;
213
+ }): Promise<StorageBlob[]>;
214
+ /**
215
+ * Get pending blobs that were never finalized (stuck direct uploads).
216
+ */
217
+ getPendingBlobs(olderThan?: string): Promise<StorageBlob[]>;
218
+ /**
219
+ * Purge unattached blobs.
220
+ */
221
+ purgeUnattached(olderThan?: string): Promise<number>;
222
+ /**
223
+ * Create a signed, tamper-proof reference to a blob.
224
+ * Use findSigned() to resolve back to blob.
225
+ *
226
+ * Algorithm:
227
+ * 1. Create payload with blobId and expiration timestamp
228
+ * 2. JSON stringify and base64url encode the payload
229
+ * 3. Create HMAC-SHA256 signature of the encoded payload
230
+ * 4. Return payload.signature format
231
+ */
232
+ signedId(blobId: string, expiresIn?: number): string;
233
+ /**
234
+ * Find blob by signed ID. Returns null if invalid or expired.
235
+ * Uses constant-time comparison to prevent timing attacks.
236
+ *
237
+ * Algorithm:
238
+ * 1. Split signed ID into payload and signature
239
+ * 2. Decode and recompute expected signature
240
+ * 3. Use timingSafeEqual for constant-time comparison
241
+ * 4. Check expiration timestamp
242
+ * 5. Return blob if valid, null otherwise
243
+ */
244
+ findSigned(signedId: string): Promise<StorageBlob | null>;
245
+ /**
246
+ * Get a single attachment handle (one-to-one relationship).
247
+ * Similar to Rails' `has_one_attached :avatar`.
248
+ *
249
+ * Algorithm:
250
+ * Returns an object with methods to manage a single attachment:
251
+ * - attach(): Replace existing attachment with new blob
252
+ * - get(): Get attached blob or null
253
+ * - url(): Get signed URL
254
+ * - variant(): Get/generate image variant
255
+ * - purge(): Delete attachment and blob
256
+ *
257
+ * @template TTable - The table name (must be in TTableNames)
258
+ */
259
+ one<TTable extends TTableNames>(recordType: TTable, recordId: string, name: AttachmentName<TAttachments, TTable>): {
260
+ /**
261
+ * Attach a blob to this record (replaces existing).
262
+ * Auto-triggers extractBlobMetadata workflow.
263
+ */
264
+ attach(blobId: string): Promise<{
265
+ id: string;
266
+ createdAt: string;
267
+ name: string;
268
+ recordType: string;
269
+ recordId: string;
270
+ blobId: string;
271
+ }>;
272
+ /** Get the attached blob or null. */
273
+ get(): Promise<StorageBlob | null>;
274
+ /** Check if a blob is attached. */
275
+ attached(): Promise<boolean>;
276
+ /** Get signed URL or null. */
277
+ url(options?: {
278
+ expiresIn?: number;
279
+ disposition?: "inline" | "attachment";
280
+ }): Promise<string | null>;
281
+ /** Get permanent public URL or null. */
282
+ publicUrl(): Promise<string | null>;
283
+ /** Get blob metadata or null. */
284
+ metadata(): Promise<Record<string, unknown> | null>;
285
+ /** Check if metadata has been extracted. */
286
+ analyzed(): Promise<boolean>;
287
+ /** Check if blob supports preview/variant generation. */
288
+ representable(): Promise<boolean>;
289
+ /**
290
+ * Get variant URL. Auto-enqueues generation if not ready.
291
+ * Returns URL if variant exists, null if generating.
292
+ */
293
+ variant(transformations: ImageTransformations, expiresIn?: number): Promise<string | null>;
294
+ /**
295
+ * Get preview URL. Auto-enqueues generation if not ready.
296
+ * Returns URL if preview exists, null if generating.
297
+ */
298
+ preview(expiresIn?: number, timeInSeconds?: number): Promise<string | null>;
299
+ /** Detach blob from record (keeps blob for reuse). */
300
+ detach(): Promise<boolean>;
301
+ /** Delete attachment AND blob immediately. */
302
+ purge(): Promise<boolean>;
303
+ /** Enqueue attachment and blob deletion in background. */
304
+ purgeLater(): Promise<boolean>;
305
+ /** Download blob content as Buffer. */
306
+ download(): Promise<Buffer | null>;
307
+ /** Download to temp file, run callback, auto-cleanup. */
308
+ open<T>(callback: (filePath: string) => Promise<T> | T): Promise<T | null>;
309
+ /**
310
+ * Smart representation - variant for images, preview for videos/PDFs.
311
+ * Auto-enqueues generation if not ready.
312
+ */
313
+ representation(transformations: ImageTransformations, expiresIn?: number): Promise<string | null>;
314
+ /** Get blob's byte size. */
315
+ byteSize(): Promise<number | null>;
316
+ /** Get blob's content type. */
317
+ contentType(): Promise<string | null>;
318
+ /** Get blob's filename. */
319
+ filename(): Promise<string | null>;
320
+ /** Get signed, tamper-proof ID for the blob. */
321
+ signedId(expiresIn?: number): Promise<string | null>;
322
+ };
323
+ /**
324
+ * Get a multiple attachment handle (one-to-many relationship).
325
+ * Similar to Rails' `has_many_attached :images`.
326
+ *
327
+ * Algorithm:
328
+ * Returns an object with methods to manage multiple attachments:
329
+ * - attach(): Add blobs (doesn't replace existing)
330
+ * - list(): Get all attached blobs
331
+ * - urls(): Get signed URLs for all
332
+ * - variants(): Get/generate variants for all
333
+ * - purge(): Delete all or specific attachment
334
+ *
335
+ * @template TTable - The table name (must be in TTableNames)
336
+ */
337
+ many<TTable extends TTableNames>(recordType: TTable, recordId: string, name: AttachmentName<TAttachments, TTable>): {
338
+ /**
339
+ * Attach one or more blobs (adds to existing, doesn't replace).
340
+ * Auto-triggers extractBlobMetadata for each blob.
341
+ */
342
+ attach(blobIds: string | string[]): Promise<{
343
+ id: string;
344
+ createdAt: string;
345
+ name: string;
346
+ recordType: string;
347
+ recordId: string;
348
+ blobId: string;
349
+ }[]>;
350
+ /** Get all attached blobs. */
351
+ list(): Promise<StorageBlob[]>;
352
+ /** Count attached blobs. */
353
+ count(): Promise<number>;
354
+ /** Get signed URLs for all blobs. */
355
+ urls(options?: {
356
+ expiresIn?: number;
357
+ }): Promise<string[]>;
358
+ /** Get public URLs for all blobs. */
359
+ publicUrls(): Promise<(string | null)[]>;
360
+ /** Get metadata for all blobs. */
361
+ metadata(): Promise<(Record<string, unknown> | null)[]>;
362
+ /** Check which blobs have been analyzed. */
363
+ analyzed(): Promise<boolean[]>;
364
+ /** Check which blobs support preview/variants. */
365
+ representable(): Promise<boolean[]>;
366
+ /** Get variant URLs for all blobs. Auto-enqueues if not ready. */
367
+ variants(transformations: ImageTransformations, expiresIn?: number): Promise<(string | null)[]>;
368
+ /** Get preview URLs for all blobs. Auto-enqueues if not ready. */
369
+ previews(expiresIn?: number, timeInSeconds?: number): Promise<(string | null)[]>;
370
+ /** Detach specific blob or all blobs (keeps blobs for reuse). */
371
+ detach(blobId?: string): Promise<number>;
372
+ /** Delete specific or all attachments AND blobs immediately. */
373
+ purge(blobId?: string): Promise<number>;
374
+ /** Enqueue specific or all attachments for background deletion. */
375
+ purgeLater(blobId?: string): Promise<number>;
376
+ /** Download all blobs as Buffers. */
377
+ download(): Promise<Buffer[]>;
378
+ /** Download each blob to temp file, run callback for each. */
379
+ open<T>(callback: (filePath: string, blob: StorageBlob) => Promise<T> | T): Promise<T[]>;
380
+ /**
381
+ * Smart representations - variant for images, preview for videos/PDFs.
382
+ * Auto-enqueues generation if not ready.
383
+ */
384
+ representations(transformations: ImageTransformations, expiresIn?: number): Promise<(string | null)[]>;
385
+ /** Get byte sizes for all blobs. */
386
+ byteSizes(): Promise<number[]>;
387
+ /** Get content types for all blobs. */
388
+ contentTypes(): Promise<(string | null)[]>;
389
+ /** Get filenames for all blobs. */
390
+ filenames(): Promise<string[]>;
391
+ /** Get signed IDs for all blobs. */
392
+ signedIds(expiresIn?: number): Promise<string[]>;
393
+ };
394
+ }
395
+ //#endregion
396
+ export { Storage };
@@ -0,0 +1,72 @@
1
+ import { WorkflowHandle } from "./workflow.mjs";
2
+ import { Container } from "./container.mjs";
3
+ import { z } from "zod";
4
+ import * as _dbos_inc_dbos_sdk0 from "@dbos-inc/dbos-sdk";
5
+
6
+ //#region src/api/workflows/track-db-changes.d.ts
7
+ /**
8
+ * Input schema for trackDbChanges workflow.
9
+ * Accepts dbChanges() output directly from .returning() clause.
10
+ */
11
+ declare const trackDbChangesInputSchema: z.ZodObject<{
12
+ changes: z.ZodArray<z.ZodObject<{
13
+ _table: z.ZodString;
14
+ old: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
15
+ new: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
16
+ }, z.core.$strip>>;
17
+ dbName: z.ZodString;
18
+ organizationId: z.ZodNullable<z.ZodString>;
19
+ requestId: z.ZodString;
20
+ sessionId: z.ZodNullable<z.ZodString>;
21
+ userId: z.ZodNullable<z.ZodString>;
22
+ }, z.core.$strip>;
23
+ type TrackDbChangesInput = z.infer<typeof trackDbChangesInputSchema>;
24
+ /**
25
+ * Built-in workflow for processing database changes.
26
+ * Handles audit logging and pub/sub notifications with type-safe table filtering.
27
+ *
28
+ * Algorithm:
29
+ * 1. For each change in input, infer the action (INSERT/UPDATE/DELETE)
30
+ * 2. If table is not excluded from audit logging:
31
+ * - Insert into audit_logs table with full context
32
+ * 3. Emit to dbChangesEvent (publishes via Redis if subscribed handlers exist)
33
+ *
34
+ * Filtering is configured via:
35
+ * - `container.auth.shouldAudit()` - Check if table should be audited
36
+ *
37
+ * @returns Object with counts: processed (total changes), audited (logged to audit_logs), published (emitted to event)
38
+ */
39
+ declare const trackDbChanges: {
40
+ inputSchema: z.ZodObject<{
41
+ changes: z.ZodArray<z.ZodObject<{
42
+ _table: z.ZodString;
43
+ old: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
44
+ new: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
45
+ }, z.core.$strip>>;
46
+ dbName: z.ZodString;
47
+ organizationId: z.ZodNullable<z.ZodString>;
48
+ requestId: z.ZodString;
49
+ sessionId: z.ZodNullable<z.ZodString>;
50
+ userId: z.ZodNullable<z.ZodString>;
51
+ }, z.core.$strip>;
52
+ readonly name: string | null;
53
+ register(c: Container, name: string, dbos: typeof _dbos_inc_dbos_sdk0.DBOS): void;
54
+ start(input: {
55
+ changes: {
56
+ _table: string;
57
+ old: Record<string, unknown> | null;
58
+ new: Record<string, unknown> | null;
59
+ }[];
60
+ dbName: string;
61
+ organizationId: string | null;
62
+ requestId: string;
63
+ sessionId: string | null;
64
+ userId: string | null;
65
+ }): Promise<WorkflowHandle<{
66
+ processed: number;
67
+ audited: number;
68
+ published: number;
69
+ }>>;
70
+ };
71
+ //#endregion
72
+ export { TrackDbChangesInput, trackDbChanges };
@@ -0,0 +1 @@
1
+ import{defineAuthSchema as e}from"./auth-schema.mjs";import{dbChangesEvent as t}from"./event.mjs";import{defineWorkflow as n}from"./workflow.mjs";import{z as r}from"zod";const i=e(),a=r.object({changes:r.array(r.object({_table:r.string(),old:r.record(r.string(),r.unknown()).nullable(),new:r.record(r.string(),r.unknown()).nullable()})),dbName:r.string(),organizationId:r.string().nullable(),requestId:r.string(),sessionId:r.string().nullable(),userId:r.string().nullable()});function o(e){return e.old===null?`INSERT`:e.new===null?`DELETE`:`UPDATE`}const s=n({input:a,async run({container:e,step:n,input:r}){let{dbName:a,changes:s,organizationId:c,userId:l,sessionId:u,requestId:d}=r;if(s.length===0)return{processed:0,audited:0,published:0};let f=new Date().toISOString(),p=0,m=0;for(let r of s){let s=r._table,h=o(r),g=`${a}.${s}`;e.auth.shouldAudit(g)&&(await n(`audit:${g}`,async()=>{await e.db.primary.insert(i.tables.auditLogs).values({tableName:g,action:h,oldData:r.old,newData:r.new,organizationId:c,userId:l,sessionId:u,requestId:d,createdAt:f})}),p++),await n(`event:${g}`,async()=>{await t.emit({action:h,oldData:r.old,newData:r.new,organizationId:c,tableName:g,timestamp:f,userId:l})}),m++}return{processed:s.length,audited:p,published:m}}});export{s as trackDbChanges};
@@ -0,0 +1,24 @@
1
+ import "./container.mjs";
2
+ import { z } from "zod";
3
+
4
+ //#region src/api/workflow.d.ts
5
+
6
+ /**
7
+ * Handle to a running or completed workflow.
8
+ */
9
+ interface WorkflowHandle<TOutput> {
10
+ /**
11
+ * Get the current status of the workflow.
12
+ */
13
+ getStatus(): Promise<unknown>;
14
+ /**
15
+ * Wait for the workflow to complete and return its result.
16
+ */
17
+ getResult(): Promise<TOutput>;
18
+ /**
19
+ * The unique ID of this workflow execution.
20
+ */
21
+ workflowId: string;
22
+ }
23
+ //#endregion
24
+ export { WorkflowHandle };
@@ -0,0 +1 @@
1
+ import{join as e}from"node:path";import"es-toolkit";function t(e){let t=null,n=null,r=null,i=null,a=async i=>{if(!t||!r)throw Error(`Workflow "${n}" not registered`);let a=r,o=a.workflowID;if(!o)throw Error(`DBOS.workflowID is not available in this context`);let s={container:t,workflowId:o,input:i,step:(e,t)=>a.runStep(t,{name:e})};return e.run(s)};return{inputSchema:e.input,get name(){return n},register(o,s,c){t=o,n=s,r=c,i=c.registerWorkflow(a,{name:s,...e.config})},async start(t){if(!i||!n||!r)throw Error(`Workflow not registered. Ensure the worker is started before triggering workflows.`);let a=e.input.parse(t),o=await r.startWorkflow(i)(a);return{workflowId:o.workflowID,getStatus:()=>o.getStatus(),getResult:()=>o.getResult()}}}}function n(e){let t=null,n=null,r=null,i=async(i,a)=>{if(!t||!r)throw Error(`Workflow "${n}" not registered`);let o=r,s=o.workflowID;if(!s)throw Error(`DBOS.workflowID is not available in this context`);let c={container:t,workflowId:s,scheduledTime:i,step:(e,t)=>o.runStep(t,{name:e})};return e.run(c)};return{crontab:e.crontab,get name(){return n},register(a,o,s){t=a,n=o,r=s,s.registerScheduled(s.registerWorkflow(i,{name:o}),{crontab:e.crontab})}}}export{n as defineScheduledWorkflow,t as defineWorkflow};
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty,t=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,i=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n&&e(r,Symbol.toStringTag,{value:`Module`}),r},a=(i,a,o,s)=>{if(a&&typeof a==`object`||typeof a==`function`)for(var c=n(a),l=0,u=c.length,d;l<u;l++)d=c[l],!r.call(i,d)&&d!==o&&e(i,d,{get:(e=>a[e]).bind(null,d),enumerable:!(s=t(a,d))||s.enumerable});return i},o=(e,t,n)=>(a(e,t,`default`),n&&a(n,t,`default`));export{i as __export,o as __reExport};
@@ -0,0 +1 @@
1
+ import{sql as e}from"drizzle-orm";import{pgTable as t}from"drizzle-orm/pg-core";function n(){let n=t(`accounts`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),accessToken:t.text(`access_token`),accessTokenExpiresAt:t.timestamp(`access_token_expires_at`,{mode:`string`,withTimezone:!0}),accountId:t.text(`account_id`).notNull(),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),idToken:t.text(`id_token`),providerId:t.text(`provider_id`).notNull(),password:t.text(`password`),userId:t.text(`user_id`).notNull().references(()=>l.id,{onDelete:`cascade`}),refreshToken:t.text(`refresh_token`),refreshTokenExpiresAt:t.timestamp(`refresh_token_expires_at`,{mode:`string`,withTimezone:!0}),scope:t.text(`scope`),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull()}),e=>[]),r=t(`api_keys`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),name:t.text(`name`),enabled:t.boolean(`enabled`).default(!0),expiresAt:t.timestamp(`expires_at`,{mode:`string`,withTimezone:!0}),key:t.text(`key`).notNull(),lastRefillAt:t.timestamp(`last_refill_at`,{mode:`string`,withTimezone:!0}),lastRequest:t.timestamp(`last_request`,{mode:`string`,withTimezone:!0}),lastUsedAt:t.timestamp(`last_used_at`,{mode:`string`,withTimezone:!0}),metadata:t.text(`metadata`),permissions:t.text(`permissions`),prefix:t.text(`prefix`),rateLimitEnabled:t.boolean(`rate_limit_enabled`).default(!0),rateLimitTimeWindow:t.integer(`rate_limit_time_window`).default(864e5),rateLimitMax:t.integer(`rate_limit_max`).default(10),refillInterval:t.integer(`refill_interval`),refillAmount:t.integer(`refill_amount`),requestCount:t.integer(`request_count`),remaining:t.integer(`remaining`),start:t.text(`start`),userId:t.text(`user_id`).notNull().references(()=>l.id,{onDelete:`cascade`}),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull()}),e=>[]),i=t(`invitations`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),email:t.text(`email`).notNull(),expiresAt:t.timestamp(`expires_at`,{mode:`string`,withTimezone:!0}).notNull(),inviterId:t.text(`inviter_id`).notNull().references(()=>l.id,{onDelete:`cascade`}),organizationId:t.text(`organization_id`).notNull().references(()=>o.id,{onDelete:`cascade`}),role:t.text(`role`),status:t.text(`status`).default(`pending`).notNull(),teamId:t.text(`team_id`),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull()}),e=>[]),a=t(`members`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),organizationId:t.text(`organization_id`).notNull().references(()=>o.id,{onDelete:`cascade`}),role:t.text(`role`).default(`member`).notNull(),userId:t.text(`user_id`).notNull().references(()=>l.id,{onDelete:`cascade`}),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull()}),e=>[]),o=t(`organizations`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),name:t.text(`name`).notNull(),slug:t.text(`slug`).unique(),logo:t.text(`logo`),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),metadata:t.text(`metadata`)}),e=>[]),s=t(`sessions`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),activeOrganizationId:t.text(`active_organization_id`).references(()=>o.id,{onDelete:`set null`}),activeTeamId:t.text(`active_team_id`),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),expiresAt:t.timestamp(`expires_at`,{mode:`string`,withTimezone:!0}).notNull(),impersonatedBy:t.text(`impersonated_by`).references(()=>l.id,{onDelete:`set null`}),ipAddress:t.text(`ip_address`),token:t.text(`token`).notNull().unique(),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),userAgent:t.text(`user_agent`),userId:t.text(`user_id`).notNull().references(()=>l.id,{onDelete:`cascade`})}),e=>[]),c=t(`sso_providers`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),domain:t.text(`domain`).notNull(),issuer:t.text(`issuer`).notNull(),oidcConfig:t.text(`oidc_config`),organizationId:t.text(`organization_id`).references(()=>o.id,{onDelete:`cascade`}),providerId:t.text(`provider_id`).notNull().unique(),samlConfig:t.text(`saml_config`),userId:t.text(`user_id`).references(()=>l.id,{onDelete:`cascade`})}),e=>[]),l=t(`users`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),banExpires:t.timestamp(`ban_expires`,{mode:`string`,withTimezone:!0}),banReason:t.text(`ban_reason`),banned:t.boolean(`banned`).default(!1),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),displayUsername:t.text(`display_username`),email:t.text(`email`).notNull().unique(),emailVerified:t.boolean(`email_verified`).default(!1).notNull(),image:t.text(`image`),isAnonymous:t.boolean(`is_anonymous`),lastLoginMethod:t.text(`last_login_method`),name:t.text(`name`).notNull(),phoneNumber:t.text(`phone_number`).unique(),phoneNumberVerified:t.boolean(`phone_number_verified`),role:t.text(`role`),twoFactorEnabled:t.boolean(`two_factor_enabled`).default(!1),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),username:t.text(`username`).unique()}),e=>[]),u=t(`teams`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),name:t.text(`name`).notNull(),organizationId:t.text(`organization_id`).notNull().references(()=>o.id,{onDelete:`cascade`}),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull()}),e=>[]),d=t(`team_members`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),teamId:t.text(`team_id`).notNull().references(()=>u.id,{onDelete:`cascade`}),userId:t.text(`user_id`).notNull().references(()=>l.id,{onDelete:`cascade`}),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull()}),e=>[]),f=t(`two_factors`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),secret:t.text(`secret`).notNull(),backupCodes:t.text(`backup_codes`).notNull(),userId:t.text(`user_id`).notNull().references(()=>l.id,{onDelete:`cascade`})}),e=>[]),p=t(`verifications`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),expiresAt:t.timestamp(`expires_at`,{mode:`string`,withTimezone:!0}).notNull(),identifier:t.text(`identifier`).notNull(),updatedAt:t.timestamp(`updated_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull(),value:t.text(`value`).notNull()}),e=>[]);return{tables:{accounts:n,apiKeys:r,auditLogs:t(`audit_logs`,t=>({id:t.text(`id`).primaryKey().default(e`uuidv7()`),tableName:t.text(`table_name`),action:t.text(`action`).notNull(),customAction:t.text(`custom_action`),oldData:t.jsonb(`old_data`),newData:t.jsonb(`new_data`),metadata:t.jsonb(`metadata`),organizationId:t.text(`organization_id`).references(()=>o.id,{onDelete:`set null`}),userId:t.text(`user_id`).references(()=>l.id,{onDelete:`set null`}),sessionId:t.text(`session_id`).references(()=>s.id,{onDelete:`set null`}),requestId:t.text(`request_id`),createdAt:t.timestamp(`created_at`,{mode:`string`,withTimezone:!0}).default(e`NOW()`).notNull()}),e=>[]),invitations:i,members:a,organizations:o,sessions:s,ssoProviders:c,teams:u,teamMembers:d,twoFactors:f,users:l,verifications:p},relations:e=>({users:{sessions:e.many.sessions({from:e.users.id,to:e.sessions.userId}),accounts:e.many.accounts({from:e.users.id,to:e.accounts.userId}),apiKeys:e.many.apiKeys({from:e.users.id,to:e.apiKeys.userId}),memberships:e.many.members({from:e.users.id,to:e.members.userId}),invitations:e.many.invitations({from:e.users.id,to:e.invitations.inviterId}),ssoProvider:e.one.ssoProviders({from:e.users.id,to:e.ssoProviders.userId}),twoFactor:e.one.twoFactors({from:e.users.id,to:e.twoFactors.userId})},sessions:{user:e.one.users({from:e.sessions.userId,to:e.users.id})},accounts:{user:e.one.users({from:e.accounts.userId,to:e.users.id})},apiKeys:{user:e.one.users({from:e.apiKeys.userId,to:e.users.id})},organizations:{members:e.many.members({from:e.organizations.id,to:e.members.organizationId}),invitations:e.many.invitations({from:e.organizations.id,to:e.invitations.organizationId}),teams:e.many.teams({from:e.organizations.id,to:e.teams.organizationId})},members:{organization:e.one.organizations({from:e.members.organizationId,to:e.organizations.id}),user:e.one.users({from:e.members.userId,to:e.users.id})},invitations:{organization:e.one.organizations({from:e.invitations.organizationId,to:e.organizations.id}),inviter:e.one.users({from:e.invitations.inviterId,to:e.users.id})},teams:{organization:e.one.organizations({from:e.teams.organizationId,to:e.organizations.id})},ssoProviders:{user:e.one.users({from:e.ssoProviders.userId,to:e.users.id})},verifications:{},twoFactors:{user:e.one.users({from:e.twoFactors.userId,to:e.users.id})},auditLogs:{organization:e.one.organizations({from:e.auditLogs.organizationId,to:e.organizations.id}),user:e.one.users({from:e.auditLogs.userId,to:e.users.id}),session:e.one.sessions({from:e.auditLogs.sessionId,to:e.sessions.id})}})}}export{n as defineAuthSchema};