@spooky-sync/query-builder 0.0.1-canary.1 → 0.0.1-canary.100
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/AGENTS.md +63 -0
- package/dist/index.d.mts +67 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +67 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
- package/skills/sp00ky-query-builder/SKILL.md +201 -0
- package/skills/sp00ky-query-builder/references/type-helpers.md +80 -0
- package/src/index.ts +3 -0
- package/src/query-builder.test.ts +75 -4
- package/src/query-builder.ts +39 -16
- package/src/repro_relationship.test.ts +1 -1
- package/src/table-schema.ts +50 -3
- package/src/types.ts +37 -5
package/src/types.ts
CHANGED
|
@@ -36,9 +36,40 @@ export interface RelatedQuery {
|
|
|
36
36
|
cardinality: 'one' | 'many';
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Comparison-operator descriptor for a single WHERE field, e.g.
|
|
41
|
+
* `{ _op: '<=', _val: 5 }` → `field <= $field`. A `$`-prefixed string `_val`
|
|
42
|
+
* references an existing query param verbatim; `_swap: true` flips the operands
|
|
43
|
+
* (`$val _op field`). Plain values still mean equality (`field = $field`).
|
|
44
|
+
*/
|
|
45
|
+
export interface ComparisonOp {
|
|
46
|
+
_op: '=' | '!=' | '>' | '>=' | '<' | '<=' | (string & {});
|
|
47
|
+
_val: unknown;
|
|
48
|
+
_swap?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A single WHERE field value: an equality value or a comparison descriptor. */
|
|
52
|
+
export type WhereFieldValue<V> = V | ComparisonOp;
|
|
53
|
+
|
|
54
|
+
/** A flat conjunction of field conditions (equality or comparison). */
|
|
55
|
+
export type WhereConditions<TModel extends GenericModel> = {
|
|
56
|
+
[K in keyof TModel]?: WhereFieldValue<TModel[K]>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* WHERE input for `.where()`. Supports equality (`{ field: value }`), comparison
|
|
61
|
+
* operators (`{ field: { _op, _val } }`), and a single top-level `_or` group of
|
|
62
|
+
* condition fragments that compile to a parenthesised `(... OR ...)` conjunct —
|
|
63
|
+
* e.g. `{ _or: [{ white: x }, { black: x }] }` → `(white = $or0 OR black = $or1)`.
|
|
64
|
+
* Backward-compatible with plain `Partial<TModel>` equality objects.
|
|
65
|
+
*/
|
|
66
|
+
export type WhereInput<TModel extends GenericModel> = WhereConditions<TModel> & {
|
|
67
|
+
_or?: WhereConditions<TModel>[];
|
|
68
|
+
};
|
|
69
|
+
|
|
39
70
|
export interface QueryOptions<TModel extends GenericModel, IsOne extends boolean> {
|
|
40
71
|
select?: ((keyof TModel & string) | '*')[];
|
|
41
|
-
where?:
|
|
72
|
+
where?: WhereInput<TModel>;
|
|
42
73
|
limit?: number;
|
|
43
74
|
offset?: number;
|
|
44
75
|
orderBy?: Partial<Record<keyof TModel, 'asc' | 'desc'>>;
|
|
@@ -47,10 +78,10 @@ export interface QueryOptions<TModel extends GenericModel, IsOne extends boolean
|
|
|
47
78
|
isOne?: IsOne;
|
|
48
79
|
}
|
|
49
80
|
|
|
50
|
-
export
|
|
81
|
+
export type LiveQueryOptions<TModel extends GenericModel> = Omit<
|
|
51
82
|
QueryOptions<TModel, boolean>,
|
|
52
83
|
'orderBy'
|
|
53
|
-
|
|
84
|
+
>;
|
|
54
85
|
|
|
55
86
|
// Import schema types for schema-aware modifiers
|
|
56
87
|
import type {
|
|
@@ -78,7 +109,7 @@ export type SchemaAwareQueryModifier<
|
|
|
78
109
|
|
|
79
110
|
// Simplified query builder interface for modifying subqueries
|
|
80
111
|
export interface QueryModifierBuilder<TModel extends GenericModel> {
|
|
81
|
-
where(conditions:
|
|
112
|
+
where(conditions: WhereInput<TModel>): this;
|
|
82
113
|
select(...fields: ((keyof TModel & string) | '*')[]): this;
|
|
83
114
|
limit(count: number): this;
|
|
84
115
|
offset(count: number): this;
|
|
@@ -93,7 +124,7 @@ export interface SchemaAwareQueryModifierBuilder<
|
|
|
93
124
|
TableName extends TableNames<S>,
|
|
94
125
|
RelatedFields extends Record<string, any> = {},
|
|
95
126
|
> {
|
|
96
|
-
where(conditions:
|
|
127
|
+
where(conditions: WhereInput<TableModel<GetTable<S, TableName>>>): this;
|
|
97
128
|
select(...fields: ((keyof TableModel<GetTable<S, TableName>> & string) | '*')[]): this;
|
|
98
129
|
limit(count: number): this;
|
|
99
130
|
offset(count: number): this;
|
|
@@ -139,6 +170,7 @@ export type RelationshipFields<TModel extends GenericModel> = {
|
|
|
139
170
|
* Simplified to directly access the nested structure
|
|
140
171
|
*/
|
|
141
172
|
export type InferRelatedModelFromMetadata<
|
|
173
|
+
// oxlint-disable-next-line no-unused-vars -- Schema is used as a generic constraint
|
|
142
174
|
Schema extends GenericSchema,
|
|
143
175
|
TableName extends string,
|
|
144
176
|
FieldName extends string,
|