@remix-run/data-table 0.0.0 → 0.1.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 (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +298 -2
  3. package/dist/index.d.ts +11 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +5 -0
  6. package/dist/lib/adapter.d.ts +180 -0
  7. package/dist/lib/adapter.d.ts.map +1 -0
  8. package/dist/lib/adapter.js +1 -0
  9. package/dist/lib/database.d.ts +361 -0
  10. package/dist/lib/database.d.ts.map +1 -0
  11. package/dist/lib/database.js +1368 -0
  12. package/dist/lib/errors.d.ts +50 -0
  13. package/dist/lib/errors.d.ts.map +1 -0
  14. package/dist/lib/errors.js +67 -0
  15. package/dist/lib/inflection.d.ts +3 -0
  16. package/dist/lib/inflection.d.ts.map +1 -0
  17. package/dist/lib/inflection.js +56 -0
  18. package/dist/lib/operators.d.ts +151 -0
  19. package/dist/lib/operators.d.ts.map +1 -0
  20. package/dist/lib/operators.js +218 -0
  21. package/dist/lib/references.d.ts +42 -0
  22. package/dist/lib/references.d.ts.map +1 -0
  23. package/dist/lib/references.js +33 -0
  24. package/dist/lib/sql.d.ts +28 -0
  25. package/dist/lib/sql.d.ts.map +1 -0
  26. package/dist/lib/sql.js +51 -0
  27. package/dist/lib/table.d.ts +254 -0
  28. package/dist/lib/table.d.ts.map +1 -0
  29. package/dist/lib/table.js +496 -0
  30. package/dist/lib/types.d.ts +4 -0
  31. package/dist/lib/types.d.ts.map +1 -0
  32. package/dist/lib/types.js +1 -0
  33. package/package.json +41 -7
  34. package/src/index.ts +115 -0
  35. package/src/lib/adapter.ts +209 -0
  36. package/src/lib/database.ts +2458 -0
  37. package/src/lib/errors.ts +109 -0
  38. package/src/lib/inflection.ts +69 -0
  39. package/src/lib/operators.ts +433 -0
  40. package/src/lib/references.ts +79 -0
  41. package/src/lib/sql.ts +67 -0
  42. package/src/lib/table.ts +981 -0
  43. package/src/lib/types.ts +3 -0
@@ -0,0 +1,209 @@
1
+ import type { AnyTable, OrderByClause } from './table.ts'
2
+ import type { Predicate } from './operators.ts'
3
+ import type { SqlStatement } from './sql.ts'
4
+ import type { Pretty } from './types.ts'
5
+
6
+ /**
7
+ * Supported SQL join kinds.
8
+ */
9
+ export type JoinType = 'inner' | 'left' | 'right'
10
+
11
+ /**
12
+ * Join configuration used in compiled select statements.
13
+ */
14
+ export type JoinClause = {
15
+ type: JoinType
16
+ table: AnyTable
17
+ on: Predicate
18
+ }
19
+
20
+ /**
21
+ * Selected output column with optional alias.
22
+ */
23
+ export type SelectColumn = {
24
+ column: string
25
+ alias: string
26
+ }
27
+
28
+ /**
29
+ * Returning selection for write statements.
30
+ */
31
+ export type ReturningSelection = '*' | string[]
32
+
33
+ /**
34
+ * Canonical select statement shape consumed by adapters.
35
+ */
36
+ export type SelectStatement<table extends AnyTable = AnyTable> = {
37
+ kind: 'select'
38
+ table: table
39
+ select: '*' | SelectColumn[]
40
+ distinct: boolean
41
+ joins: JoinClause[]
42
+ where: Predicate[]
43
+ groupBy: string[]
44
+ having: Predicate[]
45
+ orderBy: OrderByClause[]
46
+ limit?: number
47
+ offset?: number
48
+ }
49
+
50
+ /**
51
+ * Canonical count statement shape consumed by adapters.
52
+ */
53
+ export type CountStatement<table extends AnyTable = AnyTable> = {
54
+ kind: 'count'
55
+ table: table
56
+ joins: JoinClause[]
57
+ where: Predicate[]
58
+ groupBy: string[]
59
+ having: Predicate[]
60
+ }
61
+
62
+ /**
63
+ * Canonical exists statement shape consumed by adapters.
64
+ */
65
+ export type ExistsStatement<table extends AnyTable = AnyTable> = {
66
+ kind: 'exists'
67
+ table: table
68
+ joins: JoinClause[]
69
+ where: Predicate[]
70
+ groupBy: string[]
71
+ having: Predicate[]
72
+ }
73
+
74
+ /**
75
+ * Canonical insert statement shape consumed by adapters.
76
+ */
77
+ export type InsertStatement<table extends AnyTable = AnyTable> = {
78
+ kind: 'insert'
79
+ table: table
80
+ values: Record<string, unknown>
81
+ returning?: ReturningSelection
82
+ }
83
+
84
+ /**
85
+ * Canonical bulk-insert statement shape consumed by adapters.
86
+ */
87
+ export type InsertManyStatement<table extends AnyTable = AnyTable> = {
88
+ kind: 'insertMany'
89
+ table: table
90
+ values: Record<string, unknown>[]
91
+ returning?: ReturningSelection
92
+ }
93
+
94
+ /**
95
+ * Canonical update statement shape consumed by adapters.
96
+ */
97
+ export type UpdateStatement<table extends AnyTable = AnyTable> = {
98
+ kind: 'update'
99
+ table: table
100
+ changes: Record<string, unknown>
101
+ where: Predicate[]
102
+ returning?: ReturningSelection
103
+ }
104
+
105
+ /**
106
+ * Canonical delete statement shape consumed by adapters.
107
+ */
108
+ export type DeleteStatement<table extends AnyTable = AnyTable> = {
109
+ kind: 'delete'
110
+ table: table
111
+ where: Predicate[]
112
+ returning?: ReturningSelection
113
+ }
114
+
115
+ /**
116
+ * Canonical upsert statement shape consumed by adapters.
117
+ */
118
+ export type UpsertStatement<table extends AnyTable = AnyTable> = {
119
+ kind: 'upsert'
120
+ table: table
121
+ values: Record<string, unknown>
122
+ conflictTarget?: string[]
123
+ update?: Record<string, unknown>
124
+ returning?: ReturningSelection
125
+ }
126
+
127
+ /**
128
+ * Raw SQL statement execution descriptor.
129
+ */
130
+ export type RawStatement = {
131
+ kind: 'raw'
132
+ sql: SqlStatement
133
+ }
134
+
135
+ /**
136
+ * Union of all canonical statement shapes.
137
+ */
138
+ export type AdapterStatement =
139
+ | SelectStatement
140
+ | CountStatement
141
+ | ExistsStatement
142
+ | InsertStatement
143
+ | InsertManyStatement
144
+ | UpdateStatement
145
+ | DeleteStatement
146
+ | UpsertStatement
147
+ | RawStatement
148
+
149
+ /**
150
+ * Opaque transaction handle supplied by adapters.
151
+ */
152
+ export type TransactionToken = {
153
+ id: string
154
+ metadata?: Record<string, unknown>
155
+ }
156
+
157
+ /**
158
+ * Transaction hints that adapters may apply when supported by the dialect.
159
+ */
160
+ export type TransactionOptions = {
161
+ isolationLevel?: 'read uncommitted' | 'read committed' | 'repeatable read' | 'serializable'
162
+ readOnly?: boolean
163
+ }
164
+
165
+ /**
166
+ * Adapter execution request payload.
167
+ */
168
+ export type AdapterExecuteRequest = {
169
+ statement: AdapterStatement
170
+ transaction?: TransactionToken
171
+ }
172
+
173
+ /**
174
+ * Adapter execution result payload.
175
+ */
176
+ export type AdapterResult = {
177
+ rows?: Record<string, unknown>[]
178
+ affectedRows?: number
179
+ insertId?: unknown
180
+ }
181
+
182
+ /**
183
+ * Declares adapter feature support.
184
+ */
185
+ export type AdapterCapabilities = {
186
+ returning: boolean
187
+ savepoints: boolean
188
+ upsert: boolean
189
+ }
190
+
191
+ /**
192
+ * Partial capabilities used to override adapter defaults.
193
+ */
194
+ export type AdapterCapabilityOverrides = Pretty<Partial<AdapterCapabilities>>
195
+
196
+ /**
197
+ * Runtime contract implemented by concrete database adapters.
198
+ */
199
+ export interface DatabaseAdapter {
200
+ dialect: string
201
+ capabilities: AdapterCapabilities
202
+ execute(request: AdapterExecuteRequest): Promise<AdapterResult>
203
+ beginTransaction(options?: TransactionOptions): Promise<TransactionToken>
204
+ commitTransaction(token: TransactionToken): Promise<void>
205
+ rollbackTransaction(token: TransactionToken): Promise<void>
206
+ createSavepoint(token: TransactionToken, name: string): Promise<void>
207
+ rollbackToSavepoint(token: TransactionToken, name: string): Promise<void>
208
+ releaseSavepoint(token: TransactionToken, name: string): Promise<void>
209
+ }