@encodeagent/platform-helper-data 1.2510.1041539 → 1.2510.1282253
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/cosmosdb/index.d.ts +25 -0
- package/dist/cosmosdb/index.d.ts.map +1 -0
- package/dist/cosmosdb/index.js +210 -0
- package/dist/cosmosdb/index.js.map +1 -0
- package/dist/cosmosdb/query-builder.d.ts +10 -0
- package/dist/cosmosdb/query-builder.d.ts.map +1 -0
- package/dist/cosmosdb/query-builder.js +123 -0
- package/dist/cosmosdb/query-builder.js.map +1 -0
- package/dist/dynamodb/index.d.ts +24 -0
- package/dist/dynamodb/index.d.ts.map +1 -0
- package/dist/dynamodb/index.js +189 -0
- package/dist/dynamodb/index.js.map +1 -0
- package/dist/firestore/index.d.ts +9 -0
- package/dist/firestore/index.d.ts.map +1 -0
- package/dist/firestore/index.js +79 -0
- package/dist/firestore/index.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/mongodb/index.d.ts +18 -0
- package/dist/mongodb/index.d.ts.map +1 -0
- package/dist/mongodb/index.js +208 -0
- package/dist/mongodb/index.js.map +1 -0
- package/dist/util.d.ts +125 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +40 -0
- package/dist/util.js.map +1 -0
- package/dist/wrapper/index.d.ts +31 -6
- package/dist/wrapper/index.d.ts.map +1 -1
- package/dist/wrapper/index.js +197 -46
- package/dist/wrapper/index.js.map +1 -1
- package/package.json +4 -5
- package/dist/aws-dynamodb/index.d.ts +0 -17
- package/dist/aws-dynamodb/index.d.ts.map +0 -1
- package/dist/aws-dynamodb/index.js +0 -96
- package/dist/aws-dynamodb/index.js.map +0 -1
- package/dist/azure-cosmosdb/index.d.ts +0 -17
- package/dist/azure-cosmosdb/index.d.ts.map +0 -1
- package/dist/azure-cosmosdb/index.js +0 -91
- package/dist/azure-cosmosdb/index.js.map +0 -1
- package/dist/gcp-firestore/index.d.ts +0 -7
- package/dist/gcp-firestore/index.d.ts.map +0 -1
- package/dist/gcp-firestore/index.js +0 -17
- package/dist/gcp-firestore/index.js.map +0 -1
- package/dist/mongo/index.d.ts +0 -7
- package/dist/mongo/index.d.ts.map +0 -1
- package/dist/mongo/index.js +0 -17
- package/dist/mongo/index.js.map +0 -1
- package/dist/types.d.ts +0 -46
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -12
- package/dist/types.js.map +0 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview GCP Firestore implementation
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.connect = connect;
|
|
7
|
+
exports.retrieve = retrieve;
|
|
8
|
+
exports.create = create;
|
|
9
|
+
exports.upsert = upsert;
|
|
10
|
+
const ENGINE = "firestore";
|
|
11
|
+
async function connect(props) {
|
|
12
|
+
// TODO: Implement GCP Firestore connection
|
|
13
|
+
throw new Error('GCP Firestore connection not implemented');
|
|
14
|
+
}
|
|
15
|
+
async function retrieve(props) {
|
|
16
|
+
// TODO: Implement GCP Firestore retrieve by ID
|
|
17
|
+
throw new Error('GCP Firestore retrieve not implemented');
|
|
18
|
+
}
|
|
19
|
+
async function create(props) {
|
|
20
|
+
try {
|
|
21
|
+
const { databaseId, containerId, record } = props;
|
|
22
|
+
if (!databaseId) {
|
|
23
|
+
return {
|
|
24
|
+
engine: ENGINE,
|
|
25
|
+
error: 'The databaseId or process.env.DATABASE_ID is required'
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (!containerId) {
|
|
29
|
+
return {
|
|
30
|
+
engine: ENGINE,
|
|
31
|
+
error: 'The containerId or process.env.DATABASE_CONTAINER_ID is required'
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (!record) {
|
|
35
|
+
return {
|
|
36
|
+
engine: ENGINE,
|
|
37
|
+
error: 'The record is required'
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
throw new Error('GCP Firestore create not implemented');
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return {
|
|
44
|
+
engine: ENGINE,
|
|
45
|
+
error: error instanceof Error ? error.message : 'Failed to create record in GCP Firestore'
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function upsert(props) {
|
|
50
|
+
try {
|
|
51
|
+
const { databaseId, containerId, record } = props;
|
|
52
|
+
if (!databaseId) {
|
|
53
|
+
return {
|
|
54
|
+
engine: ENGINE,
|
|
55
|
+
error: 'The databaseId or process.env.DATABASE_ID is required'
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (!containerId) {
|
|
59
|
+
return {
|
|
60
|
+
engine: ENGINE,
|
|
61
|
+
error: 'The containerId or process.env.DATABASE_CONTAINER_ID is required'
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (!record) {
|
|
65
|
+
return {
|
|
66
|
+
engine: ENGINE,
|
|
67
|
+
error: 'The record is required'
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
throw new Error('GCP Firestore upsert not implemented');
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return {
|
|
74
|
+
engine: ENGINE,
|
|
75
|
+
error: error instanceof Error ? error.message : 'Failed to upsert record in GCP Firestore'
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/firestore/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAMH,0BAGC;AAGD,4BAGC;AAGD,wBAgCC;AAGD,wBAgCC;AAjFD,MAAM,MAAM,GAAG,WAAW,CAAC;AAEpB,KAAK,UAAU,OAAO,CAAC,KAAiC;IAC3D,2CAA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AAM,EAAE,MAAM;gBACd,KAAK,EAAE,kEAAkE;aAC5E,CAAC;QACN,CAAC;QAED,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO;gBACH,MAAM,EAAE,MAAM;gBACd,KAAK,EAAE,wBAAwB;aAClC,CAAC;QACN,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC5D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO;YACH,MAAM,EAAE,MAAM;YACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,0CAA0C;SAC7F,CAAC;IACN,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Main export file for @encodeagent/platform-helper-data
|
|
3
3
|
*/
|
|
4
|
-
export { connect, retrieve } from './wrapper';
|
|
5
|
-
export type { TDatabaseEngine, IConnectionResult, IRetrieveResult,
|
|
6
|
-
export { ENGINE, URI, KEY, DATABASE_ID,
|
|
4
|
+
export { connect, retrieve, create } from './wrapper';
|
|
5
|
+
export type { TDatabaseEngine, IConnectionResult, IRetrieveResult, IRetrieveProps, IConnectionForServiceProps, IConnectDatabaseError, } from './util';
|
|
6
|
+
export { ENGINE, URI, KEY, DATABASE_ID, CONTAINER_ID_FOR_DATA, CONTAINER_ID_FOR_SETTINGS } from './util';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGtD,YAAY,EACR,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,0BAA0B,EAC1B,qBAAqB,GAExB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EACH,MAAM,EACN,GAAG,EACH,GAAG,EACH,WAAW,EACX,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,QAAQ,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
* @fileoverview Main export file for @encodeagent/platform-helper-data
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.CONTAINER_ID_FOR_SETTINGS = exports.CONTAINER_ID_FOR_DATA = exports.DATABASE_ID = exports.KEY = exports.URI = exports.ENGINE = exports.create = exports.retrieve = exports.connect = void 0;
|
|
7
7
|
// Export wrapper functions (main API)
|
|
8
8
|
var wrapper_1 = require("./wrapper");
|
|
9
9
|
Object.defineProperty(exports, "connect", { enumerable: true, get: function () { return wrapper_1.connect; } });
|
|
10
10
|
Object.defineProperty(exports, "retrieve", { enumerable: true, get: function () { return wrapper_1.retrieve; } });
|
|
11
|
+
Object.defineProperty(exports, "create", { enumerable: true, get: function () { return wrapper_1.create; } });
|
|
11
12
|
// Export all constants from types.ts
|
|
12
|
-
var
|
|
13
|
-
Object.defineProperty(exports, "ENGINE", { enumerable: true, get: function () { return
|
|
14
|
-
Object.defineProperty(exports, "URI", { enumerable: true, get: function () { return
|
|
15
|
-
Object.defineProperty(exports, "KEY", { enumerable: true, get: function () { return
|
|
16
|
-
Object.defineProperty(exports, "DATABASE_ID", { enumerable: true, get: function () { return
|
|
17
|
-
Object.defineProperty(exports, "
|
|
13
|
+
var util_1 = require("./util");
|
|
14
|
+
Object.defineProperty(exports, "ENGINE", { enumerable: true, get: function () { return util_1.ENGINE; } });
|
|
15
|
+
Object.defineProperty(exports, "URI", { enumerable: true, get: function () { return util_1.URI; } });
|
|
16
|
+
Object.defineProperty(exports, "KEY", { enumerable: true, get: function () { return util_1.KEY; } });
|
|
17
|
+
Object.defineProperty(exports, "DATABASE_ID", { enumerable: true, get: function () { return util_1.DATABASE_ID; } });
|
|
18
|
+
Object.defineProperty(exports, "CONTAINER_ID_FOR_DATA", { enumerable: true, get: function () { return util_1.CONTAINER_ID_FOR_DATA; } });
|
|
19
|
+
Object.defineProperty(exports, "CONTAINER_ID_FOR_SETTINGS", { enumerable: true, get: function () { return util_1.CONTAINER_ID_FOR_SETTINGS; } });
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,sCAAsC;AACtC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,sCAAsC;AACtC,qCAAsD;AAA7C,kGAAA,OAAO,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAAE,iGAAA,MAAM,OAAA;AAalC,qCAAqC;AACrC,+BAOgB;AANZ,8FAAA,MAAM,OAAA;AACN,2FAAA,GAAG,OAAA;AACH,2FAAA,GAAG,OAAA;AACH,mGAAA,WAAW,OAAA;AACX,6GAAA,qBAAqB,OAAA;AACrB,iHAAA,yBAAyB,OAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview MongoDB implementation
|
|
3
|
+
*/
|
|
4
|
+
import { IConnectionForServiceProps, IConnectionResult, IRetrieveResult, IRetrieveProps, ICreateProps, ICreateResult, IUpsertProps, IUpsertResult } from '../util';
|
|
5
|
+
export declare function connect(props: IConnectionForServiceProps): Promise<IConnectionResult>;
|
|
6
|
+
export declare function retrieve(props: IRetrieveProps): Promise<IRetrieveResult>;
|
|
7
|
+
/**
|
|
8
|
+
* Query documents from MongoDB collection
|
|
9
|
+
* Uses same connection shape as retrieve, with optional filter, sort, and limit.
|
|
10
|
+
*/
|
|
11
|
+
export declare function create(props: ICreateProps): Promise<ICreateResult>;
|
|
12
|
+
/**
|
|
13
|
+
* Upsert (create or update) a document in MongoDB
|
|
14
|
+
* @param props Upsert properties with client, databaseId, containerId, and record
|
|
15
|
+
* @returns Promise<IUpsertResult>
|
|
16
|
+
*/
|
|
17
|
+
export declare function upsert(props: IUpsertProps): Promise<IUpsertResult>;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mongodb/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,0BAA0B,EAAE,iBAAiB,EAC7C,eAAe,EAAE,cAAc,EAE/B,YAAY,EAAE,aAAa,EAC3B,YAAY,EAAE,aAAa,EAC9B,MAAM,SAAS,CAAC;AAMjB,wBAAsB,OAAO,CAAC,KAAK,EAAE,0BAA0B,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAyB3F;AAGD,wBAAsB,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CA4C9E;AAED;;;GAGG;AAkDH,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CA8CxE;AAED;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAyDxE"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview MongoDB implementation
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.connect = connect;
|
|
7
|
+
exports.retrieve = retrieve;
|
|
8
|
+
exports.create = create;
|
|
9
|
+
exports.upsert = upsert;
|
|
10
|
+
const mongo_sdk_1 = require("mongo-sdk");
|
|
11
|
+
const platform_helper_util_1 = require("@encodeagent/platform-helper-util");
|
|
12
|
+
const ENGINE = "mongodb";
|
|
13
|
+
async function connect(props) {
|
|
14
|
+
try {
|
|
15
|
+
const { uri } = props;
|
|
16
|
+
if (!uri) {
|
|
17
|
+
return {
|
|
18
|
+
engine: ENGINE,
|
|
19
|
+
error: 'MongoDB URI is required'
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const client = new mongo_sdk_1.MongoClient(uri);
|
|
23
|
+
await client.connect();
|
|
24
|
+
return {
|
|
25
|
+
engine: ENGINE,
|
|
26
|
+
client
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
return {
|
|
31
|
+
engine: ENGINE,
|
|
32
|
+
error: error instanceof Error ? error.message : 'Failed to connect to MongoDB'
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function retrieve(props) {
|
|
37
|
+
try {
|
|
38
|
+
const { client, id, databaseId, containerId } = props;
|
|
39
|
+
if (!databaseId) {
|
|
40
|
+
return {
|
|
41
|
+
engine: ENGINE,
|
|
42
|
+
error: 'The databaseId or process.env.DATABASE_ID is required'
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (!containerId) {
|
|
46
|
+
return {
|
|
47
|
+
engine: ENGINE,
|
|
48
|
+
error: 'The containerId or process.env.DATABASE_CONTAINER_ID is required'
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const db = client.db(databaseId);
|
|
52
|
+
const collection = db.collection(containerId);
|
|
53
|
+
// Try _id as ObjectId first
|
|
54
|
+
let doc = null;
|
|
55
|
+
if (mongo_sdk_1.ObjectId.isValid(id)) {
|
|
56
|
+
doc = await collection.findOne({ _id: new mongo_sdk_1.ObjectId(id) });
|
|
57
|
+
}
|
|
58
|
+
// Fallback to id field or string _id
|
|
59
|
+
if (!doc) {
|
|
60
|
+
doc = await collection.findOne({ id }) || await collection.findOne({ _id: id });
|
|
61
|
+
}
|
|
62
|
+
const data = (doc ?? undefined);
|
|
63
|
+
return {
|
|
64
|
+
engine: ENGINE,
|
|
65
|
+
data
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
return {
|
|
70
|
+
engine: ENGINE,
|
|
71
|
+
error: error instanceof Error ? error.message : 'Failed to retrieve document from MongoDB'
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Query documents from MongoDB collection
|
|
77
|
+
* Uses same connection shape as retrieve, with optional filter, sort, and limit.
|
|
78
|
+
*/
|
|
79
|
+
// { filter ?: Record<string, any>; sort ?: Record<string, 1 | -1>; limit ?: number; }
|
|
80
|
+
// export async function query(props: IQueryProps): Promise<IQueryResult> {
|
|
81
|
+
// try {
|
|
82
|
+
// const { client, databaseId, containerId, query } = props;
|
|
83
|
+
// if (!databaseId) {
|
|
84
|
+
// return {
|
|
85
|
+
// engine: ENGINE,
|
|
86
|
+
// error: 'The databaseId or process.env.DATABASE_ID is required'
|
|
87
|
+
// };
|
|
88
|
+
// }
|
|
89
|
+
// if (!containerId) {
|
|
90
|
+
// return {
|
|
91
|
+
// engine: ENGINE,
|
|
92
|
+
// error: 'The containerId or process.env.DATABASE_CONTAINER_ID is required'
|
|
93
|
+
// };
|
|
94
|
+
// }
|
|
95
|
+
// const db = client.db(databaseId);
|
|
96
|
+
// const collection = db.collection(containerId);
|
|
97
|
+
// const { filter, sort, limit } = query;
|
|
98
|
+
// let cursor = collection.find(filter ?? {});
|
|
99
|
+
// if (sort && Object.keys(sort).length) {
|
|
100
|
+
// cursor = cursor.sort(sort as any);
|
|
101
|
+
// }
|
|
102
|
+
// if (typeof limit === 'number' && limit > 0) {
|
|
103
|
+
// cursor = cursor.limit(limit);
|
|
104
|
+
// }
|
|
105
|
+
// const items = await cursor.toArray();
|
|
106
|
+
// return {
|
|
107
|
+
// engine: ENGINE,
|
|
108
|
+
// data: items
|
|
109
|
+
// };
|
|
110
|
+
// } catch (error) {
|
|
111
|
+
// return {
|
|
112
|
+
// engine: ENGINE,
|
|
113
|
+
// error: error instanceof Error ? error.message : 'Failed to query documents from MongoDB'
|
|
114
|
+
// };
|
|
115
|
+
// }
|
|
116
|
+
// }
|
|
117
|
+
async function create(props) {
|
|
118
|
+
try {
|
|
119
|
+
const { client, databaseId, containerId, record } = props;
|
|
120
|
+
if (!databaseId) {
|
|
121
|
+
return {
|
|
122
|
+
engine: ENGINE,
|
|
123
|
+
error: 'The databaseId or process.env.DATABASE_ID is required'
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (!containerId) {
|
|
127
|
+
return {
|
|
128
|
+
engine: ENGINE,
|
|
129
|
+
error: 'The containerId or process.env.DATABASE_CONTAINER_ID is required'
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (!record) {
|
|
133
|
+
return {
|
|
134
|
+
engine: ENGINE,
|
|
135
|
+
error: 'The record is required'
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const db = client.db(databaseId);
|
|
139
|
+
const collection = db.collection(containerId);
|
|
140
|
+
const item = {
|
|
141
|
+
...record,
|
|
142
|
+
id: record.id ?? (0, platform_helper_util_1.newGuid)()
|
|
143
|
+
};
|
|
144
|
+
await collection.insertOne(item);
|
|
145
|
+
return {
|
|
146
|
+
engine: ENGINE,
|
|
147
|
+
data: item
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
return {
|
|
152
|
+
engine: ENGINE,
|
|
153
|
+
error: error instanceof Error ? error.message : 'Failed to create record in MongoDB'
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Upsert (create or update) a document in MongoDB
|
|
159
|
+
* @param props Upsert properties with client, databaseId, containerId, and record
|
|
160
|
+
* @returns Promise<IUpsertResult>
|
|
161
|
+
*/
|
|
162
|
+
async function upsert(props) {
|
|
163
|
+
try {
|
|
164
|
+
const { client, databaseId, containerId, record } = props;
|
|
165
|
+
if (!databaseId) {
|
|
166
|
+
return {
|
|
167
|
+
engine: ENGINE,
|
|
168
|
+
error: 'The databaseId or process.env.DATABASE_ID is required'
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (!containerId) {
|
|
172
|
+
return {
|
|
173
|
+
engine: ENGINE,
|
|
174
|
+
error: 'The containerId or process.env.DATABASE_CONTAINER_ID is required'
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (!record) {
|
|
178
|
+
return {
|
|
179
|
+
engine: ENGINE,
|
|
180
|
+
error: 'The record is required'
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const db = client.db(databaseId);
|
|
184
|
+
const collection = db.collection(containerId);
|
|
185
|
+
// Ensure the record has an id
|
|
186
|
+
const recordWithId = {
|
|
187
|
+
...record,
|
|
188
|
+
id: record.id ?? (0, platform_helper_util_1.newGuid)()
|
|
189
|
+
};
|
|
190
|
+
// Use updateOne with upsert option
|
|
191
|
+
// This will update if a document with the same id exists, or insert if it doesn't
|
|
192
|
+
const result = await collection.updateOne({ id: recordWithId.id }, { $set: recordWithId }, { upsert: true });
|
|
193
|
+
// Check if this was a new document or an update
|
|
194
|
+
const isNew = result.upsertedCount > 0;
|
|
195
|
+
return {
|
|
196
|
+
engine: ENGINE,
|
|
197
|
+
data: recordWithId,
|
|
198
|
+
isNew
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
return {
|
|
203
|
+
engine: ENGINE,
|
|
204
|
+
error: error instanceof Error ? error.message : 'Failed to upsert record in MongoDB'
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js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YACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,oCAAoC;SACvF,CAAC;IACN,CAAC;AACL,CAAC"}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Type definitions for database helper utilities
|
|
3
|
+
*/
|
|
4
|
+
export type TDatabaseEngine = 'cosmosdb' | 'dynamodb' | 'firestore' | 'mongodb';
|
|
5
|
+
export declare const ENGINE: TDatabaseEngine;
|
|
6
|
+
export declare const URI: string | undefined;
|
|
7
|
+
export declare const KEY: string | undefined;
|
|
8
|
+
export declare const DATABASE_ID: string;
|
|
9
|
+
export declare const CONTAINER_ID_FOR_DATA: string;
|
|
10
|
+
export declare const CONTAINER_ID_FOR_SETTINGS: string;
|
|
11
|
+
export interface IConnectionResult {
|
|
12
|
+
engine: TDatabaseEngine;
|
|
13
|
+
client?: any;
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface IConnectionForServiceProps {
|
|
17
|
+
uri: string;
|
|
18
|
+
key?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface IErrorResult {
|
|
21
|
+
engine: TDatabaseEngine;
|
|
22
|
+
error?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface IConnectDatabaseError {
|
|
25
|
+
message: string;
|
|
26
|
+
code: string;
|
|
27
|
+
engine: string;
|
|
28
|
+
timestamp: string;
|
|
29
|
+
details?: any;
|
|
30
|
+
retryable?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface IRetrieveProps {
|
|
33
|
+
client: any;
|
|
34
|
+
uri?: string;
|
|
35
|
+
key?: string;
|
|
36
|
+
databaseId?: string;
|
|
37
|
+
containerId?: string;
|
|
38
|
+
id: string;
|
|
39
|
+
partitionKey?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface IRetrieveResult<T = any> extends IErrorResult {
|
|
42
|
+
data?: T;
|
|
43
|
+
}
|
|
44
|
+
export interface IQueryProps {
|
|
45
|
+
client: any;
|
|
46
|
+
uri?: string;
|
|
47
|
+
key?: string;
|
|
48
|
+
databaseId?: string;
|
|
49
|
+
containerId?: string;
|
|
50
|
+
query: IQuery;
|
|
51
|
+
}
|
|
52
|
+
export interface IQueryResult extends IErrorResult {
|
|
53
|
+
query: IQuery;
|
|
54
|
+
dbQuery?: Record<string, any>;
|
|
55
|
+
data?: Record<string, any>[];
|
|
56
|
+
}
|
|
57
|
+
export interface ICreateProps {
|
|
58
|
+
client: any;
|
|
59
|
+
uri?: string;
|
|
60
|
+
key?: string;
|
|
61
|
+
databaseId?: string;
|
|
62
|
+
containerId?: string;
|
|
63
|
+
record: Record<string, any>;
|
|
64
|
+
}
|
|
65
|
+
export interface ICreateResult<T = any> extends IErrorResult {
|
|
66
|
+
data?: T;
|
|
67
|
+
}
|
|
68
|
+
export interface IUpsertProps {
|
|
69
|
+
client: any;
|
|
70
|
+
uri?: string;
|
|
71
|
+
key?: string;
|
|
72
|
+
databaseId?: string;
|
|
73
|
+
containerId?: string;
|
|
74
|
+
record: Record<string, any>;
|
|
75
|
+
partitionKey?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface IUpsertResult<T = any> extends IErrorResult {
|
|
78
|
+
data?: T;
|
|
79
|
+
isNew?: boolean;
|
|
80
|
+
}
|
|
81
|
+
export interface IDatabaseSetting {
|
|
82
|
+
engine: TDatabaseEngine;
|
|
83
|
+
uri?: string;
|
|
84
|
+
key?: string;
|
|
85
|
+
databaseId?: string;
|
|
86
|
+
containerId?: string;
|
|
87
|
+
}
|
|
88
|
+
export declare const getDatabaseSetting: (props: IDatabaseSetting & {
|
|
89
|
+
[key: string]: any;
|
|
90
|
+
}) => IDatabaseSetting;
|
|
91
|
+
export interface IValidateDatabaseSettingProps {
|
|
92
|
+
databaseId?: string;
|
|
93
|
+
containerId?: string;
|
|
94
|
+
checkDatabaseId?: boolean;
|
|
95
|
+
checkContainerId?: boolean;
|
|
96
|
+
}
|
|
97
|
+
export declare const validateDatabaseSetting: (props: IValidateDatabaseSettingProps) => IErrorResult | null;
|
|
98
|
+
export interface ISimpleFilter {
|
|
99
|
+
name: string;
|
|
100
|
+
op: "=" | "!=" | "<" | "<=" | ">" | ">=" | "IN" | "BETWEEN" | "LIKE" | "CONTAINS" | "STARTSWITH" | "ENDSWITH";
|
|
101
|
+
value: any;
|
|
102
|
+
}
|
|
103
|
+
export interface IGroupFilter {
|
|
104
|
+
op: "AND" | "OR" | "NOT";
|
|
105
|
+
filters: Array<ISimpleFilter | IGroupFilter>;
|
|
106
|
+
}
|
|
107
|
+
export interface IOrderBy {
|
|
108
|
+
name: string;
|
|
109
|
+
direction?: "ASC" | "DESC";
|
|
110
|
+
}
|
|
111
|
+
export interface IQuery {
|
|
112
|
+
attributes?: string[];
|
|
113
|
+
distinct?: boolean;
|
|
114
|
+
top?: number;
|
|
115
|
+
orderBy?: IOrderBy[];
|
|
116
|
+
filter?: ISimpleFilter | IGroupFilter | any;
|
|
117
|
+
page?: number;
|
|
118
|
+
pageSize?: number;
|
|
119
|
+
}
|
|
120
|
+
export interface IQueryResult extends IErrorResult {
|
|
121
|
+
query: IQuery;
|
|
122
|
+
dbQuery?: Record<string, any>;
|
|
123
|
+
data?: Record<string, any>[];
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC;AAEhF,eAAO,MAAM,MAAM,EAAkD,eAAe,CAAC;AACrF,eAAO,MAAM,GAAG,oBAA2B,CAAC;AAC5C,eAAO,MAAM,GAAG,oBAA2B,CAAC;AAC5C,eAAO,MAAM,WAAW,QAAwC,CAAC;AACjE,eAAO,MAAM,qBAAqB,QAAuD,C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AAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;CAChC"}
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Type definitions for database helper utilities
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateDatabaseSetting = exports.getDatabaseSetting = exports.CONTAINER_ID_FOR_SETTINGS = exports.CONTAINER_ID_FOR_DATA = exports.DATABASE_ID = exports.KEY = exports.URI = exports.ENGINE = void 0;
|
|
7
|
+
exports.ENGINE = (process.env.DATABASE_ENGINE || "cosmosdb");
|
|
8
|
+
exports.URI = process.env.DATABASE_URI;
|
|
9
|
+
exports.KEY = process.env.DATABASE_KEY;
|
|
10
|
+
exports.DATABASE_ID = process.env.DATABASE_ID || 'platform';
|
|
11
|
+
exports.CONTAINER_ID_FOR_DATA = process.env.DATABASE_CONTAINER_ID_FOR_DATA || "data";
|
|
12
|
+
exports.CONTAINER_ID_FOR_SETTINGS = process.env.DATABASE_CONTAINER_ID_FOR_SETTINGS || "settings";
|
|
13
|
+
const getDatabaseSetting = (props) => {
|
|
14
|
+
return {
|
|
15
|
+
engine: props.engine ?? exports.ENGINE,
|
|
16
|
+
uri: props.uri ?? exports.URI,
|
|
17
|
+
key: props.key ?? exports.KEY,
|
|
18
|
+
databaseId: props.databaseId ?? exports.DATABASE_ID,
|
|
19
|
+
containerId: props.containerId ?? exports.CONTAINER_ID_FOR_DATA
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.getDatabaseSetting = getDatabaseSetting;
|
|
23
|
+
const validateDatabaseSetting = (props) => {
|
|
24
|
+
const { databaseId, containerId, checkDatabaseId, checkContainerId } = props;
|
|
25
|
+
if (checkDatabaseId && !databaseId) {
|
|
26
|
+
return {
|
|
27
|
+
engine: exports.ENGINE,
|
|
28
|
+
error: 'The databaseId or process.env.DATABASE_ID is required'
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (checkContainerId && !containerId) {
|
|
32
|
+
return {
|
|
33
|
+
engine: exports.ENGINE,
|
|
34
|
+
error: 'The containerId or process.env.DATABASE_CONTAINER_ID is required'
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
39
|
+
exports.validateDatabaseSetting = validateDatabaseSetting;
|
|
40
|
+
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAIU,QAAA,MAAM,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,UAAU,CAAoB,CAAC;AACxE,QAAA,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;AAC/B,QAAA,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;AAC/B,QAAA,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,UAAU,CAAC;AACpD,QAAA,qBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC,8BAA8B,IAAI,MAAM,CAAC;AAC7E,QAAA,yBAAyB,GAAG,OAAO,CAAC,GAAG,CAAC,kCAAkC,IAAI,UAAU,CAAC;AA2G/F,MAAM,kBAAkB,GAAG,CAAC,KAAiD,EAAoB,EAAE;IACtG,OAAO;QACH,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,cAAM;QAC9B,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,WAAG;QACrB,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,WAAG;QACrB,UAAU,EAAE,KAAK,CAAC,UAAU,IAAI,mBAAW;QAC3C,WAAW,EAAE,KAAK,CAAC,WAAW,IAAI,6BAAqB;KAC1D,CAAA;AACL,CAAC,CAAA;AARY,QAAA,kBAAkB,sBAQ9B;AASM,MAAM,uBAAuB,GAAG,CAAC,KAAoC,EAAuB,EAAE;IACjG,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,GAAG,KAAK,CAAC;IAC7E,IAAI,eAAe,IAAI,CAAC,UAAU,EAAE,CAAC;QACjC,OAAO;YACH,MAAM,EAAE,cAAM;YACd,KAAK,EAAE,uDAAuD;SACjE,CAAC;IACN,CAAC;IAED,IAAI,gBAAgB,IAAI,CAAC,WAAW,EAAE,CAAC;QACnC,OAAO;YACH,MAAM,EAAE,cAAM;YACd,KAAK,EAAE,kEAAkE;SAC5E,CAAC;IACN,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC,CAAA;AAjBY,QAAA,uBAAuB,2BAiBnC"}
|
package/dist/wrapper/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Generic wrapper functions for multi-database operations
|
|
3
3
|
*/
|
|
4
|
-
import { IConnectionResult, IRetrieveResult, TDatabaseEngine } from '../
|
|
4
|
+
import { IConnectionResult, IRetrieveResult, TDatabaseEngine, IDatabaseSetting, ICreateResult, IQuery, IQueryResult, IUpsertResult } from '../util';
|
|
5
5
|
export interface IConnectionProps {
|
|
6
6
|
engine?: TDatabaseEngine;
|
|
7
7
|
uri?: string;
|
|
@@ -13,12 +13,9 @@ export interface IConnectionProps {
|
|
|
13
13
|
* @returns Promise<ConnectionResult>
|
|
14
14
|
*/
|
|
15
15
|
export declare function connect(props: IConnectionProps): Promise<IConnectionResult>;
|
|
16
|
-
export interface IRetrieveProps {
|
|
17
|
-
engine?: TDatabaseEngine;
|
|
18
|
-
databaseId?: string;
|
|
19
|
-
containerId?: string;
|
|
20
|
-
partitionKey?: string;
|
|
16
|
+
export interface IRetrieveProps extends IDatabaseSetting {
|
|
21
17
|
id: string;
|
|
18
|
+
partitionKey?: string;
|
|
22
19
|
}
|
|
23
20
|
/**
|
|
24
21
|
* Retrieve document by ID from any database
|
|
@@ -26,4 +23,32 @@ export interface IRetrieveProps {
|
|
|
26
23
|
* @returns Promise<IRetrieveResult>
|
|
27
24
|
*/
|
|
28
25
|
export declare const retrieve: (props: IRetrieveProps) => Promise<IRetrieveResult>;
|
|
26
|
+
export interface ICreateProps extends IDatabaseSetting {
|
|
27
|
+
record: Record<string, any>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Retrieve document by ID from any database
|
|
31
|
+
* @param props IRetrieveProps
|
|
32
|
+
* @returns Promise<IRetrieveResult>
|
|
33
|
+
*/
|
|
34
|
+
export declare const create: (props: ICreateProps) => Promise<ICreateResult>;
|
|
35
|
+
export interface IQueryProps extends IDatabaseSetting {
|
|
36
|
+
query: IQuery;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Retrieve document by ID from any database
|
|
40
|
+
* @param props IRetrieveProps
|
|
41
|
+
* @returns Promise<IRetrieveResult>
|
|
42
|
+
*/
|
|
43
|
+
export declare const query: (props: IQueryProps) => Promise<IQueryResult>;
|
|
44
|
+
export interface IUpsertProps extends IDatabaseSetting {
|
|
45
|
+
record: Record<string, any>;
|
|
46
|
+
partitionKey?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Upsert (create or update) document in any database
|
|
50
|
+
* @param props IUpsertProps
|
|
51
|
+
* @returns Promise<IUpsertResult>
|
|
52
|
+
*/
|
|
53
|
+
export declare const upsert: (props: IUpsertProps) => Promise<IUpsertResult>;
|
|
29
54
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wrapper/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":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