zeed 1.4.0 → 1.5.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/dist/{args-FLoL3OKJ.d.cts → args-CEjib9V9.d.mts} +1 -1
- package/dist/{args-WC9q5kz2.d.mts → args-DEig-jw4.d.cts} +1 -1
- package/dist/{clipboard-BkUO-syY.d.mts → clipboard-BusqmLLY.d.cts} +1 -1
- package/dist/{clipboard-Cfpr331X.d.cts → clipboard-DcuuFRwa.d.mts} +1 -1
- package/dist/common/exec/index.d.cts +2 -2
- package/dist/common/exec/index.d.mts +2 -2
- package/dist/common/exec/promise.d.cts +1 -1
- package/dist/common/exec/promise.d.mts +1 -1
- package/dist/common/exec/throttle-debounce.d.cts +1 -1
- package/dist/common/exec/throttle-debounce.d.mts +1 -1
- package/dist/common/index.cjs +21 -0
- package/dist/common/index.d.cts +14 -11
- package/dist/common/index.d.mts +15 -12
- package/dist/common/index.mjs +4 -1
- package/dist/common/msg/rpc.cjs +8 -8
- package/dist/common/msg/rpc.cjs.map +1 -1
- package/dist/common/msg/rpc.mjs +8 -8
- package/dist/common/msg/rpc.mjs.map +1 -1
- package/dist/common/schema/export-json-schema.cjs +40 -31
- package/dist/common/schema/export-json-schema.cjs.map +1 -1
- package/dist/common/schema/export-json-schema.mjs +40 -31
- package/dist/common/schema/export-json-schema.mjs.map +1 -1
- package/dist/common/schema/index.cjs +21 -0
- package/dist/common/schema/index.d.cts +6 -3
- package/dist/common/schema/index.d.mts +7 -4
- package/dist/common/schema/index.mjs +4 -1
- package/dist/common/schema/sql/expr.cjs +128 -0
- package/dist/common/schema/sql/expr.cjs.map +1 -0
- package/dist/common/schema/sql/expr.d.cts +2 -0
- package/dist/common/schema/sql/expr.d.mts +2 -0
- package/dist/common/schema/sql/expr.mjs +115 -0
- package/dist/common/schema/sql/expr.mjs.map +1 -0
- package/dist/common/schema/sql/index.cjs +23 -0
- package/dist/common/schema/sql/index.d.cts +4 -0
- package/dist/common/schema/sql/index.d.mts +4 -0
- package/dist/common/schema/sql/index.mjs +5 -0
- package/dist/common/schema/sql/select.cjs +143 -0
- package/dist/common/schema/sql/select.cjs.map +1 -0
- package/dist/common/schema/sql/select.d.cts +2 -0
- package/dist/common/schema/sql/select.d.mts +2 -0
- package/dist/common/schema/sql/select.mjs +139 -0
- package/dist/common/schema/sql/select.mjs.map +1 -0
- package/dist/common/schema/sql/table.cjs +23 -0
- package/dist/common/schema/sql/table.cjs.map +1 -0
- package/dist/common/schema/sql/table.d.cts +2 -0
- package/dist/common/schema/sql/table.d.mts +2 -0
- package/dist/common/schema/sql/table.mjs +20 -0
- package/dist/common/schema/sql/table.mjs.map +1 -0
- package/dist/common/schema/type-test.d.cts +1 -1
- package/dist/common/schema/type-test.d.mts +1 -1
- package/dist/common/schema/utils.d.cts +1 -1
- package/dist/common/schema/utils.d.mts +1 -1
- package/dist/common/schema/z.d.mts +1 -1
- package/dist/common/storage/index.d.cts +1 -1
- package/dist/common/storage/index.d.mts +1 -1
- package/dist/common/storage/memstorage.d.cts +1 -1
- package/dist/common/storage/memstorage.d.mts +1 -1
- package/dist/common/test.d.cts +1 -1
- package/dist/common/test.d.mts +1 -1
- package/dist/common/time.d.cts +1 -1
- package/dist/common/time.d.mts +1 -1
- package/dist/common/timeout.d.cts +1 -1
- package/dist/common/timeout.d.mts +1 -1
- package/dist/common/utils.d.cts +1 -1
- package/dist/common/utils.d.mts +1 -1
- package/dist/common/uuid.d.cts +1 -1
- package/dist/common/uuid.d.mts +1 -1
- package/dist/{crypto-CyTV7Qce.d.cts → crypto-D68rVmvU.d.mts} +1 -1
- package/dist/{crypto-LT7EC5_d.d.mts → crypto-KzGHoCJE.d.cts} +1 -1
- package/dist/{env-B3vOiVY8.d.cts → env-BJXdwBKq.d.mts} +1 -1
- package/dist/{env-C3npYe8w.d.mts → env-HsOnA_yK.d.cts} +1 -1
- package/dist/expr-CCKrqOw1.d.mts +25 -0
- package/dist/expr-yYgSeBZ3.d.cts +25 -0
- package/dist/{files-CDNKX9VI.d.mts → files-4O-PxnAC.d.cts} +1 -1
- package/dist/{files-DdI9UZvg.d.cts → files-BlpxqSTT.d.mts} +1 -1
- package/dist/{files-async-1V0bu_ca.d.cts → files-async-DFLC-Nkd.d.cts} +1 -1
- package/dist/{files-async-cBMkRwsu.d.mts → files-async-DfuEEDjH.d.mts} +1 -1
- package/dist/{filestorage-CXQ9MzeW.d.cts → filestorage-BjeBZEAs.d.cts} +1 -1
- package/dist/{filestorage-YzM2z9sU.d.mts → filestorage-CmfztpWm.d.mts} +1 -1
- package/dist/{fs-DHJ9AqUk.d.cts → fs-D837bjRT.d.cts} +1 -1
- package/dist/{fs-DgjZdpuF.d.mts → fs-DlYLapik.d.mts} +1 -1
- package/dist/{glob-Bfs7ZS_i.d.mts → glob-5yW09dkR.d.mts} +1 -1
- package/dist/{glob-Bt150jOY.d.cts → glob-CZaZPqiy.d.cts} +1 -1
- package/dist/index.all.cjs +21 -0
- package/dist/index.all.d.cts +28 -25
- package/dist/index.all.d.mts +29 -26
- package/dist/index.all.mjs +4 -1
- package/dist/index.browser.cjs +21 -0
- package/dist/index.browser.d.cts +14 -11
- package/dist/index.browser.d.mts +15 -12
- package/dist/index.browser.mjs +4 -1
- package/dist/index.jsr.d.cts +4 -4
- package/dist/index.jsr.d.mts +4 -4
- package/dist/index.node.cjs +21 -0
- package/dist/index.node.d.cts +28 -25
- package/dist/index.node.d.mts +29 -26
- package/dist/index.node.mjs +4 -1
- package/dist/{log-file-bsTsc9KM.d.cts → log-file-DwEDms1F.d.cts} +2 -2
- package/dist/{log-file-DTuImomJ.d.mts → log-file-QV1unm3z.d.mts} +2 -2
- package/dist/{log-file-rotation-_YruAcNc.d.cts → log-file-rotation-BpZxXYlU.d.cts} +2 -2
- package/dist/{log-file-rotation-FBmtp_Uz.d.mts → log-file-rotation-DanrO_2y.d.mts} +2 -2
- package/dist/{log-node-DlrXl3QO.d.mts → log-node-BSn7RqAc.d.mts} +1 -1
- package/dist/{log-node-Dk948mHX.d.cts → log-node-D_fiJL6x.d.cts} +1 -1
- package/dist/{log-rotation-CkyjZbK5.d.mts → log-rotation-BdGakFya.d.cts} +1 -1
- package/dist/{log-rotation-_d7iRm9s.d.cts → log-rotation-Ce4e-8LN.d.mts} +1 -1
- package/dist/{log-util-2Ls76P-0.d.cts → log-util-C0U3zCjw.d.cts} +1 -1
- package/dist/{log-util-Da_d19f8.d.mts → log-util-Da_UCcmt.d.mts} +1 -1
- package/dist/{memstorage-D5A9FwiP.d.mts → memstorage-BhWXthO8.d.mts} +1 -1
- package/dist/{memstorage-BcjQLdaQ.d.cts → memstorage-tvlWDYgS.d.cts} +1 -1
- package/dist/node/args.d.cts +1 -1
- package/dist/node/args.d.mts +1 -1
- package/dist/node/clipboard.d.cts +1 -1
- package/dist/node/clipboard.d.mts +1 -1
- package/dist/node/crypto.d.cts +1 -1
- package/dist/node/crypto.d.mts +1 -1
- package/dist/node/env.d.cts +1 -1
- package/dist/node/env.d.mts +1 -1
- package/dist/node/files-async.d.cts +1 -1
- package/dist/node/files-async.d.mts +1 -1
- package/dist/node/files.d.cts +1 -1
- package/dist/node/files.d.mts +1 -1
- package/dist/node/filestorage.d.cts +1 -1
- package/dist/node/filestorage.d.mts +1 -1
- package/dist/node/fs.d.cts +1 -1
- package/dist/node/fs.d.mts +1 -1
- package/dist/node/glob.d.cts +1 -1
- package/dist/node/glob.d.mts +1 -1
- package/dist/node/index.d.cts +14 -14
- package/dist/node/index.d.mts +14 -14
- package/dist/node/log/index.d.cts +5 -5
- package/dist/node/log/index.d.mts +5 -5
- package/dist/node/log/log-file-rotation.d.cts +1 -1
- package/dist/node/log/log-file-rotation.d.mts +1 -1
- package/dist/node/log/log-file.d.cts +1 -1
- package/dist/node/log/log-file.d.mts +1 -1
- package/dist/node/log/log-node.cjs +4 -13
- package/dist/node/log/log-node.cjs.map +1 -1
- package/dist/node/log/log-node.d.cts +1 -1
- package/dist/node/log/log-node.d.mts +1 -1
- package/dist/node/log/log-node.mjs +4 -13
- package/dist/node/log/log-node.mjs.map +1 -1
- package/dist/node/log/log-rotation.d.cts +1 -1
- package/dist/node/log/log-rotation.d.mts +1 -1
- package/dist/node/log/log-util.d.cts +1 -1
- package/dist/node/log/log-util.d.mts +1 -1
- package/dist/{promise-DGgiRckN.d.cts → promise-CU_CENbU.d.cts} +1 -1
- package/dist/{promise-MH3xAy4S.d.mts → promise-CoWXgo4w.d.mts} +1 -1
- package/dist/select-DrciHdk_.d.cts +52 -0
- package/dist/select-F2KpP6mo.d.mts +52 -0
- package/dist/table-Cr8tjDIL.d.mts +19 -0
- package/dist/table-IkLXirT-.d.cts +19 -0
- package/dist/{test-CAhm15f4.d.mts → test-DcXa0MeX.d.cts} +1 -1
- package/dist/{test-D2plOVHF.d.cts → test-jZsc7P2c.d.mts} +1 -1
- package/dist/{throttle-debounce-BLFxAZ8W.d.mts → throttle-debounce-CCh0F100.d.mts} +1 -1
- package/dist/{throttle-debounce-Psb0ay1r.d.cts → throttle-debounce-DyFiyoAk.d.cts} +1 -1
- package/dist/{time-BfKJBbym.d.cts → time-BgFZe9ys.d.cts} +1 -1
- package/dist/{time-DxE-vjjw.d.mts → time-DSV_k3mG.d.mts} +1 -1
- package/dist/{timeout-CnUk6Ruj.d.mts → timeout-DDSSNZY8.d.mts} +1 -1
- package/dist/{timeout-CpFcK8MD.d.cts → timeout-E3ZQbJgK.d.cts} +1 -1
- package/dist/{type-test-BiKyEZkc.d.mts → type-test-BvzWDJz3.d.mts} +1 -1
- package/dist/{type-test-sM7QpfQU.d.cts → type-test-CBK-iJ9d.d.cts} +1 -1
- package/dist/{utils-B8DsVgFr.d.mts → utils-1RyCGkpQ.d.mts} +1 -1
- package/dist/{utils-BfZkD2Pt.d.mts → utils-6Culwiaf.d.cts} +1 -1
- package/dist/{utils-DHQBNh-Z.d.cts → utils-CDJihcg3.d.mts} +1 -1
- package/dist/{utils-Bctk_WhH.d.cts → utils-nCQklGHV.d.cts} +1 -1
- package/dist/{uuid-Cusm2nIK.d.cts → uuid-CKFZfSff.d.mts} +1 -1
- package/dist/{uuid-ININPGKB.d.mts → uuid-D42A8UdP.d.cts} +1 -1
- package/dist/z-C0fpNWZg.d.cts +1 -0
- package/dist/z-D_jezYmm.d.mts +1 -0
- package/dist/{z-collection-BmuBin--.d.mts → z-collection-BSfgRU0Q.d.mts} +1 -1
- package/package.json +7 -8
- package/src/common/schema/export-json-schema.spec.ts +11 -7
- package/src/common/schema/export-json-schema.ts +59 -52
- package/src/common/schema/index.ts +1 -0
- package/src/common/schema/sql/README.md +254 -0
- package/src/common/schema/sql/expr.ts +99 -0
- package/src/common/schema/sql/index.ts +3 -0
- package/src/common/schema/sql/select.spec.ts +144 -0
- package/src/common/schema/sql/select.ts +207 -0
- package/src/common/schema/sql/table.ts +36 -0
- /package/dist/{index-BH1nuHdZ.d.cts → index-CIABef8t.d.mts} +0 -0
- /package/dist/{index-BL7o4fG9.d.cts → index-CliqZ9rj.d.mts} +0 -0
- /package/dist/{index-CP2eJYlK.d.mts → index-D6xqj1Qx.d.cts} +0 -0
- /package/dist/{index-DjOaHFU3.d.mts → index-DHFfG4yr.d.cts} +0 -0
- /package/dist/{index-sViox9YW.d.mts → index-N-OgGgfF.d.mts} +0 -0
- /package/dist/{z-ClMox7qS.d.mts → index-WOw4GVZo.d.cts} +0 -0
- /package/dist/{z-dtM4F8Lo.d.cts → index-luywJTzJ.d.mts} +0 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import type { Infer, Type } from '../schema'
|
|
2
|
+
import type { Expr } from './expr'
|
|
3
|
+
import type { Column, TableColumns, TableShape } from './table'
|
|
4
|
+
|
|
5
|
+
export type RowFromTable<T> = T extends TableColumns<any, infer S>
|
|
6
|
+
? { [K in keyof S]: Infer<S[K]> }
|
|
7
|
+
: never
|
|
8
|
+
|
|
9
|
+
export type RowFromSelection<S> = {
|
|
10
|
+
[K in keyof S]: S[K] extends Column<infer T> ? T : never
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface QueryDependencies {
|
|
14
|
+
readonly table: string
|
|
15
|
+
readonly select: readonly string[]
|
|
16
|
+
readonly where: readonly string[]
|
|
17
|
+
readonly orderBy: readonly string[]
|
|
18
|
+
readonly all: readonly string[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CompiledQuery<Row> {
|
|
22
|
+
readonly sql: string
|
|
23
|
+
readonly params: readonly unknown[]
|
|
24
|
+
readonly dependencies: readonly QueryDependencies[]
|
|
25
|
+
readonly __row?: Row
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface OrderByEntry {
|
|
29
|
+
col: Column
|
|
30
|
+
dir: 'ASC' | 'DESC'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface SelectState {
|
|
34
|
+
selection?: Record<string, Column>
|
|
35
|
+
from?: TableColumns<any, any>
|
|
36
|
+
where?: Expr
|
|
37
|
+
orderBy: OrderByEntry[]
|
|
38
|
+
limit?: number
|
|
39
|
+
offset?: number
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type ShapeRow<S> = { [K in keyof S]: S[K] extends Type<infer T> ? T : never }
|
|
43
|
+
|
|
44
|
+
export class SelectBuilder<Row, Shape = unknown> {
|
|
45
|
+
private _state: SelectState
|
|
46
|
+
|
|
47
|
+
constructor(state: SelectState) {
|
|
48
|
+
this._state = state
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
from<N extends string, S extends TableShape>(
|
|
52
|
+
t: TableColumns<N, S>,
|
|
53
|
+
): SelectBuilder<Row extends void ? ShapeRow<S> : Row, S> {
|
|
54
|
+
this._state.from = t
|
|
55
|
+
return this as any
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
pick<K extends Extract<keyof Shape, string>>(
|
|
59
|
+
...keys: K[]
|
|
60
|
+
): SelectBuilder<{ [P in K]: Shape[P] extends Type<infer T> ? T : never }, Shape> {
|
|
61
|
+
if (!this._state.from)
|
|
62
|
+
throw new Error('pick: from() must be called first')
|
|
63
|
+
const sel: Record<string, Column> = {}
|
|
64
|
+
for (const k of keys) sel[k] = (this._state.from as any)[k]
|
|
65
|
+
this._state.selection = sel
|
|
66
|
+
return this as any
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
where(expr: Expr): this {
|
|
70
|
+
this._state.where = expr
|
|
71
|
+
return this
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
orderBy(col: Column, dir: 'ASC' | 'DESC' = 'ASC'): this {
|
|
75
|
+
this._state.orderBy.push({ col, dir })
|
|
76
|
+
return this
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
limit(n: number): this {
|
|
80
|
+
this._state.limit = n
|
|
81
|
+
return this
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
offset(n: number): this {
|
|
85
|
+
this._state.offset = n
|
|
86
|
+
return this
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
toSQL(): CompiledQuery<Row> {
|
|
90
|
+
const s = this._state
|
|
91
|
+
if (!s.from)
|
|
92
|
+
throw new Error('select: from() is required')
|
|
93
|
+
|
|
94
|
+
const tableName = s.from._name
|
|
95
|
+
const params: unknown[] = []
|
|
96
|
+
const selectRefs: Column[] = []
|
|
97
|
+
const whereRefs: Column[] = []
|
|
98
|
+
const orderByRefs: Column[] = []
|
|
99
|
+
|
|
100
|
+
let cols: string
|
|
101
|
+
if (s.selection) {
|
|
102
|
+
const parts: string[] = []
|
|
103
|
+
for (const [alias, col] of Object.entries(s.selection)) {
|
|
104
|
+
selectRefs.push(col)
|
|
105
|
+
const ident = `"${col._table}"."${col._name}"`
|
|
106
|
+
parts.push(alias === col._name ? ident : `${ident} AS "${alias}"`)
|
|
107
|
+
}
|
|
108
|
+
cols = parts.join(', ')
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
const shape = s.from._shape
|
|
112
|
+
const names = Object.keys(shape)
|
|
113
|
+
for (const n of names) selectRefs.push((s.from as any)[n])
|
|
114
|
+
cols = names.map(n => `"${tableName}"."${n}"`).join(', ')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let sql = `SELECT ${cols} FROM "${tableName}"`
|
|
118
|
+
|
|
119
|
+
if (s.where) {
|
|
120
|
+
sql += ` WHERE ${s.where.sql}`
|
|
121
|
+
params.push(...s.where.params)
|
|
122
|
+
whereRefs.push(...s.where.refs)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (s.orderBy.length) {
|
|
126
|
+
const parts = s.orderBy.map((o) => {
|
|
127
|
+
orderByRefs.push(o.col)
|
|
128
|
+
return `"${o.col._table}"."${o.col._name}" ${o.dir}`
|
|
129
|
+
})
|
|
130
|
+
sql += ` ORDER BY ${parts.join(', ')}`
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (s.limit != null) {
|
|
134
|
+
sql += ` LIMIT ?`
|
|
135
|
+
params.push(s.limit)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (s.offset != null) {
|
|
139
|
+
sql += ` OFFSET ?`
|
|
140
|
+
params.push(s.offset)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
sql,
|
|
145
|
+
params,
|
|
146
|
+
dependencies: collectDependencies(selectRefs, whereRefs, orderByRefs),
|
|
147
|
+
__row: undefined as any,
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
dependencies(): readonly QueryDependencies[] {
|
|
152
|
+
return this.toSQL().dependencies
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function collectDependencies(
|
|
157
|
+
selectRefs: Column[],
|
|
158
|
+
whereRefs: Column[],
|
|
159
|
+
orderByRefs: Column[],
|
|
160
|
+
): QueryDependencies[] {
|
|
161
|
+
interface Buckets {
|
|
162
|
+
select: Set<string>
|
|
163
|
+
where: Set<string>
|
|
164
|
+
orderBy: Set<string>
|
|
165
|
+
}
|
|
166
|
+
const map = new Map<string, Buckets>()
|
|
167
|
+
const bucket = (table: string): Buckets => {
|
|
168
|
+
let b = map.get(table)
|
|
169
|
+
if (!b) {
|
|
170
|
+
b = { select: new Set(), where: new Set(), orderBy: new Set() }
|
|
171
|
+
map.set(table, b)
|
|
172
|
+
}
|
|
173
|
+
return b
|
|
174
|
+
}
|
|
175
|
+
for (const c of selectRefs) bucket(c._table).select.add(c._name)
|
|
176
|
+
for (const c of whereRefs) bucket(c._table).where.add(c._name)
|
|
177
|
+
for (const c of orderByRefs) bucket(c._table).orderBy.add(c._name)
|
|
178
|
+
|
|
179
|
+
return Array.from(map, ([table, b]) => {
|
|
180
|
+
const all = new Set<string>([...b.select, ...b.where, ...b.orderBy])
|
|
181
|
+
return {
|
|
182
|
+
table,
|
|
183
|
+
select: Array.from(b.select).sort(),
|
|
184
|
+
where: Array.from(b.where).sort(),
|
|
185
|
+
orderBy: Array.from(b.orderBy).sort(),
|
|
186
|
+
all: Array.from(all).sort(),
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function select(): SelectBuilder<void>
|
|
192
|
+
export function select<S extends Record<string, Column<any>>>(
|
|
193
|
+
selection: S,
|
|
194
|
+
): SelectBuilder<RowFromSelection<S>>
|
|
195
|
+
export function select(selection?: Record<string, Column>): SelectBuilder<any> {
|
|
196
|
+
return new SelectBuilder({ selection, orderBy: [] })
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function from<N extends string, S extends TableShape>(
|
|
200
|
+
t: TableColumns<N, S>,
|
|
201
|
+
): SelectBuilder<ShapeRow<S>, S> {
|
|
202
|
+
return new SelectBuilder<ShapeRow<S>, S>({ from: t, orderBy: [] })
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export type InferRow<Q> = Q extends SelectBuilder<infer R>
|
|
206
|
+
? R
|
|
207
|
+
: Q extends CompiledQuery<infer R> ? R : never
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Infer, Type } from '../schema'
|
|
2
|
+
|
|
3
|
+
export interface Column<T = unknown> {
|
|
4
|
+
readonly _table: string
|
|
5
|
+
readonly _name: string
|
|
6
|
+
readonly _type: Type<T>
|
|
7
|
+
readonly __row?: T
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type TableShape = Record<string, Type<any>>
|
|
11
|
+
|
|
12
|
+
export type TableColumns<N extends string, S extends TableShape> = {
|
|
13
|
+
readonly [K in keyof S & string]: Column<Infer<S[K]>>
|
|
14
|
+
} & {
|
|
15
|
+
readonly _name: N
|
|
16
|
+
readonly _shape: S
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function table<N extends string, S extends TableShape>(
|
|
20
|
+
name: N,
|
|
21
|
+
shape: S,
|
|
22
|
+
): TableColumns<N, S> {
|
|
23
|
+
const out: any = { _name: name, _shape: shape }
|
|
24
|
+
for (const key of Object.keys(shape)) {
|
|
25
|
+
out[key] = {
|
|
26
|
+
_table: name,
|
|
27
|
+
_name: key,
|
|
28
|
+
_type: shape[key],
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return out
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function isColumn(v: any): v is Column {
|
|
35
|
+
return !!v && typeof v._table === 'string' && typeof v._name === 'string' && v._type
|
|
36
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|