@naturalcycles/db-lib 8.40.1 → 8.41.0

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.
@@ -36,7 +36,7 @@ export declare class FileDB extends BaseCommonDB implements CommonDB {
36
36
  loadFile<ROW extends ObjectWithId>(table: string): Promise<ROW[]>;
37
37
  saveFile<ROW extends ObjectWithId>(table: string, _rows: ROW[]): Promise<void>;
38
38
  saveFiles<ROW extends ObjectWithId>(ops: DBSaveBatchOperation<ROW>[]): Promise<void>;
39
- sortRows<ROW>(rows: ROW[]): ROW[];
39
+ private sortRows;
40
40
  private logStarted;
41
41
  private logFinished;
42
42
  }
@@ -14,14 +14,14 @@ export declare class CommonDao<BM extends Partial<ObjectWithId<ID>>, DBM extends
14
14
  cfg: CommonDaoCfg<BM, DBM, TM, ID>;
15
15
  constructor(cfg: CommonDaoCfg<BM, DBM, TM, ID>);
16
16
  create(part?: Partial<BM>, opt?: CommonDaoOptions): Saved<BM>;
17
- getById(id: undefined, opt?: CommonDaoOptions): Promise<null>;
18
- getById(id?: ID, opt?: CommonDaoOptions): Promise<Saved<BM> | null>;
17
+ getById(id: undefined | null, opt?: CommonDaoOptions): Promise<null>;
18
+ getById(id?: ID | null, opt?: CommonDaoOptions): Promise<Saved<BM> | null>;
19
19
  getByIdOrEmpty(id: ID, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<Saved<BM>>;
20
20
  getByIdAsDBMOrEmpty(id: ID, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<DBM>;
21
- getByIdAsDBM(id: undefined, opt?: CommonDaoOptions): Promise<null>;
22
- getByIdAsDBM(id?: ID, opt?: CommonDaoOptions): Promise<DBM | null>;
23
- getByIdAsTM(id: undefined, opt?: CommonDaoOptions): Promise<null>;
24
- getByIdAsTM(id?: ID, opt?: CommonDaoOptions): Promise<TM | null>;
21
+ getByIdAsDBM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>;
22
+ getByIdAsDBM(id?: ID | null, opt?: CommonDaoOptions): Promise<DBM | null>;
23
+ getByIdAsTM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>;
24
+ getByIdAsTM(id?: ID | null, opt?: CommonDaoOptions): Promise<TM | null>;
25
25
  getByIds(ids: ID[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>;
26
26
  getByIdsAsDBM(ids: ID[], opt?: CommonDaoOptions): Promise<DBM[]>;
27
27
  requireById(id: ID, opt?: CommonDaoOptions): Promise<Saved<BM>>;
@@ -103,8 +103,8 @@ export declare class CommonDao<BM extends Partial<ObjectWithId<ID>>, DBM extends
103
103
  /**
104
104
  * @returns number of deleted items
105
105
  */
106
- deleteById(id: undefined, opt?: CommonDaoOptions): Promise<0>;
107
- deleteById(id?: ID, opt?: CommonDaoOptions): Promise<number>;
106
+ deleteById(id: undefined | null, opt?: CommonDaoOptions): Promise<0>;
107
+ deleteById(id?: ID | null, opt?: CommonDaoOptions): Promise<number>;
108
108
  deleteByIds(ids: ID[], opt?: CommonDaoOptions): Promise<number>;
109
109
  /**
110
110
  * Pass `stream: true` option to use Streaming: it will Stream the query, batch by 500, and execute
@@ -220,7 +220,7 @@ class CommonDao {
220
220
  (0, js_lib_1._assert)(q._selectedFieldNames?.length === 1, `runQuerySingleColumn requires exactly 1 column to be selected: ${q.pretty()}`);
221
221
  const col = q._selectedFieldNames[0];
222
222
  const { rows } = await this.runQueryExtended(q, opt);
223
- return rows.map(r => r[col]);
223
+ return rows.map((r) => r[col]);
224
224
  }
225
225
  /**
226
226
  * Convenience method that runs multiple queries in parallel and then merges their results together.
@@ -435,13 +435,17 @@ class CommonDao {
435
435
  }
436
436
  }
437
437
  assignIdCreatedUpdated(obj, opt = {}) {
438
+ var _a;
438
439
  const now = Math.floor(Date.now() / 1000);
439
440
  obj.id || (obj.id = this.cfg.hooks.createId?.(obj));
440
441
  if (this.cfg.created) {
441
- obj['created'] || (obj['created'] = obj['updated'] || now);
442
+ ;
443
+ (_a = obj)['created'] || (_a['created'] = obj['updated'] || now);
442
444
  }
443
445
  if (this.cfg.updated) {
444
- obj['updated'] = opt.preserveUpdatedCreated && obj['updated'] ? obj['updated'] : now;
446
+ ;
447
+ obj['updated'] =
448
+ opt.preserveUpdatedCreated && obj['updated'] ? obj['updated'] : now;
445
449
  }
446
450
  return obj;
447
451
  }
@@ -41,7 +41,7 @@ function runCommonDaoTest(db, features = {}, quirks = {}) {
41
41
  // CREATE TABLE, DROP
42
42
  if (createTable) {
43
43
  test('createTable, dropIfExists=true', async () => {
44
- await dao.createTable(test_model_1.testItemDBMJsonSchema.build(), { dropIfExists: true });
44
+ await dao.createTable(test_model_1.testItemDBMJsonSchema, { dropIfExists: true });
45
45
  });
46
46
  }
47
47
  if (querying) {
@@ -55,7 +55,7 @@ function runCommonDaoTest(db, features = {}, quirks = {}) {
55
55
  if (eventualConsistencyDelay)
56
56
  await (0, js_lib_1.pDelay)(eventualConsistencyDelay);
57
57
  expect(await dao.query().runQuery()).toEqual([]);
58
- expect(await dao.query().runQueryCount()).toEqual(0);
58
+ expect(await dao.query().runQueryCount()).toBe(0);
59
59
  });
60
60
  }
61
61
  // GET empty
@@ -81,7 +81,7 @@ function runCommonDaoTest(db, features = {}, quirks = {}) {
81
81
  await dao.save(item3);
82
82
  const item3Loaded = await dao.requireById(item3.id);
83
83
  (0, dbTest_1.expectMatch)([item3], [item3Loaded], quirks);
84
- expect(item3Loaded.k2).toBe(null);
84
+ expect(item3Loaded.k2).toBeNull();
85
85
  expect(Object.keys(item3)).toContain('k2');
86
86
  expect(item3.k2).toBeNull();
87
87
  });
@@ -98,7 +98,7 @@ function runCommonDaoTest(db, features = {}, quirks = {}) {
98
98
  expected.updated = item3.updated; // as it's mutated
99
99
  const item3Loaded = await dao.requireById(item3.id);
100
100
  (0, dbTest_1.expectMatch)([expected], [item3Loaded], quirks);
101
- expect(item3Loaded.k2).toBe(undefined);
101
+ expect(item3Loaded.k2).toBeUndefined();
102
102
  expect(Object.keys(item3Loaded)).not.toContain('k2');
103
103
  expect(Object.keys(item3)).toContain('k2');
104
104
  expect(item3.k2).toBeUndefined();
@@ -28,7 +28,7 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
28
28
  // CREATE TABLE, DROP
29
29
  if (createTable) {
30
30
  test('createTable, dropIfExists=true', async () => {
31
- await db.createTable(test_model_1.TEST_TABLE, test_model_1.testItemDBMJsonSchema.build(), { dropIfExists: true });
31
+ await db.createTable(test_model_1.TEST_TABLE, test_model_1.testItemDBMJsonSchema, { dropIfExists: true });
32
32
  });
33
33
  }
34
34
  if (querying) {
@@ -42,7 +42,7 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
42
42
  if (eventualConsistencyDelay)
43
43
  await (0, js_lib_1.pDelay)(eventualConsistencyDelay);
44
44
  expect((await db.runQuery(queryAll())).rows).toEqual([]);
45
- expect(await db.runQueryCount(queryAll())).toEqual(0);
45
+ expect(await db.runQueryCount(queryAll())).toBe(0);
46
46
  });
47
47
  }
48
48
  // GET empty
@@ -68,7 +68,7 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
68
68
  await db.saveBatch(test_model_1.TEST_TABLE, [item3]);
69
69
  const item3Loaded = (await db.getByIds(test_model_1.TEST_TABLE, [item3.id]))[0];
70
70
  expectMatch([item3], [item3Loaded], quirks);
71
- expect(item3Loaded.k2).toBe(null);
71
+ expect(item3Loaded.k2).toBeNull();
72
72
  });
73
73
  }
74
74
  if (documentDB) {
@@ -83,7 +83,7 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
83
83
  await db.saveBatch(test_model_1.TEST_TABLE, [item3]);
84
84
  const item3Loaded = (await db.getByIds(test_model_1.TEST_TABLE, [item3.id]))[0];
85
85
  expectMatch([expected], [item3Loaded], quirks);
86
- expect(item3Loaded.k2).toBe(undefined);
86
+ expect(item3Loaded.k2).toBeUndefined();
87
87
  expect(Object.keys(item3Loaded)).not.toContain('k2');
88
88
  });
89
89
  }
@@ -17,8 +17,8 @@ export interface TestItemTM {
17
17
  export declare const testItemBMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemBM, TestItemBM>;
18
18
  export declare const testItemDBMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemDBM, TestItemDBM>;
19
19
  export declare const testItemTMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemTM, TestItemTM>;
20
- export declare const testItemBMJsonSchema: import("@naturalcycles/js-lib/dist/json-schema/jsonSchemaBuilder").JsonSchemaObjectBuilder<TestItemBM & Partial<import("@naturalcycles/js-lib").SavedDBEntity<string>>>;
21
- export declare const testItemDBMJsonSchema: import("@naturalcycles/js-lib/dist/json-schema/jsonSchemaBuilder").JsonSchemaObjectBuilder<TestItemDBM>;
20
+ export declare const testItemBMJsonSchema: import("@naturalcycles/js-lib").JsonSchemaObject<TestItemBM & Partial<import("@naturalcycles/js-lib").SavedDBEntity<string>>>;
21
+ export declare const testItemDBMJsonSchema: import("@naturalcycles/js-lib").JsonSchemaObject<TestItemDBM>;
22
22
  export declare function createTestItemDBM(num?: number): TestItemDBM;
23
23
  export declare function createTestItemBM(num?: number): Saved<TestItemBM>;
24
24
  export declare function createTestItemsDBM(count?: number): TestItemDBM[];
@@ -31,8 +31,10 @@ exports.testItemBMJsonSchema = js_lib_1.jsonSchema
31
31
  even: js_lib_1.jsonSchema.boolean().optional(),
32
32
  b1: js_lib_1.jsonSchema.buffer().optional(),
33
33
  })
34
- .baseDBEntity();
35
- exports.testItemDBMJsonSchema = js_lib_1.jsonSchema.rootObject({
34
+ .baseDBEntity()
35
+ .build();
36
+ exports.testItemDBMJsonSchema = js_lib_1.jsonSchema
37
+ .rootObject({
36
38
  // todo: figure out how to not copy-paste these 3 fields
37
39
  id: js_lib_1.jsonSchema.string(),
38
40
  created: js_lib_1.jsonSchema.unixTimestamp(),
@@ -42,7 +44,8 @@ exports.testItemDBMJsonSchema = js_lib_1.jsonSchema.rootObject({
42
44
  k3: js_lib_1.jsonSchema.number().optional(),
43
45
  even: js_lib_1.jsonSchema.boolean().optional(),
44
46
  b1: js_lib_1.jsonSchema.buffer().optional(),
45
- });
47
+ })
48
+ .build();
46
49
  function createTestItemDBM(num = 1) {
47
50
  return {
48
51
  id: `id${num}`,
package/package.json CHANGED
@@ -10,9 +10,9 @@
10
10
  },
11
11
  "devDependencies": {
12
12
  "@naturalcycles/bench-lib": "^1.0.0",
13
- "@naturalcycles/dev-lib": "^12.0.1",
14
- "@types/node": "^17.0.0",
15
- "jest": "^28.0.3",
13
+ "@naturalcycles/dev-lib": "^13.0.0",
14
+ "@types/node": "^18.0.3",
15
+ "jest": "^29.0.0",
16
16
  "weak-napi": "^2.0.2"
17
17
  },
18
18
  "files": [
@@ -42,7 +42,7 @@
42
42
  "engines": {
43
43
  "node": ">=14.15"
44
44
  },
45
- "version": "8.40.1",
45
+ "version": "8.41.0",
46
46
  "description": "Lowest Common Denominator API to supported Databases",
47
47
  "keywords": [
48
48
  "db",
@@ -256,11 +256,11 @@ export class FileDB extends BaseCommonDB implements CommonDB {
256
256
  this.logFinished(started, op)
257
257
  }
258
258
 
259
- sortRows<ROW>(rows: ROW[]): ROW[] {
259
+ private sortRows<ROW extends ObjectWithId>(rows: ROW[]): ROW[] {
260
260
  rows = rows.map(r => _filterUndefinedValues(r))
261
261
 
262
262
  if (this.cfg.sortOnSave) {
263
- _sortBy(rows, r => r[this.cfg.sortOnSave!.name], true)
263
+ _sortBy(rows, r => r[this.cfg.sortOnSave!.name as keyof ROW], true)
264
264
  if (this.cfg.sortOnSave.descending) rows.reverse() // mutates
265
265
  }
266
266
 
@@ -84,7 +84,7 @@ export class CommonDao<
84
84
  beforeDBMValidate: dbm => dbm,
85
85
  beforeDBMToBM: dbm => dbm as any,
86
86
  beforeBMToDBM: bm => bm as any,
87
- beforeTMToBM: tm => tm,
87
+ beforeTMToBM: tm => tm as any,
88
88
  beforeBMToTM: bm => bm as any,
89
89
  anonymize: dbm => dbm,
90
90
  onValidationError: err => err,
@@ -112,9 +112,9 @@ export class CommonDao<
112
112
  }
113
113
 
114
114
  // GET
115
- async getById(id: undefined, opt?: CommonDaoOptions): Promise<null>
116
- async getById(id?: ID, opt?: CommonDaoOptions): Promise<Saved<BM> | null>
117
- async getById(id?: ID, opt: CommonDaoOptions = {}): Promise<Saved<BM> | null> {
115
+ async getById(id: undefined | null, opt?: CommonDaoOptions): Promise<null>
116
+ async getById(id?: ID | null, opt?: CommonDaoOptions): Promise<Saved<BM> | null>
117
+ async getById(id?: ID | null, opt: CommonDaoOptions = {}): Promise<Saved<BM> | null> {
118
118
  if (!id) return null
119
119
  const op = `getById(${id})`
120
120
  const table = opt.table || this.cfg.table
@@ -154,9 +154,9 @@ export class CommonDao<
154
154
  return await this.bmToDBM(bm, opt)
155
155
  }
156
156
 
157
- async getByIdAsDBM(id: undefined, opt?: CommonDaoOptions): Promise<null>
158
- async getByIdAsDBM(id?: ID, opt?: CommonDaoOptions): Promise<DBM | null>
159
- async getByIdAsDBM(id?: ID, opt: CommonDaoOptions = {}): Promise<DBM | null> {
157
+ async getByIdAsDBM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>
158
+ async getByIdAsDBM(id?: ID | null, opt?: CommonDaoOptions): Promise<DBM | null>
159
+ async getByIdAsDBM(id?: ID | null, opt: CommonDaoOptions = {}): Promise<DBM | null> {
160
160
  if (!id) return null
161
161
  const op = `getByIdAsDBM(${id})`
162
162
  const table = opt.table || this.cfg.table
@@ -169,9 +169,9 @@ export class CommonDao<
169
169
  return dbm || null
170
170
  }
171
171
 
172
- async getByIdAsTM(id: undefined, opt?: CommonDaoOptions): Promise<null>
173
- async getByIdAsTM(id?: ID, opt?: CommonDaoOptions): Promise<TM | null>
174
- async getByIdAsTM(id?: ID, opt: CommonDaoOptions = {}): Promise<TM | null> {
172
+ async getByIdAsTM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>
173
+ async getByIdAsTM(id?: ID | null, opt?: CommonDaoOptions): Promise<TM | null>
174
+ async getByIdAsTM(id?: ID | null, opt: CommonDaoOptions = {}): Promise<TM | null> {
175
175
  if (!id) return null
176
176
  const op = `getByIdAsTM(${id})`
177
177
  const table = opt.table || this.cfg.table
@@ -302,7 +302,7 @@ export class CommonDao<
302
302
  const col = q._selectedFieldNames[0]!
303
303
 
304
304
  const { rows } = await this.runQueryExtended(q, opt)
305
- return rows.map(r => r[col as any])
305
+ return rows.map((r: any) => r[col])
306
306
  }
307
307
 
308
308
  /**
@@ -594,11 +594,12 @@ export class CommonDao<
594
594
  obj.id ||= this.cfg.hooks!.createId?.(obj as BM)
595
595
 
596
596
  if (this.cfg.created) {
597
- obj['created'] ||= obj['updated'] || now
597
+ ;(obj as any)['created'] ||= (obj as any)['updated'] || now
598
598
  }
599
599
 
600
600
  if (this.cfg.updated) {
601
- obj['updated'] = opt.preserveUpdatedCreated && obj['updated'] ? obj['updated'] : now
601
+ ;(obj as any)['updated'] =
602
+ opt.preserveUpdatedCreated && (obj as any)['updated'] ? (obj as any)['updated'] : now
602
603
  }
603
604
 
604
605
  return obj as any
@@ -779,9 +780,9 @@ export class CommonDao<
779
780
  /**
780
781
  * @returns number of deleted items
781
782
  */
782
- async deleteById(id: undefined, opt?: CommonDaoOptions): Promise<0>
783
- async deleteById(id?: ID, opt?: CommonDaoOptions): Promise<number>
784
- async deleteById(id?: ID, opt: CommonDaoOptions = {}): Promise<number> {
783
+ async deleteById(id: undefined | null, opt?: CommonDaoOptions): Promise<0>
784
+ async deleteById(id?: ID | null, opt?: CommonDaoOptions): Promise<number>
785
+ async deleteById(id?: ID | null, opt: CommonDaoOptions = {}): Promise<number> {
785
786
  if (!id) return 0
786
787
  this.requireWriteAccess()
787
788
  this.requireObjectMutability(opt)
@@ -186,8 +186,8 @@ export class DBQuery<ROW extends ObjectWithId = AnyObjectWithId> {
186
186
  }
187
187
 
188
188
  tokens.push(
189
- ...this._filters.map(f => `${f.name}${f.op}${f.val}`),
190
- ...this._orders.map(o => `order by ${o.name}${o.descending ? ' desc' : ''}`),
189
+ ...this._filters.map(f => `${f.name as string}${f.op}${f.val}`),
190
+ ...this._orders.map(o => `order by ${o.name as string}${o.descending ? ' desc' : ''}`),
191
191
  )
192
192
 
193
193
  if (this._groupByFieldNames) {
@@ -66,7 +66,7 @@ export function runCommonDaoTest(
66
66
  // CREATE TABLE, DROP
67
67
  if (createTable) {
68
68
  test('createTable, dropIfExists=true', async () => {
69
- await dao.createTable(testItemDBMJsonSchema.build(), { dropIfExists: true })
69
+ await dao.createTable(testItemDBMJsonSchema, { dropIfExists: true })
70
70
  })
71
71
  }
72
72
 
@@ -84,7 +84,7 @@ export function runCommonDaoTest(
84
84
  test('runQuery(all), runQueryCount should return empty', async () => {
85
85
  if (eventualConsistencyDelay) await pDelay(eventualConsistencyDelay)
86
86
  expect(await dao.query().runQuery()).toEqual([])
87
- expect(await dao.query().runQueryCount()).toEqual(0)
87
+ expect(await dao.query().runQueryCount()).toBe(0)
88
88
  })
89
89
  }
90
90
 
@@ -114,7 +114,7 @@ export function runCommonDaoTest(
114
114
  await dao.save(item3)
115
115
  const item3Loaded = await dao.requireById(item3.id)
116
116
  expectMatch([item3], [item3Loaded], quirks)
117
- expect(item3Loaded.k2).toBe(null)
117
+ expect(item3Loaded.k2).toBeNull()
118
118
  expect(Object.keys(item3)).toContain('k2')
119
119
  expect(item3.k2).toBeNull()
120
120
  })
@@ -135,7 +135,7 @@ export function runCommonDaoTest(
135
135
 
136
136
  const item3Loaded = await dao.requireById(item3.id)
137
137
  expectMatch([expected], [item3Loaded], quirks)
138
- expect(item3Loaded.k2).toBe(undefined)
138
+ expect(item3Loaded.k2).toBeUndefined()
139
139
  expect(Object.keys(item3Loaded)).not.toContain('k2')
140
140
  expect(Object.keys(item3)).toContain('k2')
141
141
  expect(item3.k2).toBeUndefined()
@@ -110,7 +110,7 @@ export function runCommonDBTest(
110
110
  // CREATE TABLE, DROP
111
111
  if (createTable) {
112
112
  test('createTable, dropIfExists=true', async () => {
113
- await db.createTable(TEST_TABLE, testItemDBMJsonSchema.build(), { dropIfExists: true })
113
+ await db.createTable(TEST_TABLE, testItemDBMJsonSchema, { dropIfExists: true })
114
114
  })
115
115
  }
116
116
 
@@ -128,7 +128,7 @@ export function runCommonDBTest(
128
128
  test('runQuery(all), runQueryCount should return empty', async () => {
129
129
  if (eventualConsistencyDelay) await pDelay(eventualConsistencyDelay)
130
130
  expect((await db.runQuery(queryAll())).rows).toEqual([])
131
- expect(await db.runQueryCount(queryAll())).toEqual(0)
131
+ expect(await db.runQueryCount(queryAll())).toBe(0)
132
132
  })
133
133
  }
134
134
 
@@ -158,7 +158,7 @@ export function runCommonDBTest(
158
158
  await db.saveBatch(TEST_TABLE, [item3])
159
159
  const item3Loaded = (await db.getByIds<TestItemDBM>(TEST_TABLE, [item3.id]))[0]!
160
160
  expectMatch([item3], [item3Loaded], quirks)
161
- expect(item3Loaded.k2).toBe(null)
161
+ expect(item3Loaded.k2).toBeNull()
162
162
  })
163
163
  }
164
164
 
@@ -175,7 +175,7 @@ export function runCommonDBTest(
175
175
  await db.saveBatch(TEST_TABLE, [item3])
176
176
  const item3Loaded = (await db.getByIds<TestItemDBM>(TEST_TABLE, [item3.id]))[0]!
177
177
  expectMatch([expected], [item3Loaded], quirks)
178
- expect(item3Loaded.k2).toBe(undefined)
178
+ expect(item3Loaded.k2).toBeUndefined()
179
179
  expect(Object.keys(item3Loaded)).not.toContain('k2')
180
180
  })
181
181
  }
@@ -58,18 +58,21 @@ export const testItemBMJsonSchema = jsonSchema
58
58
  b1: jsonSchema.buffer().optional(),
59
59
  })
60
60
  .baseDBEntity()
61
+ .build()
61
62
 
62
- export const testItemDBMJsonSchema = jsonSchema.rootObject<TestItemDBM>({
63
- // todo: figure out how to not copy-paste these 3 fields
64
- id: jsonSchema.string(),
65
- created: jsonSchema.unixTimestamp(),
66
- updated: jsonSchema.unixTimestamp(),
67
- k1: jsonSchema.string(),
68
- k2: jsonSchema.string().optional(),
69
- k3: jsonSchema.number().optional(),
70
- even: jsonSchema.boolean().optional(),
71
- b1: jsonSchema.buffer().optional(),
72
- })
63
+ export const testItemDBMJsonSchema = jsonSchema
64
+ .rootObject<TestItemDBM>({
65
+ // todo: figure out how to not copy-paste these 3 fields
66
+ id: jsonSchema.string(),
67
+ created: jsonSchema.unixTimestamp(),
68
+ updated: jsonSchema.unixTimestamp(),
69
+ k1: jsonSchema.string(),
70
+ k2: jsonSchema.string().optional(),
71
+ k3: jsonSchema.number().optional(),
72
+ even: jsonSchema.boolean().optional(),
73
+ b1: jsonSchema.buffer().optional(),
74
+ })
75
+ .build()
73
76
 
74
77
  export function createTestItemDBM(num = 1): TestItemDBM {
75
78
  return {