tauri-plugin-mongoose 0.3.3 → 0.3.5

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.js CHANGED
@@ -33,9 +33,6 @@ var import_core2 = require("@tauri-apps/api/core");
33
33
  var import_core = require("@tauri-apps/api/core");
34
34
 
35
35
  // 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
36
  var Time = class _Time {
40
37
  constructor(hours, minutes, seconds, milliseconds) {
41
38
  this.hours = hours;
@@ -113,14 +110,30 @@ var Model = class {
113
110
  if (schemaItem.type === "array" && !Array.isArray(value)) {
114
111
  throw new Error(`Property ${key} must be an array`);
115
112
  }
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`);
113
+ if (schemaItem.type === "date") {
114
+ if (typeof value === "string") {
115
+ const date = new Date(value);
116
+ if (isNaN(date.getTime())) {
117
+ throw new Error(`Property ${key} must be a valid date`);
118
+ }
119
+ doc[key] = date;
120
+ } else if (!(value instanceof Date)) {
121
+ throw new Error(`Property ${key} must be a date`);
122
+ }
121
123
  }
122
- if (schemaItem.type === "time" && !isTime(value)) {
123
- throw new Error(`Property ${key} must be a time`);
124
+ if (schemaItem.type === "time") {
125
+ if (typeof value === "string") {
126
+ const time = Time.fromString(value);
127
+ if (isNaN(time.hours) || isNaN(time.minutes)) {
128
+ throw new Error(`Property ${key} must be a valid time`);
129
+ }
130
+ if (isNaN(time.seconds)) {
131
+ time.seconds = 0;
132
+ }
133
+ doc[key] = time;
134
+ } else if (!(value instanceof Time)) {
135
+ throw new Error(`Property ${key} must be a time`);
136
+ }
124
137
  }
125
138
  if (schemaItem.type === "object" && schemaItem.schema) {
126
139
  await this._validate(value, schemaItem.schema);
package/dist/index.mjs CHANGED
@@ -5,9 +5,6 @@ import { invoke as invoke2 } from "@tauri-apps/api/core";
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tauri-plugin-mongoose",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Tauri plugin for MongoDB/Mongoose-like database operations",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",