@travetto/model-sql 3.0.0-rc.4 → 3.0.0-rc.7

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  <!-- This file was generated by @travetto/doc and should not be modified directly -->
2
- <!-- Please modify https://github.com/travetto/travetto/tree/main/module/model-sql/doc.ts and execute "npx trv doc" to rebuild -->
2
+ <!-- Please modify https://github.com/travetto/travetto/tree/main/module/model-sql/DOC.ts and execute "npx trv doc" to rebuild -->
3
3
  # SQL Model Service
4
4
  ## SQL backing for the travetto model module, with real-time modeling support for SQL schemas.
5
5
 
File without changes
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-sql",
3
- "displayName": "SQL Model Service",
4
- "version": "3.0.0-rc.4",
3
+ "version": "3.0.0-rc.7",
5
4
  "description": "SQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
6
5
  "keywords": [
7
6
  "sql",
@@ -18,27 +17,35 @@
18
17
  "name": "Travetto Framework"
19
18
  },
20
19
  "files": [
21
- "index.ts",
20
+ "__index__.ts",
22
21
  "src",
23
- "support",
24
- "test-support"
22
+ "support"
25
23
  ],
26
- "main": "index.ts",
24
+ "main": "__index__.ts",
27
25
  "repository": {
28
26
  "url": "https://github.com/travetto/travetto.git",
29
27
  "directory": "module/model-sql"
30
28
  },
31
29
  "dependencies": {
32
- "@travetto/config": "^3.0.0-rc.4",
33
- "@travetto/context": "^3.0.0-rc.4",
34
- "@travetto/model": "^3.0.0-rc.4",
35
- "@travetto/model-query": "3.0.0-rc.4"
30
+ "@travetto/config": "^3.0.0-rc.7",
31
+ "@travetto/context": "^3.0.0-rc.7",
32
+ "@travetto/model": "^3.0.0-rc.7",
33
+ "@travetto/model-query": "^3.0.0-rc.7"
36
34
  },
37
- "devDependencies": {
38
- "@travetto/app": "^3.0.0-rc.4"
35
+ "peerDependencies": {
36
+ "@travetto/command": "^3.0.0-rc.5",
37
+ "@travetto/test": "^3.0.0-rc.7"
39
38
  },
40
- "docDependencies": {
41
- "@travetto/model-mysql": 1
39
+ "peerDependenciesMeta": {
40
+ "@travetto/command": {
41
+ "optional": true
42
+ },
43
+ "@travetto/test": {
44
+ "optional": true
45
+ }
46
+ },
47
+ "travetto": {
48
+ "displayName": "SQL Model Service"
42
49
  },
43
50
  "publishConfig": {
44
51
  "access": "public"
package/src/config.ts CHANGED
@@ -4,7 +4,7 @@ import { Config } from '@travetto/config';
4
4
  * SQL Model Config
5
5
  */
6
6
  @Config('model.sql')
7
- export class SQLModelConfig {
7
+ export class SQLModelConfig<T extends {} = {}> {
8
8
  /**
9
9
  * Host to connect to
10
10
  */
@@ -40,5 +40,6 @@ export class SQLModelConfig {
40
40
  /**
41
41
  * Raw client options
42
42
  */
43
- options = {};
43
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
44
+ options: T = {} as T;
44
45
  }
@@ -1,8 +1,8 @@
1
1
  import { Util } from '@travetto/base';
2
2
  import { AsyncContext } from '@travetto/context';
3
3
 
4
- const ContextActiveⲐ: unique symbol = Symbol.for('@trv:model/sql-active');
5
- const TxActiveⲐ: unique symbol = Symbol.for('@trv:model/sql-transaction');
4
+ const ContextActiveⲐ: unique symbol = Symbol.for('@travetto/model:sql-active');
5
+ const TxActiveⲐ: unique symbol = Symbol.for('@travetto/model:sql-transaction');
6
6
 
7
7
  export type TransactionType = 'required' | 'isolated' | 'force';
8
8
 
@@ -1,4 +1,4 @@
1
- import { MethodDescriptor } from '@travetto/base/src/internal/types';
1
+ import type { MethodDescriptor } from '@travetto/base';
2
2
  import { Connection, TransactionType } from './base';
3
3
 
4
4
  /**
@@ -1,10 +1,12 @@
1
+ import { RootIndex } from '@travetto/manifest';
1
2
  import { SchemaRegistry, FieldConfig, Schema } from '@travetto/schema';
2
- import { Class, Util, AppError } from '@travetto/base';
3
+ import { Class, ObjectUtil, AppError, TypedObject, DataUtil } from '@travetto/base';
3
4
  import { SelectClause, Query, SortClause, WhereClause, RetainFields } from '@travetto/model-query';
4
5
  import { BulkResponse, IndexConfig } from '@travetto/model';
5
6
  import { PointImpl } from '@travetto/model-query/src/internal/model/point';
6
7
  import { ModelType } from '@travetto/model/src/types/model';
7
8
  import { ModelQueryUtil } from '@travetto/model-query/src/internal/service/query';
9
+ import { ModelUtil } from '@travetto/model/src/internal/util';
8
10
 
9
11
  import { SQLUtil, VisitStack } from '../internal/util';
10
12
  import { DeleteWrapper, InsertWrapper, DialectState } from '../internal/types';
@@ -186,7 +188,7 @@ export abstract class SQLDialect implements DialectState {
186
188
  return 'NULL';
187
189
  } else if (conf.type === String) {
188
190
  if (value instanceof RegExp) {
189
- const src = Util.toRegex(value).source.replace(/\\b/g, this.regexWordBoundary);
191
+ const src = DataUtil.toRegex(value).source.replace(/\\b/g, this.regexWordBoundary);
190
192
  return this.quote(src);
191
193
  } else {
192
194
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
@@ -309,7 +311,7 @@ export abstract class SQLDialect implements DialectState {
309
311
  * Generate a UUID
310
312
  */
311
313
  generateId(): string {
312
- return Util.uuid(this.KEY_LEN);
314
+ return ModelUtil.uuid(this.KEY_LEN);
313
315
  }
314
316
 
315
317
  /**
@@ -424,7 +426,7 @@ export abstract class SQLDialect implements DialectState {
424
426
  }
425
427
  const sPath = this.resolveName(sStack);
426
428
 
427
- if (Util.isPlainObject(top)) {
429
+ if (ObjectUtil.isPlainObject(top)) {
428
430
  const subKey = Object.keys(top)[0];
429
431
  if (!subKey.startsWith('$')) {
430
432
  const inner = this.getWhereFieldSQL(sStack, top);
@@ -456,7 +458,7 @@ export abstract class SQLDialect implements DialectState {
456
458
  }
457
459
  case '$regex': {
458
460
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
459
- const re = Util.toRegex(v as string);
461
+ const re = DataUtil.toRegex(v as string);
460
462
  const src = re.source;
461
463
  const ins = re.flags && re.flags.includes('i');
462
464
 
@@ -490,7 +492,7 @@ export abstract class SQLDialect implements DialectState {
490
492
  }
491
493
  case '$lt': case '$gt': case '$gte': case '$lte': {
492
494
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
493
- const subItems = Object.keys(top as typeof SQL_OPS)
495
+ const subItems = TypedObject.keys(top as typeof SQL_OPS)
494
496
  .map(ssk => `${sPath} ${SQL_OPS[ssk]} ${resolve(top[ssk])}`);
495
497
  items.push(subItems.length > 1 ? `(${subItems.join(` ${SQL_OPS.$and} `)})` : subItems[0]);
496
498
  break;
@@ -630,7 +632,7 @@ ${this.getLimitSQL(cls, query)}`;
630
632
  const parent = stack.length > 1;
631
633
  const array = parent && config.array;
632
634
 
633
- if (config.type && config.type.ᚕsynthetic) {
635
+ if (config.type && RootIndex.getFunctionMetadata(config.type)?.synthetic) {
634
636
  throw new AppError(`Cannot create SQL tables for synthetic types, please convert ${SQLUtil.buildPath(stack)} to a concrete class`);
635
637
  }
636
638
 
@@ -710,9 +712,9 @@ CREATE TABLE IF NOT EXISTS ${this.table(stack)} (
710
712
  getCreateIndexSQL<T extends ModelType>(cls: Class<T>, idx: IndexConfig<T>): string {
711
713
  const table = this.namespace(SQLUtil.classToStack(cls));
712
714
  const fields: [string, boolean][] = idx.fields.map(x => {
713
- const key = Object.keys(x)[0];
715
+ const key = TypedObject.keys(x)[0];
714
716
  const val = x[key];
715
- if (Util.isPlainObject(val)) {
717
+ if (ObjectUtil.isPlainObject(val)) {
716
718
  throw new Error('Unable to supported nested fields for indices');
717
719
  }
718
720
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
@@ -1,4 +1,4 @@
1
- import { Class, Util } from '@travetto/base';
1
+ import { Class, TypedObject, ObjectUtil } from '@travetto/base';
2
2
  import { SelectClause, SortClause } from '@travetto/model-query';
3
3
  import { ModelRegistry, ModelType } from '@travetto/model';
4
4
  import { SchemaRegistry, ClassConfig, FieldConfig } from '@travetto/schema';
@@ -6,7 +6,7 @@ import { AllViewⲐ } from '@travetto/schema/src/internal/types';
6
6
 
7
7
  import { DialectState, InsertWrapper, VisitHandler, VisitState, VisitInstanceNode, OrderBy } from './types';
8
8
 
9
- const TableⲐ = Symbol.for('@trv:model-sql/table');
9
+ const TableⲐ = Symbol.for('@travetto/model-sql:table');
10
10
 
11
11
  export type VisitStack = {
12
12
  [TableⲐ]?: string;
@@ -45,8 +45,8 @@ export class SQLUtil {
45
45
  static cleanResults<T, U = T>(dct: DialectState, o: T | T[]): U | U[] {
46
46
  if (Array.isArray(o)) {
47
47
  return o.filter(x => x !== null && x !== undefined).map(x => this.cleanResults(dct, x));
48
- } else if (!Util.isSimple(o)) {
49
- for (const k of Object.keys(o)) {
48
+ } else if (!ObjectUtil.isSimple(o)) {
49
+ for (const k of TypedObject.keys(o)) {
50
50
  if (o[k] === null || o[k] === undefined || k === dct.parentPathField.name || k === dct.pathField.name || k === dct.idxField.name) {
51
51
  delete o[k];
52
52
  } else {
@@ -228,10 +228,10 @@ export class SQLUtil {
228
228
 
229
229
  let toGet = new Set<string>();
230
230
 
231
- for (const [k, v] of Object.entries(select)) {
231
+ for (const [k, v] of TypedObject.entries(select)) {
232
232
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
233
233
  const sk = k as string;
234
- if (!Util.isPlainObject(select[k]) && localMap[sk]) {
234
+ if (!ObjectUtil.isPlainObject(select[k]) && localMap[sk]) {
235
235
  if (!v) {
236
236
  if (toGet.size === 0) {
237
237
  toGet = new Set(SchemaRegistry.get(cls).views[AllViewⲐ].fields);
@@ -257,7 +257,7 @@ export class SQLUtil {
257
257
  const key = Object.keys(cl)[0];
258
258
  const val = cl[key];
259
259
  const field = { ...schema.views[AllViewⲐ].schema[key] };
260
- if (Util.isPrimitive(val)) {
260
+ if (ObjectUtil.isPrimitive(val)) {
261
261
  stack.push(field);
262
262
  found = { stack, asc: val === 1 };
263
263
  } else {
package/src/service.ts CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  BulkOp, BulkResponse, ModelCrudSupport, ModelStorageSupport, ModelBulkSupport,
4
4
  NotFoundError, ModelRegistry, ExistsError, OptionalId
5
5
  } from '@travetto/model';
6
- import { Util, Class } from '@travetto/base';
6
+ import { DataUtil, Class } from '@travetto/base';
7
7
  import { SchemaChange } from '@travetto/schema';
8
8
  import { AsyncContext } from '@travetto/context';
9
9
  import { Injectable } from '@travetto/di';
@@ -315,7 +315,7 @@ export class SQLModelService implements
315
315
 
316
316
  const results = await this.#exec<{ key: string, count: number }>(q.join('\n'));
317
317
  return results.records.map(x => {
318
- x.count = Util.coerceType(x.count, Number);
318
+ x.count = DataUtil.coerceType(x.count, Number);
319
319
  return x;
320
320
  });
321
321
  }
@@ -1,11 +1,11 @@
1
- import * as assert from 'assert';
1
+ import assert from 'assert';
2
2
 
3
3
  import { Schema, FieldConfig } from '@travetto/schema';
4
4
  import { Suite, Test } from '@travetto/test';
5
- import { BaseModelSuite } from '@travetto/model/test-support/base';
5
+ import { BaseModelSuite } from '@travetto/model/support/test/base';
6
6
 
7
- import { VisitStack } from '../src/internal/util';
8
- import { SQLModelService } from '../src/service';
7
+ import { VisitStack } from '../../src/internal/util';
8
+ import { SQLModelService } from '../../src/service';
9
9
 
10
10
  @Schema()
11
11
  class User {