rado 0.2.13 → 0.2.14
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/define/Column.d.ts +3 -4
- package/dist/define/Column.js +11 -11
- package/dist/define/Cursor.js +1 -1
- package/dist/define/Expr.d.ts +4 -4
- package/dist/define/Expr.js +24 -19
- package/dist/define/Table.js +1 -1
- package/dist/lib/Driver.d.ts +1 -2
- package/dist/lib/Driver.js +4 -4
- package/dist/lib/Formatter.js +3 -3
- package/dist/util/Callable.d.ts +1 -3
- package/dist/util/Callable.js +12 -11
- package/package.json +1 -1
package/dist/define/Column.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Callable } from '../util/Callable';
|
|
2
1
|
import { EV, Expr, ExprData } from './Expr';
|
|
3
2
|
import { Fields } from './Fields';
|
|
4
3
|
export declare enum ColumnType {
|
|
@@ -37,7 +36,7 @@ export declare namespace Column {
|
|
|
37
36
|
interface ValueColumn<T> extends Expr<T> {
|
|
38
37
|
<X extends T = T>(): ValueColumn<T extends null ? X | null : X>;
|
|
39
38
|
}
|
|
40
|
-
declare class ValueColumn<T>
|
|
39
|
+
declare class ValueColumn<T> implements Column<T> {
|
|
41
40
|
[Column.type]: T;
|
|
42
41
|
[Column.data]: PartialColumnData;
|
|
43
42
|
constructor(data: PartialColumnData);
|
|
@@ -57,7 +56,7 @@ export declare class PrimaryColumn<T, K> extends ValueColumn<PrimaryKey<T, K>> {
|
|
|
57
56
|
interface ObjectColumn<T> {
|
|
58
57
|
<X extends T = T>(): Column<T extends null ? X | null : X> & Fields<X>;
|
|
59
58
|
}
|
|
60
|
-
declare class ObjectColumn<T>
|
|
59
|
+
declare class ObjectColumn<T> implements Column<T> {
|
|
61
60
|
[Column.type]: T;
|
|
62
61
|
[Column.data]: PartialColumnData;
|
|
63
62
|
constructor(data: PartialColumnData);
|
|
@@ -75,7 +74,7 @@ type DefaultValue<T> = EV<T> | (() => EV<T>);
|
|
|
75
74
|
interface UnTyped {
|
|
76
75
|
(name: string): UnTyped;
|
|
77
76
|
}
|
|
78
|
-
declare class UnTyped
|
|
77
|
+
declare class UnTyped {
|
|
79
78
|
[Column.data]: PartialColumnData;
|
|
80
79
|
constructor(data?: PartialColumnData);
|
|
81
80
|
get nullable(): NullableUnTyped;
|
package/dist/define/Column.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/define/Column.ts
|
|
2
|
-
import {
|
|
2
|
+
import { callable } from "../util/Callable.js";
|
|
3
3
|
import { Expr, ExprData } from "./Expr.js";
|
|
4
4
|
var ColumnType = /* @__PURE__ */ ((ColumnType2) => {
|
|
5
5
|
ColumnType2["String"] = "String";
|
|
@@ -14,17 +14,17 @@ var Column;
|
|
|
14
14
|
Column2.data = Symbol("columnData");
|
|
15
15
|
Column2.type = Symbol("columnType");
|
|
16
16
|
})(Column || (Column = {}));
|
|
17
|
-
var ValueColumn = class
|
|
17
|
+
var ValueColumn = class {
|
|
18
18
|
[Column.type];
|
|
19
19
|
[Column.data];
|
|
20
20
|
constructor(data) {
|
|
21
|
-
|
|
21
|
+
this[Column.data] = data;
|
|
22
|
+
return callable(this, (defaultValue) => {
|
|
22
23
|
return new ValueColumn({
|
|
23
24
|
...this[Column.data],
|
|
24
25
|
defaultValue: createDefaultValue(defaultValue)
|
|
25
26
|
});
|
|
26
27
|
});
|
|
27
|
-
this[Column.data] = data;
|
|
28
28
|
}
|
|
29
29
|
get nullable() {
|
|
30
30
|
return new ValueColumn({ ...this[Column.data], nullable: true });
|
|
@@ -46,7 +46,7 @@ var ValueColumn = class extends Callable {
|
|
|
46
46
|
return new ValueColumn({
|
|
47
47
|
...this[Column.data],
|
|
48
48
|
references() {
|
|
49
|
-
return ExprData.create(column2
|
|
49
|
+
return ExprData.create(Expr.isExpr(column2) ? column2 : column2());
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
}
|
|
@@ -58,7 +58,7 @@ var ValueColumn = class extends Callable {
|
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
60
|
function createDefaultValue(value) {
|
|
61
|
-
return typeof value === "function" && !(value
|
|
61
|
+
return typeof value === "function" && !Expr.isExpr(value) ? () => ExprData.create(value()) : ExprData.create(value);
|
|
62
62
|
}
|
|
63
63
|
var OptionalColumn = class extends ValueColumn {
|
|
64
64
|
[Column.isOptional];
|
|
@@ -66,12 +66,12 @@ var OptionalColumn = class extends ValueColumn {
|
|
|
66
66
|
var PrimaryColumn = class extends ValueColumn {
|
|
67
67
|
[Column.isPrimary];
|
|
68
68
|
};
|
|
69
|
-
var ObjectColumn = class
|
|
69
|
+
var ObjectColumn = class {
|
|
70
70
|
[Column.type];
|
|
71
71
|
[Column.data];
|
|
72
72
|
constructor(data) {
|
|
73
|
-
super(() => this);
|
|
74
73
|
this[Column.data] = data;
|
|
74
|
+
return callable(this, () => this);
|
|
75
75
|
}
|
|
76
76
|
get nullable() {
|
|
77
77
|
return new ObjectColumn({ ...this[Column.data], nullable: true });
|
|
@@ -89,13 +89,13 @@ var ObjectColumn = class extends Callable {
|
|
|
89
89
|
var OptionalObjectColumn = class extends ObjectColumn {
|
|
90
90
|
[Column.isOptional];
|
|
91
91
|
};
|
|
92
|
-
var UnTyped = class
|
|
92
|
+
var UnTyped = class {
|
|
93
93
|
[Column.data];
|
|
94
94
|
constructor(data = {}) {
|
|
95
|
-
|
|
95
|
+
this[Column.data] = data;
|
|
96
|
+
return callable(this, (name) => {
|
|
96
97
|
return new ValueColumn({ ...data, name });
|
|
97
98
|
});
|
|
98
|
-
this[Column.data] = data;
|
|
99
99
|
}
|
|
100
100
|
get nullable() {
|
|
101
101
|
return new UnTyped({ ...this[Column.data], nullable: true });
|
package/dist/define/Cursor.js
CHANGED
package/dist/define/Expr.d.ts
CHANGED
|
@@ -126,10 +126,8 @@ export declare const ExprData: {
|
|
|
126
126
|
};
|
|
127
127
|
/** Expression or value of type T */
|
|
128
128
|
export type EV<T> = Expr<T> | T;
|
|
129
|
-
declare
|
|
130
|
-
|
|
131
|
-
declare const callable: typeof Empty;
|
|
132
|
-
export declare class Expr<T> extends callable {
|
|
129
|
+
declare const isExpr: unique symbol;
|
|
130
|
+
export declare class Expr<T> {
|
|
133
131
|
expr: ExprData;
|
|
134
132
|
static NULL: Expr<null>;
|
|
135
133
|
static toExpr: symbol;
|
|
@@ -137,7 +135,9 @@ export declare class Expr<T> extends callable {
|
|
|
137
135
|
static create<T>(input: EV<T>): Expr<T>;
|
|
138
136
|
static and(...conditions: Array<EV<boolean>>): Expr<boolean>;
|
|
139
137
|
static or(...conditions: Array<EV<boolean>>): Expr<boolean>;
|
|
138
|
+
static isExpr<T>(input: any): input is Expr<T>;
|
|
140
139
|
constructor(expr: ExprData);
|
|
140
|
+
[isExpr]: boolean;
|
|
141
141
|
asc(): OrderBy;
|
|
142
142
|
desc(): OrderBy;
|
|
143
143
|
not(): Expr<boolean>;
|
package/dist/define/Expr.js
CHANGED
|
@@ -94,7 +94,7 @@ var ExprData = {
|
|
|
94
94
|
return ExprData.Param(ParamData.Value(null));
|
|
95
95
|
if (input && (typeof input === "function" || typeof input === "object") && input[Expr.toExpr])
|
|
96
96
|
input = input[Expr.toExpr]();
|
|
97
|
-
if (input
|
|
97
|
+
if (Expr.isExpr(input))
|
|
98
98
|
return input.expr;
|
|
99
99
|
if (input && typeof input === "object" && !Array.isArray(input))
|
|
100
100
|
return ExprData.Record(
|
|
@@ -123,27 +123,28 @@ function dotAccess(expr, path) {
|
|
|
123
123
|
return new Expr(ExprData.Field(expr.expr, path.join(".")));
|
|
124
124
|
}
|
|
125
125
|
function exprAccess(expr, ...path) {
|
|
126
|
-
return new Proxy(
|
|
127
|
-
|
|
128
|
-
const proto = getPrototypeOf(expr);
|
|
126
|
+
return new Proxy(
|
|
127
|
+
(...args) => {
|
|
129
128
|
const method = path.pop();
|
|
129
|
+
const proto = Expr.prototype;
|
|
130
130
|
const e = path.length > 0 ? dotAccess(expr, path) : expr;
|
|
131
|
-
return proto[method]
|
|
131
|
+
return proto[method]?.apply(e, args);
|
|
132
132
|
},
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
{
|
|
134
|
+
get(_, key) {
|
|
135
|
+
const e = path.length > 0 ? dotAccess(expr, path) : expr;
|
|
136
|
+
if (key === "expr")
|
|
137
|
+
return e.expr;
|
|
138
|
+
if (typeof key !== "string")
|
|
139
|
+
return e[key];
|
|
140
|
+
return exprAccess(expr, ...path, key);
|
|
141
|
+
}
|
|
140
142
|
}
|
|
141
|
-
|
|
143
|
+
);
|
|
142
144
|
}
|
|
143
|
-
var
|
|
144
|
-
var _Expr = class
|
|
145
|
+
var isExpr = Symbol("isExpr");
|
|
146
|
+
var _Expr = class {
|
|
145
147
|
constructor(expr) {
|
|
146
|
-
super();
|
|
147
148
|
this.expr = expr;
|
|
148
149
|
return exprAccess(this);
|
|
149
150
|
}
|
|
@@ -151,7 +152,7 @@ var _Expr = class extends callable {
|
|
|
151
152
|
return new _Expr(ExprData.Param(ParamData.Value(value)));
|
|
152
153
|
}
|
|
153
154
|
static create(input) {
|
|
154
|
-
if (input
|
|
155
|
+
if (_Expr.isExpr(input))
|
|
155
156
|
return input;
|
|
156
157
|
return new _Expr(ExprData.create(input));
|
|
157
158
|
}
|
|
@@ -161,6 +162,10 @@ var _Expr = class extends callable {
|
|
|
161
162
|
static or(...conditions) {
|
|
162
163
|
return conditions.map(_Expr.create).reduce((condition, expr) => condition.or(expr), _Expr.value(false));
|
|
163
164
|
}
|
|
165
|
+
static isExpr(input) {
|
|
166
|
+
return input !== null && (typeof input === "object" || typeof input === "function") && input[isExpr];
|
|
167
|
+
}
|
|
168
|
+
[isExpr] = true;
|
|
164
169
|
asc() {
|
|
165
170
|
return { expr: this.expr, order: OrderDirection.Asc };
|
|
166
171
|
}
|
|
@@ -189,12 +194,12 @@ var _Expr = class extends callable {
|
|
|
189
194
|
return new _Expr(ExprData.BinOp("And" /* And */, a, b));
|
|
190
195
|
}
|
|
191
196
|
is(that) {
|
|
192
|
-
if (that === null || that
|
|
197
|
+
if (that === null || _Expr.isExpr(that) && isConstant(that.expr, null))
|
|
193
198
|
return this.isNull();
|
|
194
199
|
return new _Expr(ExprData.BinOp("Equals" /* Equals */, this.expr, toExpr(that)));
|
|
195
200
|
}
|
|
196
201
|
isNot(that) {
|
|
197
|
-
if (that === null || that
|
|
202
|
+
if (that === null || _Expr.isExpr(that) && isConstant(that.expr, null))
|
|
198
203
|
return this.isNotNull();
|
|
199
204
|
return new _Expr(
|
|
200
205
|
ExprData.BinOp("NotEquals" /* NotEquals */, this.expr, toExpr(that))
|
package/dist/define/Table.js
CHANGED
|
@@ -28,7 +28,7 @@ function createTable(data) {
|
|
|
28
28
|
const target = Target.Table(data);
|
|
29
29
|
const call = {
|
|
30
30
|
[data.name]: function(...args) {
|
|
31
|
-
const isConditionalRecord = args.length === 1 &&
|
|
31
|
+
const isConditionalRecord = args.length === 1 && !Expr.isExpr(args[0]);
|
|
32
32
|
const conditions = isConditionalRecord ? entries(args[0]).map(([key, value]) => {
|
|
33
33
|
const column = data.columns[key];
|
|
34
34
|
if (!column)
|
package/dist/lib/Driver.d.ts
CHANGED
|
@@ -3,10 +3,9 @@ import { Expr } from '../define/Expr';
|
|
|
3
3
|
import { Query } from '../define/Query';
|
|
4
4
|
import { SchemaInstructions } from '../define/Schema';
|
|
5
5
|
import { Table } from '../define/Table';
|
|
6
|
-
import { Callable } from '../util/Callable';
|
|
7
6
|
import { Formatter } from './Formatter';
|
|
8
7
|
import { Statement } from './Statement';
|
|
9
|
-
declare abstract class DriverBase
|
|
8
|
+
declare abstract class DriverBase {
|
|
10
9
|
formatter: Formatter;
|
|
11
10
|
constructor(formatter: Formatter);
|
|
12
11
|
compile<T extends Array<Expr<any>>, R>(create: (...params: T) => Cursor<R>): [Query<T>, Statement];
|
package/dist/lib/Driver.js
CHANGED
|
@@ -5,13 +5,14 @@ import { ParamData } from "../define/Param.js";
|
|
|
5
5
|
import { Query, QueryType } from "../define/Query.js";
|
|
6
6
|
import { Schema } from "../define/Schema.js";
|
|
7
7
|
import { table } from "../define/Table.js";
|
|
8
|
-
import {
|
|
8
|
+
import { callable } from "../util/Callable.js";
|
|
9
9
|
function isTemplateStringsArray(input) {
|
|
10
10
|
return Boolean(Array.isArray(input) && input.raw);
|
|
11
11
|
}
|
|
12
|
-
var DriverBase = class
|
|
12
|
+
var DriverBase = class {
|
|
13
13
|
constructor(formatter) {
|
|
14
|
-
|
|
14
|
+
this.formatter = formatter;
|
|
15
|
+
return callable(this, (...args) => {
|
|
15
16
|
const [input, ...rest] = args;
|
|
16
17
|
if (input instanceof Cursor && rest.length === 0)
|
|
17
18
|
return this.executeQuery(input.query());
|
|
@@ -23,7 +24,6 @@ var DriverBase = class extends Callable {
|
|
|
23
24
|
})
|
|
24
25
|
);
|
|
25
26
|
});
|
|
26
|
-
this.formatter = formatter;
|
|
27
27
|
}
|
|
28
28
|
compile(create) {
|
|
29
29
|
const { length } = create;
|
package/dist/lib/Formatter.js
CHANGED
|
@@ -134,7 +134,7 @@ var Formatter = class {
|
|
|
134
134
|
for (const key of stmt.separate(keys)) {
|
|
135
135
|
stmt.identifier(key).add("=").space();
|
|
136
136
|
const value = data[key];
|
|
137
|
-
if (value
|
|
137
|
+
if (Expr.isExpr(value))
|
|
138
138
|
this.formatExprJson(ctx, ExprData.create(data[key]));
|
|
139
139
|
else
|
|
140
140
|
this.formatValue({ ...ctx, formatAsInsert: true }, value);
|
|
@@ -245,7 +245,7 @@ var Formatter = class {
|
|
|
245
245
|
ctx.stmt.raw(strings[i]);
|
|
246
246
|
if (i < params.length) {
|
|
247
247
|
const param = params[i];
|
|
248
|
-
if (param
|
|
248
|
+
if (Expr.isExpr(param))
|
|
249
249
|
this.formatExpr(ctx, param.expr);
|
|
250
250
|
else
|
|
251
251
|
this.formatValue(ctx, param);
|
|
@@ -316,7 +316,7 @@ var Formatter = class {
|
|
|
316
316
|
}
|
|
317
317
|
formatColumnValue(ctx, column, columnValue) {
|
|
318
318
|
const { stmt } = ctx;
|
|
319
|
-
if (columnValue
|
|
319
|
+
if (Expr.isExpr(columnValue))
|
|
320
320
|
return this.formatExprValue(ctx, columnValue.expr);
|
|
321
321
|
const isNull = columnValue === void 0 || columnValue === null;
|
|
322
322
|
const isOptional = column.nullable || column.autoIncrement || column.primaryKey;
|
package/dist/util/Callable.d.ts
CHANGED
package/dist/util/Callable.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
// src/util/Callable.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
2
|
+
function callable(target, call) {
|
|
3
|
+
return new Proxy(call, {
|
|
4
|
+
set(_, prop, value) {
|
|
5
|
+
target[prop] = value;
|
|
6
|
+
return true;
|
|
7
|
+
},
|
|
8
|
+
get(_, prop) {
|
|
9
|
+
return target[prop];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
12
13
|
export {
|
|
13
|
-
|
|
14
|
+
callable
|
|
14
15
|
};
|