@noldova/context.data.sql 0.0.0-stage → 0.0.6

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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +51 -2
  3. package/api/index.d.ts +664 -0
  4. package/api/index.js +31 -0
  5. package/api/index.js.map +1 -0
  6. package/enums/column-type.js +13 -0
  7. package/enums/column-type.js.map +1 -0
  8. package/models/operations/create-index-operation.js +19 -0
  9. package/models/operations/create-index-operation.js.map +1 -0
  10. package/models/operations/create-table-operation.js +19 -0
  11. package/models/operations/create-table-operation.js.map +1 -0
  12. package/models/operations/schema-operation.js +10 -0
  13. package/models/operations/schema-operation.js.map +1 -0
  14. package/models/operations/sql-statement-operation.js +22 -0
  15. package/models/operations/sql-statement-operation.js.map +1 -0
  16. package/models/schema/column-builder.js +25 -0
  17. package/models/schema/column-builder.js.map +1 -0
  18. package/models/schema/column.js +21 -0
  19. package/models/schema/column.js.map +1 -0
  20. package/models/schema/columns-builder.js +21 -0
  21. package/models/schema/columns-builder.js.map +1 -0
  22. package/models/schema/constraints-builder.js +29 -0
  23. package/models/schema/constraints-builder.js.map +1 -0
  24. package/models/schema/foreign-key.js +23 -0
  25. package/models/schema/foreign-key.js.map +1 -0
  26. package/models/schema/migration-builder.js +45 -0
  27. package/models/schema/migration-builder.js.map +1 -0
  28. package/models/schema/primary-key.js +18 -0
  29. package/models/schema/primary-key.js.map +1 -0
  30. package/models/schema/table.js +25 -0
  31. package/models/schema/table.js.map +1 -0
  32. package/models/sql-connection.js +46 -0
  33. package/models/sql-connection.js.map +1 -0
  34. package/models/sql-migration.js +14 -0
  35. package/models/sql-migration.js.map +1 -0
  36. package/models/sql-query.js +22 -0
  37. package/models/sql-query.js.map +1 -0
  38. package/models/sql-session.js +10 -0
  39. package/models/sql-session.js.map +1 -0
  40. package/models/sql-transaction.js +36 -0
  41. package/models/sql-transaction.js.map +1 -0
  42. package/package.json +25 -4
  43. package/resources.js +58 -0
  44. package/resources.js.map +1 -0
  45. package/services/sql-change-feed.js +54 -0
  46. package/services/sql-change-feed.js.map +1 -0
  47. package/services/sql-dialect.js +49 -0
  48. package/services/sql-dialect.js.map +1 -0
  49. package/services/sql-migration-history.js +32 -0
  50. package/services/sql-migration-history.js.map +1 -0
  51. package/services/sql-migrator.js +37 -0
  52. package/services/sql-migrator.js.map +1 -0
  53. package/services/sql-provider.js +19 -0
  54. package/services/sql-provider.js.map +1 -0
  55. package/types/column-selector.js +9 -0
  56. package/types/column-selector.js.map +1 -0
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import "@noldova/context.core";
9
+ import { Change, ChangeFeed, ChangeOperation, DataException } from "@noldova/context.data";
10
+ import { SqlQuery } from "../models/sql-query.js";
11
+ import { Resources } from "../resources.js";
12
+ export class SqlChangeFeed extends ChangeFeed {
13
+ connection;
14
+ constructor(connection) {
15
+ super();
16
+ this.connection = connection;
17
+ }
18
+ async appendCoreAsync(entity, entityId, operation, payload, transaction) {
19
+ if (Object.isUndefined(transaction))
20
+ return this.connection.runInTransactionAsync(async (t) => this.appendInAsync(t, entity, entityId, operation, payload));
21
+ return this.appendInAsync(transaction, entity, entityId, operation, payload);
22
+ }
23
+ async readAfterCoreAsync(sequence, limit, transaction) {
24
+ if (Object.isUndefined(transaction))
25
+ return this.connection.runInTransactionAsync(async (t) => this.readAfterInAsync(t, sequence, limit));
26
+ return this.readAfterInAsync(transaction, sequence, limit);
27
+ }
28
+ async readAfterInAsync(transaction, sequence, limit) {
29
+ await this.prepareAsync(transaction);
30
+ return (await transaction.queryAsync(new SqlQuery(Resources.selectChangesAfter, [sequence, limit]))).map(t => SqlChangeFeed.toChange(t));
31
+ }
32
+ async appendInAsync(transaction, entity, entityId, operation, payload) {
33
+ await this.prepareAsync(transaction);
34
+ const createdAt = new Date().toISOString();
35
+ const sequence = await transaction.insertAsync(new SqlQuery(Resources.insertChange, [entity, entityId, operation, payload, createdAt]));
36
+ return new Change(sequence, entity, entityId, operation, payload, createdAt);
37
+ }
38
+ async prepareAsync(transaction) {
39
+ for (const statement of this.connection.dialect.formatLock(Resources.changesTable))
40
+ await transaction.executeAsync(new SqlQuery(statement));
41
+ await transaction.executeAsync(new SqlQuery(Resources.formatCreateChangesTable(this.connection.dialect.formatIdentityColumnType())));
42
+ await transaction.executeAsync(new SqlQuery(Resources.createChangesIndex));
43
+ }
44
+ static toChange(record) {
45
+ return new Change(record.readInteger(Resources.sequenceColumn), record.readString(Resources.entityColumn), record.readString(Resources.entityIdColumn), SqlChangeFeed.parseOperation(record.readString(Resources.operationColumn)), record.readString(Resources.payloadColumn), record.readString(Resources.createdAtColumn));
46
+ }
47
+ static parseOperation(text) {
48
+ const operation = Object.values(ChangeOperation).find(t => t === text);
49
+ if (Object.isUndefined(operation))
50
+ throw new DataException(Resources.unknownOperation);
51
+ return operation;
52
+ }
53
+ }
54
+ //# sourceMappingURL=sql-change-feed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-change-feed.js","sourceRoot":"","sources":["../../../../src/data/noldova.context.data.sql/src/services/sql-change-feed.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,aAAa,EAAmB,MAAM,uBAAuB,CAAC;AAE5G,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,aAAc,SAAQ,UAA0B;IAC1C,UAAU,CAAgB;IAE3C,YAAmB,UAAyB;QAC1C,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAEkB,KAAK,CAAC,eAAe,CACtC,MAAc,EA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AAC,UAAU,CAAC,SAAS,CAAC,aAAa,CAAC,EAC1C,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC;IAClD,CAAC;IAEO,MAAM,CAAC,cAAc,CAAC,IAAY;QACxC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;QACvE,IAAI,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC;YAC/B,MAAM,IAAI,aAAa,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;QAEtD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import "@noldova/context.core";
9
+ import { Resources } from "../resources.js";
10
+ export class SqlDialect {
11
+ quoteIdentifier(name) {
12
+ return Resources.identifierQuote + name.replaceAll(Resources.identifierQuote, Resources.escapedIdentifierQuote) + Resources.identifierQuote;
13
+ }
14
+ renderCreateTable(table) {
15
+ const definitions = table.columns.map(t => this.renderColumn(t));
16
+ if (!Object.isNull(table.primaryKey))
17
+ definitions.push(this.renderPrimaryKey(table.primaryKey));
18
+ for (const foreignKey of table.foreignKeys)
19
+ definitions.push(this.renderForeignKey(foreignKey));
20
+ return [Resources.createTable, this.quoteIdentifier(table.name), this.renderList(definitions)].join(Resources.wordSeparator);
21
+ }
22
+ renderCreateIndex(index) {
23
+ const keyword = index.isUnique ? Resources.createUniqueIndex : Resources.createIndex;
24
+ return [keyword, this.quoteIdentifier(index.name), Resources.onKeyword, this.quoteIdentifier(index.container), this.renderNames(index.fields)]
25
+ .join(Resources.wordSeparator);
26
+ }
27
+ renderColumn(column) {
28
+ const parts = [this.quoteIdentifier(column.name), this.formatColumnType(column.type)];
29
+ if (!column.isNullable)
30
+ parts.push(Resources.notNullConstraint);
31
+ return parts.join(Resources.wordSeparator);
32
+ }
33
+ renderPrimaryKey(primaryKey) {
34
+ return [Resources.primaryKeyConstraint, this.renderNames(primaryKey.columns)].join(Resources.wordSeparator);
35
+ }
36
+ renderForeignKey(foreignKey) {
37
+ const columns = this.renderNames([foreignKey.column]);
38
+ const principalColumns = this.renderNames([foreignKey.principalColumn]);
39
+ return [Resources.foreignKeyConstraint, columns, Resources.referencesConstraint, this.quoteIdentifier(foreignKey.principalTable), principalColumns]
40
+ .join(Resources.wordSeparator);
41
+ }
42
+ renderNames(names) {
43
+ return this.renderList(names.map(t => this.quoteIdentifier(t)));
44
+ }
45
+ renderList(items) {
46
+ return Resources.openParenthesis + items.join(Resources.listSeparator) + Resources.closeParenthesis;
47
+ }
48
+ }
49
+ //# sourceMappingURL=sql-dialect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-dialect.js","sourceRoot":"","sources":["../../../../src/data/noldova.context.data.sql/src/services/sql-dialect.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,uBAAuB,CAAC;AAQ/B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAgB,UAAU;IASvB,eAAe,CAAC,IAAY;QACjC,OAAO,SAAS,CAAC,eAAe,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,eAAe,EAAE,SAAS,CAAC,sBAAsB,CAAC,GAAG,SAAS,CAAC,eAAe,CAAC;IAC9I,CAAC;IAEM,iBAAiB,CAAC,KAAY;QACnC,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;QACjE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;YAClC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB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AAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAC9G,CAAC;IAEM,gBAAgB,CAAC,UAAsB;QAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;QACtD,MAAM,gBAAgB,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC;QACxE,OAAO,CAAC,SAAS,CAAC,oBAAoB,EAAE,OAAO,EAAE,SAAS,CAAC,oBAAoB,EAAE,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,gBAAgB,CAAC;aAChJ,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IACnC,CAAC;IAEO,WAAW,CAAC,KAAwB;QAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;IAEO,UAAU,CAAC,KAAwB;QACzC,OAAO,SAAS,CAAC,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC,gBAAgB,CAAC;IACtG,CAAC;CACF"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import "@noldova/context.core";
9
+ import { MigrationHistory } from "@noldova/context.data";
10
+ import { SqlQuery } from "../models/sql-query.js";
11
+ import { Resources } from "../resources.js";
12
+ export class SqlMigrationHistory extends MigrationHistory {
13
+ connection;
14
+ constructor(connection) {
15
+ super();
16
+ this.connection = connection;
17
+ }
18
+ async getAppliedAsync(transaction) {
19
+ if (Object.isUndefined(transaction))
20
+ return this.connection.runInTransactionAsync(async (t) => {
21
+ for (const statement of this.connection.dialect.formatLock(Resources.migrationsTable))
22
+ await t.executeAsync(new SqlQuery(statement));
23
+ return this.getAppliedAsync(t);
24
+ });
25
+ await transaction.executeAsync(new SqlQuery(Resources.createMigrationsTable));
26
+ return (await transaction.queryAsync(new SqlQuery(Resources.selectAppliedMigrations))).map(t => t.readString(Resources.idColumn));
27
+ }
28
+ async recordAsync(id, transaction) {
29
+ await (transaction ?? this.connection).executeAsync(new SqlQuery(Resources.insertMigration, [id, new Date().toISOString()]));
30
+ }
31
+ }
32
+ //# sourceMappingURL=sql-migration-history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-migration-history.js","sourceRoot":"","sources":["../../../../src/data/noldova.context.data.sql/src/services/sql-migration-history.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,mBAAoB,SAAQ,gBAAgB;IACtC,UAAU,CAAgB;IAE3C,YAAmB,UAAyB;QAC1C,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAEe,KAAK,CAAC,eAAe,CAAC,WAA4B;QAChE,IAAI,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC;YACjC,OAAO,IAAI,CAAC,UAAU,CAAC,qBAAqB,CAAC,KAAK,EAAC,CAAC,EAAC,EAAE;gBACrD,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,eAAe,CAAC;oBACnF,MAAM,CAAC,CAAC,YAAY,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;gBAChD,OAAO,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YACjC,CAAC,CAAC,CAAC;QAEL,MAAM,WAAW,CAAC,YAAY,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC,CAAC;QAC9E,OAAO,CAAC,MAAM,WAAW,CAAC,UAAU,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IACpI,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,EAAU,EAAE,WAA4B;QACxE,MAAM,CAAC,WAAW,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,YAAY,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/H,CAAC;CACF"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { Migrator } from "@noldova/context.data";
9
+ import { SqlQuery } from "../models/sql-query.js";
10
+ import { Resources } from "../resources.js";
11
+ import { MigrationBuilder } from "../models/schema/migration-builder.js";
12
+ import { SqlMigrationHistory } from "./sql-migration-history.js";
13
+ export class SqlMigrator extends Migrator {
14
+ connection;
15
+ sqlHistory;
16
+ constructor(connection, migrations) {
17
+ const history = new SqlMigrationHistory(connection);
18
+ super(migrations, history);
19
+ this.connection = connection;
20
+ this.sqlHistory = history;
21
+ }
22
+ async applyAsync(migration) {
23
+ const builder = new MigrationBuilder();
24
+ migration.apply(builder);
25
+ return this.connection.runInTransactionAsync(async (transaction) => {
26
+ for (const statement of this.connection.dialect.formatLock(Resources.migrationsTable))
27
+ await transaction.executeAsync(new SqlQuery(statement));
28
+ if ((await this.sqlHistory.getAppliedAsync(transaction)).includes(migration.id))
29
+ return false;
30
+ for (const operation of builder.toOperations())
31
+ await transaction.executeAsync(new SqlQuery(operation.render(this.connection.dialect)));
32
+ await this.sqlHistory.recordAsync(migration.id, transaction);
33
+ return true;
34
+ });
35
+ }
36
+ }
37
+ //# sourceMappingURL=sql-migrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-migrator.js","sourceRoot":"","sources":["../../../../src/data/noldova.context.data.sql/src/services/sql-migrator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAEzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGjE,MAAM,OAAO,WAAY,SAAQ,QAAsB;IACpC,UAAU,CAAgB;IAC1B,UAAU,CAAsB;IAEjD,YAAmB,UAAyB,EAAE,UAAmC;QAC/E,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,UAAU,CAAC,CAAC;QACpD,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAE3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC;IAC5B,CAAC;IAEkB,KAAK,CAAC,UAAU,CAAC,SAAuB;QACzD,MAAM,OAAO,GAAG,IAAI,gBAAgB,EAAE,CAAC;QACvC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC,UAAU,CAAC,qBAAqB,CAAC,KAAK,EAAC,WAAW,EAAC,EAAE;YAC/D,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,eAAe,CAAC;gBACnF,MAAM,WAAW,CAAC,YAAY,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;YAC1D,IAAI,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC7E,OAAO,KAAK,CAAC;YAEf,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,YAAY,EAAE;gBAC5C,MAAM,WAAW,CAAC,YAAY,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC1F,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;YAC7D,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { DataProvider } from "@noldova/context.data";
9
+ import { SqlChangeFeed } from "./sql-change-feed.js";
10
+ import { SqlMigrator } from "./sql-migrator.js";
11
+ export class SqlProvider extends DataProvider {
12
+ createMigrator(connection, migrations) {
13
+ return new SqlMigrator(connection, migrations);
14
+ }
15
+ createChangeFeed(connection) {
16
+ return new SqlChangeFeed(connection);
17
+ }
18
+ }
19
+ //# sourceMappingURL=sql-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-provider.js","sourceRoot":"","sources":["../../../../src/data/noldova.context.data.sql/src/services/sql-provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAmB,YAAY,EAAiB,MAAM,uBAAuB,CAAC;AAErF,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,OAAgB,WAAY,SAAQ,YAAyC;IACjE,cAAc,CAAC,UAAyB,EAAE,UAAmC;QAC3F,OAAO,IAAI,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACjD,CAAC;IAEe,gBAAgB,CAAC,UAAyB;QACxD,OAAO,IAAI,aAAa,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=column-selector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column-selector.js","sourceRoot":"","sources":["../../../../src/data/noldova.context.data.sql/src/types/column-selector.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}