@travetto/model-sql 5.0.18 → 5.0.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-sql",
3
- "version": "5.0.18",
3
+ "version": "5.0.19",
4
4
  "description": "SQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
5
5
  "keywords": [
6
6
  "sql",
@@ -27,14 +27,14 @@
27
27
  "directory": "module/model-sql"
28
28
  },
29
29
  "dependencies": {
30
- "@travetto/cli": "^5.0.17",
31
- "@travetto/config": "^5.0.14",
32
- "@travetto/context": "^5.0.14",
33
- "@travetto/model": "^5.0.15",
34
- "@travetto/model-query": "^5.0.15"
30
+ "@travetto/cli": "^5.0.18",
31
+ "@travetto/config": "^5.0.15",
32
+ "@travetto/context": "^5.0.15",
33
+ "@travetto/model": "^5.0.16",
34
+ "@travetto/model-query": "^5.0.16"
35
35
  },
36
36
  "peerDependencies": {
37
- "@travetto/test": "^5.0.16"
37
+ "@travetto/test": "^5.0.17"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "@travetto/test": {
@@ -1,8 +1,8 @@
1
1
  import { castTo, Util } from '@travetto/runtime';
2
2
  import { AsyncContext } from '@travetto/context';
3
3
 
4
- const ContextActiveⲐ: unique symbol = Symbol.for('@travetto/model:sql-active');
5
- const TxActiveⲐ: unique symbol = Symbol.for('@travetto/model:sql-transaction');
4
+ const ContextActiveSymbol: unique symbol = Symbol.for('@travetto/model:sql-active');
5
+ const TxActiveSymbol: unique symbol = Symbol.for('@travetto/model:sql-transaction');
6
6
 
7
7
  export type TransactionType = 'required' | 'isolated' | 'force';
8
8
 
@@ -34,14 +34,14 @@ export abstract class Connection<C = unknown> {
34
34
  * Get active connection
35
35
  */
36
36
  get active(): C {
37
- return this.context.get<C>(ContextActiveⲐ);
37
+ return this.context.get<C>(ContextActiveSymbol);
38
38
  }
39
39
 
40
40
  /**
41
41
  * Get active tx state
42
42
  */
43
43
  get activeTx(): boolean {
44
- return !!this.context.get<boolean>(TxActiveⲐ);
44
+ return !!this.context.get<boolean>(TxActiveSymbol);
45
45
  }
46
46
 
47
47
  /**
@@ -79,7 +79,7 @@ export abstract class Connection<C = unknown> {
79
79
 
80
80
  return this.context.run(async () => {
81
81
  try {
82
- this.context.set(ContextActiveⲐ, await this.acquire());
82
+ this.context.set(ContextActiveSymbol, await this.acquire());
83
83
  return await op();
84
84
  } finally {
85
85
  if (this.active) {
@@ -103,7 +103,7 @@ export abstract class Connection<C = unknown> {
103
103
  const self = castTo<Connection>(this);
104
104
  yield* this.context.iterate(async function* () {
105
105
  try {
106
- self.context.set(ContextActiveⲐ, await self.acquire());
106
+ self.context.set(ContextActiveSymbol, await self.acquire());
107
107
  yield* op();
108
108
  } finally {
109
109
  if (self.active) {
@@ -134,7 +134,7 @@ export abstract class Connection<C = unknown> {
134
134
  }
135
135
  } else {
136
136
  return this.runWithActive(() => {
137
- this.context.set(TxActiveⲐ, true);
137
+ this.context.set(TxActiveSymbol, true);
138
138
  return this.runWithTransaction('force', op);
139
139
  });
140
140
  }
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable @stylistic/indent */
2
2
  import { DataUtil, SchemaRegistry, FieldConfig, Schema } from '@travetto/schema';
3
- import { Class, AppError, TypedObject, describeFunction, TimeUtil, castTo, castKey } from '@travetto/runtime';
3
+ import { Class, AppError, TypedObject, TimeUtil, castTo, castKey } from '@travetto/runtime';
4
4
  import { SelectClause, Query, SortClause, WhereClause, RetainFields } from '@travetto/model-query';
5
5
  import { BulkResponse, IndexConfig } from '@travetto/model';
6
6
  import { PointImpl } from '@travetto/model-query/src/internal/model/point';
@@ -634,11 +634,6 @@ ${this.getLimitSQL(cls, query)}`;
634
634
  const config = stack[stack.length - 1];
635
635
  const parent = stack.length > 1;
636
636
  const array = parent && config.array;
637
-
638
- if (config.type && describeFunction(config.type)?.synthetic) {
639
- throw new AppError(`Cannot create SQL tables for synthetic types, please convert ${SQLUtil.buildPath(stack)} to a concrete class`);
640
- }
641
-
642
637
  const fields = SchemaRegistry.has(config.type) ?
643
638
  [...SQLUtil.getFieldsByLocation(stack).local] :
644
639
  (array ? [castTo<FieldConfig>(config)] : []);
@@ -754,7 +749,6 @@ CREATE TABLE IF NOT EXISTS ${this.table(stack)} (
754
749
  return out;
755
750
  }
756
751
 
757
-
758
752
  /**
759
753
  * Get INSERT sql for a given instance and a specific stack location
760
754
  */
@@ -2,14 +2,14 @@ import { castKey, castTo, Class, TypedObject } from '@travetto/runtime';
2
2
  import { SelectClause, SortClause } from '@travetto/model-query';
3
3
  import { ModelRegistry, ModelType, OptionalId } from '@travetto/model';
4
4
  import { SchemaRegistry, ClassConfig, FieldConfig, DataUtil } from '@travetto/schema';
5
- import { AllViewⲐ } from '@travetto/schema/src/internal/types';
5
+ import { AllViewSymbol } 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('@travetto/model-sql:table');
9
+ const TableSymbol = Symbol.for('@travetto/model-sql:table');
10
10
 
11
11
  export type VisitStack = {
12
- [TableⲐ]?: string;
12
+ [TableSymbol]?: string;
13
13
  array?: boolean;
14
14
  type: Class;
15
15
  name: string;
@@ -79,14 +79,14 @@ export class SQLUtil {
79
79
  }
80
80
 
81
81
  const model = ModelRegistry.get(cls.class)!;
82
- const conf = cls.views[AllViewⲐ];
82
+ const conf = cls.views[AllViewSymbol];
83
83
  const fields = conf.fields.map(x => ({ ...conf.schema[x] }));
84
84
 
85
85
  // Polymorphic
86
86
  if (model && (model.baseType ?? model.subType)) {
87
87
  const fieldMap = new Set(fields.map(f => f.name));
88
88
  for (const type of ModelRegistry.getClassesByBaseType(ModelRegistry.getBaseModel(cls.class))) {
89
- const typeConf = SchemaRegistry.get(type).views[AllViewⲐ];
89
+ const typeConf = SchemaRegistry.get(type).views[AllViewSymbol];
90
90
  for (const f of typeConf.fields) {
91
91
  if (!fieldMap.has(f)) {
92
92
  fieldMap.add(f);
@@ -232,7 +232,7 @@ export class SQLUtil {
232
232
  if (typeof k === 'string' && !DataUtil.isPlainObject(select[k]) && localMap[k]) {
233
233
  if (!v) {
234
234
  if (toGet.size === 0) {
235
- toGet = new Set(SchemaRegistry.get(cls).views[AllViewⲐ].fields);
235
+ toGet = new Set(SchemaRegistry.get(cls).views[AllViewSymbol].fields);
236
236
  }
237
237
  toGet.delete(k);
238
238
  } else {
@@ -254,7 +254,7 @@ export class SQLUtil {
254
254
  while (!found) {
255
255
  const key = Object.keys(cl)[0];
256
256
  const val = cl[key];
257
- const field = { ...schema.views[AllViewⲐ].schema[key] };
257
+ const field = { ...schema.views[AllViewSymbol].schema[key] };
258
258
  if (DataUtil.isPrimitive(val)) {
259
259
  stack.push(field);
260
260
  found = { stack, asc: val === 1 };
@@ -305,10 +305,10 @@ export class SQLUtil {
305
305
  */
306
306
  static buildTable(list: VisitStack[]): string {
307
307
  const top = list[list.length - 1];
308
- if (!top[TableⲐ]) {
309
- top[TableⲐ] = list.map((el, i) => i === 0 ? ModelRegistry.getStore(el.type) : el.name).join('_');
308
+ if (!top[TableSymbol]) {
309
+ top[TableSymbol] = list.map((el, i) => i === 0 ? ModelRegistry.getStore(el.type) : el.name).join('_');
310
310
  }
311
- return top[TableⲐ]!;
311
+ return top[TableSymbol]!;
312
312
  }
313
313
 
314
314
  /**
@@ -95,7 +95,6 @@ export class TableManager {
95
95
  }
96
96
  }
97
97
 
98
-
99
98
  /**
100
99
  * Get a valid connection
101
100
  */