@proteinjs/db-spanner-common 1.1.31 → 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 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Brent Bahry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -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\":\"/Users/brentbahry/repos/farm/n3xa3/packages/proteinjs/packages/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<T | null>\",\"filePath\":null,\"qualifiedName\":\"/Promise<T | null>\",\"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\":\"T\",\"filePath\":null,\"qualifiedName\":\"/T\",\"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\"}]}";
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,4/EAA4/E,CAAC;AAGjhF,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
+ {"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<T | null>;
7
- deserialize(serializedFieldValue: T): Promise<T | null>;
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;AAEtD,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,CAAC,GAAG,IAAI,CAAC;IAQ9D,WAAW,CAAC,oBAAoB,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;CAO9D"}
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
- return __generator(this, function (_a) {
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;;;gBAC9C,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,IAAI,IAAI,EAAE;oBAClD,sBAAO,IAAI,EAAC;iBACb;gBAED,sBAAO,UAAU,EAAC;;;KACnB;IAEK,gCAAW,GAAjB,UAAkB,oBAAuB;;;gBACvC,IAAI,oBAAoB,KAAK,SAAS,IAAI,oBAAoB,IAAI,IAAI,EAAE;oBACtE,sBAAO,IAAI,EAAC;iBACb;gBAED,sBAAO,oBAAoB,EAAC;;;KAC7B;IACH,iBAAC;AAAD,CAAC,AArBD,IAqBC;AArBY,gCAAU"}
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"}
@@ -4,25 +4,22 @@ import '@proteinjs/db';
4
4
  import '@proteinjs/logger';
5
5
  import '@proteinjs/reflection';
6
6
 
7
-
8
7
  /** Generate Source Graph */
9
8
 
10
- const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/db-spanner-common/JsonColumn\",\"value\":{\"packageName\":\"@proteinjs/db-spanner-common\",\"name\":\"JsonColumn\",\"filePath\":\"/Users/brentbahry/repos/farm/n3xa3/packages/proteinjs/packages/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<T | null>\",\"filePath\":null,\"qualifiedName\":\"/Promise<T | null>\",\"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\":\"T\",\"filePath\":null,\"qualifiedName\":\"/T\",\"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
-
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<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"}]}';
12
11
 
13
12
  /** Generate Source Links */
14
13
 
15
14
  import { JsonColumn } from '../src/columns/JsonColumn';
16
15
 
17
16
  const sourceLinks = {
18
- '@proteinjs/db-spanner-common/JsonColumn': JsonColumn,
17
+ '@proteinjs/db-spanner-common/JsonColumn': JsonColumn,
19
18
  };
20
19
 
21
-
22
20
  /** Load Source Graph and Links */
23
21
 
24
22
  import { SourceRepository } from '@proteinjs/reflection';
25
23
  SourceRepository.merge(sourceGraph, sourceLinks);
26
24
 
27
-
28
- export * from '../index';
25
+ export * from '../index';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteinjs/db-spanner-common",
3
- "version": "1.1.31",
3
+ "version": "1.1.32",
4
4
  "description": "Common libs for Google Spanner",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -39,5 +39,6 @@
39
39
  "typescript": "5.2.2"
40
40
  },
41
41
  "main": "./dist/generated/index.js",
42
- "types": "./dist/generated/index.d.ts"
42
+ "types": "./dist/generated/index.d.ts",
43
+ "gitHead": "504df2602db4460ac0d941ef94e0681a52209f73"
43
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<T | null> {
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: T): Promise<T | null> {
38
+ async deserialize(serializedFieldValue: any): Promise<T | null> {
18
39
  if (serializedFieldValue === undefined || serializedFieldValue == null) {
19
40
  return null;
20
41
  }
21
42
 
22
- return serializedFieldValue;
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
  }