@stonyx/orm 0.2.1-beta.9 → 0.2.1-beta.90

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 (171) hide show
  1. package/README.md +64 -6
  2. package/config/environment.js +37 -1
  3. package/dist/aggregates.d.ts +21 -0
  4. package/dist/aggregates.js +93 -0
  5. package/dist/attr.d.ts +2 -0
  6. package/dist/attr.js +22 -0
  7. package/dist/belongs-to.d.ts +11 -0
  8. package/dist/belongs-to.js +59 -0
  9. package/dist/cli.d.ts +22 -0
  10. package/dist/cli.js +148 -0
  11. package/dist/commands.d.ts +7 -0
  12. package/dist/commands.js +146 -0
  13. package/dist/db.d.ts +21 -0
  14. package/dist/db.js +180 -0
  15. package/dist/exports/db.d.ts +7 -0
  16. package/{src → dist}/exports/db.js +2 -4
  17. package/dist/has-many.d.ts +11 -0
  18. package/dist/has-many.js +58 -0
  19. package/dist/hooks.d.ts +62 -0
  20. package/dist/hooks.js +110 -0
  21. package/dist/index.d.ts +14 -0
  22. package/dist/index.js +34 -0
  23. package/dist/main.d.ts +46 -0
  24. package/dist/main.js +181 -0
  25. package/dist/manage-record.d.ts +13 -0
  26. package/dist/manage-record.js +123 -0
  27. package/dist/meta-request.d.ts +6 -0
  28. package/dist/meta-request.js +52 -0
  29. package/dist/migrate.d.ts +2 -0
  30. package/dist/migrate.js +57 -0
  31. package/dist/model-property.d.ts +9 -0
  32. package/dist/model-property.js +29 -0
  33. package/dist/model.d.ts +15 -0
  34. package/dist/model.js +18 -0
  35. package/dist/mysql/connection.d.ts +14 -0
  36. package/dist/mysql/connection.js +24 -0
  37. package/dist/mysql/migration-generator.d.ts +45 -0
  38. package/dist/mysql/migration-generator.js +254 -0
  39. package/dist/mysql/migration-runner.d.ts +12 -0
  40. package/dist/mysql/migration-runner.js +88 -0
  41. package/dist/mysql/mysql-db.d.ts +100 -0
  42. package/dist/mysql/mysql-db.js +425 -0
  43. package/dist/mysql/query-builder.d.ts +10 -0
  44. package/dist/mysql/query-builder.js +44 -0
  45. package/dist/mysql/schema-introspector.d.ts +19 -0
  46. package/dist/mysql/schema-introspector.js +291 -0
  47. package/dist/mysql/type-map.d.ts +21 -0
  48. package/dist/mysql/type-map.js +36 -0
  49. package/dist/orm-request.d.ts +38 -0
  50. package/dist/orm-request.js +474 -0
  51. package/dist/plural-registry.d.ts +4 -0
  52. package/dist/plural-registry.js +9 -0
  53. package/dist/postgres/connection.d.ts +15 -0
  54. package/dist/postgres/connection.js +32 -0
  55. package/dist/postgres/migration-generator.d.ts +45 -0
  56. package/dist/postgres/migration-generator.js +261 -0
  57. package/dist/postgres/migration-runner.d.ts +10 -0
  58. package/dist/postgres/migration-runner.js +87 -0
  59. package/dist/postgres/postgres-db.d.ts +119 -0
  60. package/dist/postgres/postgres-db.js +477 -0
  61. package/dist/postgres/query-builder.d.ts +27 -0
  62. package/dist/postgres/query-builder.js +98 -0
  63. package/dist/postgres/schema-introspector.d.ts +29 -0
  64. package/dist/postgres/schema-introspector.js +314 -0
  65. package/dist/postgres/type-map.d.ts +23 -0
  66. package/dist/postgres/type-map.js +56 -0
  67. package/dist/record.d.ts +75 -0
  68. package/dist/record.js +129 -0
  69. package/dist/relationships.d.ts +10 -0
  70. package/dist/relationships.js +41 -0
  71. package/dist/serializer.d.ts +17 -0
  72. package/dist/serializer.js +136 -0
  73. package/dist/setup-rest-server.d.ts +1 -0
  74. package/dist/setup-rest-server.js +52 -0
  75. package/dist/standalone-db.d.ts +58 -0
  76. package/dist/standalone-db.js +142 -0
  77. package/dist/store.d.ts +62 -0
  78. package/dist/store.js +286 -0
  79. package/dist/timescale/query-builder.d.ts +43 -0
  80. package/dist/timescale/query-builder.js +115 -0
  81. package/dist/timescale/timescale-db.d.ts +45 -0
  82. package/dist/timescale/timescale-db.js +84 -0
  83. package/dist/transforms.d.ts +2 -0
  84. package/dist/transforms.js +17 -0
  85. package/dist/types/orm-types.d.ts +142 -0
  86. package/dist/types/orm-types.js +1 -0
  87. package/dist/utils.d.ts +7 -0
  88. package/dist/utils.js +17 -0
  89. package/dist/view-resolver.d.ts +8 -0
  90. package/dist/view-resolver.js +171 -0
  91. package/dist/view.d.ts +11 -0
  92. package/dist/view.js +18 -0
  93. package/package.json +57 -15
  94. package/src/aggregates.ts +109 -0
  95. package/src/{attr.js → attr.ts} +2 -2
  96. package/src/belongs-to.ts +90 -0
  97. package/src/cli.ts +183 -0
  98. package/src/{commands.js → commands.ts} +179 -170
  99. package/src/{db.js → db.ts} +55 -29
  100. package/src/exports/db.ts +7 -0
  101. package/src/has-many.ts +92 -0
  102. package/src/{hooks.js → hooks.ts} +41 -27
  103. package/src/{index.js → index.ts} +11 -2
  104. package/src/main.ts +229 -0
  105. package/src/manage-record.ts +161 -0
  106. package/src/{meta-request.js → meta-request.ts} +17 -14
  107. package/src/{migrate.js → migrate.ts} +9 -9
  108. package/src/model-property.ts +35 -0
  109. package/src/model.ts +21 -0
  110. package/src/mysql/{connection.js → connection.ts} +43 -28
  111. package/src/mysql/migration-generator.ts +337 -0
  112. package/src/mysql/{migration-runner.js → migration-runner.ts} +121 -110
  113. package/src/mysql/mysql-db.ts +543 -0
  114. package/src/mysql/{query-builder.js → query-builder.ts} +69 -64
  115. package/src/mysql/schema-introspector.ts +358 -0
  116. package/src/mysql/{type-map.js → type-map.ts} +42 -37
  117. package/src/{orm-request.js → orm-request.ts} +186 -108
  118. package/src/plural-registry.ts +12 -0
  119. package/src/postgres/connection.ts +48 -0
  120. package/src/postgres/migration-generator.ts +348 -0
  121. package/src/postgres/migration-runner.ts +115 -0
  122. package/src/postgres/postgres-db.ts +616 -0
  123. package/src/postgres/query-builder.ts +148 -0
  124. package/src/postgres/schema-introspector.ts +386 -0
  125. package/src/postgres/type-map.ts +61 -0
  126. package/src/record.ts +186 -0
  127. package/src/relationships.ts +54 -0
  128. package/src/serializer.ts +161 -0
  129. package/src/{setup-rest-server.js → setup-rest-server.ts} +18 -16
  130. package/src/standalone-db.ts +185 -0
  131. package/src/store.ts +373 -0
  132. package/src/timescale/query-builder.ts +174 -0
  133. package/src/timescale/timescale-db.ts +119 -0
  134. package/src/transforms.ts +20 -0
  135. package/src/types/mysql2.d.ts +49 -0
  136. package/src/types/orm-types.ts +146 -0
  137. package/src/types/pg.d.ts +32 -0
  138. package/src/types/stonyx-cron.d.ts +5 -0
  139. package/src/types/stonyx-events.d.ts +4 -0
  140. package/src/types/stonyx-rest-server.d.ts +16 -0
  141. package/src/types/stonyx-utils.d.ts +33 -0
  142. package/src/types/stonyx.d.ts +21 -0
  143. package/src/utils.ts +22 -0
  144. package/src/view-resolver.ts +211 -0
  145. package/src/view.ts +22 -0
  146. package/.claude/code-style-rules.md +0 -44
  147. package/.claude/hooks.md +0 -250
  148. package/.claude/index.md +0 -279
  149. package/.claude/usage-patterns.md +0 -217
  150. package/.github/workflows/ci.yml +0 -16
  151. package/.github/workflows/publish.yml +0 -51
  152. package/improvements.md +0 -139
  153. package/project-structure.md +0 -343
  154. package/src/belongs-to.js +0 -63
  155. package/src/has-many.js +0 -61
  156. package/src/main.js +0 -148
  157. package/src/manage-record.js +0 -118
  158. package/src/model-property.js +0 -29
  159. package/src/model.js +0 -9
  160. package/src/mysql/migration-generator.js +0 -188
  161. package/src/mysql/mysql-db.js +0 -320
  162. package/src/mysql/schema-introspector.js +0 -158
  163. package/src/record.js +0 -127
  164. package/src/relationships.js +0 -43
  165. package/src/serializer.js +0 -138
  166. package/src/store.js +0 -211
  167. package/src/transforms.js +0 -20
  168. package/src/utils.js +0 -12
  169. package/test-events-setup.js +0 -41
  170. package/test-hooks-manual.js +0 -54
  171. package/test-hooks-with-logging.js +0 -52
@@ -0,0 +1,291 @@
1
+ import Orm from '@stonyx/orm';
2
+ import { getMysqlType } from './type-map.js';
3
+ import { camelCaseToKebabCase } from '@stonyx/utils/string';
4
+ import { getPluralName } from '../plural-registry.js';
5
+ import { dbKey } from '../db.js';
6
+ import { AggregateProperty } from '../aggregates.js';
7
+ import ModelProperty from '../model-property.js';
8
+ function getRelationshipInfo(property) {
9
+ if (typeof property !== 'function')
10
+ return null;
11
+ const relType = property.__relationshipType;
12
+ const modelName = property.__relatedModelName || null;
13
+ if (relType === 'belongsTo')
14
+ return { type: 'belongsTo', modelName };
15
+ if (relType === 'hasMany')
16
+ return { type: 'hasMany', modelName };
17
+ return null;
18
+ }
19
+ function sanitizeTableName(name) {
20
+ return name.replace(/[-/]/g, '_');
21
+ }
22
+ export function introspectModels() {
23
+ const { models } = Orm.instance;
24
+ const schemas = {};
25
+ for (const [modelKey, modelClass] of Object.entries(models)) {
26
+ const name = camelCaseToKebabCase(modelKey.slice(0, -5));
27
+ if (name === dbKey)
28
+ continue;
29
+ const model = new modelClass(modelKey);
30
+ const columns = {};
31
+ const foreignKeys = {};
32
+ const relationships = { belongsTo: {}, hasMany: {} };
33
+ let idType = 'number';
34
+ const transforms = Orm.instance.transforms;
35
+ for (const [key, property] of Object.entries(model)) {
36
+ if (key.startsWith('__'))
37
+ continue;
38
+ const relInfo = getRelationshipInfo(property);
39
+ if (relInfo?.type === 'belongsTo') {
40
+ relationships.belongsTo[key] = relInfo.modelName;
41
+ }
42
+ else if (relInfo?.type === 'hasMany') {
43
+ relationships.hasMany[key] = relInfo.modelName;
44
+ }
45
+ else if (property instanceof ModelProperty) {
46
+ if (key === 'id') {
47
+ idType = property.type;
48
+ }
49
+ else {
50
+ columns[key] = getMysqlType(property.type, transforms[property.type]);
51
+ }
52
+ }
53
+ }
54
+ // Build foreign keys from belongsTo relationships
55
+ for (const [relName, targetModelName] of Object.entries(relationships.belongsTo)) {
56
+ if (!targetModelName)
57
+ continue;
58
+ const fkColumn = `${relName}_id`;
59
+ foreignKeys[fkColumn] = {
60
+ references: sanitizeTableName(getPluralName(targetModelName)),
61
+ column: 'id',
62
+ };
63
+ }
64
+ schemas[name] = {
65
+ table: sanitizeTableName(getPluralName(name)),
66
+ idType,
67
+ columns,
68
+ foreignKeys,
69
+ relationships,
70
+ memory: modelClass.memory === true,
71
+ };
72
+ }
73
+ return schemas;
74
+ }
75
+ export function buildTableDDL(name, schema, allSchemas = {}) {
76
+ const { idType, columns, foreignKeys } = schema;
77
+ const table = sanitizeTableName(schema.table);
78
+ const lines = [];
79
+ // Primary key
80
+ if (idType === 'string') {
81
+ lines.push(' `id` VARCHAR(255) PRIMARY KEY');
82
+ }
83
+ else {
84
+ lines.push(' `id` INT AUTO_INCREMENT PRIMARY KEY');
85
+ }
86
+ // Attribute columns
87
+ for (const [col, mysqlType] of Object.entries(columns)) {
88
+ lines.push(` \`${col}\` ${mysqlType}`);
89
+ }
90
+ // Foreign key columns
91
+ for (const [fkCol, fkDef] of Object.entries(foreignKeys)) {
92
+ const refIdType = getReferencedIdType(fkDef.references, allSchemas);
93
+ lines.push(` \`${fkCol}\` ${refIdType}`);
94
+ }
95
+ // Timestamps
96
+ lines.push(' `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP');
97
+ lines.push(' `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP');
98
+ // Foreign key constraints
99
+ for (const [fkCol, fkDef] of Object.entries(foreignKeys)) {
100
+ const refTable = sanitizeTableName(fkDef.references);
101
+ lines.push(` FOREIGN KEY (\`${fkCol}\`) REFERENCES \`${refTable}\`(\`${fkDef.column}\`) ON DELETE SET NULL`);
102
+ }
103
+ return `CREATE TABLE IF NOT EXISTS \`${table}\` (\n${lines.join(',\n')}\n)`;
104
+ }
105
+ function getReferencedIdType(tableName, allSchemas) {
106
+ // Look up the referenced table's PK type from schemas
107
+ for (const schema of Object.values(allSchemas)) {
108
+ if (schema.table === tableName) {
109
+ return schema.idType === 'string' ? 'VARCHAR(255)' : 'INT';
110
+ }
111
+ }
112
+ // Default to INT if referenced table not found in schemas
113
+ return 'INT';
114
+ }
115
+ export function getTopologicalOrder(schemas) {
116
+ const visited = new Set();
117
+ const order = [];
118
+ function visit(name) {
119
+ if (visited.has(name))
120
+ return;
121
+ visited.add(name);
122
+ const schema = schemas[name];
123
+ if (!schema)
124
+ return;
125
+ // Visit dependencies (belongsTo targets) first
126
+ for (const targetModelName of Object.values(schema.relationships.belongsTo)) {
127
+ if (targetModelName)
128
+ visit(targetModelName);
129
+ }
130
+ order.push(name);
131
+ }
132
+ for (const name of Object.keys(schemas)) {
133
+ visit(name);
134
+ }
135
+ return order;
136
+ }
137
+ export function introspectViews() {
138
+ const orm = Orm.instance;
139
+ if (!orm.views)
140
+ return {};
141
+ const schemas = {};
142
+ for (const [viewKey, viewClass] of Object.entries(orm.views)) {
143
+ const name = camelCaseToKebabCase(viewKey.slice(0, -4)); // Remove 'View' suffix
144
+ const source = viewClass.source;
145
+ if (!source)
146
+ continue;
147
+ const model = new viewClass(name);
148
+ const columns = {};
149
+ const foreignKeys = {};
150
+ const aggregates = {};
151
+ const relationships = { belongsTo: {}, hasMany: {} };
152
+ for (const [key, property] of Object.entries(model)) {
153
+ if (key.startsWith('__'))
154
+ continue;
155
+ if (key === 'id')
156
+ continue;
157
+ if (property instanceof AggregateProperty) {
158
+ aggregates[key] = property;
159
+ continue;
160
+ }
161
+ const relInfo = getRelationshipInfo(property);
162
+ if (relInfo?.type === 'belongsTo') {
163
+ relationships.belongsTo[key] = relInfo.modelName;
164
+ if (relInfo.modelName) {
165
+ const fkColumn = `${key}_id`;
166
+ foreignKeys[fkColumn] = {
167
+ references: sanitizeTableName(getPluralName(relInfo.modelName)),
168
+ column: 'id',
169
+ };
170
+ }
171
+ }
172
+ else if (relInfo?.type === 'hasMany') {
173
+ relationships.hasMany[key] = relInfo.modelName;
174
+ }
175
+ else if (property instanceof ModelProperty) {
176
+ const transforms = orm.transforms;
177
+ columns[key] = getMysqlType(property.type, transforms[property.type]);
178
+ }
179
+ }
180
+ schemas[name] = {
181
+ viewName: sanitizeTableName(getPluralName(name)),
182
+ source,
183
+ groupBy: viewClass.groupBy || undefined,
184
+ columns,
185
+ foreignKeys,
186
+ aggregates,
187
+ relationships,
188
+ isView: true,
189
+ memory: false,
190
+ };
191
+ }
192
+ return schemas;
193
+ }
194
+ export function buildViewDDL(name, viewSchema, modelSchemas = {}) {
195
+ if (!viewSchema.source) {
196
+ throw new Error(`View '${name}' must define a source model`);
197
+ }
198
+ const sourceModelName = viewSchema.source;
199
+ const sourceSchema = modelSchemas[sourceModelName];
200
+ const sourceTable = sanitizeTableName(sourceSchema
201
+ ? sourceSchema.table
202
+ : getPluralName(sourceModelName));
203
+ const selectColumns = [];
204
+ const joins = [];
205
+ const hasAggregates = Object.keys(viewSchema.aggregates || {}).length > 0;
206
+ const groupByField = viewSchema.groupBy;
207
+ // ID column: groupBy field or source table PK
208
+ if (groupByField) {
209
+ selectColumns.push(`\`${sourceTable}\`.\`${groupByField}\` AS \`id\``);
210
+ }
211
+ else {
212
+ selectColumns.push(`\`${sourceTable}\`.\`id\` AS \`id\``);
213
+ }
214
+ // Aggregate columns
215
+ for (const [key, aggProp] of Object.entries(viewSchema.aggregates || {})) {
216
+ if (aggProp.relationship === undefined) {
217
+ // Field-level aggregate (groupBy views)
218
+ if (aggProp.aggregateType === 'count') {
219
+ selectColumns.push(`COUNT(*) AS \`${key}\``);
220
+ }
221
+ else {
222
+ selectColumns.push(`${aggProp.mysqlFunction}(\`${sourceTable}\`.\`${aggProp.field}\`) AS \`${key}\``);
223
+ }
224
+ }
225
+ else {
226
+ // Relationship aggregate
227
+ const relName = aggProp.relationship;
228
+ const relTable = sanitizeTableName(getPluralName(relName));
229
+ if (aggProp.aggregateType === 'count') {
230
+ selectColumns.push(`${aggProp.mysqlFunction}(\`${relTable}\`.\`id\`) AS \`${key}\``);
231
+ }
232
+ else {
233
+ const field = aggProp.field;
234
+ selectColumns.push(`${aggProp.mysqlFunction}(\`${relTable}\`.\`${field}\`) AS \`${key}\``);
235
+ }
236
+ // Add LEFT JOIN for the relationship if not already added
237
+ const joinKey = `${relTable}`;
238
+ if (!joins.find(j => j.table === joinKey)) {
239
+ const fkColumn = `${sourceModelName}_id`;
240
+ joins.push({
241
+ table: relTable,
242
+ condition: `\`${relTable}\`.\`${fkColumn}\` = \`${sourceTable}\`.\`id\``
243
+ });
244
+ }
245
+ }
246
+ }
247
+ // Regular columns (from resolve map string paths or direct attr fields)
248
+ for (const [key] of Object.entries(viewSchema.columns || {})) {
249
+ selectColumns.push(`\`${sourceTable}\`.\`${key}\` AS \`${key}\``);
250
+ }
251
+ // Build JOIN clauses
252
+ const joinClauses = joins.map(j => `LEFT JOIN \`${j.table}\` ON ${j.condition}`).join('\n ');
253
+ // Build GROUP BY
254
+ let groupBy = '';
255
+ if (groupByField) {
256
+ groupBy = `\nGROUP BY \`${sourceTable}\`.\`${groupByField}\``;
257
+ }
258
+ else if (hasAggregates) {
259
+ groupBy = `\nGROUP BY \`${sourceTable}\`.\`id\``;
260
+ }
261
+ const viewName = sanitizeTableName(viewSchema.viewName);
262
+ const sql = `CREATE OR REPLACE VIEW \`${viewName}\` AS\nSELECT\n ${selectColumns.join(',\n ')}\nFROM \`${sourceTable}\`${joinClauses ? '\n ' + joinClauses : ''}${groupBy}`;
263
+ return sql;
264
+ }
265
+ export function viewSchemasToSnapshot(viewSchemas) {
266
+ const snapshot = {};
267
+ for (const [name, schema] of Object.entries(viewSchemas)) {
268
+ snapshot[name] = {
269
+ viewName: schema.viewName,
270
+ source: schema.source,
271
+ ...(schema.groupBy ? { groupBy: schema.groupBy } : {}),
272
+ columns: { ...schema.columns },
273
+ foreignKeys: { ...schema.foreignKeys },
274
+ isView: true,
275
+ viewQuery: buildViewDDL(name, schema),
276
+ };
277
+ }
278
+ return snapshot;
279
+ }
280
+ export function schemasToSnapshot(schemas) {
281
+ const snapshot = {};
282
+ for (const [name, schema] of Object.entries(schemas)) {
283
+ snapshot[name] = {
284
+ table: schema.table,
285
+ idType: schema.idType,
286
+ columns: { ...schema.columns },
287
+ foreignKeys: { ...schema.foreignKeys },
288
+ };
289
+ }
290
+ return snapshot;
291
+ }
@@ -0,0 +1,21 @@
1
+ interface TransformFn {
2
+ mysqlType?: string;
3
+ (...args: unknown[]): unknown;
4
+ }
5
+ declare const typeMap: Record<string, string>;
6
+ /**
7
+ * Resolves a Stonyx ORM attribute type to a MySQL column type.
8
+ *
9
+ * For built-in types, returns the mapped MySQL type directly.
10
+ *
11
+ * For custom transforms (e.g. an `animal` transform that maps strings to ints):
12
+ * - If the transform function exports a `mysqlType` property, that value is used.
13
+ * Example: `const transform = (v) => codeMap[v]; transform.mysqlType = 'INT'; export default transform;`
14
+ * - Otherwise, defaults to JSON. Values are JSON-stringified on write and
15
+ * JSON-parsed on read. This handles primitives and plain objects correctly.
16
+ * Class instances will be reduced to plain objects — if a custom transform
17
+ * produces class instances, it must declare a `mysqlType` and handle
18
+ * serialization itself.
19
+ */
20
+ export declare function getMysqlType(attrType: string, transformFn?: TransformFn): string;
21
+ export default typeMap;
@@ -0,0 +1,36 @@
1
+ const typeMap = {
2
+ string: 'VARCHAR(255)',
3
+ number: 'INT',
4
+ float: 'FLOAT',
5
+ boolean: 'TINYINT(1)',
6
+ date: 'DATETIME',
7
+ timestamp: 'BIGINT',
8
+ passthrough: 'TEXT',
9
+ trim: 'VARCHAR(255)',
10
+ uppercase: 'VARCHAR(255)',
11
+ ceil: 'INT',
12
+ floor: 'INT',
13
+ round: 'INT',
14
+ };
15
+ /**
16
+ * Resolves a Stonyx ORM attribute type to a MySQL column type.
17
+ *
18
+ * For built-in types, returns the mapped MySQL type directly.
19
+ *
20
+ * For custom transforms (e.g. an `animal` transform that maps strings to ints):
21
+ * - If the transform function exports a `mysqlType` property, that value is used.
22
+ * Example: `const transform = (v) => codeMap[v]; transform.mysqlType = 'INT'; export default transform;`
23
+ * - Otherwise, defaults to JSON. Values are JSON-stringified on write and
24
+ * JSON-parsed on read. This handles primitives and plain objects correctly.
25
+ * Class instances will be reduced to plain objects — if a custom transform
26
+ * produces class instances, it must declare a `mysqlType` and handle
27
+ * serialization itself.
28
+ */
29
+ export function getMysqlType(attrType, transformFn) {
30
+ if (typeMap[attrType])
31
+ return typeMap[attrType];
32
+ if (transformFn?.mysqlType)
33
+ return transformFn.mysqlType;
34
+ return 'JSON';
35
+ }
36
+ export default typeMap;
@@ -0,0 +1,38 @@
1
+ import { Request } from '@stonyx/rest-server';
2
+ interface OrmRequest$ extends Request {
3
+ protocol?: string;
4
+ method: string;
5
+ params: {
6
+ [key: string]: string;
7
+ };
8
+ body?: {
9
+ [key: string]: unknown;
10
+ };
11
+ query?: {
12
+ [key: string]: string;
13
+ };
14
+ get(header: string): string;
15
+ }
16
+ type AccessMethod = string | boolean | string[] | ((record: unknown) => boolean);
17
+ type HandlerFn = (request: OrmRequest$, state: {
18
+ [key: string]: unknown;
19
+ }) => unknown | Promise<unknown>;
20
+ export default class OrmRequest extends Request {
21
+ model: string;
22
+ access: (request: unknown) => AccessMethod;
23
+ handlers: {
24
+ [key: string]: {
25
+ [key: string]: HandlerFn;
26
+ };
27
+ };
28
+ constructor({ model, access }: {
29
+ model: string;
30
+ access: (request: unknown) => AccessMethod;
31
+ });
32
+ private _withHooks;
33
+ private _generateRelationshipRoutes;
34
+ auth(request: OrmRequest$, state: {
35
+ [key: string]: unknown;
36
+ }): number | undefined;
37
+ }
38
+ export {};