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.
Files changed (187) hide show
  1. package/dist/{args-FLoL3OKJ.d.cts → args-CEjib9V9.d.mts} +1 -1
  2. package/dist/{args-WC9q5kz2.d.mts → args-DEig-jw4.d.cts} +1 -1
  3. package/dist/{clipboard-BkUO-syY.d.mts → clipboard-BusqmLLY.d.cts} +1 -1
  4. package/dist/{clipboard-Cfpr331X.d.cts → clipboard-DcuuFRwa.d.mts} +1 -1
  5. package/dist/common/exec/index.d.cts +2 -2
  6. package/dist/common/exec/index.d.mts +2 -2
  7. package/dist/common/exec/promise.d.cts +1 -1
  8. package/dist/common/exec/promise.d.mts +1 -1
  9. package/dist/common/exec/throttle-debounce.d.cts +1 -1
  10. package/dist/common/exec/throttle-debounce.d.mts +1 -1
  11. package/dist/common/index.cjs +21 -0
  12. package/dist/common/index.d.cts +14 -11
  13. package/dist/common/index.d.mts +15 -12
  14. package/dist/common/index.mjs +4 -1
  15. package/dist/common/msg/rpc.cjs +8 -8
  16. package/dist/common/msg/rpc.cjs.map +1 -1
  17. package/dist/common/msg/rpc.mjs +8 -8
  18. package/dist/common/msg/rpc.mjs.map +1 -1
  19. package/dist/common/schema/export-json-schema.cjs +40 -31
  20. package/dist/common/schema/export-json-schema.cjs.map +1 -1
  21. package/dist/common/schema/export-json-schema.mjs +40 -31
  22. package/dist/common/schema/export-json-schema.mjs.map +1 -1
  23. package/dist/common/schema/index.cjs +21 -0
  24. package/dist/common/schema/index.d.cts +6 -3
  25. package/dist/common/schema/index.d.mts +7 -4
  26. package/dist/common/schema/index.mjs +4 -1
  27. package/dist/common/schema/sql/expr.cjs +128 -0
  28. package/dist/common/schema/sql/expr.cjs.map +1 -0
  29. package/dist/common/schema/sql/expr.d.cts +2 -0
  30. package/dist/common/schema/sql/expr.d.mts +2 -0
  31. package/dist/common/schema/sql/expr.mjs +115 -0
  32. package/dist/common/schema/sql/expr.mjs.map +1 -0
  33. package/dist/common/schema/sql/index.cjs +23 -0
  34. package/dist/common/schema/sql/index.d.cts +4 -0
  35. package/dist/common/schema/sql/index.d.mts +4 -0
  36. package/dist/common/schema/sql/index.mjs +5 -0
  37. package/dist/common/schema/sql/select.cjs +143 -0
  38. package/dist/common/schema/sql/select.cjs.map +1 -0
  39. package/dist/common/schema/sql/select.d.cts +2 -0
  40. package/dist/common/schema/sql/select.d.mts +2 -0
  41. package/dist/common/schema/sql/select.mjs +139 -0
  42. package/dist/common/schema/sql/select.mjs.map +1 -0
  43. package/dist/common/schema/sql/table.cjs +23 -0
  44. package/dist/common/schema/sql/table.cjs.map +1 -0
  45. package/dist/common/schema/sql/table.d.cts +2 -0
  46. package/dist/common/schema/sql/table.d.mts +2 -0
  47. package/dist/common/schema/sql/table.mjs +20 -0
  48. package/dist/common/schema/sql/table.mjs.map +1 -0
  49. package/dist/common/schema/type-test.d.cts +1 -1
  50. package/dist/common/schema/type-test.d.mts +1 -1
  51. package/dist/common/schema/utils.d.cts +1 -1
  52. package/dist/common/schema/utils.d.mts +1 -1
  53. package/dist/common/schema/z.d.mts +1 -1
  54. package/dist/common/storage/index.d.cts +1 -1
  55. package/dist/common/storage/index.d.mts +1 -1
  56. package/dist/common/storage/memstorage.d.cts +1 -1
  57. package/dist/common/storage/memstorage.d.mts +1 -1
  58. package/dist/common/test.d.cts +1 -1
  59. package/dist/common/test.d.mts +1 -1
  60. package/dist/common/time.d.cts +1 -1
  61. package/dist/common/time.d.mts +1 -1
  62. package/dist/common/timeout.d.cts +1 -1
  63. package/dist/common/timeout.d.mts +1 -1
  64. package/dist/common/utils.d.cts +1 -1
  65. package/dist/common/utils.d.mts +1 -1
  66. package/dist/common/uuid.d.cts +1 -1
  67. package/dist/common/uuid.d.mts +1 -1
  68. package/dist/{crypto-CyTV7Qce.d.cts → crypto-D68rVmvU.d.mts} +1 -1
  69. package/dist/{crypto-LT7EC5_d.d.mts → crypto-KzGHoCJE.d.cts} +1 -1
  70. package/dist/{env-B3vOiVY8.d.cts → env-BJXdwBKq.d.mts} +1 -1
  71. package/dist/{env-C3npYe8w.d.mts → env-HsOnA_yK.d.cts} +1 -1
  72. package/dist/expr-CCKrqOw1.d.mts +25 -0
  73. package/dist/expr-yYgSeBZ3.d.cts +25 -0
  74. package/dist/{files-CDNKX9VI.d.mts → files-4O-PxnAC.d.cts} +1 -1
  75. package/dist/{files-DdI9UZvg.d.cts → files-BlpxqSTT.d.mts} +1 -1
  76. package/dist/{files-async-1V0bu_ca.d.cts → files-async-DFLC-Nkd.d.cts} +1 -1
  77. package/dist/{files-async-cBMkRwsu.d.mts → files-async-DfuEEDjH.d.mts} +1 -1
  78. package/dist/{filestorage-CXQ9MzeW.d.cts → filestorage-BjeBZEAs.d.cts} +1 -1
  79. package/dist/{filestorage-YzM2z9sU.d.mts → filestorage-CmfztpWm.d.mts} +1 -1
  80. package/dist/{fs-DHJ9AqUk.d.cts → fs-D837bjRT.d.cts} +1 -1
  81. package/dist/{fs-DgjZdpuF.d.mts → fs-DlYLapik.d.mts} +1 -1
  82. package/dist/{glob-Bfs7ZS_i.d.mts → glob-5yW09dkR.d.mts} +1 -1
  83. package/dist/{glob-Bt150jOY.d.cts → glob-CZaZPqiy.d.cts} +1 -1
  84. package/dist/index.all.cjs +21 -0
  85. package/dist/index.all.d.cts +28 -25
  86. package/dist/index.all.d.mts +29 -26
  87. package/dist/index.all.mjs +4 -1
  88. package/dist/index.browser.cjs +21 -0
  89. package/dist/index.browser.d.cts +14 -11
  90. package/dist/index.browser.d.mts +15 -12
  91. package/dist/index.browser.mjs +4 -1
  92. package/dist/index.jsr.d.cts +4 -4
  93. package/dist/index.jsr.d.mts +4 -4
  94. package/dist/index.node.cjs +21 -0
  95. package/dist/index.node.d.cts +28 -25
  96. package/dist/index.node.d.mts +29 -26
  97. package/dist/index.node.mjs +4 -1
  98. package/dist/{log-file-bsTsc9KM.d.cts → log-file-DwEDms1F.d.cts} +2 -2
  99. package/dist/{log-file-DTuImomJ.d.mts → log-file-QV1unm3z.d.mts} +2 -2
  100. package/dist/{log-file-rotation-_YruAcNc.d.cts → log-file-rotation-BpZxXYlU.d.cts} +2 -2
  101. package/dist/{log-file-rotation-FBmtp_Uz.d.mts → log-file-rotation-DanrO_2y.d.mts} +2 -2
  102. package/dist/{log-node-DlrXl3QO.d.mts → log-node-BSn7RqAc.d.mts} +1 -1
  103. package/dist/{log-node-Dk948mHX.d.cts → log-node-D_fiJL6x.d.cts} +1 -1
  104. package/dist/{log-rotation-CkyjZbK5.d.mts → log-rotation-BdGakFya.d.cts} +1 -1
  105. package/dist/{log-rotation-_d7iRm9s.d.cts → log-rotation-Ce4e-8LN.d.mts} +1 -1
  106. package/dist/{log-util-2Ls76P-0.d.cts → log-util-C0U3zCjw.d.cts} +1 -1
  107. package/dist/{log-util-Da_d19f8.d.mts → log-util-Da_UCcmt.d.mts} +1 -1
  108. package/dist/{memstorage-D5A9FwiP.d.mts → memstorage-BhWXthO8.d.mts} +1 -1
  109. package/dist/{memstorage-BcjQLdaQ.d.cts → memstorage-tvlWDYgS.d.cts} +1 -1
  110. package/dist/node/args.d.cts +1 -1
  111. package/dist/node/args.d.mts +1 -1
  112. package/dist/node/clipboard.d.cts +1 -1
  113. package/dist/node/clipboard.d.mts +1 -1
  114. package/dist/node/crypto.d.cts +1 -1
  115. package/dist/node/crypto.d.mts +1 -1
  116. package/dist/node/env.d.cts +1 -1
  117. package/dist/node/env.d.mts +1 -1
  118. package/dist/node/files-async.d.cts +1 -1
  119. package/dist/node/files-async.d.mts +1 -1
  120. package/dist/node/files.d.cts +1 -1
  121. package/dist/node/files.d.mts +1 -1
  122. package/dist/node/filestorage.d.cts +1 -1
  123. package/dist/node/filestorage.d.mts +1 -1
  124. package/dist/node/fs.d.cts +1 -1
  125. package/dist/node/fs.d.mts +1 -1
  126. package/dist/node/glob.d.cts +1 -1
  127. package/dist/node/glob.d.mts +1 -1
  128. package/dist/node/index.d.cts +14 -14
  129. package/dist/node/index.d.mts +14 -14
  130. package/dist/node/log/index.d.cts +5 -5
  131. package/dist/node/log/index.d.mts +5 -5
  132. package/dist/node/log/log-file-rotation.d.cts +1 -1
  133. package/dist/node/log/log-file-rotation.d.mts +1 -1
  134. package/dist/node/log/log-file.d.cts +1 -1
  135. package/dist/node/log/log-file.d.mts +1 -1
  136. package/dist/node/log/log-node.cjs +4 -13
  137. package/dist/node/log/log-node.cjs.map +1 -1
  138. package/dist/node/log/log-node.d.cts +1 -1
  139. package/dist/node/log/log-node.d.mts +1 -1
  140. package/dist/node/log/log-node.mjs +4 -13
  141. package/dist/node/log/log-node.mjs.map +1 -1
  142. package/dist/node/log/log-rotation.d.cts +1 -1
  143. package/dist/node/log/log-rotation.d.mts +1 -1
  144. package/dist/node/log/log-util.d.cts +1 -1
  145. package/dist/node/log/log-util.d.mts +1 -1
  146. package/dist/{promise-DGgiRckN.d.cts → promise-CU_CENbU.d.cts} +1 -1
  147. package/dist/{promise-MH3xAy4S.d.mts → promise-CoWXgo4w.d.mts} +1 -1
  148. package/dist/select-DrciHdk_.d.cts +52 -0
  149. package/dist/select-F2KpP6mo.d.mts +52 -0
  150. package/dist/table-Cr8tjDIL.d.mts +19 -0
  151. package/dist/table-IkLXirT-.d.cts +19 -0
  152. package/dist/{test-CAhm15f4.d.mts → test-DcXa0MeX.d.cts} +1 -1
  153. package/dist/{test-D2plOVHF.d.cts → test-jZsc7P2c.d.mts} +1 -1
  154. package/dist/{throttle-debounce-BLFxAZ8W.d.mts → throttle-debounce-CCh0F100.d.mts} +1 -1
  155. package/dist/{throttle-debounce-Psb0ay1r.d.cts → throttle-debounce-DyFiyoAk.d.cts} +1 -1
  156. package/dist/{time-BfKJBbym.d.cts → time-BgFZe9ys.d.cts} +1 -1
  157. package/dist/{time-DxE-vjjw.d.mts → time-DSV_k3mG.d.mts} +1 -1
  158. package/dist/{timeout-CnUk6Ruj.d.mts → timeout-DDSSNZY8.d.mts} +1 -1
  159. package/dist/{timeout-CpFcK8MD.d.cts → timeout-E3ZQbJgK.d.cts} +1 -1
  160. package/dist/{type-test-BiKyEZkc.d.mts → type-test-BvzWDJz3.d.mts} +1 -1
  161. package/dist/{type-test-sM7QpfQU.d.cts → type-test-CBK-iJ9d.d.cts} +1 -1
  162. package/dist/{utils-B8DsVgFr.d.mts → utils-1RyCGkpQ.d.mts} +1 -1
  163. package/dist/{utils-BfZkD2Pt.d.mts → utils-6Culwiaf.d.cts} +1 -1
  164. package/dist/{utils-DHQBNh-Z.d.cts → utils-CDJihcg3.d.mts} +1 -1
  165. package/dist/{utils-Bctk_WhH.d.cts → utils-nCQklGHV.d.cts} +1 -1
  166. package/dist/{uuid-Cusm2nIK.d.cts → uuid-CKFZfSff.d.mts} +1 -1
  167. package/dist/{uuid-ININPGKB.d.mts → uuid-D42A8UdP.d.cts} +1 -1
  168. package/dist/z-C0fpNWZg.d.cts +1 -0
  169. package/dist/z-D_jezYmm.d.mts +1 -0
  170. package/dist/{z-collection-BmuBin--.d.mts → z-collection-BSfgRU0Q.d.mts} +1 -1
  171. package/package.json +7 -8
  172. package/src/common/schema/export-json-schema.spec.ts +11 -7
  173. package/src/common/schema/export-json-schema.ts +59 -52
  174. package/src/common/schema/index.ts +1 -0
  175. package/src/common/schema/sql/README.md +254 -0
  176. package/src/common/schema/sql/expr.ts +99 -0
  177. package/src/common/schema/sql/index.ts +3 -0
  178. package/src/common/schema/sql/select.spec.ts +144 -0
  179. package/src/common/schema/sql/select.ts +207 -0
  180. package/src/common/schema/sql/table.ts +36 -0
  181. /package/dist/{index-BH1nuHdZ.d.cts → index-CIABef8t.d.mts} +0 -0
  182. /package/dist/{index-BL7o4fG9.d.cts → index-CliqZ9rj.d.mts} +0 -0
  183. /package/dist/{index-CP2eJYlK.d.mts → index-D6xqj1Qx.d.cts} +0 -0
  184. /package/dist/{index-DjOaHFU3.d.mts → index-DHFfG4yr.d.cts} +0 -0
  185. /package/dist/{index-sViox9YW.d.mts → index-N-OgGgfF.d.mts} +0 -0
  186. /package/dist/{z-ClMox7qS.d.mts → index-WOw4GVZo.d.cts} +0 -0
  187. /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