tauri-plugin-mongoose 0.2.1 → 0.2.4

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 CHANGED
@@ -56,7 +56,11 @@ interface ConnectOptions {
56
56
  url: string;
57
57
  dbName?: string;
58
58
  }
59
- declare function connect(options: ConnectOptions): Promise<void>;
60
- declare function connect(url: string, dbName?: string): Promise<void>;
59
+ interface ConnectCallbacks {
60
+ onSuccess?: () => void;
61
+ onError?: (error: string) => void;
62
+ }
63
+ declare function connect(options: ConnectOptions, callbacks?: ConnectCallbacks): Promise<void>;
64
+ declare function connect(url: string, dbName?: string, callbacks?: ConnectCallbacks): Promise<void>;
61
65
 
62
- export { type ConnectOptions, type InferSchemaType, Model, type Schema, type SchemaItem, type SchemaTypes, type TypeMap, connect };
66
+ export { type ConnectCallbacks, type ConnectOptions, type InferSchemaType, Model, type Schema, type SchemaItem, type SchemaTypes, type TypeMap, connect };
package/dist/index.d.ts CHANGED
@@ -56,7 +56,11 @@ interface ConnectOptions {
56
56
  url: string;
57
57
  dbName?: string;
58
58
  }
59
- declare function connect(options: ConnectOptions): Promise<void>;
60
- declare function connect(url: string, dbName?: string): Promise<void>;
59
+ interface ConnectCallbacks {
60
+ onSuccess?: () => void;
61
+ onError?: (error: string) => void;
62
+ }
63
+ declare function connect(options: ConnectOptions, callbacks?: ConnectCallbacks): Promise<void>;
64
+ declare function connect(url: string, dbName?: string, callbacks?: ConnectCallbacks): Promise<void>;
61
65
 
62
- export { type ConnectOptions, type InferSchemaType, Model, type Schema, type SchemaItem, type SchemaTypes, type TypeMap, connect };
66
+ export { type ConnectCallbacks, type ConnectOptions, type InferSchemaType, Model, type Schema, type SchemaItem, type SchemaTypes, type TypeMap, connect };
package/dist/index.js CHANGED
@@ -142,11 +142,30 @@ var Model = class {
142
142
  };
143
143
 
144
144
  // index.ts
145
- async function connect(urlOrOptions, dbName) {
145
+ async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
146
+ let url;
147
+ let dbName;
148
+ let cbs;
146
149
  if (typeof urlOrOptions === "string") {
147
- await (0, import_core2.invoke)("plugin:mongoose|connect", { url: urlOrOptions, dbName });
150
+ url = urlOrOptions;
151
+ if (typeof dbNameOrCallbacks === "string") {
152
+ dbName = dbNameOrCallbacks;
153
+ cbs = callbacks;
154
+ } else {
155
+ cbs = dbNameOrCallbacks;
156
+ }
148
157
  } else {
149
- await (0, import_core2.invoke)("plugin:mongoose|connect", { url: urlOrOptions.url, dbName: urlOrOptions.dbName });
158
+ url = urlOrOptions.url;
159
+ dbName = urlOrOptions.dbName;
160
+ cbs = dbNameOrCallbacks;
161
+ }
162
+ try {
163
+ await (0, import_core2.invoke)("plugin:mongoose|connect", { url, dbName });
164
+ cbs?.onSuccess?.();
165
+ } catch (error) {
166
+ const errorMessage = error instanceof Error ? error.message : String(error);
167
+ cbs?.onError?.(errorMessage);
168
+ throw error;
150
169
  }
151
170
  }
152
171
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -117,11 +117,30 @@ var Model = class {
117
117
  };
118
118
 
119
119
  // index.ts
120
- async function connect(urlOrOptions, dbName) {
120
+ async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
121
+ let url;
122
+ let dbName;
123
+ let cbs;
121
124
  if (typeof urlOrOptions === "string") {
122
- await invoke2("plugin:mongoose|connect", { url: urlOrOptions, dbName });
125
+ url = urlOrOptions;
126
+ if (typeof dbNameOrCallbacks === "string") {
127
+ dbName = dbNameOrCallbacks;
128
+ cbs = callbacks;
129
+ } else {
130
+ cbs = dbNameOrCallbacks;
131
+ }
123
132
  } else {
124
- await invoke2("plugin:mongoose|connect", { url: urlOrOptions.url, dbName: urlOrOptions.dbName });
133
+ url = urlOrOptions.url;
134
+ dbName = urlOrOptions.dbName;
135
+ cbs = dbNameOrCallbacks;
136
+ }
137
+ try {
138
+ await invoke2("plugin:mongoose|connect", { url, dbName });
139
+ cbs?.onSuccess?.();
140
+ } catch (error) {
141
+ const errorMessage = error instanceof Error ? error.message : String(error);
142
+ cbs?.onError?.(errorMessage);
143
+ throw error;
125
144
  }
126
145
  }
127
146
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tauri-plugin-mongoose",
3
- "version": "0.2.1",
3
+ "version": "0.2.4",
4
4
  "description": "Tauri plugin for MongoDB/Mongoose-like database operations",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",