@encodeagent/platform-helper-data 1.2510.1041539 → 1.2510.1231638
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/{azure-cosmosdb → cosmosdb}/index.d.ts +5 -3
- package/dist/cosmosdb/index.d.ts.map +1 -0
- package/dist/{azure-cosmosdb → cosmosdb}/index.js +84 -8
- 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/{aws-dynamodb → dynamodb}/index.d.ts +3 -2
- package/dist/dynamodb/index.d.ts.map +1 -0
- package/dist/{aws-dynamodb → dynamodb}/index.js +40 -2
- package/dist/dynamodb/index.js.map +1 -0
- package/dist/firestore/index.d.ts +8 -0
- package/dist/firestore/index.d.ts.map +1 -0
- package/dist/firestore/index.js +48 -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 +12 -0
- package/dist/mongodb/index.d.ts.map +1 -0
- package/dist/mongodb/index.js +156 -0
- package/dist/mongodb/index.js.map +1 -0
- package/dist/util.d.ts +112 -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 +21 -6
- package/dist/wrapper/index.d.ts.map +1 -1
- package/dist/wrapper/index.js +143 -46
- package/dist/wrapper/index.js.map +1 -1
- package/package.json +4 -5
- package/dist/aws-dynamodb/index.d.ts.map +0 -1
- package/dist/aws-dynamodb/index.js.map +0 -1
- package/dist/azure-cosmosdb/index.d.ts.map +0 -1
- 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,156 @@
|
|
|
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
|
+
const mongo_sdk_1 = require("mongo-sdk");
|
|
10
|
+
const platform_helper_util_1 = require("@encodeagent/platform-helper-util");
|
|
11
|
+
const ENGINE = "mongodb";
|
|
12
|
+
async function connect(props) {
|
|
13
|
+
try {
|
|
14
|
+
const { uri } = props;
|
|
15
|
+
if (!uri) {
|
|
16
|
+
return {
|
|
17
|
+
engine: ENGINE,
|
|
18
|
+
error: 'MongoDB URI is required'
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const client = new mongo_sdk_1.MongoClient(uri);
|
|
22
|
+
await client.connect();
|
|
23
|
+
return {
|
|
24
|
+
engine: ENGINE,
|
|
25
|
+
client
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return {
|
|
30
|
+
engine: ENGINE,
|
|
31
|
+
error: error instanceof Error ? error.message : 'Failed to connect to MongoDB'
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function retrieve(props) {
|
|
36
|
+
try {
|
|
37
|
+
const { client, id, databaseId, containerId } = props;
|
|
38
|
+
if (!databaseId) {
|
|
39
|
+
return {
|
|
40
|
+
engine: ENGINE,
|
|
41
|
+
error: 'The databaseId or process.env.DATABASE_ID is required'
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (!containerId) {
|
|
45
|
+
return {
|
|
46
|
+
engine: ENGINE,
|
|
47
|
+
error: 'The containerId or process.env.DATABASE_CONTAINER_ID is required'
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const db = client.db(databaseId);
|
|
51
|
+
const collection = db.collection(containerId);
|
|
52
|
+
// Try _id as ObjectId first
|
|
53
|
+
let doc = null;
|
|
54
|
+
if (mongo_sdk_1.ObjectId.isValid(id)) {
|
|
55
|
+
doc = await collection.findOne({ _id: new mongo_sdk_1.ObjectId(id) });
|
|
56
|
+
}
|
|
57
|
+
// Fallback to id field or string _id
|
|
58
|
+
if (!doc) {
|
|
59
|
+
doc = await collection.findOne({ id }) || await collection.findOne({ _id: id });
|
|
60
|
+
}
|
|
61
|
+
const data = (doc ?? undefined);
|
|
62
|
+
return {
|
|
63
|
+
engine: ENGINE,
|
|
64
|
+
data
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
return {
|
|
69
|
+
engine: ENGINE,
|
|
70
|
+
error: error instanceof Error ? error.message : 'Failed to retrieve document from MongoDB'
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Query documents from MongoDB collection
|
|
76
|
+
* Uses same connection shape as retrieve, with optional filter, sort, and limit.
|
|
77
|
+
*/
|
|
78
|
+
// { filter ?: Record<string, any>; sort ?: Record<string, 1 | -1>; limit ?: number; }
|
|
79
|
+
// export async function query(props: IQueryProps): Promise<IQueryResult> {
|
|
80
|
+
// try {
|
|
81
|
+
// const { client, databaseId, containerId, query } = props;
|
|
82
|
+
// if (!databaseId) {
|
|
83
|
+
// return {
|
|
84
|
+
// engine: ENGINE,
|
|
85
|
+
// error: 'The databaseId or process.env.DATABASE_ID is required'
|
|
86
|
+
// };
|
|
87
|
+
// }
|
|
88
|
+
// if (!containerId) {
|
|
89
|
+
// return {
|
|
90
|
+
// engine: ENGINE,
|
|
91
|
+
// error: 'The containerId or process.env.DATABASE_CONTAINER_ID is required'
|
|
92
|
+
// };
|
|
93
|
+
// }
|
|
94
|
+
// const db = client.db(databaseId);
|
|
95
|
+
// const collection = db.collection(containerId);
|
|
96
|
+
// const { filter, sort, limit } = query;
|
|
97
|
+
// let cursor = collection.find(filter ?? {});
|
|
98
|
+
// if (sort && Object.keys(sort).length) {
|
|
99
|
+
// cursor = cursor.sort(sort as any);
|
|
100
|
+
// }
|
|
101
|
+
// if (typeof limit === 'number' && limit > 0) {
|
|
102
|
+
// cursor = cursor.limit(limit);
|
|
103
|
+
// }
|
|
104
|
+
// const items = await cursor.toArray();
|
|
105
|
+
// return {
|
|
106
|
+
// engine: ENGINE,
|
|
107
|
+
// data: items
|
|
108
|
+
// };
|
|
109
|
+
// } catch (error) {
|
|
110
|
+
// return {
|
|
111
|
+
// engine: ENGINE,
|
|
112
|
+
// error: error instanceof Error ? error.message : 'Failed to query documents from MongoDB'
|
|
113
|
+
// };
|
|
114
|
+
// }
|
|
115
|
+
// }
|
|
116
|
+
async function create(props) {
|
|
117
|
+
try {
|
|
118
|
+
const { client, databaseId, containerId, record } = props;
|
|
119
|
+
if (!databaseId) {
|
|
120
|
+
return {
|
|
121
|
+
engine: ENGINE,
|
|
122
|
+
error: 'The databaseId or process.env.DATABASE_ID is required'
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (!containerId) {
|
|
126
|
+
return {
|
|
127
|
+
engine: ENGINE,
|
|
128
|
+
error: 'The containerId or process.env.DATABASE_CONTAINER_ID is required'
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (!record) {
|
|
132
|
+
return {
|
|
133
|
+
engine: ENGINE,
|
|
134
|
+
error: 'The record is required'
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const db = client.db(databaseId);
|
|
138
|
+
const collection = db.collection(containerId);
|
|
139
|
+
const item = {
|
|
140
|
+
...record,
|
|
141
|
+
id: record.id ?? (0, platform_helper_util_1.newGuid)()
|
|
142
|
+
};
|
|
143
|
+
await collection.insertOne(item);
|
|
144
|
+
return {
|
|
145
|
+
engine: ENGINE,
|
|
146
|
+
data: item
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
return {
|
|
151
|
+
engine: ENGINE,
|
|
152
|
+
error: error instanceof Error ? error.message : 'Failed to create record in MongoDB'
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mongodb/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAaH,0BAyBC;AAGD,4BA4CC;AAuDD,wBA8CC;AAlLD,yCAAkD;AAClD,4EAA4D;AAE5D,MAAM,MAAM,GAAG,SAAS,CAAC;AAElB,KAAK,UAAU,OAAO,CAAC,KAAiC;IAC3D,IAAI,CAAC;QACD,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;QAEtB,IAAI,CAAC,GAAG,EAAE,CAAC;YACP,OAAO;gBACH,MAAM,EAAE,MAAM;gBACd,KAAK,EAAE,yBAAyB;aACnC,CAAC;QACN,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,uBAAW,CAAC,GAAG,CAAC,CAAC;QACpC,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;QAEvB,OAAO;YACH,MAAM,EAAE,MAAM;YACd,MAAM;SACT,CAAC;IAEN,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,8BAA8B;SACjF,CAAC;IACN,CAAC;AACL,CAAC;AAGM,KAAK,UAAU,QAAQ,CAAC,KAAqB;IAChD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;YACT,GAAG,MAAM;YACT,EAAE,EAAG,MAAc,CAAC,EAAE,IAAI,IAAA,8BAAO,GAAE;SACf,CAAC;QAEzB,MAAM,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAEjC,OAAO;YACH,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI;SACb,CAAC;IAEN,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,oCAAoC;SACvF,CAAC;IACN,CAAC;AACL,CAAC"}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
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 IDatabaseSetting {
|
|
69
|
+
engine: TDatabaseEngine;
|
|
70
|
+
uri?: string;
|
|
71
|
+
key?: string;
|
|
72
|
+
databaseId?: string;
|
|
73
|
+
containerId?: string;
|
|
74
|
+
}
|
|
75
|
+
export declare const getDatabaseSetting: (props: IDatabaseSetting & {
|
|
76
|
+
[key: string]: any;
|
|
77
|
+
}) => IDatabaseSetting;
|
|
78
|
+
export interface IValidateDatabaseSettingProps {
|
|
79
|
+
databaseId?: string;
|
|
80
|
+
containerId?: string;
|
|
81
|
+
checkDatabaseId?: boolean;
|
|
82
|
+
checkContainerId?: boolean;
|
|
83
|
+
}
|
|
84
|
+
export declare const validateDatabaseSetting: (props: IValidateDatabaseSettingProps) => IErrorResult | null;
|
|
85
|
+
export interface ISimpleFilter {
|
|
86
|
+
name: string;
|
|
87
|
+
op: "=" | "!=" | "<" | "<=" | ">" | ">=" | "IN" | "BETWEEN" | "LIKE" | "CONTAINS" | "STARTSWITH" | "ENDSWITH";
|
|
88
|
+
value: any;
|
|
89
|
+
}
|
|
90
|
+
export interface IGroupFilter {
|
|
91
|
+
op: "AND" | "OR" | "NOT";
|
|
92
|
+
filters: Array<ISimpleFilter | IGroupFilter>;
|
|
93
|
+
}
|
|
94
|
+
export interface IOrderBy {
|
|
95
|
+
name: string;
|
|
96
|
+
direction?: "ASC" | "DESC";
|
|
97
|
+
}
|
|
98
|
+
export interface IQuery {
|
|
99
|
+
attributes?: string[];
|
|
100
|
+
distinct?: boolean;
|
|
101
|
+
top?: number;
|
|
102
|
+
orderBy?: IOrderBy[];
|
|
103
|
+
filter?: ISimpleFilter | IGroupFilter | any;
|
|
104
|
+
page?: number;
|
|
105
|
+
pageSize?: number;
|
|
106
|
+
}
|
|
107
|
+
export interface IQueryResult extends IErrorResult {
|
|
108
|
+
query: IQuery;
|
|
109
|
+
dbQuery?: Record<string, any>;
|
|
110
|
+
data?: Record<string, any>[];
|
|
111
|
+
}
|
|
112
|
+
//# 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,CAA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AAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GACpC,IAAI,GAAG,SAAS,GAAG,MAAM,GACzB,UAAU,GAAG,YAAY,GAAG,UAAU,CAAC;IACzC,KAAK,EAAE,GAAG,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IACzB,EAAE,EAAE,KAAK,GAAG,IAAI,GAAG,KAAK,CAAC;IACzB,OAAO,EAAE,KAAK,CAAC,aAAa,GAAG,YAAY,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,MAAM;IACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,aAAa,GAAG,YAAY,GAAG,GAAG,CAAC;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAa,SAAQ,YAAY;IAC9C,KAAK,EAAE,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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E,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 } 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,22 @@ 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>;
|
|
29
44
|
//# 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":["../../src/wrapper/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,iBAAiB,EAAE,eAAe,EAAE,eAAe,EAGnD,gBAAgB,EAAsB,aAAa,EACnD,MAAM,EAAkC,YAAY,EACvD,MAAM,SAAS,CAAC;AAUjB,MAAM,WAAW,gBAAgB;IAC7B,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CAChB;AAGD;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA+DjF;AAGD,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACpD,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAU,OAAO,cAAc,KAAG,OAAO,CAAC,eAAe,CAmD7E,CAAA;AAID,MAAM,WAAW,YAAa,SAAQ,gBAAgB;IAClD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC9B;AAED;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAAU,OAAO,YAAY,KAAG,OAAO,CAAC,aAAa,CAoDvE,CAAA;AAGD,MAAM,WAAW,WAAY,SAAQ,gBAAgB;IACjD,KAAK,EAAE,MAAM,CAAA;CAChB;AAED;;;;GAIG;AACH,eAAO,MAAM,KAAK,GAAU,OAAO,WAAW,KAAG,OAAO,CAAC,YAAY,CAmDpE,CAAA"}
|
package/dist/wrapper/index.js
CHANGED
|
@@ -3,63 +3,58 @@
|
|
|
3
3
|
* @fileoverview Generic wrapper functions for multi-database operations
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.retrieve = void 0;
|
|
6
|
+
exports.query = exports.create = exports.retrieve = void 0;
|
|
7
7
|
exports.connect = connect;
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
8
|
+
const util_1 = require("../util");
|
|
9
|
+
const util_2 = require("../util");
|
|
10
|
+
const cosmosdb_1 = require("../cosmosdb");
|
|
11
|
+
const dynamodb_1 = require("../dynamodb");
|
|
12
|
+
const firestore_1 = require("../firestore");
|
|
13
|
+
const mongodb_1 = require("../mongodb");
|
|
14
14
|
/**
|
|
15
15
|
* Connect to database based on engine type
|
|
16
16
|
* @param props Database configuration with engine type
|
|
17
17
|
* @returns Promise<ConnectionResult>
|
|
18
18
|
*/
|
|
19
19
|
async function connect(props) {
|
|
20
|
-
const engine = props.engine ??
|
|
20
|
+
const engine = props.engine ?? util_2.ENGINE;
|
|
21
21
|
if (!props.uri) {
|
|
22
22
|
return {
|
|
23
23
|
engine,
|
|
24
24
|
error: 'The database URI is required'
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
engine,
|
|
30
|
-
error: 'The database key is required'
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
const uri = props.uri ?? types_1.URI;
|
|
34
|
-
const key = props.key ?? types_1.KEY;
|
|
27
|
+
const uri = props.uri ?? util_2.URI;
|
|
28
|
+
const key = props.key ?? util_2.KEY;
|
|
35
29
|
const connectionProps = {
|
|
36
30
|
uri,
|
|
37
31
|
key
|
|
38
32
|
};
|
|
39
|
-
let connection =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
let connection = undefined;
|
|
34
|
+
// let connection: IConnectionResult | undefined = connections[engine];
|
|
35
|
+
// if (connection) {
|
|
36
|
+
// return connection;
|
|
37
|
+
// }
|
|
43
38
|
try {
|
|
44
39
|
switch (engine) {
|
|
45
|
-
case '
|
|
40
|
+
case 'cosmosdb':
|
|
46
41
|
{
|
|
47
|
-
connection = await (0,
|
|
42
|
+
connection = await (0, cosmosdb_1.connect)(connectionProps);
|
|
48
43
|
break;
|
|
49
44
|
}
|
|
50
|
-
case '
|
|
45
|
+
case 'dynamodb':
|
|
51
46
|
{
|
|
52
|
-
connection = await (0,
|
|
47
|
+
connection = await (0, dynamodb_1.connect)(connectionProps);
|
|
53
48
|
break;
|
|
54
49
|
}
|
|
55
|
-
case '
|
|
50
|
+
case 'firestore':
|
|
56
51
|
{
|
|
57
|
-
connection = await (0,
|
|
52
|
+
connection = await (0, firestore_1.connect)(connectionProps);
|
|
58
53
|
break;
|
|
59
54
|
}
|
|
60
55
|
case 'mongodb':
|
|
61
56
|
{
|
|
62
|
-
connection = await (0,
|
|
57
|
+
connection = await (0, mongodb_1.connect)(connectionProps);
|
|
63
58
|
break;
|
|
64
59
|
}
|
|
65
60
|
default:
|
|
@@ -84,46 +79,39 @@ async function connect(props) {
|
|
|
84
79
|
* @returns Promise<IRetrieveResult>
|
|
85
80
|
*/
|
|
86
81
|
const retrieve = async (props) => {
|
|
87
|
-
const { id, partitionKey } = props;
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
const databaseId = props.databaseId ?? types_1.DATABASE_ID;
|
|
91
|
-
const containerId = props.containerId ?? types_1.DATABASE_CONTAINER_ID;
|
|
82
|
+
const { id, partitionKey, ...rest } = props;
|
|
83
|
+
const { engine, databaseId, containerId, uri, key } = (0, util_1.getDatabaseSetting)(rest);
|
|
84
|
+
const connection = await connect({ engine, uri, key });
|
|
92
85
|
if (!connection.client) {
|
|
93
86
|
return {
|
|
94
87
|
engine,
|
|
95
88
|
error: `The ${engine} client is required`
|
|
96
89
|
};
|
|
97
90
|
}
|
|
98
|
-
if (!containerId) {
|
|
99
|
-
return {
|
|
100
|
-
engine,
|
|
101
|
-
error: 'The containerId or process.env.CONTAINER_ID is required'
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
91
|
if (!id) {
|
|
105
92
|
return {
|
|
106
93
|
engine,
|
|
107
|
-
error: '
|
|
94
|
+
error: 'The id is required'
|
|
108
95
|
};
|
|
109
96
|
}
|
|
110
97
|
const retrieveProps = {
|
|
111
98
|
client: connection.client,
|
|
112
99
|
id,
|
|
100
|
+
key,
|
|
113
101
|
databaseId,
|
|
114
102
|
containerId,
|
|
115
103
|
partitionKey
|
|
116
104
|
};
|
|
117
105
|
try {
|
|
118
106
|
switch (engine) {
|
|
119
|
-
case '
|
|
120
|
-
return await (0,
|
|
121
|
-
case '
|
|
122
|
-
return await (0,
|
|
123
|
-
case '
|
|
124
|
-
return await (0,
|
|
107
|
+
case 'cosmosdb':
|
|
108
|
+
return await (0, cosmosdb_1.retrieve)(retrieveProps);
|
|
109
|
+
case 'dynamodb':
|
|
110
|
+
return await (0, dynamodb_1.retrieve)(retrieveProps);
|
|
111
|
+
case 'firestore':
|
|
112
|
+
return await (0, firestore_1.retrieve)(retrieveProps);
|
|
125
113
|
case 'mongodb':
|
|
126
|
-
return await (0,
|
|
114
|
+
return await (0, mongodb_1.retrieve)(retrieveProps);
|
|
127
115
|
default:
|
|
128
116
|
return {
|
|
129
117
|
engine,
|
|
@@ -139,4 +127,113 @@ const retrieve = async (props) => {
|
|
|
139
127
|
}
|
|
140
128
|
};
|
|
141
129
|
exports.retrieve = retrieve;
|
|
130
|
+
/**
|
|
131
|
+
* Retrieve document by ID from any database
|
|
132
|
+
* @param props IRetrieveProps
|
|
133
|
+
* @returns Promise<IRetrieveResult>
|
|
134
|
+
*/
|
|
135
|
+
const create = async (props) => {
|
|
136
|
+
const { record, ...rest } = props;
|
|
137
|
+
const { engine, databaseId, containerId, uri, key } = (0, util_1.getDatabaseSetting)(rest);
|
|
138
|
+
const connection = await connect({ engine, uri, key });
|
|
139
|
+
console.log(connection);
|
|
140
|
+
if (!connection.client) {
|
|
141
|
+
return {
|
|
142
|
+
engine,
|
|
143
|
+
error: `The ${engine} client is required`
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
if (!record) {
|
|
147
|
+
return {
|
|
148
|
+
engine,
|
|
149
|
+
error: 'The record is required'
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const createProps = {
|
|
153
|
+
client: connection.client,
|
|
154
|
+
record,
|
|
155
|
+
key,
|
|
156
|
+
databaseId,
|
|
157
|
+
containerId
|
|
158
|
+
};
|
|
159
|
+
try {
|
|
160
|
+
switch (engine) {
|
|
161
|
+
case 'cosmosdb':
|
|
162
|
+
return await (0, cosmosdb_1.create)(createProps);
|
|
163
|
+
case 'dynamodb':
|
|
164
|
+
return await (0, dynamodb_1.create)(createProps);
|
|
165
|
+
case 'firestore':
|
|
166
|
+
return await (0, firestore_1.create)(createProps);
|
|
167
|
+
case 'mongodb':
|
|
168
|
+
return await (0, mongodb_1.create)(createProps);
|
|
169
|
+
default:
|
|
170
|
+
return {
|
|
171
|
+
engine,
|
|
172
|
+
error: 'Invalid engine type'
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
return {
|
|
178
|
+
engine,
|
|
179
|
+
error: error instanceof Error ? error.message : 'Unknown error occurred'
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
exports.create = create;
|
|
184
|
+
/**
|
|
185
|
+
* Retrieve document by ID from any database
|
|
186
|
+
* @param props IRetrieveProps
|
|
187
|
+
* @returns Promise<IRetrieveResult>
|
|
188
|
+
*/
|
|
189
|
+
const query = async (props) => {
|
|
190
|
+
const { query, ...rest } = props;
|
|
191
|
+
let dbQuery = undefined;
|
|
192
|
+
const { engine, databaseId, containerId, uri, key } = (0, util_1.getDatabaseSetting)(rest);
|
|
193
|
+
const connection = await connect({ engine, uri, key });
|
|
194
|
+
if (!connection.client) {
|
|
195
|
+
return {
|
|
196
|
+
engine,
|
|
197
|
+
query,
|
|
198
|
+
dbQuery,
|
|
199
|
+
error: `The ${engine} client is required`
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const queryProps = {
|
|
203
|
+
client: connection.client,
|
|
204
|
+
query,
|
|
205
|
+
key,
|
|
206
|
+
databaseId,
|
|
207
|
+
containerId
|
|
208
|
+
};
|
|
209
|
+
try {
|
|
210
|
+
switch (engine) {
|
|
211
|
+
case 'cosmosdb':
|
|
212
|
+
return await (0, cosmosdb_1.query)(queryProps);
|
|
213
|
+
// case 'dynamodb':
|
|
214
|
+
// return await createFromAWS(createProps);
|
|
215
|
+
// case 'firestore':
|
|
216
|
+
// return await createFromGCP(createProps);
|
|
217
|
+
// case 'mongodb':
|
|
218
|
+
// return await createFromMongo(createProps);
|
|
219
|
+
default:
|
|
220
|
+
return {
|
|
221
|
+
engine,
|
|
222
|
+
query,
|
|
223
|
+
dbQuery,
|
|
224
|
+
error: 'Invalid engine type'
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
return {
|
|
230
|
+
engine,
|
|
231
|
+
data: [],
|
|
232
|
+
query,
|
|
233
|
+
dbQuery,
|
|
234
|
+
error: error instanceof Error ? error.message : 'Unknown error occurred'
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
exports.query = query;
|
|
142
239
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/wrapper/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/wrapper/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AA8BH,0BA+DC;AA3FD,kCAMiB;AACjB,kCAA2C;AAE3C,0CAAyI;AACzI,0CAA0G;AAC1G,4CAA2G;AAC3G,wCAA+G;AAW/G;;;;GAIG;AACI,KAAK,UAAU,OAAO,CAAC,KAAuB;IACjD,MAAM,MAAM,GAAoB,KAAK,CAAC,MAAM,IAAI,aAAM,CAAC;IAEvD,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QACb,OAAO;YACH,MAAM;YACN,KAAK,EAAE,8BAA8B;SACxC,CAAC;IACN,CAAC;IAED,MAAM,GAAG,GAAW,KAAK,CAAC,GAAG,IAAI,UAAG,CAAC;IACrC,MAAM,GAAG,GAAuB,KAAK,CAAC,GAAG,IAAI,UAAG,CAAC;IAEjD,MAAM,eAAe,GAA+B;QAChD,GAAG;QACH,GAAG;KACN,CAAC;IAEF,IAAI,UAAU,GAAkC,SAAS,CAAC;IAE1D,uEAAuE;IAEvE,oBAAoB;IACpB,yBAAyB;IACzB,IAAI;IAEJ,IAAI,CAAC;QACD,QAAQ,MAAM,EAAE,CAAC;YACb,KAAK,UAAU;gBACX,CAAC;oBACG,UAAU,GAAG,MAAM,IAAA,kBAAY,EAAC,eAAe,CAAC,CAAC;oBACjD,MAAM;gBACV,CAAC;YACL,KAAK,UAAU;gBACX,CAAC;oBACG,UAAU,GAAG,MAAM,IAAA,kBAAU,EAAC,eAAe,CAAC,CAAC;oBAC/C,MAAM;gBACV,CAAC;YACL,KAAK,WAAW;gBACZ,CAAC;oBACG,UAAU,GAAG,MAAM,IAAA,mBAAU,EAAC,eAAe,CAAC,CAAC;oBAC/C,MAAM;gBACV,CAAC;YACL,KAAK,SAAS;gBACV,CAAC;oBACG,U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