unconventional 1.0.0 → 1.0.2
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.
|
@@ -23,7 +23,7 @@ export declare class BaseModel extends Document {
|
|
|
23
23
|
static findMany<T extends typeof BaseModel>(this: T, config?: PageConfig & FilterConfig): Promise<Array<InstanceType<T>>>;
|
|
24
24
|
static update<T extends typeof BaseModel>(this: T, id: string | number, data: Partial<InstanceType<T>>): Promise<InstanceType<T> | null>;
|
|
25
25
|
static updateMany<T extends typeof BaseModel>(this: T, data: Partial<InstanceType<T>>[]): Promise<InstanceType<T>[] | null>;
|
|
26
|
-
static delete<T extends typeof BaseModel>(this: T, id: string): Promise<InstanceType<T> | null>;
|
|
26
|
+
static delete<T extends typeof BaseModel>(this: T, id: string | number): Promise<InstanceType<T> | null>;
|
|
27
27
|
static deleteMany<T extends typeof BaseModel>(this: T, config?: FilterConfig): Promise<InstanceType<T>[] | null>;
|
|
28
28
|
static count<T extends typeof BaseModel>(this: T): Promise<number | null>;
|
|
29
29
|
static fromDatabaseJson<T extends typeof BaseModel>(this: T, json: object): InstanceType<T>;
|
package/dist/core/base.model.js
CHANGED
|
@@ -94,12 +94,15 @@ class BaseModel extends Document {
|
|
|
94
94
|
}
|
|
95
95
|
static async update(id, data) {
|
|
96
96
|
const timestamp = this.schema.timestamped ? { updatedAt: new Date() } : {};
|
|
97
|
-
|
|
97
|
+
const targetField = isNaN(+id) ? this.keyField : this.idField;
|
|
98
|
+
if (!targetField)
|
|
99
|
+
return null;
|
|
100
|
+
delete data[targetField];
|
|
98
101
|
const response = await this.db.fetch({
|
|
99
102
|
action: db_types_1.SqlAction.Update,
|
|
100
103
|
type: unconventional_pg_queries_1.OneOrMany.One,
|
|
101
104
|
table: this.collection,
|
|
102
|
-
where: [{ field:
|
|
105
|
+
where: [{ field: targetField, operator: unconventional_pg_queries_1.SqlWhereOperator.Eq, value: id }],
|
|
103
106
|
data: { ...data, ...timestamp }
|
|
104
107
|
});
|
|
105
108
|
if (!response)
|
|
@@ -120,11 +123,14 @@ class BaseModel extends Document {
|
|
|
120
123
|
return response.map(item => this.fromDatabaseJson(item));
|
|
121
124
|
}
|
|
122
125
|
static async delete(id) {
|
|
126
|
+
const targetField = isNaN(+id) ? this.keyField : this.idField;
|
|
127
|
+
if (!targetField)
|
|
128
|
+
return null;
|
|
123
129
|
const response = await this.db.fetch({
|
|
124
130
|
action: db_types_1.SqlAction.Delete,
|
|
125
131
|
type: unconventional_pg_queries_1.OneOrMany.One,
|
|
126
132
|
table: this.collection,
|
|
127
|
-
where: [{ field:
|
|
133
|
+
where: [{ field: targetField, operator: unconventional_pg_queries_1.SqlWhereOperator.Eq, value: id }]
|
|
128
134
|
});
|
|
129
135
|
if (!response)
|
|
130
136
|
return null;
|
|
@@ -40,7 +40,7 @@ export declare class BaseService<M extends typeof BaseModel> {
|
|
|
40
40
|
* @param data - An object containing all the fields to be modified and their new values.
|
|
41
41
|
* @returns The updated document.
|
|
42
42
|
*/
|
|
43
|
-
update(identifier: string, data: Partial<InstanceType<M>>, config?: ServiceConfig<M>): Promise<InstanceType<M>>;
|
|
43
|
+
update(identifier: string | number, data: Partial<InstanceType<M>>, config?: ServiceConfig<M>): Promise<InstanceType<M>>;
|
|
44
44
|
/**
|
|
45
45
|
* Patches all fields provided in the array of documents. Certain fields may be restricted.
|
|
46
46
|
* @param data - An array of objects containing all the fields to be modified and their new values.
|
|
@@ -49,10 +49,10 @@ export declare class BaseService<M extends typeof BaseModel> {
|
|
|
49
49
|
updateMany(data: Partial<InstanceType<M>>[], config?: ServiceConfig<M>): Promise<InstanceType<M>[]>;
|
|
50
50
|
/**
|
|
51
51
|
* Deletes the document with the given identifier.
|
|
52
|
-
* @param identifier - The id or key of a document. If type is
|
|
52
|
+
* @param identifier - The id or key of a document. If type is number, lookup will be done with the model's idColumn. Otherwise, keyColumn is used.
|
|
53
53
|
* @returns The deleted document.
|
|
54
54
|
*/
|
|
55
|
-
delete(identifier: string, config?: ServiceConfig<M>): Promise<InstanceType<M>>;
|
|
55
|
+
delete(identifier: string | number, config?: ServiceConfig<M>): Promise<InstanceType<M>>;
|
|
56
56
|
/**
|
|
57
57
|
* Deletes the documents identified by config.filter.
|
|
58
58
|
* @returns An array of the deleted documents.
|
|
@@ -138,7 +138,7 @@ class BaseService {
|
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
140
140
|
* Deletes the document with the given identifier.
|
|
141
|
-
* @param identifier - The id or key of a document. If type is
|
|
141
|
+
* @param identifier - The id or key of a document. If type is number, lookup will be done with the model's idColumn. Otherwise, keyColumn is used.
|
|
142
142
|
* @returns The deleted document.
|
|
143
143
|
*/
|
|
144
144
|
async delete(identifier, config) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="@cloudflare/workers-types" />
|
|
2
|
-
import { Handler, Input } from "hono";
|
|
2
|
+
import { Handler, Input, Env as HonoEnv } from "hono";
|
|
3
3
|
export declare enum Query {
|
|
4
4
|
Expand = "expand"
|
|
5
5
|
}
|
|
@@ -22,7 +22,7 @@ export type Variables = {
|
|
|
22
22
|
[BaseEnvKey.ownerId]?: number;
|
|
23
23
|
[BaseEnvKey.isPrivileged]?: boolean;
|
|
24
24
|
};
|
|
25
|
-
export type Env<V extends object = {}, B extends object = {}> = {
|
|
25
|
+
export type Env<V extends object = {}, B extends object = {}> = HonoEnv & {
|
|
26
26
|
Bindings: Bindings & B;
|
|
27
27
|
Variables: Variables & V;
|
|
28
28
|
};
|