tauri-plugin-mongoose 0.3.5 → 0.3.9

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
@@ -1,3 +1,26 @@
1
+ interface SaveFileOptions {
2
+ filename?: string;
3
+ metadata?: Record<string, unknown>;
4
+ chunkSizeBytes?: number;
5
+ }
6
+ interface SaveFileResult {
7
+ _id: unknown;
8
+ filename?: string;
9
+ length?: number;
10
+ chunkSizeBytes?: number;
11
+ uploadDate?: string;
12
+ bucket: string;
13
+ metadata?: Record<string, unknown>;
14
+ }
15
+ type BinaryLike = ArrayBuffer | ArrayBufferView | number[] | Blob;
16
+ declare class Files {
17
+ name: string;
18
+ constructor(name: string);
19
+ savePath(path: string, options?: SaveFileOptions): Promise<SaveFileResult>;
20
+ save(data: BinaryLike, options?: SaveFileOptions): Promise<SaveFileResult>;
21
+ private toBytes;
22
+ }
23
+
1
24
  declare class Time {
2
25
  hours: number;
3
26
  minutes: number;
@@ -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, Files as default, getUser, getUsers };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,26 @@
1
+ interface SaveFileOptions {
2
+ filename?: string;
3
+ metadata?: Record<string, unknown>;
4
+ chunkSizeBytes?: number;
5
+ }
6
+ interface SaveFileResult {
7
+ _id: unknown;
8
+ filename?: string;
9
+ length?: number;
10
+ chunkSizeBytes?: number;
11
+ uploadDate?: string;
12
+ bucket: string;
13
+ metadata?: Record<string, unknown>;
14
+ }
15
+ type BinaryLike = ArrayBuffer | ArrayBufferView | number[] | Blob;
16
+ declare class Files {
17
+ name: string;
18
+ constructor(name: string);
19
+ savePath(path: string, options?: SaveFileOptions): Promise<SaveFileResult>;
20
+ save(data: BinaryLike, options?: SaveFileOptions): Promise<SaveFileResult>;
21
+ private toBytes;
22
+ }
23
+
1
24
  declare class Time {
2
25
  hours: number;
3
26
  minutes: number;
@@ -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, Files as default, getUser, getUsers };
package/dist/index.js CHANGED
@@ -20,17 +20,59 @@ 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
+ default: () => index_default,
26
28
  getUser: () => getUser,
27
29
  getUsers: () => getUsers
28
30
  });
29
31
  module.exports = __toCommonJS(index_exports);
30
- var import_core2 = require("@tauri-apps/api/core");
32
+ var import_core3 = require("@tauri-apps/api/core");
31
33
 
32
- // model/index.ts
34
+ // files/index.ts
33
35
  var import_core = require("@tauri-apps/api/core");
36
+ var Files = class {
37
+ constructor(name) {
38
+ this.name = name;
39
+ }
40
+ async savePath(path, options = {}) {
41
+ return await (0, import_core.invoke)("plugin:mongoose|save_file", {
42
+ collection: this.name,
43
+ path,
44
+ ...options
45
+ });
46
+ }
47
+ async save(data, options = {}) {
48
+ const bytes = await this.toBytes(data);
49
+ return await (0, import_core.invoke)("plugin:mongoose|save_file", {
50
+ collection: this.name,
51
+ data: Array.from(bytes),
52
+ ...options
53
+ });
54
+ }
55
+ async toBytes(data) {
56
+ if (data instanceof Blob) {
57
+ const buffer = await data.arrayBuffer();
58
+ return new Uint8Array(buffer);
59
+ }
60
+ if (Array.isArray(data)) {
61
+ return Uint8Array.from(data);
62
+ }
63
+ if (data instanceof ArrayBuffer) {
64
+ return new Uint8Array(data);
65
+ }
66
+ if (ArrayBuffer.isView(data)) {
67
+ const view = data;
68
+ return new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
69
+ }
70
+ throw new Error("Unsupported data type for Files.save");
71
+ }
72
+ };
73
+
74
+ // model/index.ts
75
+ var import_core2 = require("@tauri-apps/api/core");
34
76
 
35
77
  // types/time.type.ts
36
78
  var Time = class _Time {
@@ -78,7 +120,7 @@ var Model = class {
78
120
  this.schema = schema;
79
121
  }
80
122
  async getById(id) {
81
- const doc = await (0, import_core.invoke)("plugin:mongoose|get_by_id", {
123
+ const doc = await (0, import_core2.invoke)("plugin:mongoose|get_by_id", {
82
124
  collection: this.name,
83
125
  id
84
126
  });
@@ -143,7 +185,7 @@ var Model = class {
143
185
  doc[key] = schemaItem.default();
144
186
  }
145
187
  if (schemaItem.unique && value !== void 0 && value !== null) {
146
- const existing = await (0, import_core.invoke)("plugin:mongoose|get_by_id", {
188
+ const existing = await (0, import_core2.invoke)("plugin:mongoose|get_by_id", {
147
189
  collection: this.name,
148
190
  id: value
149
191
  });
@@ -155,7 +197,7 @@ var Model = class {
155
197
  return doc;
156
198
  }
157
199
  async find(filter = {}, options = {}) {
158
- const docs = await (0, import_core.invoke)("plugin:mongoose|find", {
200
+ const docs = await (0, import_core2.invoke)("plugin:mongoose|find", {
159
201
  collection: this.name,
160
202
  filter,
161
203
  options
@@ -163,7 +205,7 @@ var Model = class {
163
205
  return Promise.all(docs.map((doc) => this.validate(doc)));
164
206
  }
165
207
  async findOne(filter = {}, options = {}) {
166
- const doc = await (0, import_core.invoke)("plugin:mongoose|find_one", {
208
+ const doc = await (0, import_core2.invoke)("plugin:mongoose|find_one", {
167
209
  collection: this.name,
168
210
  filter,
169
211
  options
@@ -175,13 +217,13 @@ var Model = class {
175
217
  }
176
218
  async create(doc) {
177
219
  const validatedDoc = await this.validate(doc);
178
- return await (0, import_core.invoke)("plugin:mongoose|create", {
220
+ return await (0, import_core2.invoke)("plugin:mongoose|create", {
179
221
  collection: this.name,
180
222
  document: validatedDoc
181
223
  });
182
224
  }
183
225
  async updateOne(filter, update, options = {}) {
184
- return await (0, import_core.invoke)("plugin:mongoose|update_one", {
226
+ return await (0, import_core2.invoke)("plugin:mongoose|update_one", {
185
227
  collection: this.name,
186
228
  filter,
187
229
  update,
@@ -209,7 +251,7 @@ async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
209
251
  cbs = dbNameOrCallbacks;
210
252
  }
211
253
  try {
212
- await (0, import_core2.invoke)("plugin:mongoose|connect", { url, dbName });
254
+ await (0, import_core3.invoke)("plugin:mongoose|connect", { url, dbName });
213
255
  cbs?.onSuccess?.();
214
256
  } catch (error) {
215
257
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -218,16 +260,18 @@ async function connect(urlOrOptions, dbNameOrCallbacks, callbacks) {
218
260
  }
219
261
  }
220
262
  async function getUsers() {
221
- return await (0, import_core2.invoke)("plugin:mongoose|get_users");
263
+ return await (0, import_core3.invoke)("plugin:mongoose|get_users");
222
264
  }
223
265
  async function getUser(username, db) {
224
- return await (0, import_core2.invoke)("plugin:mongoose|get_user", { username, db });
266
+ return await (0, import_core3.invoke)("plugin:mongoose|get_user", { username, db });
225
267
  }
226
268
  async function createUser(options) {
227
- return await (0, import_core2.invoke)("plugin:mongoose|create_db_user", { ...options });
269
+ return await (0, import_core3.invoke)("plugin:mongoose|create_db_user", { ...options });
228
270
  }
271
+ var index_default = Files;
229
272
  // Annotate the CommonJS export names for ESM import in node:
230
273
  0 && (module.exports = {
274
+ Files,
231
275
  Model,
232
276
  connect,
233
277
  createUser,
package/dist/index.mjs CHANGED
@@ -1,8 +1,48 @@
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
- // model/index.ts
4
+ // files/index.ts
5
5
  import { invoke } from "@tauri-apps/api/core";
6
+ var Files = class {
7
+ constructor(name) {
8
+ this.name = name;
9
+ }
10
+ async savePath(path, options = {}) {
11
+ return await invoke("plugin:mongoose|save_file", {
12
+ collection: this.name,
13
+ path,
14
+ ...options
15
+ });
16
+ }
17
+ async save(data, options = {}) {
18
+ const bytes = await this.toBytes(data);
19
+ return await invoke("plugin:mongoose|save_file", {
20
+ collection: this.name,
21
+ data: Array.from(bytes),
22
+ ...options
23
+ });
24
+ }
25
+ async toBytes(data) {
26
+ if (data instanceof Blob) {
27
+ const buffer = await data.arrayBuffer();
28
+ return new Uint8Array(buffer);
29
+ }
30
+ if (Array.isArray(data)) {
31
+ return Uint8Array.from(data);
32
+ }
33
+ if (data instanceof ArrayBuffer) {
34
+ return new Uint8Array(data);
35
+ }
36
+ if (ArrayBuffer.isView(data)) {
37
+ const view = data;
38
+ return new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
39
+ }
40
+ throw new Error("Unsupported data type for Files.save");
41
+ }
42
+ };
43
+
44
+ // model/index.ts
45
+ import { invoke as invoke2 } from "@tauri-apps/api/core";
6
46
 
7
47
  // types/time.type.ts
8
48
  var Time = class _Time {
@@ -50,7 +90,7 @@ var Model = class {
50
90
  this.schema = schema;
51
91
  }
52
92
  async getById(id) {
53
- const doc = await invoke("plugin:mongoose|get_by_id", {
93
+ const doc = await invoke2("plugin:mongoose|get_by_id", {
54
94
  collection: this.name,
55
95
  id
56
96
  });
@@ -115,7 +155,7 @@ var Model = class {
115
155
  doc[key] = schemaItem.default();
116
156
  }
117
157
  if (schemaItem.unique && value !== void 0 && value !== null) {
118
- const existing = await invoke("plugin:mongoose|get_by_id", {
158
+ const existing = await invoke2("plugin:mongoose|get_by_id", {
119
159
  collection: this.name,
120
160
  id: value
121
161
  });
@@ -127,7 +167,7 @@ var Model = class {
127
167
  return doc;
128
168
  }
129
169
  async find(filter = {}, options = {}) {
130
- const docs = await invoke("plugin:mongoose|find", {
170
+ const docs = await invoke2("plugin:mongoose|find", {
131
171
  collection: this.name,
132
172
  filter,
133
173
  options
@@ -135,7 +175,7 @@ var Model = class {
135
175
  return Promise.all(docs.map((doc) => this.validate(doc)));
136
176
  }
137
177
  async findOne(filter = {}, options = {}) {
138
- const doc = await invoke("plugin:mongoose|find_one", {
178
+ const doc = await invoke2("plugin:mongoose|find_one", {
139
179
  collection: this.name,
140
180
  filter,
141
181
  options
@@ -147,13 +187,13 @@ var Model = class {
147
187
  }
148
188
  async create(doc) {
149
189
  const validatedDoc = await this.validate(doc);
150
- return await invoke("plugin:mongoose|create", {
190
+ return await invoke2("plugin:mongoose|create", {
151
191
  collection: this.name,
152
192
  document: validatedDoc
153
193
  });
154
194
  }
155
195
  async updateOne(filter, update, options = {}) {
156
- return await invoke("plugin:mongoose|update_one", {
196
+ return await invoke2("plugin:mongoose|update_one", {
157
197
  collection: this.name,
158
198
  filter,
159
199
  update,
@@ -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,18 +230,21 @@ 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
  }
241
+ var index_default = Files;
201
242
  export {
243
+ Files,
202
244
  Model,
203
245
  connect,
204
246
  createUser,
247
+ index_default as default,
205
248
  getUser,
206
249
  getUsers
207
250
  };
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.9",
4
4
  "description": "Tauri plugin for MongoDB/Mongoose-like database operations",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",