@mdxui/terminal 2.0.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/README.md +571 -0
- package/dist/ansi-css-Sk5mWtdK.d.ts +119 -0
- package/dist/ansi-css-V6JIHGsM.d.ts +119 -0
- package/dist/ansi-css-_3eSEU9d.d.ts +119 -0
- package/dist/chunk-3EFDH7PK.js +5235 -0
- package/dist/chunk-3RG5ZIWI.js +10 -0
- package/dist/chunk-3X5IR6WE.js +884 -0
- package/dist/chunk-4FV5ZDCE.js +5236 -0
- package/dist/chunk-4OVMSF2J.js +243 -0
- package/dist/chunk-63FEETIS.js +4048 -0
- package/dist/chunk-B43KP7XJ.js +884 -0
- package/dist/chunk-BMTJXWUV.js +655 -0
- package/dist/chunk-C3SVH4N7.js +882 -0
- package/dist/chunk-EVWR7Y47.js +874 -0
- package/dist/chunk-F6A5VWUC.js +1285 -0
- package/dist/chunk-FD7KW7GE.js +882 -0
- package/dist/chunk-GBQ6UD6I.js +655 -0
- package/dist/chunk-GMDD3M6U.js +5227 -0
- package/dist/chunk-JBHRXOXM.js +1058 -0
- package/dist/chunk-JFOO3EYO.js +1182 -0
- package/dist/chunk-JQ5H3WXL.js +1291 -0
- package/dist/chunk-JQD5NASE.js +234 -0
- package/dist/chunk-KRHJP5R7.js +592 -0
- package/dist/chunk-KWF6WVJE.js +962 -0
- package/dist/chunk-LHYQVN3H.js +1038 -0
- package/dist/chunk-M3TLQLGC.js +1032 -0
- package/dist/chunk-MVW4Q5OP.js +240 -0
- package/dist/chunk-NXCZSWLU.js +1294 -0
- package/dist/chunk-O25TNRO6.js +607 -0
- package/dist/chunk-PNECDA2I.js +884 -0
- package/dist/chunk-QIHWRLJR.js +962 -0
- package/dist/chunk-QW5YMQ7K.js +882 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-RP2MVQLR.js +962 -0
- package/dist/chunk-TP6RXGXA.js +1087 -0
- package/dist/chunk-TQQSTITZ.js +655 -0
- package/dist/chunk-X24GWXQV.js +1281 -0
- package/dist/components/index.d.ts +802 -0
- package/dist/components/index.js +149 -0
- package/dist/data/index.d.ts +2554 -0
- package/dist/data/index.js +51 -0
- package/dist/forms/index.d.ts +1596 -0
- package/dist/forms/index.js +464 -0
- package/dist/index-CQRFZntR.d.ts +867 -0
- package/dist/index.d.ts +579 -0
- package/dist/index.js +786 -0
- package/dist/interactive-D0JkWosD.d.ts +217 -0
- package/dist/keyboard/index.d.ts +2 -0
- package/dist/keyboard/index.js +43 -0
- package/dist/renderers/index.d.ts +546 -0
- package/dist/renderers/index.js +2157 -0
- package/dist/storybook/index.d.ts +396 -0
- package/dist/storybook/index.js +641 -0
- package/dist/theme/index.d.ts +1339 -0
- package/dist/theme/index.js +123 -0
- package/dist/types-Bxu5PAgA.d.ts +710 -0
- package/dist/types-CIlop5Ji.d.ts +701 -0
- package/dist/types-Ca8p_p5X.d.ts +710 -0
- package/package.json +90 -0
- package/src/__tests__/components/data/card.test.ts +458 -0
- package/src/__tests__/components/data/list.test.ts +473 -0
- package/src/__tests__/components/data/metrics.test.ts +541 -0
- package/src/__tests__/components/data/table.test.ts +448 -0
- package/src/__tests__/components/input/field.test.ts +555 -0
- package/src/__tests__/components/input/form.test.ts +870 -0
- package/src/__tests__/components/input/search.test.ts +1238 -0
- package/src/__tests__/components/input/select.test.ts +658 -0
- package/src/__tests__/components/navigation/breadcrumb.test.ts +923 -0
- package/src/__tests__/components/navigation/command-palette.test.ts +1095 -0
- package/src/__tests__/components/navigation/sidebar.test.ts +1018 -0
- package/src/__tests__/components/navigation/tabs.test.ts +995 -0
- package/src/__tests__/components.test.tsx +1197 -0
- package/src/__tests__/core/compiler.test.ts +986 -0
- package/src/__tests__/core/parser.test.ts +785 -0
- package/src/__tests__/core/tier-switcher.test.ts +1103 -0
- package/src/__tests__/core/types.test.ts +1398 -0
- package/src/__tests__/data/collections.test.ts +1337 -0
- package/src/__tests__/data/db.test.ts +1265 -0
- package/src/__tests__/data/reactive.test.ts +1010 -0
- package/src/__tests__/data/sync.test.ts +1614 -0
- package/src/__tests__/errors.test.ts +660 -0
- package/src/__tests__/forms/integration.test.ts +444 -0
- package/src/__tests__/integration.test.ts +905 -0
- package/src/__tests__/keyboard.test.ts +1791 -0
- package/src/__tests__/renderer.test.ts +489 -0
- package/src/__tests__/renderers/ansi-css.test.ts +948 -0
- package/src/__tests__/renderers/ansi.test.ts +1366 -0
- package/src/__tests__/renderers/ascii.test.ts +1360 -0
- package/src/__tests__/renderers/interactive.test.ts +2353 -0
- package/src/__tests__/renderers/markdown.test.ts +1483 -0
- package/src/__tests__/renderers/text.test.ts +1369 -0
- package/src/__tests__/renderers/unicode.test.ts +1307 -0
- package/src/__tests__/theme.test.ts +639 -0
- package/src/__tests__/utils/assertions.ts +685 -0
- package/src/__tests__/utils/index.ts +115 -0
- package/src/__tests__/utils/test-renderer.ts +381 -0
- package/src/__tests__/utils/utils.test.ts +560 -0
- package/src/components/containers/card.ts +56 -0
- package/src/components/containers/dialog.ts +53 -0
- package/src/components/containers/index.ts +9 -0
- package/src/components/containers/panel.ts +59 -0
- package/src/components/feedback/badge.ts +40 -0
- package/src/components/feedback/index.ts +8 -0
- package/src/components/feedback/spinner.ts +23 -0
- package/src/components/helpers.ts +81 -0
- package/src/components/index.ts +153 -0
- package/src/components/layout/breadcrumb.ts +31 -0
- package/src/components/layout/index.ts +10 -0
- package/src/components/layout/list.ts +29 -0
- package/src/components/layout/sidebar.ts +79 -0
- package/src/components/layout/table.ts +62 -0
- package/src/components/primitives/box.ts +95 -0
- package/src/components/primitives/button.ts +54 -0
- package/src/components/primitives/index.ts +11 -0
- package/src/components/primitives/input.ts +88 -0
- package/src/components/primitives/select.ts +97 -0
- package/src/components/primitives/text.ts +60 -0
- package/src/components/render.ts +155 -0
- package/src/components/templates/app.ts +43 -0
- package/src/components/templates/index.ts +8 -0
- package/src/components/templates/site.ts +54 -0
- package/src/components/types.ts +777 -0
- package/src/core/compiler.ts +718 -0
- package/src/core/parser.ts +127 -0
- package/src/core/tier-switcher.ts +607 -0
- package/src/core/types.ts +672 -0
- package/src/data/collection.ts +316 -0
- package/src/data/collections.ts +50 -0
- package/src/data/context.tsx +174 -0
- package/src/data/db.ts +127 -0
- package/src/data/hooks.ts +532 -0
- package/src/data/index.ts +138 -0
- package/src/data/reactive.ts +1225 -0
- package/src/data/saas-collections.ts +375 -0
- package/src/data/sync.ts +1213 -0
- package/src/data/types.ts +660 -0
- package/src/forms/converters.ts +512 -0
- package/src/forms/index.ts +133 -0
- package/src/forms/schemas.ts +403 -0
- package/src/forms/types.ts +476 -0
- package/src/index.ts +542 -0
- package/src/keyboard/focus.ts +748 -0
- package/src/keyboard/index.ts +96 -0
- package/src/keyboard/integration.ts +371 -0
- package/src/keyboard/manager.ts +377 -0
- package/src/keyboard/presets.ts +90 -0
- package/src/renderers/ansi-css.ts +576 -0
- package/src/renderers/ansi.ts +802 -0
- package/src/renderers/ascii.ts +680 -0
- package/src/renderers/breadcrumb.ts +480 -0
- package/src/renderers/command-palette.ts +802 -0
- package/src/renderers/components/field.ts +210 -0
- package/src/renderers/components/form.ts +327 -0
- package/src/renderers/components/index.ts +21 -0
- package/src/renderers/components/search.ts +449 -0
- package/src/renderers/components/select.ts +222 -0
- package/src/renderers/index.ts +101 -0
- package/src/renderers/interactive/component-handlers.ts +622 -0
- package/src/renderers/interactive/cursor-manager.ts +147 -0
- package/src/renderers/interactive/focus-manager.ts +279 -0
- package/src/renderers/interactive/index.ts +661 -0
- package/src/renderers/interactive/input-handler.ts +164 -0
- package/src/renderers/interactive/keyboard-handler.ts +212 -0
- package/src/renderers/interactive/mouse-handler.ts +167 -0
- package/src/renderers/interactive/state-manager.ts +109 -0
- package/src/renderers/interactive/types.ts +338 -0
- package/src/renderers/interactive-string.ts +299 -0
- package/src/renderers/interactive.ts +59 -0
- package/src/renderers/markdown.ts +950 -0
- package/src/renderers/sidebar.ts +549 -0
- package/src/renderers/tabs.ts +682 -0
- package/src/renderers/text.ts +791 -0
- package/src/renderers/unicode.ts +917 -0
- package/src/renderers/utils.ts +942 -0
- package/src/router/adapters.ts +383 -0
- package/src/router/types.ts +140 -0
- package/src/router/utils.ts +452 -0
- package/src/schemas.ts +205 -0
- package/src/storybook/index.ts +91 -0
- package/src/storybook/interactive-decorator.tsx +659 -0
- package/src/storybook/keyboard-simulator.ts +501 -0
- package/src/theme/ansi-codes.ts +80 -0
- package/src/theme/box-drawing.ts +132 -0
- package/src/theme/color-convert.ts +254 -0
- package/src/theme/color-support.ts +321 -0
- package/src/theme/index.ts +134 -0
- package/src/theme/strip-ansi.ts +50 -0
- package/src/theme/tailwind-map.ts +469 -0
- package/src/theme/text-styles.ts +206 -0
- package/src/theme/theme-system.ts +568 -0
- package/src/types.ts +103 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mdxui/terminal SaaS Collections
|
|
3
|
+
*
|
|
4
|
+
* Pre-built Zod schemas and collections for common SaaS primitives:
|
|
5
|
+
* - Users: Authentication and user management
|
|
6
|
+
* - APIKeys: API key management with permissions
|
|
7
|
+
* - Webhooks: Webhook configuration and event subscriptions
|
|
8
|
+
* - Teams: Team/organization management with members
|
|
9
|
+
* - Usage: Usage metrics tracking
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import {
|
|
14
|
+
* UsersCollection,
|
|
15
|
+
* APIKeysCollection,
|
|
16
|
+
* WebhooksCollection,
|
|
17
|
+
* TeamsCollection,
|
|
18
|
+
* UsageCollection,
|
|
19
|
+
* type User,
|
|
20
|
+
* type APIKey,
|
|
21
|
+
* } from '@mdxui/terminal'
|
|
22
|
+
*
|
|
23
|
+
* // Create collections
|
|
24
|
+
* const users = UsersCollection()
|
|
25
|
+
* const apiKeys = APIKeysCollection()
|
|
26
|
+
*
|
|
27
|
+
* // Insert data
|
|
28
|
+
* await users.insert({
|
|
29
|
+
* id: 'user-1',
|
|
30
|
+
* name: 'Alice',
|
|
31
|
+
* email: 'alice@example.com',
|
|
32
|
+
* role: 'admin',
|
|
33
|
+
* createdAt: new Date(),
|
|
34
|
+
* })
|
|
35
|
+
*
|
|
36
|
+
* // Query
|
|
37
|
+
* const admins = await users.findMany({
|
|
38
|
+
* where: { role: 'admin' }
|
|
39
|
+
* })
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
import { z } from 'zod'
|
|
44
|
+
import { createCollection } from './collection'
|
|
45
|
+
import type { Collection } from './types'
|
|
46
|
+
|
|
47
|
+
// ============================================================================
|
|
48
|
+
// Zod Schemas
|
|
49
|
+
// ============================================================================
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* User role enum - defines access levels
|
|
53
|
+
*/
|
|
54
|
+
export const UserRoleSchema = z.enum(['admin', 'user', 'viewer'])
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* User schema - validates user account information
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const user = UserSchema.parse({
|
|
62
|
+
* id: 'user-1',
|
|
63
|
+
* name: 'Alice',
|
|
64
|
+
* email: 'alice@example.com',
|
|
65
|
+
* role: 'admin',
|
|
66
|
+
* createdAt: new Date(),
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export const UserSchema = z.object({
|
|
71
|
+
/** Unique user identifier */
|
|
72
|
+
id: z.string(),
|
|
73
|
+
/** User's display name */
|
|
74
|
+
name: z.string(),
|
|
75
|
+
/** User's email address (validated format) */
|
|
76
|
+
email: z.string().email(),
|
|
77
|
+
/** User's role: admin, user, or viewer */
|
|
78
|
+
role: UserRoleSchema,
|
|
79
|
+
/** When the user account was created */
|
|
80
|
+
createdAt: z.date(),
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* APIKey schema - validates API key configuration
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const key = APIKeySchema.parse({
|
|
89
|
+
* id: 'key-1',
|
|
90
|
+
* key: 'sk_test_abc123',
|
|
91
|
+
* name: 'Development',
|
|
92
|
+
* permissions: ['read:api', 'write:webhooks'],
|
|
93
|
+
* expiresAt: new Date('2025-12-31'),
|
|
94
|
+
* })
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export const APIKeySchema = z.object({
|
|
98
|
+
/** Unique key identifier */
|
|
99
|
+
id: z.string(),
|
|
100
|
+
/** The actual API key string (secret) */
|
|
101
|
+
key: z.string(),
|
|
102
|
+
/** Human-readable name for the key */
|
|
103
|
+
name: z.string(),
|
|
104
|
+
/** Array of permission strings this key grants */
|
|
105
|
+
permissions: z.array(z.string()),
|
|
106
|
+
/** When the key expires */
|
|
107
|
+
expiresAt: z.date(),
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Webhook schema - validates webhook configuration
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const webhook = WebhookSchema.parse({
|
|
116
|
+
* id: 'webhook-1',
|
|
117
|
+
* url: 'https://example.com/webhook',
|
|
118
|
+
* events: ['user.created', 'user.updated'],
|
|
119
|
+
* secret: 'whsec_test_abc123',
|
|
120
|
+
* active: true,
|
|
121
|
+
* })
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export const WebhookSchema = z.object({
|
|
125
|
+
/** Unique webhook identifier */
|
|
126
|
+
id: z.string(),
|
|
127
|
+
/** Webhook endpoint URL (validated format) */
|
|
128
|
+
url: z.string().url(),
|
|
129
|
+
/** Events this webhook listens to (non-empty array) */
|
|
130
|
+
events: z.array(z.string()).min(1),
|
|
131
|
+
/** Webhook signing secret */
|
|
132
|
+
secret: z.string(),
|
|
133
|
+
/** Whether the webhook is currently active */
|
|
134
|
+
active: z.boolean(),
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Team schema - validates team configuration
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const team = TeamSchema.parse({
|
|
143
|
+
* id: 'team-1',
|
|
144
|
+
* name: 'Engineering',
|
|
145
|
+
* members: ['user-1', 'user-2', 'user-3'],
|
|
146
|
+
* })
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export const TeamSchema = z.object({
|
|
150
|
+
/** Unique team identifier */
|
|
151
|
+
id: z.string(),
|
|
152
|
+
/** Team name */
|
|
153
|
+
name: z.string(),
|
|
154
|
+
/** Array of user IDs who are members */
|
|
155
|
+
members: z.array(z.string()),
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Usage schema - validates usage metrics
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const usage = UsageSchema.parse({
|
|
164
|
+
* id: 'usage-1',
|
|
165
|
+
* metric: 'api_calls',
|
|
166
|
+
* value: 1500,
|
|
167
|
+
* timestamp: new Date(),
|
|
168
|
+
* })
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
export const UsageSchema = z.object({
|
|
172
|
+
/** Unique usage record identifier */
|
|
173
|
+
id: z.string(),
|
|
174
|
+
/** Name of the metric being tracked */
|
|
175
|
+
metric: z.string(),
|
|
176
|
+
/** Numeric value of the metric */
|
|
177
|
+
value: z.number(),
|
|
178
|
+
/** When this metric was recorded */
|
|
179
|
+
timestamp: z.date(),
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
// ============================================================================
|
|
183
|
+
// Type exports (inferred from schemas)
|
|
184
|
+
// ============================================================================
|
|
185
|
+
|
|
186
|
+
/** User type - inferred from UserSchema */
|
|
187
|
+
export type User = z.infer<typeof UserSchema>
|
|
188
|
+
|
|
189
|
+
/** APIKey type - inferred from APIKeySchema */
|
|
190
|
+
export type APIKey = z.infer<typeof APIKeySchema>
|
|
191
|
+
|
|
192
|
+
/** Webhook type - inferred from WebhookSchema */
|
|
193
|
+
export type Webhook = z.infer<typeof WebhookSchema>
|
|
194
|
+
|
|
195
|
+
/** Team type - inferred from TeamSchema */
|
|
196
|
+
export type Team = z.infer<typeof TeamSchema>
|
|
197
|
+
|
|
198
|
+
/** Usage type - inferred from UsageSchema */
|
|
199
|
+
export type Usage = z.infer<typeof UsageSchema>
|
|
200
|
+
|
|
201
|
+
/** User role type - admin, user, or viewer */
|
|
202
|
+
export type UserRole = z.infer<typeof UserRoleSchema>
|
|
203
|
+
|
|
204
|
+
// ============================================================================
|
|
205
|
+
// Collection Factory Functions
|
|
206
|
+
// ============================================================================
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Creates a Users collection with Zod validation
|
|
210
|
+
*
|
|
211
|
+
* @returns A typed Collection<User> for managing user accounts
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const users = UsersCollection()
|
|
216
|
+
*
|
|
217
|
+
* // Insert a user
|
|
218
|
+
* const user = await users.insert({
|
|
219
|
+
* id: 'user-1',
|
|
220
|
+
* name: 'Alice',
|
|
221
|
+
* email: 'alice@example.com',
|
|
222
|
+
* role: 'admin',
|
|
223
|
+
* createdAt: new Date(),
|
|
224
|
+
* })
|
|
225
|
+
*
|
|
226
|
+
* // Find admins
|
|
227
|
+
* const admins = await users.findMany({
|
|
228
|
+
* where: { role: 'admin' }
|
|
229
|
+
* })
|
|
230
|
+
*
|
|
231
|
+
* // Subscribe to changes
|
|
232
|
+
* const unsubscribe = users.subscribe((allUsers) => {
|
|
233
|
+
* console.log('Users changed:', allUsers.length)
|
|
234
|
+
* })
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
export function UsersCollection(): Collection<User> {
|
|
238
|
+
return createCollection<User>({
|
|
239
|
+
name: 'users',
|
|
240
|
+
schema: UserSchema,
|
|
241
|
+
primaryKey: 'id',
|
|
242
|
+
indexes: ['email', 'role'],
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Creates an APIKeys collection with Zod validation
|
|
248
|
+
*
|
|
249
|
+
* @returns A typed Collection<APIKey> for managing API keys
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* const apiKeys = APIKeysCollection()
|
|
254
|
+
*
|
|
255
|
+
* // Create a new key
|
|
256
|
+
* const key = await apiKeys.insert({
|
|
257
|
+
* id: 'key-1',
|
|
258
|
+
* key: 'sk_test_abc123',
|
|
259
|
+
* name: 'Development',
|
|
260
|
+
* permissions: ['read:api'],
|
|
261
|
+
* expiresAt: new Date('2025-12-31'),
|
|
262
|
+
* })
|
|
263
|
+
*
|
|
264
|
+
* // Find non-expired keys
|
|
265
|
+
* const validKeys = await apiKeys.findMany({
|
|
266
|
+
* where: { expiresAt: { $gt: new Date() } }
|
|
267
|
+
* })
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
export function APIKeysCollection(): Collection<APIKey> {
|
|
271
|
+
return createCollection<APIKey>({
|
|
272
|
+
name: 'apiKeys',
|
|
273
|
+
schema: APIKeySchema,
|
|
274
|
+
primaryKey: 'id',
|
|
275
|
+
indexes: ['key', 'name'],
|
|
276
|
+
})
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Creates a Webhooks collection with Zod validation
|
|
281
|
+
*
|
|
282
|
+
* @returns A typed Collection<Webhook> for managing webhook configurations
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* const webhooks = WebhooksCollection()
|
|
287
|
+
*
|
|
288
|
+
* // Create a webhook
|
|
289
|
+
* await webhooks.insert({
|
|
290
|
+
* id: 'webhook-1',
|
|
291
|
+
* url: 'https://example.com/webhook',
|
|
292
|
+
* events: ['user.created'],
|
|
293
|
+
* secret: 'whsec_abc123',
|
|
294
|
+
* active: true,
|
|
295
|
+
* })
|
|
296
|
+
*
|
|
297
|
+
* // Find active webhooks
|
|
298
|
+
* const active = await webhooks.findMany({
|
|
299
|
+
* where: { active: true }
|
|
300
|
+
* })
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
export function WebhooksCollection(): Collection<Webhook> {
|
|
304
|
+
return createCollection<Webhook>({
|
|
305
|
+
name: 'webhooks',
|
|
306
|
+
schema: WebhookSchema,
|
|
307
|
+
primaryKey: 'id',
|
|
308
|
+
indexes: ['url', 'active'],
|
|
309
|
+
})
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Creates a Teams collection with Zod validation
|
|
314
|
+
*
|
|
315
|
+
* @returns A typed Collection<Team> for managing teams and their members
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```typescript
|
|
319
|
+
* const teams = TeamsCollection()
|
|
320
|
+
*
|
|
321
|
+
* // Create a team
|
|
322
|
+
* await teams.insert({
|
|
323
|
+
* id: 'team-1',
|
|
324
|
+
* name: 'Engineering',
|
|
325
|
+
* members: ['user-1', 'user-2'],
|
|
326
|
+
* })
|
|
327
|
+
*
|
|
328
|
+
* // Add a member
|
|
329
|
+
* await teams.update(
|
|
330
|
+
* { id: 'team-1' },
|
|
331
|
+
* { members: ['user-1', 'user-2', 'user-3'] }
|
|
332
|
+
* )
|
|
333
|
+
* ```
|
|
334
|
+
*/
|
|
335
|
+
export function TeamsCollection(): Collection<Team> {
|
|
336
|
+
return createCollection<Team>({
|
|
337
|
+
name: 'teams',
|
|
338
|
+
schema: TeamSchema,
|
|
339
|
+
primaryKey: 'id',
|
|
340
|
+
indexes: ['name'],
|
|
341
|
+
})
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Creates a Usage collection with Zod validation
|
|
346
|
+
*
|
|
347
|
+
* @returns A typed Collection<Usage> for tracking usage metrics
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```typescript
|
|
351
|
+
* const usage = UsageCollection()
|
|
352
|
+
*
|
|
353
|
+
* // Record usage
|
|
354
|
+
* await usage.insert({
|
|
355
|
+
* id: 'usage-1',
|
|
356
|
+
* metric: 'api_calls',
|
|
357
|
+
* value: 1500,
|
|
358
|
+
* timestamp: new Date(),
|
|
359
|
+
* })
|
|
360
|
+
*
|
|
361
|
+
* // Get usage for a specific metric
|
|
362
|
+
* const apiCalls = await usage.findMany({
|
|
363
|
+
* where: { metric: 'api_calls' },
|
|
364
|
+
* orderBy: { timestamp: 'desc' }
|
|
365
|
+
* })
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
export function UsageCollection(): Collection<Usage> {
|
|
369
|
+
return createCollection<Usage>({
|
|
370
|
+
name: 'usage',
|
|
371
|
+
schema: UsageSchema,
|
|
372
|
+
primaryKey: 'id',
|
|
373
|
+
indexes: ['metric', 'timestamp'],
|
|
374
|
+
})
|
|
375
|
+
}
|