@objectstack/driver-memory 0.3.1 → 0.3.3
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 +23 -0
- package/dist/objectstack.config.d.ts +1 -1
- package/dist/objectstack.config.js +1 -1
- package/dist/src/index.js +4 -4
- package/dist/src/memory-driver.d.ts +7 -1
- package/dist/src/memory-driver.js +30 -5
- package/objectstack.config.ts +2 -2
- package/package.json +2 -2
- package/src/index.ts +4 -4
- package/src/memory-driver.ts +36 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @objectstack/driver-memory
|
|
2
2
|
|
|
3
|
+
## 0.3.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Workflow and configuration improvements
|
|
8
|
+
|
|
9
|
+
- Enhanced GitHub workflows for CI, release, and PR automation
|
|
10
|
+
- Added comprehensive prompt templates for different protocol areas
|
|
11
|
+
- Improved project documentation and automation guides
|
|
12
|
+
- Updated changeset configuration
|
|
13
|
+
- Added cursor rules for better development experience
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
- @objectstack/spec@0.3.3
|
|
17
|
+
|
|
18
|
+
## 0.3.2
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Patch release for maintenance and stability improvements
|
|
23
|
+
- Updated dependencies
|
|
24
|
+
- @objectstack/spec@0.3.2
|
|
25
|
+
|
|
3
26
|
## 0.3.1
|
|
4
27
|
|
|
5
28
|
### 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: '
|
|
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 (
|
|
19
|
-
const driver = new InMemoryDriver();
|
|
20
|
-
|
|
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 {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryInput } from '@objectstack/spec/data';
|
|
2
|
-
import { DriverInterface, DriverOptions } from '@objectstack/spec/
|
|
2
|
+
import { DriverInterface, DriverOptions } from '@objectstack/spec/driver';
|
|
3
3
|
/**
|
|
4
4
|
* Example: In-Memory Driver
|
|
5
5
|
*
|
|
@@ -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,6 +36,7 @@ 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
42
|
created_at: Date;
|
|
@@ -39,6 +44,7 @@ export declare class InMemoryDriver implements DriverInterface {
|
|
|
39
44
|
id: string;
|
|
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<{
|
|
@@ -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 '
|
|
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,13 +66,19 @@ export class InMemoryDriver {
|
|
|
63
66
|
// 💡 Naive Implementation
|
|
64
67
|
let results = [...table];
|
|
65
68
|
// Simple limiting for demonstration
|
|
66
|
-
if (query.
|
|
67
|
-
results = results.slice(0, query.
|
|
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,
|
|
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) {
|
|
@@ -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);
|
package/objectstack.config.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ObjectStackManifest } from '@objectstack/spec/
|
|
1
|
+
import { ObjectStackManifest } from '@objectstack/spec/kernel';
|
|
2
2
|
|
|
3
3
|
const MemoryDriverPlugin: ObjectStackManifest = {
|
|
4
4
|
id: 'com.objectstack.driver.memory',
|
|
5
5
|
name: 'In-Memory Driver',
|
|
6
6
|
version: '1.0.0',
|
|
7
|
-
type: '
|
|
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.
|
|
3
|
+
"version": "0.3.3",
|
|
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.
|
|
8
|
+
"@objectstack/spec": "0.3.3"
|
|
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 (
|
|
26
|
-
const driver = new InMemoryDriver();
|
|
27
|
-
|
|
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.');
|
package/src/memory-driver.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryAST, QueryInput } from '@objectstack/spec/data';
|
|
2
|
-
import { DriverInterface, DriverOptions } from '@objectstack/spec/
|
|
2
|
+
import { DriverInterface, DriverOptions } from '@objectstack/spec/driver';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Example: In-Memory Driver
|
|
@@ -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 '
|
|
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.
|
|
83
|
-
results = results.slice(0, query.
|
|
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,
|
|
104
|
+
const results = await this.find(object, { ...query, limit: 1 }, options);
|
|
91
105
|
return results[0] || null;
|
|
92
106
|
}
|
|
93
107
|
|
|
@@ -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);
|