@stacksjs/database 0.70.88 → 0.70.90

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 (83) hide show
  1. package/dist/auth-tables.d.ts +60 -0
  2. package/dist/auth-tables.js +220 -0
  3. package/dist/class-seeder.d.ts +65 -0
  4. package/dist/class-seeder.js +116 -0
  5. package/dist/column.d.ts +17 -0
  6. package/dist/column.js +26 -0
  7. package/dist/custom/audits.d.ts +16 -0
  8. package/dist/custom/audits.js +57 -0
  9. package/dist/custom/errors.d.ts +1 -0
  10. package/dist/custom/errors.js +48 -0
  11. package/dist/custom/index.d.ts +3 -0
  12. package/dist/custom/index.js +3 -0
  13. package/dist/custom/jobs.d.ts +3 -0
  14. package/dist/custom/jobs.js +449 -0
  15. package/dist/database.d.ts +89 -0
  16. package/dist/database.js +178 -0
  17. package/dist/defaults.d.ts +48 -0
  18. package/dist/defaults.js +48 -0
  19. package/dist/driver-config.d.ts +149 -0
  20. package/dist/driver-config.js +144 -0
  21. package/dist/drivers/defaults/index.d.ts +2 -0
  22. package/dist/drivers/defaults/index.js +2 -0
  23. package/dist/drivers/defaults/passwords.d.ts +4 -0
  24. package/dist/drivers/defaults/passwords.js +106 -0
  25. package/dist/drivers/defaults/traits.d.ts +33 -0
  26. package/dist/drivers/defaults/traits.js +1125 -0
  27. package/dist/drivers/dynamodb.d.ts +200 -0
  28. package/dist/drivers/dynamodb.js +607 -0
  29. package/dist/drivers/helpers.d.ts +35 -0
  30. package/dist/drivers/helpers.js +206 -0
  31. package/dist/drivers/index.d.ts +16 -0
  32. package/dist/drivers/index.js +9 -0
  33. package/dist/drivers/mysql.d.ts +7 -0
  34. package/dist/drivers/mysql.js +322 -0
  35. package/dist/drivers/postgres.d.ts +7 -0
  36. package/dist/drivers/postgres.js +411 -0
  37. package/dist/drivers/sqlite.d.ts +20 -0
  38. package/dist/drivers/sqlite.js +397 -0
  39. package/dist/factory.d.ts +41 -0
  40. package/dist/factory.js +51 -0
  41. package/dist/fk-audit.d.ts +101 -0
  42. package/dist/fk-audit.js +181 -0
  43. package/dist/index.d.ts +149 -0
  44. package/dist/index.js +55 -0
  45. package/dist/migration-lock.d.ts +23 -0
  46. package/dist/migration-lock.js +143 -0
  47. package/dist/migrations.d.ts +76 -0
  48. package/dist/migrations.js +528 -0
  49. package/dist/notification-tables.d.ts +20 -0
  50. package/dist/notification-tables.js +54 -0
  51. package/dist/query-logger.d.ts +26 -0
  52. package/dist/query-logger.js +213 -0
  53. package/dist/query-parser.d.ts +4 -0
  54. package/dist/query-parser.js +93 -0
  55. package/dist/rbac-tables.d.ts +17 -0
  56. package/dist/rbac-tables.js +84 -0
  57. package/dist/safe-migrations.d.ts +72 -0
  58. package/dist/safe-migrations.js +59 -0
  59. package/dist/schema.d.ts +4 -0
  60. package/dist/schema.js +10 -0
  61. package/dist/seed-scaffold.d.ts +34 -0
  62. package/dist/seed-scaffold.js +144 -0
  63. package/dist/seeder.d.ts +116 -0
  64. package/dist/seeder.js +363 -0
  65. package/dist/sql-helpers.d.ts +33 -0
  66. package/dist/sql-helpers.js +24 -0
  67. package/dist/table.d.ts +7 -0
  68. package/dist/table.js +26 -0
  69. package/dist/tools/setup.d.ts +1 -0
  70. package/dist/tools/setup.js +6 -0
  71. package/dist/transaction-context.d.ts +52 -0
  72. package/dist/transaction-context.js +62 -0
  73. package/dist/types.d.ts +151 -0
  74. package/dist/types.js +23 -0
  75. package/dist/unique-audit.d.ts +60 -0
  76. package/dist/unique-audit.js +174 -0
  77. package/dist/utils.d.ts +189 -0
  78. package/dist/utils.js +163 -0
  79. package/dist/uuid-columns.d.ts +22 -0
  80. package/dist/uuid-columns.js +68 -0
  81. package/dist/validators.d.ts +26 -0
  82. package/dist/validators.js +122 -0
  83. package/package.json +11 -11
@@ -0,0 +1,200 @@
1
+ import type { Model } from '@stacksjs/types';
2
+ /**
3
+ * Marshall a JS object to DynamoDB format
4
+ */
5
+ declare function marshall(obj: Record<string, unknown>): DynamoItem;
6
+ /**
7
+ * Unmarshall a DynamoDB object to JS format
8
+ */
9
+ declare function unmarshall(obj: DynamoItem): Record<string, unknown>;
10
+ /**
11
+ * Generate key pattern for an entity
12
+ */
13
+ export declare function generateKeyPattern(entityName: string, idField?: string): string;
14
+ /**
15
+ * Parse a key pattern and extract values
16
+ */
17
+ export declare function parseKeyPattern(pattern: string, key: string): Record<string, string>;
18
+ /**
19
+ * Build a key from a pattern and values
20
+ */
21
+ export declare function buildKey(pattern: string, values: Record<string, string>): string;
22
+ /**
23
+ * Create a new DynamoDB client instance
24
+ */
25
+ export declare function createDynamo(): DynamoClient;
26
+ /**
27
+ * DynamoDB client singleton
28
+ */
29
+ export declare const dynamo: DynamoClient;
30
+ /**
31
+ * Minimal AWS-SDK `DynamoDBClient` shape — just the methods this
32
+ * driver calls. Typed locally so callers wiring their own SDK
33
+ * client into `setClient()` get a clear compile-time contract
34
+ * instead of a runtime "function not found" surprise.
35
+ */
36
+ export declare interface DynamoSdkClient {
37
+ query: (req: Record<string, unknown>) => Promise<{
38
+ Items?: DynamoItem[]
39
+ Count?: number
40
+ ScannedCount?: number
41
+ LastEvaluatedKey?: DynamoItem
42
+ }>
43
+ scan: (req: Record<string, unknown>) => Promise<{
44
+ Items?: DynamoItem[]
45
+ Count?: number
46
+ ScannedCount?: number
47
+ LastEvaluatedKey?: DynamoItem
48
+ }>
49
+ getItem: (req: Record<string, unknown>) => Promise<{ Item?: DynamoItem }>
50
+ putItem: (req: Record<string, unknown>) => Promise<unknown>
51
+ deleteItem: (req: Record<string, unknown>) => Promise<unknown>
52
+ updateItem: (req: Record<string, unknown>) => Promise<unknown>
53
+ batchWriteItem: (req: Record<string, unknown>) => Promise<unknown>
54
+ transactWriteItems: (req: Record<string, unknown>) => Promise<unknown>
55
+ }
56
+ /**
57
+ * DynamoDB connection configuration
58
+ */
59
+ export declare interface DynamoConnectionConfig {
60
+ region: string
61
+ table: string
62
+ endpoint?: string
63
+ credentials?: {
64
+ accessKeyId: string
65
+ secretAccessKey: string
66
+ sessionToken?: string
67
+ }
68
+ pkAttribute?: string
69
+ skAttribute?: string
70
+ entityTypeAttribute?: string
71
+ keyDelimiter?: string
72
+ }
73
+ /**
74
+ * Entity mapping for single-table design
75
+ */
76
+ export declare interface SingleTableEntityMapping {
77
+ entityType: string
78
+ pkPattern: string
79
+ skPattern?: string
80
+ gsi1pk?: string
81
+ gsi1sk?: string
82
+ gsi2pk?: string
83
+ gsi2sk?: string
84
+ }
85
+ /**
86
+ * Sort key builder for fluent API
87
+ */
88
+ export declare interface SortKeyBuilder {
89
+ equals(value: string): EntityQueryBuilder
90
+ beginsWith(prefix: string): EntityQueryBuilder
91
+ between(start: string, end: string): EntityQueryBuilder
92
+ lt(value: string): EntityQueryBuilder
93
+ lte(value: string): EntityQueryBuilder
94
+ gt(value: string): EntityQueryBuilder
95
+ gte(value: string): EntityQueryBuilder
96
+ }
97
+ /**
98
+ * Batch write operation
99
+ */
100
+ export declare interface BatchWriteOperation {
101
+ put?: { entity: string, item: Record<string, unknown> }
102
+ delete?: { entity: string, pk: string, sk: string }
103
+ }
104
+ /**
105
+ * Transact write operation
106
+ */
107
+ export declare interface TransactWriteOperation {
108
+ put?: { entity: string, item: Record<string, unknown>, condition?: string }
109
+ update?: { entity: string, pk: string, sk?: string, set?: Record<string, unknown>, add?: Record<string, number>, remove?: string[] }
110
+ delete?: { entity: string, pk: string, sk: string, condition?: string }
111
+ conditionCheck?: { entity: string, pk: string, sk: string, condition: string }
112
+ }
113
+ /**
114
+ * Query result
115
+ */
116
+ export declare interface QueryResult<T = unknown> {
117
+ items: T[]
118
+ count: number
119
+ scannedCount?: number
120
+ lastKey?: Record<string, unknown>
121
+ }
122
+ /**
123
+ * DynamoDB AttributeValue discriminated union (stacksjs/stacks#1894 T-8).
124
+ *
125
+ * Mirrors the wire format AWS SDK's `DynamoDBClient` produces and
126
+ * consumes, declared locally so this package doesn't take a hard
127
+ * dependency on `@aws-sdk/client-dynamodb` just for its types. Each
128
+ * concrete variant carries its own typed payload; consumers narrow
129
+ * via `'S' in attr` / etc.
130
+ *
131
+ * Why not just import from AWS SDK: the framework's DynamoDB driver
132
+ * ships as an optional peer integration. Pulling AWS SDK as a type-
133
+ * level dep would force every Stacks app to install it whether or
134
+ * not they use the driver.
135
+ */
136
+ export type DynamoAttributeValue = | { S: string }
137
+ | { N: string }
138
+ | { B: Uint8Array | string }
139
+ | { BOOL: boolean }
140
+ | { NULL: true }
141
+ | { L: DynamoAttributeValue[] }
142
+ | { M: Record<string, DynamoAttributeValue> }
143
+ | { SS: string[] }
144
+ | { NS: string[] }
145
+ | { BS: Array<Uint8Array | string> }
146
+ /** Marshalled item — the on-the-wire representation. */
147
+ export type DynamoItem = Record<string, DynamoAttributeValue>;
148
+ /**
149
+ * Entity-centric query builder for DynamoDB
150
+ */
151
+ export declare class EntityQueryBuilder<T = unknown> {
152
+ constructor(client: DynamoSdkClient | undefined, tableName: string, config: { pkAttribute: string, skAttribute: string, entityTypeAttribute: string, keyDelimiter: string });
153
+ entity(entityType: string): this;
154
+ pk(value: string): this;
155
+ get sk(): SortKeyBuilder;
156
+ index(indexName: string): this;
157
+ project(...attributes: string[]): this;
158
+ filter(attribute: string, operator: string, value?: unknown): this;
159
+ where(attribute: string, value: unknown): this;
160
+ whereIn(attribute: string, values: unknown[]): this;
161
+ limit(count: number): this;
162
+ asc(): this;
163
+ desc(): this;
164
+ consistent(): this;
165
+ startFrom(key: Record<string, unknown>): this;
166
+ toRequest(): Record<string, unknown>;
167
+ get(): Promise<T[]>;
168
+ first(): Promise<T | undefined>;
169
+ getAll(): Promise<T[]>;
170
+ count(): Promise<number>;
171
+ }
172
+ /**
173
+ * DynamoDB client with entity-centric API
174
+ */
175
+ declare class DynamoClient {
176
+ connection(config: DynamoConnectionConfig): this;
177
+ isConfigured(): boolean;
178
+ setClient(client: DynamoSdkClient): this;
179
+ getClient(): DynamoSdkClient | undefined;
180
+ registerEntity(mapping: SingleTableEntityMapping): this;
181
+ registerModel(model: Model): this;
182
+ getEntityMapping(entityType: string): SingleTableEntityMapping | undefined;
183
+ entity<T = any>(entityType: string): EntityQueryBuilder<T>;
184
+ batchWrite(operations: BatchWriteOperation[]): Promise<void>;
185
+ transactWrite(operations: TransactWriteOperation[]): Promise<void>;
186
+ put(entity: string, item: Record<string, unknown>): Promise<void>;
187
+ get<T = any>(pk: string, sk?: string): Promise<T | undefined>;
188
+ delete(pk: string, sk?: string): Promise<void>;
189
+ update(pk: string, sk: string | undefined, updates: Record<string, unknown>): Promise<void>;
190
+ getTableName(): string;
191
+ getConfig(): {
192
+ tableName: string
193
+ pkAttribute: string
194
+ skAttribute: string
195
+ entityTypeAttribute: string
196
+ keyDelimiter: string
197
+ };
198
+ }
199
+ // Export marshall/unmarshall utilities
200
+ export { marshall, unmarshall };