unconventional 2.1.0 → 2.2.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/core/base.model.js
CHANGED
|
@@ -42,7 +42,7 @@ class BaseModel extends Document {
|
|
|
42
42
|
action: db_types_1.SqlAction.Insert,
|
|
43
43
|
type: unconventional_pg_queries_1.OneOrMany.One,
|
|
44
44
|
table: this.collection,
|
|
45
|
-
conflict: (0, db_utils_1.getConflict)(this, upsertConfig?.action || unconventional_pg_queries_1.ConflictResolution.doUpdate, upsertConfig?.constraint),
|
|
45
|
+
conflict: (0, db_utils_1.getConflict)(this, upsertConfig?.action || unconventional_pg_queries_1.ConflictResolution.doUpdate, upsertConfig?.constraint, upsertConfig?.where),
|
|
46
46
|
data: this.prepareData({ ...data, ...timestamp })
|
|
47
47
|
});
|
|
48
48
|
if (!response)
|
|
@@ -59,7 +59,7 @@ class BaseModel extends Document {
|
|
|
59
59
|
action: db_types_1.SqlAction.Insert,
|
|
60
60
|
type: unconventional_pg_queries_1.OneOrMany.Many,
|
|
61
61
|
table: this.collection,
|
|
62
|
-
conflict: (0, db_utils_1.getConflict)(this, upsertConfig?.action || unconventional_pg_queries_1.ConflictResolution.doUpdate, upsertConfig?.constraint),
|
|
62
|
+
conflict: (0, db_utils_1.getConflict)(this, upsertConfig?.action || unconventional_pg_queries_1.ConflictResolution.doUpdate, upsertConfig?.constraint, upsertConfig?.where),
|
|
63
63
|
data: data.map(item => this.prepareData({ ...item, ...timestamp }))
|
|
64
64
|
});
|
|
65
65
|
if (!response)
|
|
@@ -18,6 +18,7 @@ interface DownloadResponse {
|
|
|
18
18
|
export interface UpsertConfig<M extends typeof BaseModel> {
|
|
19
19
|
constraint?: Array<keyof InstanceType<M>>;
|
|
20
20
|
action?: ConflictResolution;
|
|
21
|
+
where?: string;
|
|
21
22
|
}
|
|
22
23
|
export interface ServiceConfig<M extends typeof BaseModel> {
|
|
23
24
|
cache?: KVNamespace;
|
package/dist/utils/db.utils.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare function getOrder<T extends typeof BaseModel>(model: T, sort?: st
|
|
|
9
9
|
export declare function getPage<T extends typeof BaseModel>(model: T, cursor?: string | number): SqlPaginate | undefined;
|
|
10
10
|
/** Retrieves all non-relational fields from a model for the 'returning' clause of a SQL call */
|
|
11
11
|
export declare function getReturn<T extends typeof BaseModel>(model: T): string[];
|
|
12
|
-
export declare function getConflict<T extends typeof BaseModel>(model: T, action: ConflictResolution, constraint?: Array<keyof InstanceType<T
|
|
12
|
+
export declare function getConflict<T extends typeof BaseModel>(model: T, action: ConflictResolution, constraint?: Array<keyof InstanceType<T>>, where?: string): SqlConflict | undefined;
|
|
13
13
|
/** A type-safe way to build filter strings */
|
|
14
14
|
export declare function buildFilter<T>(field: keyof T, operator: SqlWhereOperator, value?: any): string;
|
|
15
15
|
/** Creates expansions for relational filters */
|
package/dist/utils/db.utils.js
CHANGED
|
@@ -213,14 +213,15 @@ function getReturn(model) {
|
|
|
213
213
|
return fields;
|
|
214
214
|
}
|
|
215
215
|
exports.getReturn = getReturn;
|
|
216
|
-
function getConflict(model, action, constraint) {
|
|
216
|
+
function getConflict(model, action, constraint, where) {
|
|
217
217
|
if (!constraint)
|
|
218
218
|
return undefined;
|
|
219
219
|
const indexes = model.schema.indexes;
|
|
220
220
|
for (const index of indexes) {
|
|
221
221
|
const keys = Object.keys(index.definition);
|
|
222
|
-
if ((0, array_utils_1.equalArrays)(keys, constraint))
|
|
223
|
-
return { action, constraint: keys };
|
|
222
|
+
if ((0, array_utils_1.equalArrays)(keys, constraint)) {
|
|
223
|
+
return { action, constraint: keys, where: where ?? index.options?.where };
|
|
224
|
+
}
|
|
224
225
|
}
|
|
225
226
|
return undefined;
|
|
226
227
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unconventional",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "A complete server built on Cloudflare Workers/Pages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -46,15 +46,16 @@
|
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"hono": "^4",
|
|
49
|
-
"unconventional-pg-queries": "^1.
|
|
49
|
+
"unconventional-pg-queries": "^1.8.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@cloudflare/workers-types": "^4.20231121.0",
|
|
53
53
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
54
54
|
"@typescript-eslint/parser": "^5.62.0",
|
|
55
|
+
"generate-changelog": "^1.8.0",
|
|
55
56
|
"hono": "^4",
|
|
56
57
|
"tsx": "^4.20.6",
|
|
57
58
|
"typescript": "^5.3.3",
|
|
58
|
-
"unconventional-pg-queries": "^1.
|
|
59
|
+
"unconventional-pg-queries": "^1.8.0"
|
|
59
60
|
}
|
|
60
61
|
}
|