@naturalcycles/datastore-lib 4.17.0 → 4.18.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.
@@ -2,9 +2,9 @@ import type { Key, Transaction } from '@google-cloud/datastore';
2
2
  import { Datastore } from '@google-cloud/datastore';
3
3
  import type { CommonDB, CommonDBOptions, CommonDBReadOptions, CommonDBSaveOptions, CommonDBSupport, CommonDBTransactionOptions, DBQuery, DBTransaction, DBTransactionFn, RunQueryResult } from '@naturalcycles/db-lib';
4
4
  import { BaseCommonDB } from '@naturalcycles/db-lib';
5
- import type { JsonSchemaObject, JsonSchemaRootObject } from '@naturalcycles/js-lib/json-schema';
6
5
  import type { CommonLogger } from '@naturalcycles/js-lib/log';
7
6
  import { type ObjectWithId, type StringMap } from '@naturalcycles/js-lib/types';
7
+ import type { JsonSchema } from '@naturalcycles/nodejs-lib/ajv';
8
8
  import { Pipeline } from '@naturalcycles/nodejs-lib/stream';
9
9
  import type { DatastoreDBCfg, DatastoreDBOptions, DatastoreDBReadOptions, DatastoreDBSaveOptions, DatastoreDBStreamOptions, DatastorePropertyStats, DatastoreStats } from './datastore.model.js';
10
10
  /**
@@ -57,9 +57,9 @@ export declare class DatastoreDB extends BaseCommonDB implements CommonDB {
57
57
  key(ds: Datastore, kind: string, id: string): Key;
58
58
  private getDsKey;
59
59
  private getIdFromKey;
60
- createTable<ROW extends ObjectWithId>(_table: string, _schema: JsonSchemaObject<ROW>): Promise<void>;
60
+ createTable<ROW extends ObjectWithId>(_table: string, _schema: JsonSchema<ROW>): Promise<void>;
61
61
  getTables(): Promise<string[]>;
62
- getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
62
+ getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchema<ROW>>;
63
63
  private getPRetryOptions;
64
64
  /**
65
65
  * Silently rollback the transaction.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/datastore-lib",
3
3
  "type": "module",
4
- "version": "4.17.0",
4
+ "version": "4.18.0",
5
5
  "description": "Opinionated library to work with Google Datastore, implements CommonDB",
6
6
  "dependencies": {
7
7
  "@google-cloud/datastore": "^10",
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "devDependencies": {
13
13
  "@types/node": "^24",
14
- "@naturalcycles/dev-lib": "20.6.0"
14
+ "@naturalcycles/dev-lib": "18.4.2"
15
15
  },
16
16
  "exports": {
17
17
  ".": "./dist/index.js"
@@ -20,15 +20,6 @@ import { _chunk } from '@naturalcycles/js-lib/array/array.util.js'
20
20
  import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js'
21
21
  import { _assert } from '@naturalcycles/js-lib/error/assert.js'
22
22
  import { _errorDataAppend, TimeoutError } from '@naturalcycles/js-lib/error/error.util.js'
23
- import type {
24
- JsonSchemaAny,
25
- JsonSchemaBoolean,
26
- JsonSchemaNull,
27
- JsonSchemaNumber,
28
- JsonSchemaObject,
29
- JsonSchemaRootObject,
30
- JsonSchemaString,
31
- } from '@naturalcycles/js-lib/json-schema'
32
23
  import type { CommonLogger } from '@naturalcycles/js-lib/log'
33
24
  import { _omit } from '@naturalcycles/js-lib/object/object.util.js'
34
25
  import type { PRetryOptions } from '@naturalcycles/js-lib/promise'
@@ -41,6 +32,7 @@ import {
41
32
  type ObjectWithId,
42
33
  type StringMap,
43
34
  } from '@naturalcycles/js-lib/types'
35
+ import type { JsonSchema } from '@naturalcycles/nodejs-lib/ajv'
44
36
  import { boldWhite } from '@naturalcycles/nodejs-lib/colors'
45
37
  import { Pipeline } from '@naturalcycles/nodejs-lib/stream'
46
38
  import type {
@@ -585,7 +577,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
585
577
 
586
578
  override async createTable<ROW extends ObjectWithId>(
587
579
  _table: string,
588
- _schema: JsonSchemaObject<ROW>,
580
+ _schema: JsonSchema<ROW>,
589
581
  ): Promise<void> {}
590
582
 
591
583
  override async getTables(): Promise<string[]> {
@@ -594,12 +586,10 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
594
586
  return statsArray.map(stats => stats.kind_name).filter(table => table && !table.startsWith('_'))
595
587
  }
596
588
 
597
- override async getTableSchema<ROW extends ObjectWithId>(
598
- table: string,
599
- ): Promise<JsonSchemaRootObject<ROW>> {
589
+ override async getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchema<ROW>> {
600
590
  const stats = await this.getTableProperties(table)
601
591
 
602
- const s: JsonSchemaRootObject<ROW> = {
592
+ const s: JsonSchema<ROW> = {
603
593
  $id: `${table}.schema.json`,
604
594
  type: 'object',
605
595
  properties: {
@@ -616,40 +606,40 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
616
606
  const name = stats.property_name as keyof ROW
617
607
 
618
608
  if (dtype === DatastoreType.Blob) {
619
- s.properties[name] = {
609
+ s.properties![name] = {
620
610
  instanceof: 'Buffer',
621
- } as JsonSchemaAny
611
+ } as JsonSchema<any, ROW[typeof name]>
622
612
  } else if (dtype === DatastoreType.Text || dtype === DatastoreType.String) {
623
- s.properties[name] = {
613
+ s.properties![name] = {
624
614
  type: 'string',
625
- } as JsonSchemaString
615
+ } as JsonSchema<ROW[typeof name]>
626
616
  } else if (dtype === DatastoreType.EmbeddedEntity) {
627
- s.properties[name] = {
617
+ s.properties![name] = {
628
618
  type: 'object',
629
619
  additionalProperties: true,
630
- properties: {},
620
+ properties: {} as any,
631
621
  required: [],
632
- } as JsonSchemaObject
622
+ } as JsonSchema<ROW[typeof name]>
633
623
  } else if (dtype === DatastoreType.Integer) {
634
- s.properties[name] = {
624
+ s.properties![name] = {
635
625
  type: 'integer',
636
- } as JsonSchemaNumber
626
+ } as JsonSchema<ROW[typeof name]>
637
627
  } else if (dtype === DatastoreType.Float) {
638
- s.properties[name] = {
628
+ s.properties![name] = {
639
629
  type: 'number',
640
- } as JsonSchemaNumber
630
+ } as JsonSchema<ROW[typeof name]>
641
631
  } else if (dtype === DatastoreType.Boolean) {
642
- s.properties[name] = {
632
+ s.properties![name] = {
643
633
  type: 'boolean',
644
- } as JsonSchemaBoolean
634
+ } as JsonSchema<ROW[typeof name]>
645
635
  } else if (dtype === DatastoreType.DATE_TIME) {
646
636
  // Don't know how to map it properly
647
- s.properties[name] = {} as JsonSchemaAny
637
+ s.properties![name] = {} as JsonSchema<any>
648
638
  } else if (dtype === DatastoreType.NULL) {
649
639
  // check, maybe we can just skip this type and do nothing?
650
- s.properties[name] ||= {
640
+ s.properties![name] ||= {
651
641
  type: 'null',
652
- } as JsonSchemaNull
642
+ } as JsonSchema<ROW[typeof name]>
653
643
  } else {
654
644
  throw new Error(
655
645
  `Unknown Datastore Type '${stats.property_type}' for ${table}.${name as string}`,