cvx-kit 0.0.2 → 0.0.4

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 (65) hide show
  1. package/README.md +1 -0
  2. package/dist/auth.d.mts +52 -5
  3. package/dist/auth.mjs +1 -1
  4. package/dist/auth.mjs.map +1 -1
  5. package/dist/components/foundation/client.d.mts +40 -3
  6. package/dist/components/foundation/client.mjs +1 -1
  7. package/dist/components/foundation/client.mjs.map +1 -1
  8. package/dist/index.d.mts +6 -5
  9. package/dist/index.mjs +1 -1
  10. package/dist/tenancy.d.mts +34 -0
  11. package/dist/tenancy.mjs +2 -0
  12. package/dist/tenancy.mjs.map +1 -0
  13. package/dist/triggers.d.mts +9 -1
  14. package/dist/triggers.mjs +1 -1
  15. package/dist/triggers.mjs.map +1 -1
  16. package/dist/zod-table.d.mts +21 -1
  17. package/dist/zod-table.mjs +1 -1
  18. package/dist/zod-table.mjs.map +1 -1
  19. package/docs/auth.md +10 -0
  20. package/docs/commands.md +56 -4
  21. package/docs/conventions.md +21 -0
  22. package/docs/explain/modules-and-multitenancy.html +469 -0
  23. package/docs/llms.md +16 -4
  24. package/docs/tenancy.md +179 -0
  25. package/docs/triggers.md +5 -0
  26. package/docs/zod-table.md +23 -0
  27. package/package.json +6 -8
  28. package/src/test.ts +7 -5
  29. package/src/auth.ts +0 -360
  30. package/src/components/approvals/_generated/api.ts +0 -69
  31. package/src/components/approvals/_generated/component.ts +0 -335
  32. package/src/components/approvals/_generated/dataModel.ts +0 -60
  33. package/src/components/approvals/_generated/server.ts +0 -156
  34. package/src/components/approvals/audit.ts +0 -148
  35. package/src/components/approvals/client.ts +0 -321
  36. package/src/components/approvals/constants.ts +0 -51
  37. package/src/components/approvals/convex.config.ts +0 -10
  38. package/src/components/approvals/decisions.ts +0 -376
  39. package/src/components/approvals/functions.ts +0 -27
  40. package/src/components/approvals/requests.ts +0 -240
  41. package/src/components/approvals/schema.ts +0 -23
  42. package/src/components/approvals/validators.ts +0 -272
  43. package/src/components/approvals/workflow.ts +0 -204
  44. package/src/components/approvals/workflow_steps.ts +0 -189
  45. package/src/components/foundation/_generated/api.ts +0 -62
  46. package/src/components/foundation/_generated/component.ts +0 -29
  47. package/src/components/foundation/_generated/dataModel.ts +0 -60
  48. package/src/components/foundation/_generated/server.ts +0 -156
  49. package/src/components/foundation/client.ts +0 -190
  50. package/src/components/foundation/convex.config.ts +0 -3
  51. package/src/components/foundation/functions.ts +0 -10
  52. package/src/components/foundation/modules/command/__tests__/command.test.ts +0 -106
  53. package/src/components/foundation/modules/command/command.ts +0 -154
  54. package/src/components/foundation/modules/observability/__tests__/observability.test.ts +0 -79
  55. package/src/components/foundation/modules/observability/observability.ts +0 -95
  56. package/src/components/foundation/modules/query/__tests__/query.test.ts +0 -25
  57. package/src/components/foundation/modules/query/query.ts +0 -47
  58. package/src/components/foundation/result.ts +0 -77
  59. package/src/components/foundation/schema.ts +0 -4
  60. package/src/components/foundation/telemetry.ts +0 -23
  61. package/src/errors.ts +0 -25
  62. package/src/index.ts +0 -41
  63. package/src/triggers.ts +0 -90
  64. package/src/zod-table.ts +0 -197
  65. /package/docs/{convex-architecture-explainer.html → explain/convex-architecture-explainer.html} +0 -0
package/src/zod-table.ts DELETED
@@ -1,197 +0,0 @@
1
- import {
2
- type ConvexValidatorFromZod,
3
- zid,
4
- zodToConvex,
5
- } from 'convex-helpers/server/zod4'
6
- import { defineTable, type TableDefinition } from 'convex/server'
7
- import type { GenericId } from 'convex/values'
8
- import { z } from 'zod'
9
-
10
- type Shape = Record<string, z.ZodType>
11
- type ShapeKey<Fields extends Shape> = Extract<keyof Fields, string>
12
-
13
- /**
14
- * Opinionated lifecycle timestamps — every table has them, server-owned,
15
- * always excluded from insert/command boundaries. Maintained by the
16
- * `timestamps` trigger helper (see cvx-kit/triggers).
17
- */
18
- const timestampShape = {
19
- createdAt: z.number().optional(),
20
- updatedAt: z.number().optional(),
21
- archivedAt: z.number().optional(),
22
- } satisfies Shape
23
-
24
- type TimestampShape = typeof timestampShape
25
-
26
- export const TIMESTAMP_FIELDS = [
27
- 'createdAt',
28
- 'updatedAt',
29
- 'archivedAt',
30
- ] as const
31
-
32
- export type TableBoundaryOptions<
33
- Fields extends Shape,
34
- ServerFields extends readonly ShapeKey<Fields>[],
35
- CommandFields extends readonly ShapeKey<Fields>[],
36
- PublicFields extends readonly ShapeKey<Fields & TimestampShape>[],
37
- > = {
38
- serverFields?: ServerFields
39
- commandFields?: CommandFields
40
- publicFields?: PublicFields
41
- }
42
-
43
- /** Defines one table and derives its storage, document, write, and DTO boundaries. */
44
- export function zodTable<
45
- Table extends string,
46
- Fields extends Shape,
47
- const ServerFields extends readonly ShapeKey<Fields>[] = readonly [],
48
- const CommandFields extends readonly ShapeKey<Fields>[] = readonly [],
49
- const PublicFields extends readonly ShapeKey<
50
- Fields & TimestampShape
51
- >[] = readonly [],
52
- >(
53
- tableName: Table,
54
- fields: (id: typeof zid) => Fields,
55
- options: TableBoundaryOptions<
56
- Fields,
57
- ServerFields,
58
- CommandFields,
59
- PublicFields
60
- > = {},
61
- ) {
62
- const shape = { ...fields(zid), ...timestampShape } as Fields &
63
- TimestampShape
64
- const storage = z.object(shape).strict()
65
- const schema = storage.extend({
66
- _id: zid(tableName),
67
- _creationTime: z.number(),
68
- })
69
- const insertSchema = z
70
- .object(
71
- omitShape(shape, [
72
- ...TIMESTAMP_FIELDS,
73
- ...(options.serverFields ?? ([] as never)),
74
- ] as never),
75
- )
76
- .strict() as z.ZodObject<
77
- Omit<Fields, ServerFields[number] | (typeof TIMESTAMP_FIELDS)[number]>
78
- >
79
- const updateSchema = insertSchema.partial()
80
- const commandInput = z
81
- .object(pickShape(shape, options.commandFields ?? ([] as never)))
82
- .strict()
83
- const publicDto = z
84
- .object(pickShape(shape, options.publicFields ?? ([] as never)))
85
- .strict()
86
- const toPublicDto = (row: z.input<typeof storage>) =>
87
- publicDto.parse(
88
- Object.fromEntries(
89
- Object.keys(publicDto.shape).map((key) => [
90
- key,
91
- (row as Record<string, unknown>)[key],
92
- ]),
93
- ),
94
- )
95
-
96
- type InsertSchema = typeof insertSchema
97
- type UpdateSchema = typeof updateSchema
98
- type InsertMask = z.util.Mask<keyof InsertSchema['shape']>
99
- type UpdateMask = z.util.Mask<keyof UpdateSchema['shape']>
100
-
101
- function insert(): InsertSchema
102
- function insert<OmitMask extends InsertMask>(
103
- omit: OmitMask,
104
- ): ZodObjectOmit<InsertSchema, OmitMask>
105
- function insert(omit?: InsertMask) {
106
- return omit ? insertSchema.omit(omit as never) : insertSchema
107
- }
108
-
109
- function update(): UpdateSchema
110
- function update<OmitMask extends UpdateMask>(
111
- omit: OmitMask,
112
- ): ZodObjectOmit<UpdateSchema, OmitMask>
113
- function update(omit?: UpdateMask) {
114
- return omit ? updateSchema.omit(omit as never) : updateSchema
115
- }
116
-
117
- return {
118
- tableName,
119
- schema,
120
- storage,
121
- insertSchema,
122
- updateSchema,
123
- commandInput,
124
- publicDto,
125
- toPublicDto,
126
- table: defineTable(zodToConvex(storage)) as TableDefinition<
127
- ConvexValidatorFromZod<typeof storage, 'required'>
128
- >,
129
- insert,
130
- update,
131
- tools: {
132
- insert: commandInput,
133
- update: z
134
- .object({ data: commandInput.partial(), id: zid(tableName) })
135
- .strict(),
136
- id: z.object({ id: zid(tableName) }).strict(),
137
- },
138
- }
139
- }
140
-
141
- /** Preserves discriminated-union storage while retaining the same table owner. */
142
- export function zodVariantTable<Table extends string, Schema extends z.ZodType>(
143
- tableName: Table,
144
- storage: Schema,
145
- ) {
146
- return {
147
- tableName,
148
- storage,
149
- insertSchema: storage,
150
- table: defineTable(zodToConvex(storage)),
151
- }
152
- }
153
-
154
- /**
155
- * A zid that presents as a plain string in generated JSON schemas so
156
- * LLM-tool inputs stay primitive, while keeping the Id type at compile time.
157
- */
158
- export function jsonSafeZid<Table extends string>(tableName: Table) {
159
- return z
160
- .string()
161
- .describe(
162
- `Convex document id for table "${tableName}"`,
163
- ) as unknown as z.ZodType<GenericId<Table>, string>
164
- }
165
-
166
- type ZodObjectOmit<
167
- Schema extends z.ZodObject<any, any>,
168
- OmitMask extends z.util.Mask<keyof Schema['shape']>,
169
- > =
170
- Schema extends z.ZodObject<infer ObjectShape, infer Config>
171
- ? z.ZodObject<
172
- z.util.Flatten<
173
- Omit<ObjectShape, Extract<keyof ObjectShape, keyof OmitMask>>
174
- >,
175
- Config
176
- >
177
- : never
178
-
179
- function pickShape<
180
- Fields extends Shape,
181
- const Keys extends readonly ShapeKey<Fields>[],
182
- >(fields: Fields, keys: Keys) {
183
- return Object.fromEntries(keys.map((key) => [key, fields[key]])) as Pick<
184
- Fields,
185
- Keys[number]
186
- >
187
- }
188
-
189
- function omitShape<
190
- Fields extends Shape,
191
- const Keys extends readonly ShapeKey<Fields>[],
192
- >(fields: Fields, keys: Keys) {
193
- const omitted = new Set<string>(keys)
194
- return Object.fromEntries(
195
- Object.entries(fields).filter(([key]) => !omitted.has(key)),
196
- ) as Omit<Fields, Keys[number]>
197
- }