@proteinjs/db-spanner-common 1.1.30 → 1.1.32
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/CHANGELOG.md +11 -0
- package/dist/generated/index.js +1 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/src/columns/JsonColumn.d.ts +13 -2
- package/dist/src/columns/JsonColumn.d.ts.map +1 -1
- package/dist/src/columns/JsonColumn.js +28 -1
- package/dist/src/columns/JsonColumn.js.map +1 -1
- package/generated/index.ts +1 -1
- package/package.json +5 -5
- package/src/columns/JsonColumn.ts +33 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.1.32](https://github.com/proteinjs/db/compare/@proteinjs/db-spanner-common@1.1.31...@proteinjs/db-spanner-common@1.1.32) (2026-06-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* support top-level array values in JsonColumn ([6a4922b](https://github.com/proteinjs/db/commit/6a4922bb40487bb3e251a66408557c0d74635607))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [1.1.30](https://github.com/proteinjs/db/compare/@proteinjs/db-spanner-common@1.1.29...@proteinjs/db-spanner-common@1.1.30) (2026-04-18)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @proteinjs/db-spanner-common
|
package/dist/generated/index.js
CHANGED
|
@@ -19,7 +19,7 @@ require("@proteinjs/db");
|
|
|
19
19
|
require("@proteinjs/logger");
|
|
20
20
|
require("@proteinjs/reflection");
|
|
21
21
|
/** Generate Source Graph */
|
|
22
|
-
var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/db-spanner-common/JsonColumn\",\"value\":{\"packageName\":\"@proteinjs/db-spanner-common\",\"name\":\"JsonColumn\",\"filePath\":\"/home/runner/work/db/db/packages/spanner-common/src/columns/JsonColumn.ts\",\"qualifiedName\":\"@proteinjs/db-spanner-common/JsonColumn\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"options\",\"type\":{\"packageName\":\"@proteinjs/db\",\"name\":\"ColumnOptions\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/ColumnOptions\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":true,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"serialize\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<
|
|
22
|
+
var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/db-spanner-common/JsonColumn\",\"value\":{\"packageName\":\"@proteinjs/db-spanner-common\",\"name\":\"JsonColumn\",\"filePath\":\"/home/runner/work/db/db/packages/spanner-common/src/columns/JsonColumn.ts\",\"qualifiedName\":\"@proteinjs/db-spanner-common/JsonColumn\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"options\",\"type\":{\"packageName\":\"@proteinjs/db\",\"name\":\"ColumnOptions\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/ColumnOptions\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":true,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"serialize\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<any>\",\"filePath\":null,\"qualifiedName\":\"/Promise<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"fieldValue\",\"type\":{\"packageName\":\"\",\"name\":\"T | null | undefined\",\"filePath\":null,\"qualifiedName\":\"/T | null | undefined\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"deserialize\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<T | null>\",\"filePath\":null,\"qualifiedName\":\"/Promise<T | null>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"serializedFieldValue\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[\"/T\"],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Column\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Column\",\"properties\":[],\"methods\":[],\"typeParameters\":[\"/T\",\"/any\"],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/db/Column\"}],\"edges\":[{\"v\":\"@proteinjs/db-spanner-common/JsonColumn\",\"w\":\"@proteinjs/db/Column\",\"value\":\"implements interface\"}]}";
|
|
23
23
|
/** Generate Source Links */
|
|
24
24
|
var JsonColumn_1 = require("../src/columns/JsonColumn");
|
|
25
25
|
var sourceLinks = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,yBAAuB;AACvB,6BAA2B;AAC3B,iCAA+B;AAG/B,4BAA4B;AAE5B,IAAM,WAAW,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,yBAAuB;AACvB,6BAA2B;AAC3B,iCAA+B;AAG/B,4BAA4B;AAE5B,IAAM,WAAW,GAAG,48EAA48E,CAAC;AAGj+E,4BAA4B;AAE5B,wDAAuD;AAEvD,IAAM,WAAW,GAAG;IACnB,yCAAyC,EAAE,uBAAU;CACrD,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { Column, ColumnOptions } from '@proteinjs/db';
|
|
2
|
+
/**
|
|
3
|
+
* A column backed by a Spanner `JSON` value.
|
|
4
|
+
*
|
|
5
|
+
* Spanner infers a DML parameter's type from the JS value's shape, so a top-level
|
|
6
|
+
* ARRAY is sent as `ARRAY<JSON>` — which a `JSON` column rejects ("Value has type
|
|
7
|
+
* ARRAY<JSON> which cannot be inserted into column ..., which has type JSON"). To
|
|
8
|
+
* let a JSON column hold an array, we wrap arrays in a single marker object on
|
|
9
|
+
* write (so the driver sends one JSON document) and unwrap on read. Object values
|
|
10
|
+
* pass through untouched, so object-valued JSON columns are unaffected. The
|
|
11
|
+
* wrapping is invisible to consumers — the field round-trips as the same array.
|
|
12
|
+
*/
|
|
2
13
|
export declare class JsonColumn<T> implements Column<T, any> {
|
|
3
14
|
name: string;
|
|
4
15
|
options?: ColumnOptions | undefined;
|
|
5
16
|
constructor(name: string, options?: ColumnOptions | undefined);
|
|
6
|
-
serialize(fieldValue: T | null | undefined): Promise<
|
|
7
|
-
deserialize(serializedFieldValue:
|
|
17
|
+
serialize(fieldValue: T | null | undefined): Promise<any>;
|
|
18
|
+
deserialize(serializedFieldValue: any): Promise<T | null>;
|
|
8
19
|
}
|
|
9
20
|
//# sourceMappingURL=JsonColumn.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonColumn.d.ts","sourceRoot":"","sources":["../../../src/columns/JsonColumn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"JsonColumn.d.ts","sourceRoot":"","sources":["../../../src/columns/JsonColumn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAQtD;;;;;;;;;;GAUG;AACH,qBAAa,UAAU,CAAC,CAAC,CAAE,YAAW,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC;IAEzC,IAAI,EAAE,MAAM;IACZ,OAAO,CAAC;gBADR,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,2BAAe;IAG1B,SAAS,CAAC,UAAU,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC;IAYzD,WAAW,CAAC,oBAAoB,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;CAgBhE"}
|
|
@@ -37,6 +37,22 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.JsonColumn = void 0;
|
|
40
|
+
/**
|
|
41
|
+
* Reserved key used to wrap a top-level array stored in a JSON column. Namespaced
|
|
42
|
+
* so it cannot collide with a real object value's own fields. See JsonColumn.
|
|
43
|
+
*/
|
|
44
|
+
var JSON_ARRAY_MARKER = '__jsonColumnArray';
|
|
45
|
+
/**
|
|
46
|
+
* A column backed by a Spanner `JSON` value.
|
|
47
|
+
*
|
|
48
|
+
* Spanner infers a DML parameter's type from the JS value's shape, so a top-level
|
|
49
|
+
* ARRAY is sent as `ARRAY<JSON>` — which a `JSON` column rejects ("Value has type
|
|
50
|
+
* ARRAY<JSON> which cannot be inserted into column ..., which has type JSON"). To
|
|
51
|
+
* let a JSON column hold an array, we wrap arrays in a single marker object on
|
|
52
|
+
* write (so the driver sends one JSON document) and unwrap on read. Object values
|
|
53
|
+
* pass through untouched, so object-valued JSON columns are unaffected. The
|
|
54
|
+
* wrapping is invisible to consumers — the field round-trips as the same array.
|
|
55
|
+
*/
|
|
40
56
|
var JsonColumn = /** @class */ (function () {
|
|
41
57
|
function JsonColumn(name, options) {
|
|
42
58
|
this.name = name;
|
|
@@ -44,10 +60,14 @@ var JsonColumn = /** @class */ (function () {
|
|
|
44
60
|
}
|
|
45
61
|
JsonColumn.prototype.serialize = function (fieldValue) {
|
|
46
62
|
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
|
|
63
|
+
var _a;
|
|
64
|
+
return __generator(this, function (_b) {
|
|
48
65
|
if (fieldValue === undefined || fieldValue == null) {
|
|
49
66
|
return [2 /*return*/, null];
|
|
50
67
|
}
|
|
68
|
+
if (Array.isArray(fieldValue)) {
|
|
69
|
+
return [2 /*return*/, (_a = {}, _a[JSON_ARRAY_MARKER] = fieldValue, _a)];
|
|
70
|
+
}
|
|
51
71
|
return [2 /*return*/, fieldValue];
|
|
52
72
|
});
|
|
53
73
|
});
|
|
@@ -58,6 +78,13 @@ var JsonColumn = /** @class */ (function () {
|
|
|
58
78
|
if (serializedFieldValue === undefined || serializedFieldValue == null) {
|
|
59
79
|
return [2 /*return*/, null];
|
|
60
80
|
}
|
|
81
|
+
// A raw array can appear if a row predates this wrapping; pass it through.
|
|
82
|
+
if (Array.isArray(serializedFieldValue)) {
|
|
83
|
+
return [2 /*return*/, serializedFieldValue];
|
|
84
|
+
}
|
|
85
|
+
if (typeof serializedFieldValue === 'object' && Array.isArray(serializedFieldValue[JSON_ARRAY_MARKER])) {
|
|
86
|
+
return [2 /*return*/, serializedFieldValue[JSON_ARRAY_MARKER]];
|
|
87
|
+
}
|
|
61
88
|
return [2 /*return*/, serializedFieldValue];
|
|
62
89
|
});
|
|
63
90
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonColumn.js","sourceRoot":"","sources":["../../../src/columns/JsonColumn.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;IACE,oBACS,IAAY,EACZ,OAAuB;QADvB,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAgB;IAC7B,CAAC;IAEE,8BAAS,GAAf,UAAgB,UAAgC
|
|
1
|
+
{"version":3,"file":"JsonColumn.js","sourceRoot":"","sources":["../../../src/columns/JsonColumn.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;;GAGG;AACH,IAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAE9C;;;;;;;;;;GAUG;AACH;IACE,oBACS,IAAY,EACZ,OAAuB;QADvB,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAgB;IAC7B,CAAC;IAEE,8BAAS,GAAf,UAAgB,UAAgC;;;;gBAC9C,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,IAAI,IAAI,EAAE;oBAClD,sBAAO,IAAI,EAAC;iBACb;gBAED,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;oBAC7B,gCAAS,GAAC,iBAAiB,IAAG,UAAU,OAAG;iBAC5C;gBAED,sBAAO,UAAU,EAAC;;;KACnB;IAEK,gCAAW,GAAjB,UAAkB,oBAAyB;;;gBACzC,IAAI,oBAAoB,KAAK,SAAS,IAAI,oBAAoB,IAAI,IAAI,EAAE;oBACtE,sBAAO,IAAI,EAAC;iBACb;gBAED,2EAA2E;gBAC3E,IAAI,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE;oBACvC,sBAAO,oBAAyB,EAAC;iBAClC;gBAED,IAAI,OAAO,oBAAoB,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC,EAAE;oBACtG,sBAAO,oBAAoB,CAAC,iBAAiB,CAAM,EAAC;iBACrD;gBAED,sBAAO,oBAAyB,EAAC;;;KAClC;IACH,iBAAC;AAAD,CAAC,AAlCD,IAkCC;AAlCY,gCAAU"}
|
package/generated/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import '@proteinjs/reflection';
|
|
|
7
7
|
/** Generate Source Graph */
|
|
8
8
|
|
|
9
9
|
const sourceGraph =
|
|
10
|
-
'{"options":{"directed":true,"multigraph":false,"compound":false},"nodes":[{"v":"@proteinjs/db-spanner-common/JsonColumn","value":{"packageName":"@proteinjs/db-spanner-common","name":"JsonColumn","filePath":"/home/runner/work/db/db/packages/spanner-common/src/columns/JsonColumn.ts","qualifiedName":"@proteinjs/db-spanner-common/JsonColumn","isAbstract":false,"isStatic":false,"visibility":"public","properties":[{"name":"name","type":{"packageName":"","name":"string","filePath":null,"qualifiedName":"/string","typeParameters":null,"directParents":null},"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public"},{"name":"options","type":{"packageName":"@proteinjs/db","name":"ColumnOptions","filePath":null,"qualifiedName":"@proteinjs/db/ColumnOptions","typeParameters":null,"directParents":null},"isOptional":true,"isAbstract":false,"isStatic":false,"visibility":"public"}],"methods":[{"name":"serialize","returnType":{"packageName":"","name":"Promise<
|
|
10
|
+
'{"options":{"directed":true,"multigraph":false,"compound":false},"nodes":[{"v":"@proteinjs/db-spanner-common/JsonColumn","value":{"packageName":"@proteinjs/db-spanner-common","name":"JsonColumn","filePath":"/home/runner/work/db/db/packages/spanner-common/src/columns/JsonColumn.ts","qualifiedName":"@proteinjs/db-spanner-common/JsonColumn","isAbstract":false,"isStatic":false,"visibility":"public","properties":[{"name":"name","type":{"packageName":"","name":"string","filePath":null,"qualifiedName":"/string","typeParameters":null,"directParents":null},"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public"},{"name":"options","type":{"packageName":"@proteinjs/db","name":"ColumnOptions","filePath":null,"qualifiedName":"@proteinjs/db/ColumnOptions","typeParameters":null,"directParents":null},"isOptional":true,"isAbstract":false,"isStatic":false,"visibility":"public"}],"methods":[{"name":"serialize","returnType":{"packageName":"","name":"Promise<any>","filePath":null,"qualifiedName":"/Promise<any>","typeParameters":null,"directParents":null},"isAsync":true,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public","parameters":[{"name":"fieldValue","type":{"packageName":"","name":"T | null | undefined","filePath":null,"qualifiedName":"/T | null | undefined","typeParameters":null,"directParents":null}}]},{"name":"deserialize","returnType":{"packageName":"","name":"Promise<T | null>","filePath":null,"qualifiedName":"/Promise<T | null>","typeParameters":null,"directParents":null},"isAsync":true,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public","parameters":[{"name":"serializedFieldValue","type":{"packageName":"","name":"any","filePath":null,"qualifiedName":"/any","typeParameters":null,"directParents":null}}]}],"typeParameters":["/T"],"directParentInterfaces":[{"packageName":"@proteinjs/db","name":"Column","filePath":null,"qualifiedName":"@proteinjs/db/Column","properties":[],"methods":[],"typeParameters":["/T","/any"],"directParents":[]}],"directParentClasses":[],"sourceType":2}},{"v":"@proteinjs/db/Column"}],"edges":[{"v":"@proteinjs/db-spanner-common/JsonColumn","w":"@proteinjs/db/Column","value":"implements interface"}]}';
|
|
11
11
|
|
|
12
12
|
/** Generate Source Links */
|
|
13
13
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/db-spanner-common",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.32",
|
|
4
4
|
"description": "Common libs for Google Spanner",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"watch": "reflection-watch"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@proteinjs/db": "^1.21.
|
|
25
|
-
"@proteinjs/logger": "^1.0.
|
|
24
|
+
"@proteinjs/db": "^1.21.10",
|
|
25
|
+
"@proteinjs/logger": "^1.0.19",
|
|
26
26
|
"@proteinjs/reflection": "^1.1.11"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@proteinjs/reflection-build": "^1.4.
|
|
29
|
+
"@proteinjs/reflection-build": "^1.4.7",
|
|
30
30
|
"@types/jest": "29.5.5",
|
|
31
31
|
"@types/node": "14.0.27",
|
|
32
32
|
"@typescript-eslint/eslint-plugin": "7.8.0",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
},
|
|
41
41
|
"main": "./dist/generated/index.js",
|
|
42
42
|
"types": "./dist/generated/index.d.ts",
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "504df2602db4460ac0d941ef94e0681a52209f73"
|
|
44
44
|
}
|
|
@@ -1,24 +1,54 @@
|
|
|
1
1
|
import { Column, ColumnOptions } from '@proteinjs/db';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Reserved key used to wrap a top-level array stored in a JSON column. Namespaced
|
|
5
|
+
* so it cannot collide with a real object value's own fields. See JsonColumn.
|
|
6
|
+
*/
|
|
7
|
+
const JSON_ARRAY_MARKER = '__jsonColumnArray';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A column backed by a Spanner `JSON` value.
|
|
11
|
+
*
|
|
12
|
+
* Spanner infers a DML parameter's type from the JS value's shape, so a top-level
|
|
13
|
+
* ARRAY is sent as `ARRAY<JSON>` — which a `JSON` column rejects ("Value has type
|
|
14
|
+
* ARRAY<JSON> which cannot be inserted into column ..., which has type JSON"). To
|
|
15
|
+
* let a JSON column hold an array, we wrap arrays in a single marker object on
|
|
16
|
+
* write (so the driver sends one JSON document) and unwrap on read. Object values
|
|
17
|
+
* pass through untouched, so object-valued JSON columns are unaffected. The
|
|
18
|
+
* wrapping is invisible to consumers — the field round-trips as the same array.
|
|
19
|
+
*/
|
|
3
20
|
export class JsonColumn<T> implements Column<T, any> {
|
|
4
21
|
constructor(
|
|
5
22
|
public name: string,
|
|
6
23
|
public options?: ColumnOptions
|
|
7
24
|
) {}
|
|
8
25
|
|
|
9
|
-
async serialize(fieldValue: T | null | undefined): Promise<
|
|
26
|
+
async serialize(fieldValue: T | null | undefined): Promise<any> {
|
|
10
27
|
if (fieldValue === undefined || fieldValue == null) {
|
|
11
28
|
return null;
|
|
12
29
|
}
|
|
13
30
|
|
|
31
|
+
if (Array.isArray(fieldValue)) {
|
|
32
|
+
return { [JSON_ARRAY_MARKER]: fieldValue };
|
|
33
|
+
}
|
|
34
|
+
|
|
14
35
|
return fieldValue;
|
|
15
36
|
}
|
|
16
37
|
|
|
17
|
-
async deserialize(serializedFieldValue:
|
|
38
|
+
async deserialize(serializedFieldValue: any): Promise<T | null> {
|
|
18
39
|
if (serializedFieldValue === undefined || serializedFieldValue == null) {
|
|
19
40
|
return null;
|
|
20
41
|
}
|
|
21
42
|
|
|
22
|
-
|
|
43
|
+
// A raw array can appear if a row predates this wrapping; pass it through.
|
|
44
|
+
if (Array.isArray(serializedFieldValue)) {
|
|
45
|
+
return serializedFieldValue as T;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (typeof serializedFieldValue === 'object' && Array.isArray(serializedFieldValue[JSON_ARRAY_MARKER])) {
|
|
49
|
+
return serializedFieldValue[JSON_ARRAY_MARKER] as T;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return serializedFieldValue as T;
|
|
23
53
|
}
|
|
24
54
|
}
|