orange-orm 5.2.1 → 5.2.3-beta
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/README.md +9 -9
- package/SKILL.md +4 -0
- package/dist/index.browser.mjs +14 -6
- package/dist/index.mjs +14 -6
- package/docs/changelog.md +2 -0
- package/package.json +1 -1
- package/src/index.d.ts +12 -6
- package/src/map.d.ts +25 -18
- package/src/table/column.js +12 -4
- package/src/table/resultToRows/newDecodeDbRow.js +2 -2
package/README.md
CHANGED
|
@@ -12,11 +12,6 @@ The ultimate Object Relational Mapper for Node.js, Bun and Deno, offering seamle
|
|
|
12
12
|
[](https://discord.gg/QjuEgvQXzd)
|
|
13
13
|
[](https://youtu.be/1IwwjPr2lMs)
|
|
14
14
|
|
|
15
|
-
## MCP (Model Context Protocol)
|
|
16
|
-
Orange ORM is available as an MCP resource on Context7. Use it with AI-powered tools like GitHub Copilot, Cursor, or Claude to get up-to-date documentation and code examples directly in your IDE.
|
|
17
|
-
|
|
18
|
-
👉 [https://context7.com/alfateam/orange-orm](https://context7.com/alfateam/orange-orm)
|
|
19
|
-
|
|
20
15
|
## Key Features
|
|
21
16
|
|
|
22
17
|
- **Rich Querying Model**: Orange provides a powerful and intuitive querying model, making it easy to retrieve, filter, and manipulate data from your databases.
|
|
@@ -40,6 +35,10 @@ Orange ORM is available as an MCP resource on Context7. Use it with AI-powered t
|
|
|
40
35
|
## Sponsorship <span style="font-size: larger; color: darkred;">♡</span>
|
|
41
36
|
If you value the hard work behind Orange and wish to see it evolve further, consider [sponsoring](https://github.com/sponsors/lroal). Your support fuels the journey of refining and expanding this tool for our developer community.
|
|
42
37
|
|
|
38
|
+
## MCP (Model Context Protocol)
|
|
39
|
+
Orange ORM is available as an MCP resource on Context7. Use it with AI-powered tools like GitHub Copilot, Cursor, or Claude to get up-to-date documentation and code examples directly in your IDE.
|
|
40
|
+
👉 [https://context7.com/alfateam/orange-orm](https://context7.com/alfateam/orange-orm)
|
|
41
|
+
|
|
43
42
|
## Installation
|
|
44
43
|
|
|
45
44
|
```bash
|
|
@@ -2059,6 +2058,7 @@ export default map;
|
|
|
2059
2058
|
|
|
2060
2059
|
<details><summary><strong>Validation</strong></summary>
|
|
2061
2060
|
<p>In the previous sections you have already seen the <strong><i>notNull()</i></strong> validator being used on some columns. This will not only generate correct typescript mapping, but also throw an error if value is set to null or undefined. However, sometimes we do not want the notNull-validator to be run on inserts. Typically, when we have an autoincremental key or server generated uuid, it does not make sense to check for null on insert. This is where <strong><i>notNullExceptInsert()</strong></i> comes to rescue. You can also create your own custom validator as shown below. The last kind of validator, is the <a href="https://ajv.js.org/json-schema.html">ajv JSON schema validator</a>. This can be used on json columns as well as any other column type.</p>
|
|
2061
|
+
<p>Custom validators receive <code>value</code> and an optional metadata object with <code>table</code>, <code>column</code>, <code>property</code>, and <code>isInsert</code>.</p>
|
|
2062
2062
|
|
|
2063
2063
|
<sub>📄 map.ts</sub>
|
|
2064
2064
|
```ts
|
|
@@ -2076,9 +2076,9 @@ let petSchema = {
|
|
|
2076
2076
|
}
|
|
2077
2077
|
};
|
|
2078
2078
|
|
|
2079
|
-
function validateName(value?: string) {
|
|
2079
|
+
function validateName(value?: string, meta?: { table?: string; column?: string; property?: string; isInsert?: boolean }) {
|
|
2080
2080
|
if (value && value.length > 10)
|
|
2081
|
-
throw new Error(
|
|
2081
|
+
throw new Error(`Length cannot exceed 10 characters in ${meta?.table}.${meta?.column}`);
|
|
2082
2082
|
}
|
|
2083
2083
|
|
|
2084
2084
|
const map = orange.map(x => ({
|
|
@@ -2111,9 +2111,9 @@ let petSchema = {
|
|
|
2111
2111
|
}
|
|
2112
2112
|
};
|
|
2113
2113
|
|
|
2114
|
-
function validateName(value) {
|
|
2114
|
+
function validateName(value, meta) {
|
|
2115
2115
|
if (value && value.length > 10)
|
|
2116
|
-
throw new Error(
|
|
2116
|
+
throw new Error(`Length cannot exceed 10 characters in ${meta?.table}.${meta?.column}`);
|
|
2117
2117
|
}
|
|
2118
2118
|
|
|
2119
2119
|
const map = orange.map(x => ({
|
package/SKILL.md
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
> Supports: PostgreSQL, SQLite, MySQL, MS SQL, Oracle, SAP ASE, PGlite, Cloudflare D1.
|
|
7
7
|
> Works in the browser via Express/Hono adapters.
|
|
8
8
|
|
|
9
|
+
## Repository maintenance note
|
|
10
|
+
|
|
11
|
+
- Treat `dist/index.mjs` and `dist/index.browser.mjs` as generated build output from the build command, not as source files to review or edit directly unless the task explicitly targets build artifacts.
|
|
12
|
+
|
|
9
13
|
---
|
|
10
14
|
|
|
11
15
|
## Table of Contents
|
package/dist/index.browser.mjs
CHANGED
|
@@ -6270,6 +6270,10 @@ function requireColumn () {
|
|
|
6270
6270
|
return c;
|
|
6271
6271
|
};
|
|
6272
6272
|
|
|
6273
|
+
c.jsonOf = function() {
|
|
6274
|
+
return c.json();
|
|
6275
|
+
};
|
|
6276
|
+
|
|
6273
6277
|
c.guid = function() {
|
|
6274
6278
|
requireGuid()(column);
|
|
6275
6279
|
return c;
|
|
@@ -6387,8 +6391,8 @@ function requireColumn () {
|
|
|
6387
6391
|
|
|
6388
6392
|
c.notNullExceptInsert = function() {
|
|
6389
6393
|
column._notNullExceptInsert = true;
|
|
6390
|
-
function validate(value,
|
|
6391
|
-
if (isInsert)
|
|
6394
|
+
function validate(value, meta) {
|
|
6395
|
+
if (meta?.isInsert)
|
|
6392
6396
|
return;
|
|
6393
6397
|
if (value === undefined || value === null)
|
|
6394
6398
|
throw new Error(`Column ${column.alias} cannot be null or undefined`);
|
|
@@ -6402,12 +6406,12 @@ function requireColumn () {
|
|
|
6402
6406
|
if (previousValue)
|
|
6403
6407
|
column.validate = nestedValidate;
|
|
6404
6408
|
else
|
|
6405
|
-
column.validate =
|
|
6409
|
+
column.validate = invokeValidate;
|
|
6406
6410
|
|
|
6407
6411
|
function nestedValidate() {
|
|
6408
6412
|
try {
|
|
6409
6413
|
previousValue.apply(null, arguments);
|
|
6410
|
-
|
|
6414
|
+
invokeValidate.apply(null, arguments);
|
|
6411
6415
|
}
|
|
6412
6416
|
catch (e) {
|
|
6413
6417
|
const error = new Error(e.message || e);
|
|
@@ -6416,6 +6420,10 @@ function requireColumn () {
|
|
|
6416
6420
|
throw error;
|
|
6417
6421
|
}
|
|
6418
6422
|
}
|
|
6423
|
+
|
|
6424
|
+
function invokeValidate(inputValue, meta) {
|
|
6425
|
+
value(inputValue, meta);
|
|
6426
|
+
}
|
|
6419
6427
|
return c;
|
|
6420
6428
|
};
|
|
6421
6429
|
|
|
@@ -8605,7 +8613,7 @@ function requireNewDecodeDbRow () {
|
|
|
8605
8613
|
value = purify(value);
|
|
8606
8614
|
this._dbRow[key] = value;
|
|
8607
8615
|
if (column.validate)
|
|
8608
|
-
column.validate(value,
|
|
8616
|
+
column.validate(value, { table: table._dbName, column: column._dbName, property: column.alias });
|
|
8609
8617
|
updateField(this._context, table, column, this);
|
|
8610
8618
|
let emit = this._emitColumnChanged[name];
|
|
8611
8619
|
if (emit)
|
|
@@ -8761,7 +8769,7 @@ function requireNewDecodeDbRow () {
|
|
|
8761
8769
|
if (row[key] !== undefined && !isInsert)
|
|
8762
8770
|
row[key] = columns[i].decode(context, row[key]);
|
|
8763
8771
|
if (shouldValidate && columns[i].validate)
|
|
8764
|
-
columns[i].validate(row[key],
|
|
8772
|
+
columns[i].validate(row[key], { table: table._dbName, column: columns[i]._dbName, property: columns[i].alias, isInsert });
|
|
8765
8773
|
}
|
|
8766
8774
|
let target = new Row(context, row);
|
|
8767
8775
|
const p = new Proxy(target, {
|
package/dist/index.mjs
CHANGED
|
@@ -6271,6 +6271,10 @@ function requireColumn () {
|
|
|
6271
6271
|
return c;
|
|
6272
6272
|
};
|
|
6273
6273
|
|
|
6274
|
+
c.jsonOf = function() {
|
|
6275
|
+
return c.json();
|
|
6276
|
+
};
|
|
6277
|
+
|
|
6274
6278
|
c.guid = function() {
|
|
6275
6279
|
requireGuid()(column);
|
|
6276
6280
|
return c;
|
|
@@ -6388,8 +6392,8 @@ function requireColumn () {
|
|
|
6388
6392
|
|
|
6389
6393
|
c.notNullExceptInsert = function() {
|
|
6390
6394
|
column._notNullExceptInsert = true;
|
|
6391
|
-
function validate(value,
|
|
6392
|
-
if (isInsert)
|
|
6395
|
+
function validate(value, meta) {
|
|
6396
|
+
if (meta?.isInsert)
|
|
6393
6397
|
return;
|
|
6394
6398
|
if (value === undefined || value === null)
|
|
6395
6399
|
throw new Error(`Column ${column.alias} cannot be null or undefined`);
|
|
@@ -6403,12 +6407,12 @@ function requireColumn () {
|
|
|
6403
6407
|
if (previousValue)
|
|
6404
6408
|
column.validate = nestedValidate;
|
|
6405
6409
|
else
|
|
6406
|
-
column.validate =
|
|
6410
|
+
column.validate = invokeValidate;
|
|
6407
6411
|
|
|
6408
6412
|
function nestedValidate() {
|
|
6409
6413
|
try {
|
|
6410
6414
|
previousValue.apply(null, arguments);
|
|
6411
|
-
|
|
6415
|
+
invokeValidate.apply(null, arguments);
|
|
6412
6416
|
}
|
|
6413
6417
|
catch (e) {
|
|
6414
6418
|
const error = new Error(e.message || e);
|
|
@@ -6417,6 +6421,10 @@ function requireColumn () {
|
|
|
6417
6421
|
throw error;
|
|
6418
6422
|
}
|
|
6419
6423
|
}
|
|
6424
|
+
|
|
6425
|
+
function invokeValidate(inputValue, meta) {
|
|
6426
|
+
value(inputValue, meta);
|
|
6427
|
+
}
|
|
6420
6428
|
return c;
|
|
6421
6429
|
};
|
|
6422
6430
|
|
|
@@ -8606,7 +8614,7 @@ function requireNewDecodeDbRow () {
|
|
|
8606
8614
|
value = purify(value);
|
|
8607
8615
|
this._dbRow[key] = value;
|
|
8608
8616
|
if (column.validate)
|
|
8609
|
-
column.validate(value,
|
|
8617
|
+
column.validate(value, { table: table._dbName, column: column._dbName, property: column.alias });
|
|
8610
8618
|
updateField(this._context, table, column, this);
|
|
8611
8619
|
let emit = this._emitColumnChanged[name];
|
|
8612
8620
|
if (emit)
|
|
@@ -8762,7 +8770,7 @@ function requireNewDecodeDbRow () {
|
|
|
8762
8770
|
if (row[key] !== undefined && !isInsert)
|
|
8763
8771
|
row[key] = columns[i].decode(context, row[key]);
|
|
8764
8772
|
if (shouldValidate && columns[i].validate)
|
|
8765
|
-
columns[i].validate(row[key],
|
|
8773
|
+
columns[i].validate(row[key], { table: table._dbName, column: columns[i]._dbName, property: columns[i].alias, isInsert });
|
|
8766
8774
|
}
|
|
8767
8775
|
let target = new Row(context, row);
|
|
8768
8776
|
const p = new Proxy(target, {
|
package/docs/changelog.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
## Changelog
|
|
2
|
+
__5.2.2__
|
|
3
|
+
Bugfix: jsonOf<T>() exists in type definitions but is missing at runtime [#166](https://github.com/alfateam/orange-orm/issues/166)
|
|
2
4
|
__5.2.1__
|
|
3
5
|
Bugfix: Bun Postgres fails on proxied JSON params [#158](https://github.com/alfateam/orange-orm/issues/158)
|
|
4
6
|
__5.2.0__
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -10,6 +10,12 @@ import type { Filter as MapFilter, RawFilter as MapRawFilter, Pool as MapPool, P
|
|
|
10
10
|
declare function r(config: r.Config): unknown;
|
|
11
11
|
|
|
12
12
|
declare namespace r {
|
|
13
|
+
export interface ValidationMeta {
|
|
14
|
+
table?: string;
|
|
15
|
+
column?: string;
|
|
16
|
+
property?: string;
|
|
17
|
+
isInsert?: boolean;
|
|
18
|
+
}
|
|
13
19
|
|
|
14
20
|
function table(name: string): Table;
|
|
15
21
|
function close(): Promise<void>;
|
|
@@ -94,7 +100,7 @@ declare namespace r {
|
|
|
94
100
|
date(): DateColumnDef;
|
|
95
101
|
}
|
|
96
102
|
export interface DateColumnDef {
|
|
97
|
-
validate(validator: (value?: Date | string,
|
|
103
|
+
validate(validator: (value?: Date | string, meta?: ValidationMeta) => void): DateColumnDef;
|
|
98
104
|
notNull(): DateColumnNotNullDef;
|
|
99
105
|
JSONSchema(schema: object, options?: Options): DateColumnDef;
|
|
100
106
|
serializable(value: boolean): DateColumnDef;
|
|
@@ -104,7 +110,7 @@ declare namespace r {
|
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
export interface DateColumnNotNullDef {
|
|
107
|
-
validate(validator: (value: Date | string,
|
|
113
|
+
validate(validator: (value: Date | string, meta?: ValidationMeta) => void): DateColumnNotNullDef;
|
|
108
114
|
JSONSchema(schema: object, options?: Options): DateColumnNotNullDef;
|
|
109
115
|
serializable(value: boolean): DateColumnNotNullDef;
|
|
110
116
|
as(dbName: string): DateColumnNotNullDef;
|
|
@@ -113,7 +119,7 @@ declare namespace r {
|
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
export interface BinaryColumnDef {
|
|
116
|
-
validate(validator: (value?: Buffer | string,
|
|
122
|
+
validate(validator: (value?: Buffer | string, meta?: ValidationMeta) => void): BinaryColumnDef;
|
|
117
123
|
notNull(): BinaryColumnNotNullDef;
|
|
118
124
|
JSONSchema(schema: object, options?: Options): BinaryColumnDef;
|
|
119
125
|
serializable(value: boolean): BinaryColumnDef;
|
|
@@ -123,7 +129,7 @@ declare namespace r {
|
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
export interface BinaryColumnNotNullDef {
|
|
126
|
-
validate(validator: (value: Buffer | string,
|
|
132
|
+
validate(validator: (value: Buffer | string, meta?: ValidationMeta) => void): BinaryColumnNotNullDef;
|
|
127
133
|
JSONSchema(schema: object, options?: Options): BinaryColumnNotNullDef;
|
|
128
134
|
serializable(value: boolean): BinaryColumnNotNullDef;
|
|
129
135
|
as(dbName: string): BinaryColumnNotNullDef;
|
|
@@ -132,7 +138,7 @@ declare namespace r {
|
|
|
132
138
|
}
|
|
133
139
|
|
|
134
140
|
export interface ColumnOf<T> {
|
|
135
|
-
validate(validator: (value?: T,
|
|
141
|
+
validate(validator: (value?: T, meta?: ValidationMeta) => void): ColumnOf<T>;
|
|
136
142
|
notNull(): ColumnNotNullOf<T>;
|
|
137
143
|
JSONSchema(schema: object, options?: Options): ColumnOf<T>;
|
|
138
144
|
serializable(value: boolean): ColumnOf<T>;
|
|
@@ -142,7 +148,7 @@ declare namespace r {
|
|
|
142
148
|
}
|
|
143
149
|
|
|
144
150
|
export interface ColumnNotNullOf<T> {
|
|
145
|
-
validate(validator: (value: T,
|
|
151
|
+
validate(validator: (value: T, meta?: ValidationMeta) => void): ColumnNotNullOf<T>;
|
|
146
152
|
notNull(): ColumnNotNullOf<T>;
|
|
147
153
|
JSONSchema(schema: object, options?: Options): ColumnNotNullOf<T>;
|
|
148
154
|
serializable(value: boolean): ColumnNotNullOf<T>;
|
package/src/map.d.ts
CHANGED
|
@@ -636,6 +636,13 @@ type JsonOf<T> = {
|
|
|
636
636
|
type: T;
|
|
637
637
|
};
|
|
638
638
|
|
|
639
|
+
interface ValidationMeta {
|
|
640
|
+
table?: string;
|
|
641
|
+
column?: string;
|
|
642
|
+
property?: string;
|
|
643
|
+
isInsert?: boolean;
|
|
644
|
+
}
|
|
645
|
+
|
|
639
646
|
interface ColumnType<M> {
|
|
640
647
|
string(): StringColumnTypeDef<M & StringColumnSymbol>;
|
|
641
648
|
uuid(): UuidColumnTypeDef<M & UuidColumnSymbol>;
|
|
@@ -652,90 +659,90 @@ interface ColumnType<M> {
|
|
|
652
659
|
|
|
653
660
|
type UuidValidator<M> = M extends NotNull
|
|
654
661
|
? {
|
|
655
|
-
validate(validator: (value: string) => void): UuidColumnTypeDef<M>;
|
|
662
|
+
validate(validator: (value: string, meta?: ValidationMeta) => void): UuidColumnTypeDef<M>;
|
|
656
663
|
}
|
|
657
664
|
: {
|
|
658
665
|
validate(
|
|
659
|
-
validator: (value?: string | null) => void
|
|
666
|
+
validator: (value?: string | null, meta?: ValidationMeta) => void
|
|
660
667
|
): UuidColumnTypeDef<M>;
|
|
661
668
|
};
|
|
662
669
|
type StringValidator<M> = M extends NotNull
|
|
663
670
|
? {
|
|
664
|
-
validate(validator: (value: string) => void): StringColumnTypeDef<M>;
|
|
671
|
+
validate(validator: (value: string, meta?: ValidationMeta) => void): StringColumnTypeDef<M>;
|
|
665
672
|
}
|
|
666
673
|
: {
|
|
667
674
|
validate(
|
|
668
|
-
validator: (value?: string | null) => void
|
|
675
|
+
validator: (value?: string | null, meta?: ValidationMeta) => void
|
|
669
676
|
): StringColumnTypeDef<M>;
|
|
670
677
|
};
|
|
671
678
|
type NumericValidator<M> = M extends NotNull
|
|
672
679
|
? {
|
|
673
|
-
validate(validator: (value: number) => void): NumericColumnTypeDef<M>;
|
|
680
|
+
validate(validator: (value: number, meta?: ValidationMeta) => void): NumericColumnTypeDef<M>;
|
|
674
681
|
}
|
|
675
682
|
: {
|
|
676
683
|
validate(
|
|
677
|
-
validator: (value?: number | null) => void
|
|
684
|
+
validator: (value?: number | null, meta?: ValidationMeta) => void
|
|
678
685
|
): NumericColumnTypeDef<M>;
|
|
679
686
|
};
|
|
680
687
|
type BigIntValidator<M> = M extends NotNull
|
|
681
688
|
? {
|
|
682
|
-
validate(validator: (value: bigint) => void): BigIntColumnTypeDef<M>;
|
|
689
|
+
validate(validator: (value: bigint, meta?: ValidationMeta) => void): BigIntColumnTypeDef<M>;
|
|
683
690
|
}
|
|
684
691
|
: {
|
|
685
692
|
validate(
|
|
686
|
-
validator: (value?: bigint | null) => void
|
|
693
|
+
validator: (value?: bigint | null, meta?: ValidationMeta) => void
|
|
687
694
|
): BigIntColumnTypeDef<M>;
|
|
688
695
|
};
|
|
689
696
|
type BinaryValidator<M> = M extends NotNull
|
|
690
697
|
? {
|
|
691
|
-
validate(validator: (value: string) => void): BinaryColumnTypeDef<M>;
|
|
698
|
+
validate(validator: (value: string, meta?: ValidationMeta) => void): BinaryColumnTypeDef<M>;
|
|
692
699
|
}
|
|
693
700
|
: {
|
|
694
701
|
validate(
|
|
695
|
-
validator: (value?: string | null) => void
|
|
702
|
+
validator: (value?: string | null, meta?: ValidationMeta) => void
|
|
696
703
|
): BinaryColumnTypeDef<M>;
|
|
697
704
|
};
|
|
698
705
|
type BooleanValidator<M> = M extends NotNull
|
|
699
706
|
? {
|
|
700
|
-
validate(validator: (value: boolean) => void): BooleanColumnTypeDef<M>;
|
|
707
|
+
validate(validator: (value: boolean, meta?: ValidationMeta) => void): BooleanColumnTypeDef<M>;
|
|
701
708
|
}
|
|
702
709
|
: {
|
|
703
710
|
validate(
|
|
704
|
-
validator: (value?: boolean | null) => void
|
|
711
|
+
validator: (value?: boolean | null, meta?: ValidationMeta) => void
|
|
705
712
|
): BooleanColumnTypeDef<M>;
|
|
706
713
|
};
|
|
707
714
|
type JSONValidator<M> = M extends NotNull
|
|
708
715
|
? {
|
|
709
716
|
validate(
|
|
710
|
-
validator: (value: ToJsonType<M
|
|
717
|
+
validator: (value: ToJsonType<M>, meta?: ValidationMeta) => void
|
|
711
718
|
): JSONColumnTypeDef<M>;
|
|
712
719
|
}
|
|
713
720
|
: {
|
|
714
721
|
validate(
|
|
715
|
-
validator: (value?: ToJsonType<M> | null) => void
|
|
722
|
+
validator: (value?: ToJsonType<M> | null, meta?: ValidationMeta) => void
|
|
716
723
|
): JSONColumnTypeDef<M>;
|
|
717
724
|
};
|
|
718
725
|
type DateValidator<M> = M extends NotNull
|
|
719
726
|
? {
|
|
720
727
|
validate(
|
|
721
|
-
validator: (value: string | Date) => void
|
|
728
|
+
validator: (value: string | Date, meta?: ValidationMeta) => void
|
|
722
729
|
): DateColumnTypeDef<M>;
|
|
723
730
|
}
|
|
724
731
|
: {
|
|
725
732
|
validate(
|
|
726
|
-
validator: (value?: string | Date | null) => void
|
|
733
|
+
validator: (value?: string | Date | null, meta?: ValidationMeta) => void
|
|
727
734
|
): DateColumnTypeDef<M>;
|
|
728
735
|
};
|
|
729
736
|
|
|
730
737
|
type DateWithTimeZoneValidator<M> = M extends NotNull
|
|
731
738
|
? {
|
|
732
739
|
validate(
|
|
733
|
-
validator: (value: string | Date) => void
|
|
740
|
+
validator: (value: string | Date, meta?: ValidationMeta) => void
|
|
734
741
|
): DateWithTimeZoneColumnTypeDef<M>;
|
|
735
742
|
}
|
|
736
743
|
: {
|
|
737
744
|
validate(
|
|
738
|
-
validator: (value?: string | Date | null) => void
|
|
745
|
+
validator: (value?: string | Date | null, meta?: ValidationMeta) => void
|
|
739
746
|
): DateWithTimeZoneColumnTypeDef<M>;
|
|
740
747
|
};
|
|
741
748
|
|
package/src/table/column.js
CHANGED
|
@@ -13,6 +13,10 @@ function defineColumn(column, table) {
|
|
|
13
13
|
return c;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
c.jsonOf = function() {
|
|
17
|
+
return c.json();
|
|
18
|
+
};
|
|
19
|
+
|
|
16
20
|
c.guid = function() {
|
|
17
21
|
require('./column/guid')(column);
|
|
18
22
|
return c;
|
|
@@ -130,8 +134,8 @@ function defineColumn(column, table) {
|
|
|
130
134
|
|
|
131
135
|
c.notNullExceptInsert = function() {
|
|
132
136
|
column._notNullExceptInsert = true;
|
|
133
|
-
function validate(value,
|
|
134
|
-
if (isInsert)
|
|
137
|
+
function validate(value, meta) {
|
|
138
|
+
if (meta?.isInsert)
|
|
135
139
|
return;
|
|
136
140
|
if (value === undefined || value === null)
|
|
137
141
|
throw new Error(`Column ${column.alias} cannot be null or undefined`);
|
|
@@ -145,12 +149,12 @@ function defineColumn(column, table) {
|
|
|
145
149
|
if (previousValue)
|
|
146
150
|
column.validate = nestedValidate;
|
|
147
151
|
else
|
|
148
|
-
column.validate =
|
|
152
|
+
column.validate = invokeValidate;
|
|
149
153
|
|
|
150
154
|
function nestedValidate() {
|
|
151
155
|
try {
|
|
152
156
|
previousValue.apply(null, arguments);
|
|
153
|
-
|
|
157
|
+
invokeValidate.apply(null, arguments);
|
|
154
158
|
}
|
|
155
159
|
catch (e) {
|
|
156
160
|
const error = new Error(e.message || e);
|
|
@@ -159,6 +163,10 @@ function defineColumn(column, table) {
|
|
|
159
163
|
throw error;
|
|
160
164
|
}
|
|
161
165
|
}
|
|
166
|
+
|
|
167
|
+
function invokeValidate(inputValue, meta) {
|
|
168
|
+
value(inputValue, meta);
|
|
169
|
+
}
|
|
162
170
|
return c;
|
|
163
171
|
};
|
|
164
172
|
|
|
@@ -48,7 +48,7 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
48
48
|
value = purify(value);
|
|
49
49
|
this._dbRow[key] = value;
|
|
50
50
|
if (column.validate)
|
|
51
|
-
column.validate(value,
|
|
51
|
+
column.validate(value, { table: table._dbName, column: column._dbName, property: column.alias });
|
|
52
52
|
updateField(this._context, table, column, this);
|
|
53
53
|
let emit = this._emitColumnChanged[name];
|
|
54
54
|
if (emit)
|
|
@@ -204,7 +204,7 @@ function newDecodeDbRow(table, dbRow, filteredAliases, shouldValidate, isInsert)
|
|
|
204
204
|
if (row[key] !== undefined && !isInsert)
|
|
205
205
|
row[key] = columns[i].decode(context, row[key]);
|
|
206
206
|
if (shouldValidate && columns[i].validate)
|
|
207
|
-
columns[i].validate(row[key],
|
|
207
|
+
columns[i].validate(row[key], { table: table._dbName, column: columns[i]._dbName, property: columns[i].alias, isInsert });
|
|
208
208
|
}
|
|
209
209
|
let target = new Row(context, row);
|
|
210
210
|
const p = new Proxy(target, {
|