@rindle/client 0.1.0-rc.5
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/LICENSE +201 -0
- package/README.md +65 -0
- package/dist/ast.d.ts +83 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/ast.js +5 -0
- package/dist/ast.js.map +1 -0
- package/dist/compare.d.ts +17 -0
- package/dist/compare.d.ts.map +1 -0
- package/dist/compare.js +81 -0
- package/dist/compare.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/key.d.ts +2 -0
- package/dist/key.d.ts.map +1 -0
- package/dist/key.js +26 -0
- package/dist/key.js.map +1 -0
- package/dist/operators.d.ts +39 -0
- package/dist/operators.d.ts.map +1 -0
- package/dist/operators.js +45 -0
- package/dist/operators.js.map +1 -0
- package/dist/query.d.ts +280 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +348 -0
- package/dist/query.js.map +1 -0
- package/dist/schema.d.ts +111 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +92 -0
- package/dist/schema.js.map +1 -0
- package/dist/ssr.d.ts +73 -0
- package/dist/ssr.d.ts.map +1 -0
- package/dist/ssr.js +66 -0
- package/dist/ssr.js.map +1 -0
- package/dist/store.d.ts +90 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +225 -0
- package/dist/store.js.map +1 -0
- package/dist/types.d.ts +250 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +20 -0
- package/dist/types.js.map +1 -0
- package/dist/view.d.ts +88 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +294 -0
- package/dist/view.js.map +1 -0
- package/package.json +36 -0
- package/src/ast.ts +94 -0
- package/src/compare.ts +85 -0
- package/src/index.ts +57 -0
- package/src/key.ts +23 -0
- package/src/operators.ts +68 -0
- package/src/query.ts +734 -0
- package/src/schema.ts +181 -0
- package/src/ssr.ts +115 -0
- package/src/store.ts +279 -0
- package/src/types.ts +234 -0
- package/src/view.ts +348 -0
package/src/operators.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Named value-operators (`eq`/`gt`/`like`/…) + boolean combinators (`or`/`and`) for the
|
|
2
|
+
// query builder. Operators are VALUE-ONLY — the value type `V` is inferred from the value,
|
|
3
|
+
// and the FIELD is bound separately (by `where.<field>(…)` or `table.<field>(…)`), so
|
|
4
|
+
// `or`/`exists` need no closure (WASM-CLIENT-DESIGN.md §6).
|
|
5
|
+
|
|
6
|
+
import type { Condition, LitValue, SimpleOp } from "./ast.ts";
|
|
7
|
+
|
|
8
|
+
const PRED: unique symbol = Symbol("rindle.pred");
|
|
9
|
+
|
|
10
|
+
/** A value predicate (an operator applied to a value). `V` is a phantom for type-checking. */
|
|
11
|
+
export interface Pred<V> {
|
|
12
|
+
readonly [PRED]: true;
|
|
13
|
+
readonly op: SimpleOp;
|
|
14
|
+
readonly value: LitValue;
|
|
15
|
+
readonly __v?: V;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function mk<V>(op: SimpleOp, value: LitValue): Pred<V> {
|
|
19
|
+
return { [PRED]: true, op, value } as Pred<V>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function isPred(x: unknown): x is Pred<unknown> {
|
|
23
|
+
return typeof x === "object" && x !== null && (x as Record<symbol, unknown>)[PRED] === true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const eq = <V>(v: V): Pred<V> => mk("=", v as LitValue);
|
|
27
|
+
export const ne = <V>(v: V): Pred<V> => mk("!=", v as LitValue);
|
|
28
|
+
export const gt = <V extends number | string>(v: V): Pred<V> => mk(">", v as LitValue);
|
|
29
|
+
export const ge = <V extends number | string>(v: V): Pred<V> => mk(">=", v as LitValue);
|
|
30
|
+
export const lt = <V extends number | string>(v: V): Pred<V> => mk("<", v as LitValue);
|
|
31
|
+
export const le = <V extends number | string>(v: V): Pred<V> => mk("<=", v as LitValue);
|
|
32
|
+
export const like = (pattern: string): Pred<string> => mk("LIKE", pattern);
|
|
33
|
+
export const notLike = (pattern: string): Pred<string> => mk("NOT LIKE", pattern);
|
|
34
|
+
export const ilike = (pattern: string): Pred<string> => mk("ILIKE", pattern);
|
|
35
|
+
export const notIlike = (pattern: string): Pred<string> => mk("NOT ILIKE", pattern);
|
|
36
|
+
export const inList = <V>(values: V[]): Pred<V> => mk("IN", values as LitValue);
|
|
37
|
+
export const notInList = <V>(values: V[]): Pred<V> => mk("NOT IN", values as LitValue);
|
|
38
|
+
export const is = <V>(v: V): Pred<V> => mk("IS", v as LitValue);
|
|
39
|
+
export const isNot = <V>(v: V): Pred<V> => mk("IS NOT", v as LitValue);
|
|
40
|
+
|
|
41
|
+
/** A field argument: its typed predicate, or a bare value (bare = `eq` sugar). */
|
|
42
|
+
export type Arg<V> = Pred<V> | V;
|
|
43
|
+
|
|
44
|
+
/** A condition over row `R`. The runtime value is the wire {@link Condition}; `R` is a
|
|
45
|
+
* phantom brand so a condition for one table can't be `.where()`d onto another. */
|
|
46
|
+
export type Cond<R> = Condition & { readonly __row?: R };
|
|
47
|
+
|
|
48
|
+
/** Build a `simple` condition from a field name + (predicate | bare value). */
|
|
49
|
+
export function fieldCondition(field: string, arg: unknown): Condition {
|
|
50
|
+
const op: SimpleOp = isPred(arg) ? arg.op : "=";
|
|
51
|
+
const value: LitValue = isPred(arg) ? arg.value : (arg as LitValue);
|
|
52
|
+
return {
|
|
53
|
+
type: "simple",
|
|
54
|
+
op,
|
|
55
|
+
left: { type: "column", name: field },
|
|
56
|
+
right: { type: "literal", value },
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** All children must hold. */
|
|
61
|
+
export function and<R>(...conds: Cond<R>[]): Cond<R> {
|
|
62
|
+
return { type: "and", conditions: conds } as Cond<R>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** At least one child must hold. */
|
|
66
|
+
export function or<R>(...conds: Cond<R>[]): Cond<R> {
|
|
67
|
+
return { type: "or", conditions: conds } as Cond<R>;
|
|
68
|
+
}
|