@stonyx/orm 0.3.2-alpha.0 → 0.3.2-beta.0

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/dist/index.js CHANGED
@@ -29,11 +29,6 @@ export { count, avg, sum, min, max }; // aggregate helpers
29
29
  export { beforeHook, afterHook, clearHook, clearAllHooks } from './hooks.js'; // middleware hooks
30
30
  // Store API:
31
31
  // store.get(model, id) -- sync, memory-only
32
- // store.find(model, id) -- async, SQL for memory:false models
32
+ // store.find(model, id) -- async, MySQL for memory:false models
33
33
  // store.findAll(model) -- async, all records
34
- // store.query(model, conditions) -- async, always hits SQL
35
- //
36
- // Programmatic CRUD (memory + SQL persistence):
37
- // Orm.create(model, data) -- async, createRecord + sqlDb.persist
38
- // Orm.update(model, id, data) -- async, updateRecord + sqlDb.persist
39
- // Orm.remove(model, id) -- async, sqlDb.persist + store.remove
34
+ // store.query(model, conditions) -- async, always hits MySQL
package/dist/main.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import Store from './store.js';
2
- import type { OrmRecord } from './types/orm-types.js';
3
2
  interface OrmOptions {
4
3
  dbType?: string;
5
4
  }
@@ -40,21 +39,6 @@ export default class Orm {
40
39
  serializerClass: unknown;
41
40
  };
42
41
  isView(modelName: string): boolean;
43
- /**
44
- * Programmatic create — writes to memory AND persists to SQL database.
45
- * Use instead of createRecord() when records must be persisted to PostgreSQL/TimescaleDB.
46
- */
47
- static create(modelName: string, data?: Record<string, unknown>): Promise<OrmRecord>;
48
- /**
49
- * Programmatic update — updates in memory AND persists to SQL database.
50
- * Captures old state for diff-based UPDATE queries.
51
- */
52
- static update(modelName: string, id: string | number, data: Record<string, unknown>): Promise<OrmRecord>;
53
- /**
54
- * Programmatic delete — removes from SQL database AND memory store.
55
- * SQL delete runs first to ensure consistency on failure.
56
- */
57
- static remove(modelName: string, id: string | number): Promise<void>;
58
42
  warn(message: string): void;
59
43
  }
60
44
  export declare const store: Store;
package/dist/main.js CHANGED
@@ -24,7 +24,6 @@ import baseTransforms from './transforms.js';
24
24
  import Store from './store.js';
25
25
  import Serializer from './serializer.js';
26
26
  import { setup } from '@stonyx/events';
27
- import { isOrmRecord } from './utils.js';
28
27
  const defaultOptions = {
29
28
  dbType: 'json'
30
29
  };
@@ -169,55 +168,6 @@ export default class Orm {
169
168
  const modelClassPrefix = kebabCaseToPascalCase(modelName);
170
169
  return !!this.views[`${modelClassPrefix}View`];
171
170
  }
172
- /**
173
- * Programmatic create — writes to memory AND persists to SQL database.
174
- * Use instead of createRecord() when records must be persisted to PostgreSQL/TimescaleDB.
175
- */
176
- static async create(modelName, data = {}) {
177
- if (!Orm.initialized)
178
- throw new Error('ORM is not ready');
179
- const { createRecord } = await import('./manage-record.js');
180
- const record = createRecord(modelName, data, { serialize: false });
181
- if (Orm.instance.sqlDb) {
182
- const response = { data: { id: record.id } };
183
- await Orm.instance.sqlDb.persist('create', modelName, {}, response);
184
- }
185
- return record;
186
- }
187
- /**
188
- * Programmatic update — updates in memory AND persists to SQL database.
189
- * Captures old state for diff-based UPDATE queries.
190
- */
191
- static async update(modelName, id, data) {
192
- if (!Orm.initialized)
193
- throw new Error('ORM is not ready');
194
- const record = Orm.store.get(modelName, id);
195
- if (!record || !isOrmRecord(record))
196
- throw new Error(`Record ${modelName}:${id} not found`);
197
- const oldState = JSON.parse(JSON.stringify(record.__data));
198
- // Apply attribute updates directly, matching the REST handler pattern
199
- for (const [key, value] of Object.entries(data)) {
200
- if (key === 'id')
201
- continue;
202
- record[key] = value;
203
- }
204
- if (Orm.instance.sqlDb) {
205
- await Orm.instance.sqlDb.persist('update', modelName, { record, oldState }, {});
206
- }
207
- return record;
208
- }
209
- /**
210
- * Programmatic delete — removes from SQL database AND memory store.
211
- * SQL delete runs first to ensure consistency on failure.
212
- */
213
- static async remove(modelName, id) {
214
- if (!Orm.initialized)
215
- throw new Error('ORM is not ready');
216
- if (Orm.instance.sqlDb) {
217
- await Orm.instance.sqlDb.persist('delete', modelName, { recordId: id }, {});
218
- }
219
- Orm.store.remove(modelName, id);
220
- }
221
171
  // Queue warnings to avoid the same error from being logged in the same iteration
222
172
  warn(message) {
223
173
  this.warnings.add(message);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "stonyx-async",
5
5
  "stonyx-module"
6
6
  ],
7
- "version": "0.3.2-alpha.0",
7
+ "version": "0.3.2-beta.0",
8
8
  "description": "",
9
9
  "main": "dist/index.js",
10
10
  "type": "module",
package/src/index.ts CHANGED
@@ -33,11 +33,6 @@ export { beforeHook, afterHook, clearHook, clearAllHooks } from './hooks.js'; //
33
33
 
34
34
  // Store API:
35
35
  // store.get(model, id) -- sync, memory-only
36
- // store.find(model, id) -- async, SQL for memory:false models
36
+ // store.find(model, id) -- async, MySQL for memory:false models
37
37
  // store.findAll(model) -- async, all records
38
- // store.query(model, conditions) -- async, always hits SQL
39
- //
40
- // Programmatic CRUD (memory + SQL persistence):
41
- // Orm.create(model, data) -- async, createRecord + sqlDb.persist
42
- // Orm.update(model, id, data) -- async, updateRecord + sqlDb.persist
43
- // Orm.remove(model, id) -- async, sqlDb.persist + store.remove
38
+ // store.query(model, conditions) -- async, always hits MySQL
package/src/main.ts CHANGED
@@ -25,8 +25,6 @@ import baseTransforms from './transforms.js';
25
25
  import Store from './store.js';
26
26
  import Serializer from './serializer.js';
27
27
  import { setup } from '@stonyx/events';
28
- import type { OrmRecord } from './types/orm-types.js';
29
- import { isOrmRecord } from './utils.js';
30
28
 
31
29
  interface OrmOptions {
32
30
  dbType?: string;
@@ -216,63 +214,6 @@ export default class Orm {
216
214
  return !!this.views[`${modelClassPrefix}View`];
217
215
  }
218
216
 
219
- /**
220
- * Programmatic create — writes to memory AND persists to SQL database.
221
- * Use instead of createRecord() when records must be persisted to PostgreSQL/TimescaleDB.
222
- */
223
- static async create(modelName: string, data: Record<string, unknown> = {}): Promise<OrmRecord> {
224
- if (!Orm.initialized) throw new Error('ORM is not ready');
225
-
226
- const { createRecord } = await import('./manage-record.js');
227
- const record = createRecord(modelName, data, { serialize: false }) as unknown as OrmRecord;
228
-
229
- if (Orm.instance.sqlDb) {
230
- const response: { data: { id: unknown } } = { data: { id: record.id } };
231
- await Orm.instance.sqlDb.persist('create', modelName, {}, response);
232
- }
233
-
234
- return record;
235
- }
236
-
237
- /**
238
- * Programmatic update — updates in memory AND persists to SQL database.
239
- * Captures old state for diff-based UPDATE queries.
240
- */
241
- static async update(modelName: string, id: string | number, data: Record<string, unknown>): Promise<OrmRecord> {
242
- if (!Orm.initialized) throw new Error('ORM is not ready');
243
-
244
- const record = Orm.store.get(modelName, id);
245
- if (!record || !isOrmRecord(record)) throw new Error(`Record ${modelName}:${id} not found`);
246
-
247
- const oldState = JSON.parse(JSON.stringify(record.__data));
248
-
249
- // Apply attribute updates directly, matching the REST handler pattern
250
- for (const [key, value] of Object.entries(data)) {
251
- if (key === 'id') continue;
252
- record[key] = value;
253
- }
254
-
255
- if (Orm.instance.sqlDb) {
256
- await Orm.instance.sqlDb.persist('update', modelName, { record, oldState }, {});
257
- }
258
-
259
- return record;
260
- }
261
-
262
- /**
263
- * Programmatic delete — removes from SQL database AND memory store.
264
- * SQL delete runs first to ensure consistency on failure.
265
- */
266
- static async remove(modelName: string, id: string | number): Promise<void> {
267
- if (!Orm.initialized) throw new Error('ORM is not ready');
268
-
269
- if (Orm.instance.sqlDb) {
270
- await Orm.instance.sqlDb.persist('delete', modelName, { recordId: id }, {});
271
- }
272
-
273
- Orm.store.remove(modelName, id);
274
- }
275
-
276
217
  // Queue warnings to avoid the same error from being logged in the same iteration
277
218
  warn(message: string): void {
278
219
  this.warnings.add(message);