tauri-plugin-mongoose 0.3.5 → 0.3.8

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
@@ -68,6 +68,29 @@ declare class Model {
68
68
  }): Promise<any>;
69
69
  }
70
70
 
71
+ interface SaveFileOptions {
72
+ filename?: string;
73
+ metadata?: Record<string, unknown>;
74
+ chunkSizeBytes?: number;
75
+ }
76
+ interface SaveFileResult {
77
+ _id: unknown;
78
+ filename?: string;
79
+ length?: number;
80
+ chunkSizeBytes?: number;
81
+ uploadDate?: string;
82
+ bucket: string;
83
+ metadata?: Record<string, unknown>;
84
+ }
85
+ type BinaryLike = ArrayBuffer | ArrayBufferView | number[] | Blob;
86
+ declare class Files {
87
+ name: string;
88
+ constructor(name: string);
89
+ savePath(path: string, options?: SaveFileOptions): Promise<SaveFileResult>;
90
+ save(data: BinaryLike, options?: SaveFileOptions): Promise<SaveFileResult>;
91
+ private toBytes;
92
+ }
93
+
71
94
  interface ConnectOptions {
72
95
  url: string;
73
96
  dbName?: string;
@@ -108,4 +131,4 @@ declare function createUser(options: CreateUserOptions): Promise<{
108
131
  ok: number;
109
132
  }>;
110
133
 
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 };
134
+ export { type ConnectCallbacks, type ConnectOptions, type CreateUserOptions, Files, type InferSchemaType, type InferType, Model, type MongoDBRole, type MongoDBUser, type SaveFileOptions, type SaveFileResult, type Schema, type SchemaItem, type SchemaTypes, type TypeMap, connect, createUser, getUser, getUsers };
package/dist/index.d.ts CHANGED
@@ -68,6 +68,29 @@ declare class Model {
68
68
  }): Promise<any>;
69
69
  }
70
70
 
71
+ interface SaveFileOptions {
72
+ filename?: string;
73
+ metadata?: Record<string, unknown>;
74
+ chunkSizeBytes?: number;
75
+ }
76
+ interface SaveFileResult {
77
+ _id: unknown;
78
+ filename?: string;
79
+ length?: number;
80
+ chunkSizeBytes?: number;
81
+ uploadDate?: string;
82
+ bucket: string;
83
+ metadata?: Record<string, unknown>;
84
+ }
85
+ type BinaryLike = ArrayBuffer | ArrayBufferView | number[] | Blob;
86
+ declare class Files {
87
+ name: string;
88
+ constructor(name: string);
89
+ savePath(path: string, options?: SaveFileOptions): Promise<SaveFileResult>;
90
+ save(data: BinaryLike, options?: SaveFileOptions): Promise<SaveFileResult>;
91
+ private toBytes;
92
+ }
93
+
71
94
  interface ConnectOptions {
72
95
  url: string;
73
96
  dbName?: string;
@@ -108,4 +131,4 @@ declare function createUser(options: CreateUserOptions): Promise<{
108
131
  ok: number;
109
132
  }>;
110
133
 
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 };
134
+ export { type ConnectCallbacks, type ConnectOptions, type CreateUserOptions, Files, type InferSchemaType, type InferType, Model, type MongoDBRole, type MongoDBUser, type SaveFileOptions, type SaveFileResult, type Schema, type SchemaItem, type SchemaTypes, type TypeMap, connect, createUser, getUser, getUsers };
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ Files: () => Files,
23
24
  Model: () => Model,
24
25
  connect: () => connect,
25
26
  createUser: () => createUser,
@@ -27,7 +28,7 @@ __export(index_exports, {
27
28
  getUsers: () => getUsers
28
29
  });
29
30
  module.exports = __toCommonJS(index_exports);
30
- var import_core2 = require("@tauri-apps/api/core");
31
+ var import_core3 = require("@tauri-apps/api/core");
31
32
 
32
33
  // model/index.ts
33
34
  var import_core = require("@tauri-apps/api/core");
@@ -190,6 +191,46 @@ var Model = class {
190
191
  }
191
192
  };
192
193
 
194
+ // files/index.ts
195
+ var import_core2 = require("@tauri-apps/api/core");
196
+ var Files = class {
197
+ constructor(name) {
198
+ this.name = name;
199
+ }
200
+ async savePath(path, options = {}) {
201
+ return await (0, import_core2.invoke)("plugin:mongoose|save_file", {
202
+ collection: this.name,
203
+ path,
204
+ ...options
205
+ });
206
+ }
207
+ async save(data, options = {}) {
208
+ const bytes = await this.toBytes(data);
209
+ return await (0, import_core2.invoke)("plugin:mongoose|save_file", {
210
+ collection: this.name,
211
+ data: Array.from(bytes),
212
+ ...options
213
+ });
214
+ }
215
+ async toBytes(data) {
216
+ if (data instanceof Blob) {
217
+ const buffer = await data.arrayBuffer();
218
+ return new Uint8Array(buffer);
219
+ }
220
+ if (Array.isArray(data)) {
221
+ return Uint8Array.from(data);
222
+ }
223
+ if (data instanceof ArrayBuffer) {
224
+ return new Uint8Array(data);
225
+ }
226
+ if (ArrayBuffer.isView(data)) {
227
+ const view = data;
228
+ return new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
229
+ }
230
+ throw new Error("Unsupported data type for Files.save");
231
+ }
232
+ };
233
+
193
234
  // index.ts
194
235
  async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
195
236
  let url;
@@ -209,7 +250,7 @@ async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
209
250
  cbs = dbNameOrCallbacks;
210
251
  }
211
252
  try {
212
- await (0, import_core2.invoke)("plugin:mongoose|connect", { url, dbName });
253
+ await (0, import_core3.invoke)("plugin:mongoose|connect", { url, dbName });
213
254
  cbs?.onSuccess?.();
214
255
  } catch (error) {
215
256
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -218,16 +259,17 @@ async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
218
259
  }
219
260
  }
220
261
  async function getUsers() {
221
- return await (0, import_core2.invoke)("plugin:mongoose|get_users");
262
+ return await (0, import_core3.invoke)("plugin:mongoose|get_users");
222
263
  }
223
264
  async function getUser(username, db) {
224
- return await (0, import_core2.invoke)("plugin:mongoose|get_user", { username, db });
265
+ return await (0, import_core3.invoke)("plugin:mongoose|get_user", { username, db });
225
266
  }
226
267
  async function createUser(options) {
227
- return await (0, import_core2.invoke)("plugin:mongoose|create_db_user", { ...options });
268
+ return await (0, import_core3.invoke)("plugin:mongoose|create_db_user", { ...options });
228
269
  }
229
270
  // Annotate the CommonJS export names for ESM import in node:
230
271
  0 && (module.exports = {
272
+ Files,
231
273
  Model,
232
274
  connect,
233
275
  createUser,
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // index.ts
2
- import { invoke as invoke2 } from "@tauri-apps/api/core";
2
+ import { invoke as invoke3 } from "@tauri-apps/api/core";
3
3
 
4
4
  // model/index.ts
5
5
  import { invoke } from "@tauri-apps/api/core";
@@ -162,6 +162,46 @@ var Model = class {
162
162
  }
163
163
  };
164
164
 
165
+ // files/index.ts
166
+ import { invoke as invoke2 } from "@tauri-apps/api/core";
167
+ var Files = class {
168
+ constructor(name) {
169
+ this.name = name;
170
+ }
171
+ async savePath(path, options = {}) {
172
+ return await invoke2("plugin:mongoose|save_file", {
173
+ collection: this.name,
174
+ path,
175
+ ...options
176
+ });
177
+ }
178
+ async save(data, options = {}) {
179
+ const bytes = await this.toBytes(data);
180
+ return await invoke2("plugin:mongoose|save_file", {
181
+ collection: this.name,
182
+ data: Array.from(bytes),
183
+ ...options
184
+ });
185
+ }
186
+ async toBytes(data) {
187
+ if (data instanceof Blob) {
188
+ const buffer = await data.arrayBuffer();
189
+ return new Uint8Array(buffer);
190
+ }
191
+ if (Array.isArray(data)) {
192
+ return Uint8Array.from(data);
193
+ }
194
+ if (data instanceof ArrayBuffer) {
195
+ return new Uint8Array(data);
196
+ }
197
+ if (ArrayBuffer.isView(data)) {
198
+ const view = data;
199
+ return new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
200
+ }
201
+ throw new Error("Unsupported data type for Files.save");
202
+ }
203
+ };
204
+
165
205
  // index.ts
166
206
  async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
167
207
  let url;
@@ -181,7 +221,7 @@ async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
181
221
  cbs = dbNameOrCallbacks;
182
222
  }
183
223
  try {
184
- await invoke2("plugin:mongoose|connect", { url, dbName });
224
+ await invoke3("plugin:mongoose|connect", { url, dbName });
185
225
  cbs?.onSuccess?.();
186
226
  } catch (error) {
187
227
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -190,15 +230,16 @@ async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
190
230
  }
191
231
  }
192
232
  async function getUsers() {
193
- return await invoke2("plugin:mongoose|get_users");
233
+ return await invoke3("plugin:mongoose|get_users");
194
234
  }
195
235
  async function getUser(username, db) {
196
- return await invoke2("plugin:mongoose|get_user", { username, db });
236
+ return await invoke3("plugin:mongoose|get_user", { username, db });
197
237
  }
198
238
  async function createUser(options) {
199
- return await invoke2("plugin:mongoose|create_db_user", { ...options });
239
+ return await invoke3("plugin:mongoose|create_db_user", { ...options });
200
240
  }
201
241
  export {
242
+ Files,
202
243
  Model,
203
244
  connect,
204
245
  createUser,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tauri-plugin-mongoose",
3
- "version": "0.3.5",
3
+ "version": "0.3.8",
4
4
  "description": "Tauri plugin for MongoDB/Mongoose-like database operations",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",