@tachybase/database 0.23.8

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 (226) hide show
  1. package/.turbo/turbo-build.log +10 -0
  2. package/LICENSE +201 -0
  3. package/lib/collection-factory.d.ts +17 -0
  4. package/lib/collection-factory.js +52 -0
  5. package/lib/collection-group-manager.d.ts +26 -0
  6. package/lib/collection-group-manager.js +57 -0
  7. package/lib/collection-importer.d.ts +7 -0
  8. package/lib/collection-importer.js +74 -0
  9. package/lib/collection.d.ts +138 -0
  10. package/lib/collection.js +686 -0
  11. package/lib/database-utils/index.d.ts +9 -0
  12. package/lib/database-utils/index.js +71 -0
  13. package/lib/database-utils/traverseJSON.d.ts +10 -0
  14. package/lib/database-utils/traverseJSON.js +126 -0
  15. package/lib/database.d.ts +201 -0
  16. package/lib/database.js +765 -0
  17. package/lib/decorators/must-have-filter-decorator.d.ts +2 -0
  18. package/lib/decorators/must-have-filter-decorator.js +38 -0
  19. package/lib/decorators/target-collection-decorator.d.ts +2 -0
  20. package/lib/decorators/target-collection-decorator.js +47 -0
  21. package/lib/decorators/transaction-decorator.d.ts +1 -0
  22. package/lib/decorators/transaction-decorator.js +88 -0
  23. package/lib/eager-loading/eager-loading-tree.d.ts +31 -0
  24. package/lib/eager-loading/eager-loading-tree.js +439 -0
  25. package/lib/errors/identifier-error.d.ts +3 -0
  26. package/lib/errors/identifier-error.js +35 -0
  27. package/lib/errors/zero-column-table-error.d.ts +2 -0
  28. package/lib/errors/zero-column-table-error.js +31 -0
  29. package/lib/features/references-map.d.ts +18 -0
  30. package/lib/features/references-map.js +109 -0
  31. package/lib/features/referential-integrity-check.d.ts +8 -0
  32. package/lib/features/referential-integrity-check.js +83 -0
  33. package/lib/field-repository/array-field-repository.d.ts +28 -0
  34. package/lib/field-repository/array-field-repository.js +197 -0
  35. package/lib/fields/array-field.d.ts +11 -0
  36. package/lib/fields/array-field.js +57 -0
  37. package/lib/fields/belongs-to-field.d.ts +17 -0
  38. package/lib/fields/belongs-to-field.js +154 -0
  39. package/lib/fields/belongs-to-many-field.d.ts +20 -0
  40. package/lib/fields/belongs-to-many-field.js +187 -0
  41. package/lib/fields/boolean-field.d.ts +8 -0
  42. package/lib/fields/boolean-field.js +36 -0
  43. package/lib/fields/context-field.d.ts +14 -0
  44. package/lib/fields/context-field.js +70 -0
  45. package/lib/fields/date-field.d.ts +13 -0
  46. package/lib/fields/date-field.js +64 -0
  47. package/lib/fields/field.d.ts +43 -0
  48. package/lib/fields/field.js +156 -0
  49. package/lib/fields/has-inverse-field.d.ts +4 -0
  50. package/lib/fields/has-inverse-field.js +15 -0
  51. package/lib/fields/has-many-field.d.ts +68 -0
  52. package/lib/fields/has-many-field.js +156 -0
  53. package/lib/fields/has-one-field.d.ts +68 -0
  54. package/lib/fields/has-one-field.js +150 -0
  55. package/lib/fields/index.d.ts +46 -0
  56. package/lib/fields/index.js +65 -0
  57. package/lib/fields/json-field.d.ts +14 -0
  58. package/lib/fields/json-field.js +54 -0
  59. package/lib/fields/nanoid-field.d.ts +13 -0
  60. package/lib/fields/nanoid-field.js +58 -0
  61. package/lib/fields/number-field.d.ts +41 -0
  62. package/lib/fields/number-field.js +85 -0
  63. package/lib/fields/password-field.d.ts +21 -0
  64. package/lib/fields/password-field.js +95 -0
  65. package/lib/fields/radio-field.d.ts +16 -0
  66. package/lib/fields/radio-field.js +66 -0
  67. package/lib/fields/relation-field.d.ts +21 -0
  68. package/lib/fields/relation-field.js +79 -0
  69. package/lib/fields/set-field.d.ts +10 -0
  70. package/lib/fields/set-field.js +46 -0
  71. package/lib/fields/sort-field.d.ts +16 -0
  72. package/lib/fields/sort-field.js +187 -0
  73. package/lib/fields/string-field.d.ts +8 -0
  74. package/lib/fields/string-field.js +36 -0
  75. package/lib/fields/text-field.d.ts +8 -0
  76. package/lib/fields/text-field.js +36 -0
  77. package/lib/fields/time-field.d.ts +8 -0
  78. package/lib/fields/time-field.js +36 -0
  79. package/lib/fields/uid-field.d.ts +13 -0
  80. package/lib/fields/uid-field.js +63 -0
  81. package/lib/fields/uuid-field.d.ts +9 -0
  82. package/lib/fields/uuid-field.js +45 -0
  83. package/lib/fields/virtual-field.d.ts +8 -0
  84. package/lib/fields/virtual-field.js +36 -0
  85. package/lib/filter-match.d.ts +1 -0
  86. package/lib/filter-match.js +66 -0
  87. package/lib/filter-parser.d.ts +21 -0
  88. package/lib/filter-parser.js +230 -0
  89. package/lib/helpers.d.ts +3 -0
  90. package/lib/helpers.js +167 -0
  91. package/lib/index.d.ts +30 -0
  92. package/lib/index.js +114 -0
  93. package/lib/inherited-collection.d.ts +14 -0
  94. package/lib/inherited-collection.js +138 -0
  95. package/lib/inherited-map.d.ts +21 -0
  96. package/lib/inherited-map.js +113 -0
  97. package/lib/inherited-sync-runner.d.ts +4 -0
  98. package/lib/inherited-sync-runner.js +175 -0
  99. package/lib/listeners/adjacency-list.d.ts +2 -0
  100. package/lib/listeners/adjacency-list.js +42 -0
  101. package/lib/listeners/append-child-collection-name-after-repository-find.d.ts +6 -0
  102. package/lib/listeners/append-child-collection-name-after-repository-find.js +66 -0
  103. package/lib/listeners/index.d.ts +2 -0
  104. package/lib/listeners/index.js +33 -0
  105. package/lib/magic-attribute-model.d.ts +8 -0
  106. package/lib/magic-attribute-model.js +203 -0
  107. package/lib/migration.d.ts +35 -0
  108. package/lib/migration.js +103 -0
  109. package/lib/mock-database.d.ts +25 -0
  110. package/lib/mock-database.js +126 -0
  111. package/lib/model-hook.d.ts +12 -0
  112. package/lib/model-hook.js +92 -0
  113. package/lib/model.d.ts +23 -0
  114. package/lib/model.js +152 -0
  115. package/lib/operators/array.d.ts +2 -0
  116. package/lib/operators/array.js +158 -0
  117. package/lib/operators/association.d.ts +2 -0
  118. package/lib/operators/association.js +35 -0
  119. package/lib/operators/boolean.d.ts +2 -0
  120. package/lib/operators/boolean.js +38 -0
  121. package/lib/operators/child-collection.d.ts +2 -0
  122. package/lib/operators/child-collection.js +67 -0
  123. package/lib/operators/date.d.ts +2 -0
  124. package/lib/operators/date.js +140 -0
  125. package/lib/operators/empty.d.ts +5 -0
  126. package/lib/operators/empty.js +89 -0
  127. package/lib/operators/eq.d.ts +2 -0
  128. package/lib/operators/eq.js +35 -0
  129. package/lib/operators/index.d.ts +5 -0
  130. package/lib/operators/index.js +56 -0
  131. package/lib/operators/jsonb.d.ts +2 -0
  132. package/lib/operators/jsonb.js +50 -0
  133. package/lib/operators/ne.d.ts +2 -0
  134. package/lib/operators/ne.js +40 -0
  135. package/lib/operators/notIn.d.ts +2 -0
  136. package/lib/operators/notIn.js +33 -0
  137. package/lib/operators/string.d.ts +2 -0
  138. package/lib/operators/string.js +109 -0
  139. package/lib/operators/utils.d.ts +4 -0
  140. package/lib/operators/utils.js +40 -0
  141. package/lib/options-parser.d.ts +37 -0
  142. package/lib/options-parser.js +332 -0
  143. package/lib/playground.d.ts +1 -0
  144. package/lib/playground.js +43 -0
  145. package/lib/query-interface/mysql-query-interface.d.ts +35 -0
  146. package/lib/query-interface/mysql-query-interface.js +122 -0
  147. package/lib/query-interface/postgres-query-interface.d.ts +32 -0
  148. package/lib/query-interface/postgres-query-interface.js +189 -0
  149. package/lib/query-interface/query-interface-builder.d.ts +2 -0
  150. package/lib/query-interface/query-interface-builder.js +46 -0
  151. package/lib/query-interface/query-interface.d.ts +42 -0
  152. package/lib/query-interface/query-interface.js +46 -0
  153. package/lib/query-interface/sqlite-query-interface.d.ts +35 -0
  154. package/lib/query-interface/sqlite-query-interface.js +131 -0
  155. package/lib/relation-repository/belongs-to-many-repository.d.ts +21 -0
  156. package/lib/relation-repository/belongs-to-many-repository.js +280 -0
  157. package/lib/relation-repository/belongs-to-repository.d.ts +6 -0
  158. package/lib/relation-repository/belongs-to-repository.js +39 -0
  159. package/lib/relation-repository/hasmany-repository.d.ts +10 -0
  160. package/lib/relation-repository/hasmany-repository.js +182 -0
  161. package/lib/relation-repository/hasone-repository.d.ts +6 -0
  162. package/lib/relation-repository/hasone-repository.js +39 -0
  163. package/lib/relation-repository/multiple-relation-repository.d.ts +20 -0
  164. package/lib/relation-repository/multiple-relation-repository.js +229 -0
  165. package/lib/relation-repository/relation-repository.d.ts +29 -0
  166. package/lib/relation-repository/relation-repository.js +202 -0
  167. package/lib/relation-repository/single-relation-repository.d.ts +25 -0
  168. package/lib/relation-repository/single-relation-repository.js +162 -0
  169. package/lib/relation-repository/types.d.ts +7 -0
  170. package/lib/relation-repository/types.js +15 -0
  171. package/lib/repositories/tree-repository/adjacency-list-repository.d.ts +18 -0
  172. package/lib/repositories/tree-repository/adjacency-list-repository.js +183 -0
  173. package/lib/repositories/view-repository.d.ts +3 -0
  174. package/lib/repositories/view-repository.js +32 -0
  175. package/lib/repository.d.ts +206 -0
  176. package/lib/repository.js +597 -0
  177. package/lib/sql-collection/index.d.ts +2 -0
  178. package/lib/sql-collection/index.js +23 -0
  179. package/lib/sql-collection/query-generator.d.ts +10 -0
  180. package/lib/sql-collection/query-generator.js +70 -0
  181. package/lib/sql-collection/sql-collection.d.ts +7 -0
  182. package/lib/sql-collection/sql-collection.js +69 -0
  183. package/lib/sql-collection/sql-model.d.ts +16 -0
  184. package/lib/sql-collection/sql-model.js +168 -0
  185. package/lib/sql-parser/index.d.ts +10 -0
  186. package/lib/sql-parser/index.js +10699 -0
  187. package/lib/sql-parser/postgres.d.ts +10 -0
  188. package/lib/sql-parser/postgres.js +31506 -0
  189. package/lib/sql-parser/sql.pegjs +1297 -0
  190. package/lib/sync-runner.d.ts +30 -0
  191. package/lib/sync-runner.js +277 -0
  192. package/lib/types.d.ts +49 -0
  193. package/lib/types.js +15 -0
  194. package/lib/update-associations.d.ts +60 -0
  195. package/lib/update-associations.js +405 -0
  196. package/lib/update-guard.d.ts +28 -0
  197. package/lib/update-guard.js +202 -0
  198. package/lib/utils.d.ts +7 -0
  199. package/lib/utils.js +127 -0
  200. package/lib/value-parsers/array-value-parser.d.ts +8 -0
  201. package/lib/value-parsers/array-value-parser.js +58 -0
  202. package/lib/value-parsers/base-value-parser.d.ts +12 -0
  203. package/lib/value-parsers/base-value-parser.js +63 -0
  204. package/lib/value-parsers/boolean-value-parser.d.ts +4 -0
  205. package/lib/value-parsers/boolean-value-parser.js +52 -0
  206. package/lib/value-parsers/date-value-parser.d.ts +5 -0
  207. package/lib/value-parsers/date-value-parser.js +88 -0
  208. package/lib/value-parsers/index.d.ts +12 -0
  209. package/lib/value-parsers/index.js +78 -0
  210. package/lib/value-parsers/json-value-parser.d.ts +4 -0
  211. package/lib/value-parsers/json-value-parser.js +47 -0
  212. package/lib/value-parsers/number-value-parser.d.ts +4 -0
  213. package/lib/value-parsers/number-value-parser.js +58 -0
  214. package/lib/value-parsers/string-value-parser.d.ts +8 -0
  215. package/lib/value-parsers/string-value-parser.js +64 -0
  216. package/lib/value-parsers/to-many-value-parser.d.ts +13 -0
  217. package/lib/value-parsers/to-many-value-parser.js +108 -0
  218. package/lib/value-parsers/to-one-value-parser.d.ts +4 -0
  219. package/lib/value-parsers/to-one-value-parser.js +48 -0
  220. package/lib/view/field-type-map.d.ts +97 -0
  221. package/lib/view/field-type-map.js +90 -0
  222. package/lib/view/view-inference.d.ts +32 -0
  223. package/lib/view/view-inference.js +146 -0
  224. package/lib/view-collection.d.ts +6 -0
  225. package/lib/view-collection.js +45 -0
  226. package/package.json +38 -0
@@ -0,0 +1,70 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var query_generator_exports = {};
20
+ __export(query_generator_exports, {
21
+ selectQuery: () => selectQuery
22
+ });
23
+ module.exports = __toCommonJS(query_generator_exports);
24
+ var import_utils = require("@tachybase/utils");
25
+ function selectQuery(tableName, options, model) {
26
+ var _a;
27
+ options = options || {};
28
+ if (import_utils.lodash.isEmpty(options)) {
29
+ return `${model.sql};`;
30
+ }
31
+ const queryItems = [];
32
+ let attributes = options.attributes && options.attributes.slice();
33
+ if (attributes) {
34
+ const fields = Array.from(((_a = model.collection) == null ? void 0 : _a.fields.keys()) || []);
35
+ attributes = attributes.filter((attr) => attr === "*" || typeof attr !== "string" || fields.includes(attr));
36
+ }
37
+ attributes = this.escapeAttributes(attributes, { model });
38
+ attributes = attributes || ["*"];
39
+ if (Object.prototype.hasOwnProperty.call(options, "where")) {
40
+ options.where = this.getWhereConditions(options.where, tableName, model, options);
41
+ if (options.where) {
42
+ queryItems.push(` WHERE ${options.where}`);
43
+ }
44
+ }
45
+ if (options.group) {
46
+ options.group = Array.isArray(options.group) ? options.group.map((t) => this.aliasGrouping(t, model, tableName, options)).join(", ") : this.aliasGrouping(options.group, model, tableName, options);
47
+ if (options.group) {
48
+ queryItems.push(` GROUP BY ${options.group}`);
49
+ }
50
+ }
51
+ if (options.order) {
52
+ const orders = this.getQueryOrders(options, model, false);
53
+ if (orders.mainQueryOrder.length) {
54
+ queryItems.push(` ORDER BY ${orders.mainQueryOrder.join(", ")}`);
55
+ }
56
+ }
57
+ const limitOrder = this.addLimitAndOffset(options, model);
58
+ if (limitOrder) {
59
+ queryItems.push(limitOrder);
60
+ }
61
+ const query = `SELECT ${attributes.join(", ")} FROM (${model.sql}) ${this.getAliasToken()} ${this.quoteIdentifier(
62
+ model.name
63
+ )}${queryItems.join("")}`;
64
+ return `${query};`;
65
+ }
66
+ __name(selectQuery, "selectQuery");
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ selectQuery
70
+ });
@@ -0,0 +1,7 @@
1
+ import { Collection, CollectionContext, CollectionOptions } from '../collection';
2
+ export declare class SqlCollection extends Collection {
3
+ constructor(options: CollectionOptions, context: CollectionContext);
4
+ isSql(): boolean;
5
+ collectionSchema(): any;
6
+ modelInit(): void;
7
+ }
@@ -0,0 +1,69 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var sql_collection_exports = {};
20
+ __export(sql_collection_exports, {
21
+ SqlCollection: () => SqlCollection
22
+ });
23
+ module.exports = __toCommonJS(sql_collection_exports);
24
+ var import_collection = require("../collection");
25
+ var import_sql_model = require("./sql-model");
26
+ const _SqlCollection = class _SqlCollection extends import_collection.Collection {
27
+ constructor(options, context) {
28
+ options.autoGenId = false;
29
+ options.timestamps = false;
30
+ options.underscored = false;
31
+ super(options, context);
32
+ }
33
+ isSql() {
34
+ return true;
35
+ }
36
+ collectionSchema() {
37
+ return void 0;
38
+ }
39
+ modelInit() {
40
+ var _a;
41
+ const { autoGenId, sql } = this.options;
42
+ const model = (_a = class extends import_sql_model.SQLModel {
43
+ }, __name(_a, "model"), _a);
44
+ model.init(null, {
45
+ ...this.sequelizeModelOptions(),
46
+ schema: void 0
47
+ });
48
+ if (!autoGenId) {
49
+ model.removeAttribute("id");
50
+ }
51
+ model.sql = sql;
52
+ model.database = this.context.database;
53
+ model.collection = this;
54
+ this.model = new Proxy(model, {
55
+ get(target, prop) {
56
+ if (prop === "_schema") {
57
+ return void 0;
58
+ }
59
+ return Reflect.get(target, prop);
60
+ }
61
+ });
62
+ }
63
+ };
64
+ __name(_SqlCollection, "SqlCollection");
65
+ let SqlCollection = _SqlCollection;
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ SqlCollection
69
+ });
@@ -0,0 +1,16 @@
1
+ import { Model } from '../model';
2
+ export declare class SQLModel extends Model {
3
+ static sql: string;
4
+ static get queryInterface(): import("sequelize").QueryInterface;
5
+ static sync(): Promise<any>;
6
+ private static parseTablesAndColumns;
7
+ private static getTableNameWithSchema;
8
+ static inferFields(): {
9
+ [field: string]: {
10
+ type: string;
11
+ source: string;
12
+ collection: string;
13
+ interface: string;
14
+ };
15
+ };
16
+ }
@@ -0,0 +1,168 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
31
+ var sql_model_exports = {};
32
+ __export(sql_model_exports, {
33
+ SQLModel: () => SQLModel
34
+ });
35
+ module.exports = __toCommonJS(sql_model_exports);
36
+ var import_model = require("../model");
37
+ var import_sql_parser = __toESM(require("../sql-parser"));
38
+ var import_query_generator = require("./query-generator");
39
+ const _SQLModel = class _SQLModel extends import_model.Model {
40
+ static get queryInterface() {
41
+ const queryInterface = this.sequelize.getQueryInterface();
42
+ const queryGenerator = queryInterface.queryGenerator;
43
+ const sqlGenerator = new Proxy(queryGenerator, {
44
+ get(target, prop) {
45
+ if (prop === "selectQuery") {
46
+ return import_query_generator.selectQuery.bind(target);
47
+ }
48
+ return Reflect.get(target, prop);
49
+ }
50
+ });
51
+ return new Proxy(queryInterface, {
52
+ get(target, prop) {
53
+ if (prop === "queryGenerator") {
54
+ return sqlGenerator;
55
+ }
56
+ return Reflect.get(target, prop);
57
+ }
58
+ });
59
+ }
60
+ static async sync() {
61
+ }
62
+ static parseTablesAndColumns() {
63
+ let { ast } = import_sql_parser.default.parse(this.sql);
64
+ if (Array.isArray(ast)) {
65
+ ast = ast[0];
66
+ }
67
+ if (ast.with) {
68
+ const tables = /* @__PURE__ */ new Set();
69
+ ast.with.forEach((withItem) => {
70
+ const tableList = withItem.tableList;
71
+ tableList.forEach((table) => {
72
+ const name = table.split("::")[2];
73
+ tables.add(name);
74
+ });
75
+ });
76
+ return Array.from(tables).map((table) => ({ table, columns: "*" }));
77
+ }
78
+ if (ast.columns === "*") {
79
+ return ast.from.map((fromItem) => ({
80
+ table: fromItem.table,
81
+ columns: "*"
82
+ }));
83
+ }
84
+ const columns = ast.columns.reduce(
85
+ (tableMp, column) => {
86
+ if (column.expr.type !== "column_ref") {
87
+ return tableMp;
88
+ }
89
+ const table = column.expr.table;
90
+ const columnAttr = { name: column.expr.column, as: column.as };
91
+ if (!tableMp[table]) {
92
+ tableMp[table] = [columnAttr];
93
+ } else {
94
+ tableMp[table].push(columnAttr);
95
+ }
96
+ return tableMp;
97
+ },
98
+ {}
99
+ );
100
+ ast.from.forEach((fromItem) => {
101
+ if (columns[fromItem.as]) {
102
+ columns[fromItem.table] = columns[fromItem.as];
103
+ columns[fromItem.as] = void 0;
104
+ }
105
+ });
106
+ return Object.entries(columns).filter(([_, columns2]) => columns2).map(([table, columns2]) => ({ table, columns: columns2 }));
107
+ }
108
+ static getTableNameWithSchema(table) {
109
+ if (this.database.inDialect("postgres") && !table.includes(".")) {
110
+ return `public.${table}`;
111
+ }
112
+ return table;
113
+ }
114
+ static inferFields() {
115
+ const tables = this.parseTablesAndColumns();
116
+ const fields = tables.reduce((fields2, { table, columns }) => {
117
+ const tableName = this.getTableNameWithSchema(table);
118
+ const collection = this.database.tableNameCollectionMap.get(tableName);
119
+ if (!collection) {
120
+ return fields2;
121
+ }
122
+ const attributes = collection.model.getAttributes();
123
+ const sourceFields = {};
124
+ if (columns === "*") {
125
+ Object.values(attributes).forEach((attribute) => {
126
+ const field = collection.getField(attribute.fieldName);
127
+ if (!(field == null ? void 0 : field.options.interface)) {
128
+ return;
129
+ }
130
+ sourceFields[field.name] = {
131
+ collection: field.collection.name,
132
+ type: field.type,
133
+ source: `${field.collection.name}.${field.name}`,
134
+ interface: field.options.interface,
135
+ uiSchema: field.options.uiSchema
136
+ };
137
+ });
138
+ } else {
139
+ columns.forEach((column) => {
140
+ const modelField = Object.values(attributes).find((attribute) => attribute.field === column.name);
141
+ if (!modelField) {
142
+ return;
143
+ }
144
+ const field = collection.getField(modelField.fieldName);
145
+ if (!(field == null ? void 0 : field.options.interface)) {
146
+ return;
147
+ }
148
+ sourceFields[column.as || column.name] = {
149
+ collection: field.collection.name,
150
+ type: field.type,
151
+ source: `${field.collection.name}.${field.name}`,
152
+ interface: field.options.interface,
153
+ uiSchema: field.options.uiSchema
154
+ };
155
+ });
156
+ }
157
+ return { ...fields2, ...sourceFields };
158
+ }, {});
159
+ return fields;
160
+ }
161
+ };
162
+ __name(_SQLModel, "SQLModel");
163
+ __publicField(_SQLModel, "sql");
164
+ let SQLModel = _SQLModel;
165
+ // Annotate the CommonJS export names for ESM import in node:
166
+ 0 && (module.exports = {
167
+ SQLModel
168
+ });
@@ -0,0 +1,10 @@
1
+ declare function peg$SyntaxError(message: any, expected: any, found: any, location: any): any;
2
+ declare class peg$SyntaxError {
3
+ constructor(message: any, expected: any, found: any, location: any);
4
+ format(sources: any): string;
5
+ }
6
+ declare namespace peg$SyntaxError {
7
+ function buildMessage(expected: any, found: any): string;
8
+ }
9
+ declare function peg$parse(input: any, options: any): any;
10
+ export { peg$SyntaxError as SyntaxError, peg$parse as parse };