@objectstack/driver-memory 0.3.2 → 0.4.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # @objectstack/driver-memory
2
2
 
3
+ ## 0.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Version synchronization and dependency updates
8
+
9
+ - Synchronized plugin-msw version to 0.4.1
10
+ - Updated runtime peer dependency versions to ^0.4.1
11
+ - Fixed internal dependency version mismatches
12
+
13
+ - Updated dependencies
14
+ - @objectstack/spec@0.4.1
15
+
16
+ ## 0.4.0
17
+
18
+ ### Minor Changes
19
+
20
+ - Release version 0.4.0
21
+
22
+ ## 0.3.3
23
+
24
+ ### Patch Changes
25
+
26
+ - Workflow and configuration improvements
27
+
28
+ - Enhanced GitHub workflows for CI, release, and PR automation
29
+ - Added comprehensive prompt templates for different protocol areas
30
+ - Improved project documentation and automation guides
31
+ - Updated changeset configuration
32
+ - Added cursor rules for better development experience
33
+
34
+ - Updated dependencies
35
+ - @objectstack/spec@0.3.3
36
+
3
37
  ## 0.3.2
4
38
 
5
39
  ### Patch Changes
@@ -2,7 +2,7 @@ const MemoryDriverPlugin = {
2
2
  id: 'com.objectstack.driver.memory',
3
3
  name: 'In-Memory Driver',
4
4
  version: '1.0.0',
5
- type: 'plugin', // Acts as a plugin that contributes a driver
5
+ type: 'driver',
6
6
  description: 'A reference specificiation implementation of the DriverInterface using in-memory arrays.',
7
7
  configuration: {
8
8
  title: 'Memory Driver Settings',
package/dist/src/index.js CHANGED
@@ -11,13 +11,13 @@ export default {
11
11
  id: 'com.objectstack.driver.memory',
12
12
  version: '1.0.0',
13
13
  onEnable: async (context) => {
14
- const { logger } = context;
14
+ const { logger, config, drivers } = context;
15
15
  logger.info('[Memory Driver] Initializing...');
16
16
  // Simulate driver registration
17
17
  // This assumes the runtime exposes a 'drivers' registry
18
- if (context.drivers) {
19
- const driver = new InMemoryDriver();
20
- context.drivers.register(driver);
18
+ if (drivers) {
19
+ const driver = new InMemoryDriver(config); // Pass config to driver
20
+ drivers.register(driver);
21
21
  logger.info(`[Memory Driver] Registered driver: ${driver.name}`);
22
22
  }
23
23
  else {
@@ -9,6 +9,8 @@ import { DriverInterface, DriverOptions } from '@objectstack/spec/system';
9
9
  export declare class InMemoryDriver implements DriverInterface {
10
10
  name: string;
11
11
  version: string;
12
+ private config;
13
+ constructor(config?: any);
12
14
  install(ctx: any): void;
13
15
  supports: {
14
16
  transactions: boolean;
@@ -20,6 +22,8 @@ export declare class InMemoryDriver implements DriverInterface {
20
22
  querySubqueries: boolean;
21
23
  joins: boolean;
22
24
  fullTextSearch: boolean;
25
+ vectorSearch: boolean;
26
+ geoSpatial: boolean;
23
27
  jsonFields: boolean;
24
28
  arrayFields: boolean;
25
29
  };
@@ -32,19 +36,21 @@ export declare class InMemoryDriver implements DriverInterface {
32
36
  checkHealth(): Promise<boolean>;
33
37
  execute(command: any, params?: any[]): Promise<null>;
34
38
  find(object: string, query: QueryInput, options?: DriverOptions): Promise<any[]>;
39
+ findStream(object: string, query: QueryInput, options?: DriverOptions): AsyncGenerator<any, void, unknown>;
35
40
  findOne(object: string, query: QueryInput, options?: DriverOptions): Promise<any>;
36
41
  create(object: string, data: Record<string, any>, options?: DriverOptions): Promise<{
37
- created_at: Date;
38
- updated_at: Date;
39
- id: string;
42
+ created_at: any;
43
+ updated_at: any;
44
+ id: any;
40
45
  }>;
41
46
  update(object: string, id: string | number, data: Record<string, any>, options?: DriverOptions): Promise<any>;
47
+ upsert(object: string, data: Record<string, any>, conflictKeys?: string[], options?: DriverOptions): Promise<any>;
42
48
  delete(object: string, id: string | number, options?: DriverOptions): Promise<boolean>;
43
49
  count(object: string, query?: QueryInput, options?: DriverOptions): Promise<number>;
44
50
  bulkCreate(object: string, dataArray: Record<string, any>[], options?: DriverOptions): Promise<{
45
- created_at: Date;
46
- updated_at: Date;
47
- id: string;
51
+ created_at: any;
52
+ updated_at: any;
53
+ id: any;
48
54
  }[]>;
49
55
  bulkUpdate(object: string, updates: {
50
56
  id: string | number;
@@ -5,7 +5,7 @@
5
5
  * This driver stores data in a simple JavaScript object (Heap).
6
6
  */
7
7
  export class InMemoryDriver {
8
- constructor() {
8
+ constructor(config) {
9
9
  this.name = 'in-memory-driver';
10
10
  this.version = '0.0.1';
11
11
  this.supports = {
@@ -15,12 +15,14 @@ export class InMemoryDriver {
15
15
  queryFilters: false, // TODO: Not implemented - basic find() doesn't handle filters
16
16
  queryAggregations: false, // TODO: Not implemented - count() only returns total
17
17
  querySorting: false, // TODO: Not implemented - find() doesn't handle sorting
18
- queryPagination: true, // Basic pagination via 'top' is implemented
18
+ queryPagination: true, // Basic pagination via 'limit' is implemented
19
19
  queryWindowFunctions: false, // TODO: Not implemented
20
20
  querySubqueries: false, // TODO: Not implemented
21
21
  joins: false, // TODO: Not implemented
22
22
  // Advanced Features
23
23
  fullTextSearch: false, // TODO: Not implemented
24
+ vectorSearch: false, // TODO: Not implemented
25
+ geoSpatial: false, // TODO: Not implemented
24
26
  jsonFields: true, // Native JS object support
25
27
  arrayFields: true, // Native JS array support
26
28
  };
@@ -28,6 +30,7 @@ export class InMemoryDriver {
28
30
  * The "Database": A map of TableName -> Array of Records
29
31
  */
30
32
  this.db = {};
33
+ this.config = config || {};
31
34
  }
32
35
  // Duck-typed RuntimePlugin hook
33
36
  install(ctx) {
@@ -63,23 +66,29 @@ export class InMemoryDriver {
63
66
  // 💡 Naive Implementation
64
67
  let results = [...table];
65
68
  // Simple limiting for demonstration
66
- if (query.top) {
67
- results = results.slice(0, query.top);
69
+ if (query.limit) {
70
+ results = results.slice(0, query.limit);
68
71
  }
69
72
  return results;
70
73
  }
74
+ async *findStream(object, query, options) {
75
+ const results = await this.find(object, query, options);
76
+ for (const record of results) {
77
+ yield record;
78
+ }
79
+ }
71
80
  async findOne(object, query, options) {
72
- const results = await this.find(object, { ...query, top: 1 }, options);
81
+ const results = await this.find(object, { ...query, limit: 1 }, options);
73
82
  return results[0] || null;
74
83
  }
75
84
  async create(object, data, options) {
76
85
  const table = this.getTable(object);
77
86
  // COMPATIBILITY: Driver must return 'id' as string
78
87
  const newRecord = {
79
- id: this.generateId(),
88
+ id: data.id || this.generateId(),
80
89
  ...data,
81
- created_at: new Date(),
82
- updated_at: new Date(),
90
+ created_at: data.created_at || new Date(),
91
+ updated_at: data.updated_at || new Date(),
83
92
  };
84
93
  table.push(newRecord);
85
94
  return newRecord;
@@ -98,6 +107,22 @@ export class InMemoryDriver {
98
107
  table[index] = updatedRecord;
99
108
  return updatedRecord;
100
109
  }
110
+ async upsert(object, data, conflictKeys, options) {
111
+ const table = this.getTable(object);
112
+ let existingRecord = null;
113
+ if (data.id) {
114
+ existingRecord = table.find(r => r.id === data.id);
115
+ }
116
+ else if (conflictKeys && conflictKeys.length > 0) {
117
+ existingRecord = table.find(r => conflictKeys.every(key => r[key] === data[key]));
118
+ }
119
+ if (existingRecord) {
120
+ return this.update(object, existingRecord.id, data, options);
121
+ }
122
+ else {
123
+ return this.create(object, data, options);
124
+ }
125
+ }
101
126
  async delete(object, id, options) {
102
127
  const table = this.getTable(object);
103
128
  const index = table.findIndex(r => r.id == id);
@@ -4,7 +4,7 @@ const MemoryDriverPlugin: ObjectStackManifest = {
4
4
  id: 'com.objectstack.driver.memory',
5
5
  name: 'In-Memory Driver',
6
6
  version: '1.0.0',
7
- type: 'plugin', // Acts as a plugin that contributes a driver
7
+ type: 'driver',
8
8
  description: 'A reference specificiation implementation of the DriverInterface using in-memory arrays.',
9
9
 
10
10
  configuration: {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@objectstack/driver-memory",
3
- "version": "0.3.2",
3
+ "version": "0.4.1",
4
4
  "description": "In-Memory Driver for ObjectStack (Reference Implementation)",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
7
7
  "dependencies": {
8
- "@objectstack/spec": "0.3.2"
8
+ "@objectstack/spec": "0.4.1"
9
9
  },
10
10
  "devDependencies": {
11
11
  "typescript": "^5.0.0"
package/src/index.ts CHANGED
@@ -17,14 +17,14 @@ export default {
17
17
  version: '1.0.0',
18
18
 
19
19
  onEnable: async (context: any) => {
20
- const { logger } = context;
20
+ const { logger, config, drivers } = context;
21
21
  logger.info('[Memory Driver] Initializing...');
22
22
 
23
23
  // Simulate driver registration
24
24
  // This assumes the runtime exposes a 'drivers' registry
25
- if (context.drivers) {
26
- const driver = new InMemoryDriver();
27
- context.drivers.register(driver);
25
+ if (drivers) {
26
+ const driver = new InMemoryDriver(config); // Pass config to driver
27
+ drivers.register(driver);
28
28
  logger.info(`[Memory Driver] Registered driver: ${driver.name}`);
29
29
  } else {
30
30
  logger.warn('[Memory Driver] No driver registry found in context.');
@@ -10,6 +10,11 @@ import { DriverInterface, DriverOptions } from '@objectstack/spec/system';
10
10
  export class InMemoryDriver implements DriverInterface {
11
11
  name = 'in-memory-driver';
12
12
  version = '0.0.1';
13
+ private config: any;
14
+
15
+ constructor(config?: any) {
16
+ this.config = config || {};
17
+ }
13
18
 
14
19
  // Duck-typed RuntimePlugin hook
15
20
  install(ctx: any) {
@@ -26,13 +31,15 @@ export class InMemoryDriver implements DriverInterface {
26
31
  queryFilters: false, // TODO: Not implemented - basic find() doesn't handle filters
27
32
  queryAggregations: false, // TODO: Not implemented - count() only returns total
28
33
  querySorting: false, // TODO: Not implemented - find() doesn't handle sorting
29
- queryPagination: true, // Basic pagination via 'top' is implemented
34
+ queryPagination: true, // Basic pagination via 'limit' is implemented
30
35
  queryWindowFunctions: false, // TODO: Not implemented
31
36
  querySubqueries: false, // TODO: Not implemented
32
37
  joins: false, // TODO: Not implemented
33
38
 
34
39
  // Advanced Features
35
40
  fullTextSearch: false, // TODO: Not implemented
41
+ vectorSearch: false, // TODO: Not implemented
42
+ geoSpatial: false, // TODO: Not implemented
36
43
  jsonFields: true, // Native JS object support
37
44
  arrayFields: true, // Native JS array support
38
45
  };
@@ -79,15 +86,22 @@ export class InMemoryDriver implements DriverInterface {
79
86
  let results = [...table];
80
87
 
81
88
  // Simple limiting for demonstration
82
- if (query.top) {
83
- results = results.slice(0, query.top);
89
+ if (query.limit) {
90
+ results = results.slice(0, query.limit);
84
91
  }
85
92
 
86
93
  return results;
87
94
  }
88
95
 
96
+ async *findStream(object: string, query: QueryInput, options?: DriverOptions) {
97
+ const results = await this.find(object, query, options);
98
+ for (const record of results) {
99
+ yield record;
100
+ }
101
+ }
102
+
89
103
  async findOne(object: string, query: QueryInput, options?: DriverOptions) {
90
- const results = await this.find(object, { ...query, top: 1 }, options);
104
+ const results = await this.find(object, { ...query, limit: 1 }, options);
91
105
  return results[0] || null;
92
106
  }
93
107
 
@@ -96,10 +110,10 @@ export class InMemoryDriver implements DriverInterface {
96
110
 
97
111
  // COMPATIBILITY: Driver must return 'id' as string
98
112
  const newRecord = {
99
- id: this.generateId(),
113
+ id: data.id || this.generateId(),
100
114
  ...data,
101
- created_at: new Date(),
102
- updated_at: new Date(),
115
+ created_at: data.created_at || new Date(),
116
+ updated_at: data.updated_at || new Date(),
103
117
  };
104
118
 
105
119
  table.push(newRecord);
@@ -124,6 +138,23 @@ export class InMemoryDriver implements DriverInterface {
124
138
  return updatedRecord;
125
139
  }
126
140
 
141
+ async upsert(object: string, data: Record<string, any>, conflictKeys?: string[], options?: DriverOptions) {
142
+ const table = this.getTable(object);
143
+ let existingRecord: any = null;
144
+
145
+ if (data.id) {
146
+ existingRecord = table.find(r => r.id === data.id);
147
+ } else if (conflictKeys && conflictKeys.length > 0) {
148
+ existingRecord = table.find(r => conflictKeys.every(key => r[key] === data[key]));
149
+ }
150
+
151
+ if (existingRecord) {
152
+ return this.update(object, existingRecord.id, data, options);
153
+ } else {
154
+ return this.create(object, data, options);
155
+ }
156
+ }
157
+
127
158
  async delete(object: string, id: string | number, options?: DriverOptions) {
128
159
  const table = this.getTable(object);
129
160
  const index = table.findIndex(r => r.id == id);