tauri-plugin-mongoose 0.3.4 → 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,15 +28,12 @@ __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");
34
35
 
35
36
  // types/time.type.ts
36
- var isTime = (obj) => {
37
- return obj && typeof obj.hours === "number" && typeof obj.minutes === "number" && typeof obj.seconds === "number" && typeof obj.milliseconds === "number";
38
- };
39
37
  var Time = class _Time {
40
38
  constructor(hours, minutes, seconds, milliseconds) {
41
39
  this.hours = hours;
@@ -113,14 +111,30 @@ var Model = class {
113
111
  if (schemaItem.type === "array" && !Array.isArray(value)) {
114
112
  throw new Error(`Property ${key} must be an array`);
115
113
  }
116
- if (schemaItem.type === "date" && !(value instanceof Date)) {
117
- throw new Error(`Property ${key} must be a date`);
118
- }
119
- if (schemaItem.type === "time" && !(value instanceof Time)) {
120
- throw new Error(`Property ${key} must be a time`);
114
+ if (schemaItem.type === "date") {
115
+ if (typeof value === "string") {
116
+ const date = new Date(value);
117
+ if (isNaN(date.getTime())) {
118
+ throw new Error(`Property ${key} must be a valid date`);
119
+ }
120
+ doc[key] = date;
121
+ } else if (!(value instanceof Date)) {
122
+ throw new Error(`Property ${key} must be a date`);
123
+ }
121
124
  }
122
- if (schemaItem.type === "time" && !isTime(value)) {
123
- throw new Error(`Property ${key} must be a time`);
125
+ if (schemaItem.type === "time") {
126
+ if (typeof value === "string") {
127
+ const time = Time.fromString(value);
128
+ if (isNaN(time.hours) || isNaN(time.minutes)) {
129
+ throw new Error(`Property ${key} must be a valid time`);
130
+ }
131
+ if (isNaN(time.seconds)) {
132
+ time.seconds = 0;
133
+ }
134
+ doc[key] = time;
135
+ } else if (!(value instanceof Time)) {
136
+ throw new Error(`Property ${key} must be a time`);
137
+ }
124
138
  }
125
139
  if (schemaItem.type === "object" && schemaItem.schema) {
126
140
  await this._validate(value, schemaItem.schema);
@@ -177,6 +191,46 @@ var Model = class {
177
191
  }
178
192
  };
179
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
+
180
234
  // index.ts
181
235
  async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
182
236
  let url;
@@ -196,7 +250,7 @@ async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
196
250
  cbs = dbNameOrCallbacks;
197
251
  }
198
252
  try {
199
- await (0, import_core2.invoke)("plugin:mongoose|connect", { url, dbName });
253
+ await (0, import_core3.invoke)("plugin:mongoose|connect", { url, dbName });
200
254
  cbs?.onSuccess?.();
201
255
  } catch (error) {
202
256
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -205,16 +259,17 @@ async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
205
259
  }
206
260
  }
207
261
  async function getUsers() {
208
- return await (0, import_core2.invoke)("plugin:mongoose|get_users");
262
+ return await (0, import_core3.invoke)("plugin:mongoose|get_users");
209
263
  }
210
264
  async function getUser(username, db) {
211
- 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 });
212
266
  }
213
267
  async function createUser(options) {
214
- 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 });
215
269
  }
216
270
  // Annotate the CommonJS export names for ESM import in node:
217
271
  0 && (module.exports = {
272
+ Files,
218
273
  Model,
219
274
  connect,
220
275
  createUser,
package/dist/index.mjs CHANGED
@@ -1,13 +1,10 @@
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";
6
6
 
7
7
  // types/time.type.ts
8
- var isTime = (obj) => {
9
- return obj && typeof obj.hours === "number" && typeof obj.minutes === "number" && typeof obj.seconds === "number" && typeof obj.milliseconds === "number";
10
- };
11
8
  var Time = class _Time {
12
9
  constructor(hours, minutes, seconds, milliseconds) {
13
10
  this.hours = hours;
@@ -85,14 +82,30 @@ var Model = class {
85
82
  if (schemaItem.type === "array" && !Array.isArray(value)) {
86
83
  throw new Error(`Property ${key} must be an array`);
87
84
  }
88
- if (schemaItem.type === "date" && !(value instanceof Date)) {
89
- throw new Error(`Property ${key} must be a date`);
90
- }
91
- if (schemaItem.type === "time" && !(value instanceof Time)) {
92
- throw new Error(`Property ${key} must be a time`);
85
+ if (schemaItem.type === "date") {
86
+ if (typeof value === "string") {
87
+ const date = new Date(value);
88
+ if (isNaN(date.getTime())) {
89
+ throw new Error(`Property ${key} must be a valid date`);
90
+ }
91
+ doc[key] = date;
92
+ } else if (!(value instanceof Date)) {
93
+ throw new Error(`Property ${key} must be a date`);
94
+ }
93
95
  }
94
- if (schemaItem.type === "time" && !isTime(value)) {
95
- throw new Error(`Property ${key} must be a time`);
96
+ if (schemaItem.type === "time") {
97
+ if (typeof value === "string") {
98
+ const time = Time.fromString(value);
99
+ if (isNaN(time.hours) || isNaN(time.minutes)) {
100
+ throw new Error(`Property ${key} must be a valid time`);
101
+ }
102
+ if (isNaN(time.seconds)) {
103
+ time.seconds = 0;
104
+ }
105
+ doc[key] = time;
106
+ } else if (!(value instanceof Time)) {
107
+ throw new Error(`Property ${key} must be a time`);
108
+ }
96
109
  }
97
110
  if (schemaItem.type === "object" && schemaItem.schema) {
98
111
  await this._validate(value, schemaItem.schema);
@@ -149,6 +162,46 @@ var Model = class {
149
162
  }
150
163
  };
151
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
+
152
205
  // index.ts
153
206
  async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
154
207
  let url;
@@ -168,7 +221,7 @@ async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
168
221
  cbs = dbNameOrCallbacks;
169
222
  }
170
223
  try {
171
- await invoke2("plugin:mongoose|connect", { url, dbName });
224
+ await invoke3("plugin:mongoose|connect", { url, dbName });
172
225
  cbs?.onSuccess?.();
173
226
  } catch (error) {
174
227
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -177,15 +230,16 @@ async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
177
230
  }
178
231
  }
179
232
  async function getUsers() {
180
- return await invoke2("plugin:mongoose|get_users");
233
+ return await invoke3("plugin:mongoose|get_users");
181
234
  }
182
235
  async function getUser(username, db) {
183
- return await invoke2("plugin:mongoose|get_user", { username, db });
236
+ return await invoke3("plugin:mongoose|get_user", { username, db });
184
237
  }
185
238
  async function createUser(options) {
186
- return await invoke2("plugin:mongoose|create_db_user", { ...options });
239
+ return await invoke3("plugin:mongoose|create_db_user", { ...options });
187
240
  }
188
241
  export {
242
+ Files,
189
243
  Model,
190
244
  connect,
191
245
  createUser,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tauri-plugin-mongoose",
3
- "version": "0.3.4",
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",