tauri-plugin-mongoose 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/dist/index.d.mts +10 -4
- package/dist/index.d.ts +10 -4
- package/dist/index.js +16 -2
- package/dist/index.mjs +16 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -22,6 +22,7 @@ interface SchemaItem {
|
|
|
22
22
|
required?: boolean;
|
|
23
23
|
unique?: boolean;
|
|
24
24
|
ref?: string;
|
|
25
|
+
schema?: Schema;
|
|
25
26
|
}
|
|
26
27
|
interface Schema {
|
|
27
28
|
[key: string]: SchemaItem;
|
|
@@ -37,10 +38,11 @@ type TypeMap = {
|
|
|
37
38
|
buffer: Uint8Array;
|
|
38
39
|
mixed: any;
|
|
39
40
|
};
|
|
41
|
+
type InferType<T extends SchemaItem> = T['type'] extends 'object' ? (T['schema'] extends Schema ? InferSchemaType<T['schema']> : object) : TypeMap[T['type']];
|
|
40
42
|
type InferSchemaType<T extends Schema> = {
|
|
41
|
-
[K in keyof T]?: T[K]['required'] extends true ?
|
|
43
|
+
[K in keyof T]?: T[K]['required'] extends true ? InferType<T[K]> : InferType<T[K]> | undefined;
|
|
42
44
|
} & {
|
|
43
|
-
[K in keyof T as T[K]['required'] extends true ? K : never]-?:
|
|
45
|
+
[K in keyof T as T[K]['required'] extends true ? K : never]-?: InferType<T[K]>;
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
declare class Model {
|
|
@@ -48,7 +50,8 @@ declare class Model {
|
|
|
48
50
|
schema: Schema;
|
|
49
51
|
constructor(name: string, schema: Schema);
|
|
50
52
|
getById(id: string): Promise<InferSchemaType<typeof this.schema>>;
|
|
51
|
-
validate(doc: InferSchemaType<typeof this.schema>): Promise<
|
|
53
|
+
validate(doc: InferSchemaType<typeof this.schema>): Promise<any>;
|
|
54
|
+
_validate(doc: any, schema: Schema): Promise<any>;
|
|
52
55
|
find(filter?: object, options?: {
|
|
53
56
|
limit?: number;
|
|
54
57
|
skip?: number;
|
|
@@ -60,6 +63,9 @@ declare class Model {
|
|
|
60
63
|
sort?: object;
|
|
61
64
|
}): Promise<InferSchemaType<typeof this.schema> | null>;
|
|
62
65
|
create(doc: InferSchemaType<typeof this.schema>): Promise<InferSchemaType<typeof this.schema>>;
|
|
66
|
+
updateOne(filter: object, update: object, options?: {
|
|
67
|
+
upsert?: boolean;
|
|
68
|
+
}): Promise<any>;
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
interface ConnectOptions {
|
|
@@ -102,4 +108,4 @@ declare function createUser(options: CreateUserOptions): Promise<{
|
|
|
102
108
|
ok: number;
|
|
103
109
|
}>;
|
|
104
110
|
|
|
105
|
-
export { type ConnectCallbacks, type ConnectOptions, type CreateUserOptions, type InferSchemaType, Model, type MongoDBRole, type MongoDBUser, type Schema, type SchemaItem, type SchemaTypes, type TypeMap, connect, createUser, getUser, getUsers };
|
|
111
|
+
export { type ConnectCallbacks, type ConnectOptions, type CreateUserOptions, type InferSchemaType, type InferType, Model, type MongoDBRole, type MongoDBUser, type Schema, type SchemaItem, type SchemaTypes, type TypeMap, connect, createUser, getUser, getUsers };
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ interface SchemaItem {
|
|
|
22
22
|
required?: boolean;
|
|
23
23
|
unique?: boolean;
|
|
24
24
|
ref?: string;
|
|
25
|
+
schema?: Schema;
|
|
25
26
|
}
|
|
26
27
|
interface Schema {
|
|
27
28
|
[key: string]: SchemaItem;
|
|
@@ -37,10 +38,11 @@ type TypeMap = {
|
|
|
37
38
|
buffer: Uint8Array;
|
|
38
39
|
mixed: any;
|
|
39
40
|
};
|
|
41
|
+
type InferType<T extends SchemaItem> = T['type'] extends 'object' ? (T['schema'] extends Schema ? InferSchemaType<T['schema']> : object) : TypeMap[T['type']];
|
|
40
42
|
type InferSchemaType<T extends Schema> = {
|
|
41
|
-
[K in keyof T]?: T[K]['required'] extends true ?
|
|
43
|
+
[K in keyof T]?: T[K]['required'] extends true ? InferType<T[K]> : InferType<T[K]> | undefined;
|
|
42
44
|
} & {
|
|
43
|
-
[K in keyof T as T[K]['required'] extends true ? K : never]-?:
|
|
45
|
+
[K in keyof T as T[K]['required'] extends true ? K : never]-?: InferType<T[K]>;
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
declare class Model {
|
|
@@ -48,7 +50,8 @@ declare class Model {
|
|
|
48
50
|
schema: Schema;
|
|
49
51
|
constructor(name: string, schema: Schema);
|
|
50
52
|
getById(id: string): Promise<InferSchemaType<typeof this.schema>>;
|
|
51
|
-
validate(doc: InferSchemaType<typeof this.schema>): Promise<
|
|
53
|
+
validate(doc: InferSchemaType<typeof this.schema>): Promise<any>;
|
|
54
|
+
_validate(doc: any, schema: Schema): Promise<any>;
|
|
52
55
|
find(filter?: object, options?: {
|
|
53
56
|
limit?: number;
|
|
54
57
|
skip?: number;
|
|
@@ -60,6 +63,9 @@ declare class Model {
|
|
|
60
63
|
sort?: object;
|
|
61
64
|
}): Promise<InferSchemaType<typeof this.schema> | null>;
|
|
62
65
|
create(doc: InferSchemaType<typeof this.schema>): Promise<InferSchemaType<typeof this.schema>>;
|
|
66
|
+
updateOne(filter: object, update: object, options?: {
|
|
67
|
+
upsert?: boolean;
|
|
68
|
+
}): Promise<any>;
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
interface ConnectOptions {
|
|
@@ -102,4 +108,4 @@ declare function createUser(options: CreateUserOptions): Promise<{
|
|
|
102
108
|
ok: number;
|
|
103
109
|
}>;
|
|
104
110
|
|
|
105
|
-
export { type ConnectCallbacks, type ConnectOptions, type CreateUserOptions, type InferSchemaType, Model, type MongoDBRole, type MongoDBUser, type Schema, type SchemaItem, type SchemaTypes, type TypeMap, connect, createUser, getUser, getUsers };
|
|
111
|
+
export { type ConnectCallbacks, type ConnectOptions, type CreateUserOptions, type InferSchemaType, type InferType, Model, type MongoDBRole, type MongoDBUser, type Schema, type SchemaItem, type SchemaTypes, type TypeMap, connect, createUser, getUser, getUsers };
|
package/dist/index.js
CHANGED
|
@@ -88,8 +88,11 @@ var Model = class {
|
|
|
88
88
|
return this.validate(doc);
|
|
89
89
|
}
|
|
90
90
|
async validate(doc) {
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
return this._validate(doc, this.schema);
|
|
92
|
+
}
|
|
93
|
+
async _validate(doc, schema) {
|
|
94
|
+
for (const key in schema) {
|
|
95
|
+
const schemaItem = schema[key];
|
|
93
96
|
const value = doc[key];
|
|
94
97
|
if (schemaItem.required && (value === void 0 || value === null || value === "")) {
|
|
95
98
|
throw new Error(`Property ${key} is required`);
|
|
@@ -119,6 +122,9 @@ var Model = class {
|
|
|
119
122
|
if (schemaItem.type === "time" && !isTime(value)) {
|
|
120
123
|
throw new Error(`Property ${key} must be a time`);
|
|
121
124
|
}
|
|
125
|
+
if (schemaItem.type === "object" && schemaItem.schema) {
|
|
126
|
+
await this._validate(value, schemaItem.schema);
|
|
127
|
+
}
|
|
122
128
|
}
|
|
123
129
|
if (schemaItem.default && value === void 0) {
|
|
124
130
|
doc[key] = schemaItem.default();
|
|
@@ -161,6 +167,14 @@ var Model = class {
|
|
|
161
167
|
document: validatedDoc
|
|
162
168
|
});
|
|
163
169
|
}
|
|
170
|
+
async updateOne(filter, update, options = {}) {
|
|
171
|
+
return await (0, import_core.invoke)("plugin:mongoose|update_one", {
|
|
172
|
+
collection: this.name,
|
|
173
|
+
filter,
|
|
174
|
+
update,
|
|
175
|
+
options
|
|
176
|
+
});
|
|
177
|
+
}
|
|
164
178
|
};
|
|
165
179
|
|
|
166
180
|
// index.ts
|
package/dist/index.mjs
CHANGED
|
@@ -60,8 +60,11 @@ var Model = class {
|
|
|
60
60
|
return this.validate(doc);
|
|
61
61
|
}
|
|
62
62
|
async validate(doc) {
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
return this._validate(doc, this.schema);
|
|
64
|
+
}
|
|
65
|
+
async _validate(doc, schema) {
|
|
66
|
+
for (const key in schema) {
|
|
67
|
+
const schemaItem = schema[key];
|
|
65
68
|
const value = doc[key];
|
|
66
69
|
if (schemaItem.required && (value === void 0 || value === null || value === "")) {
|
|
67
70
|
throw new Error(`Property ${key} is required`);
|
|
@@ -91,6 +94,9 @@ var Model = class {
|
|
|
91
94
|
if (schemaItem.type === "time" && !isTime(value)) {
|
|
92
95
|
throw new Error(`Property ${key} must be a time`);
|
|
93
96
|
}
|
|
97
|
+
if (schemaItem.type === "object" && schemaItem.schema) {
|
|
98
|
+
await this._validate(value, schemaItem.schema);
|
|
99
|
+
}
|
|
94
100
|
}
|
|
95
101
|
if (schemaItem.default && value === void 0) {
|
|
96
102
|
doc[key] = schemaItem.default();
|
|
@@ -133,6 +139,14 @@ var Model = class {
|
|
|
133
139
|
document: validatedDoc
|
|
134
140
|
});
|
|
135
141
|
}
|
|
142
|
+
async updateOne(filter, update, options = {}) {
|
|
143
|
+
return await invoke("plugin:mongoose|update_one", {
|
|
144
|
+
collection: this.name,
|
|
145
|
+
filter,
|
|
146
|
+
update,
|
|
147
|
+
options
|
|
148
|
+
});
|
|
149
|
+
}
|
|
136
150
|
};
|
|
137
151
|
|
|
138
152
|
// index.ts
|