@web-ts-toolkit/moo 0.43.0 → 0.48.0

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/schema.d.ts CHANGED
@@ -1,10 +1,17 @@
1
+ /**
2
+ * Arbitrary Mongoose schema-type options merged over the helper defaults.
3
+ * Provided keys win over the defaults at runtime via object spread; the
4
+ * helpers type this with `Omit<Base, keyof TOverrides> & TOverrides` so an
5
+ * override of `default`, `trim`, or `index` is reflected in the inferred
6
+ * return type instead of keeping the fixed default type.
7
+ */
1
8
  type SchemaOptionOverrides = Record<string, unknown>;
2
- declare const uniqueNullableString: (field: string, options?: SchemaOptionOverrides) => {
9
+ type UniqueNullableBase = {
3
10
  type: StringConstructor;
4
11
  index: {
5
12
  unique: boolean;
6
13
  partialFilterExpression: {
7
- [x: string]: {
14
+ [field: string]: {
8
15
  $type: string;
9
16
  };
10
17
  };
@@ -12,12 +19,12 @@ declare const uniqueNullableString: (field: string, options?: SchemaOptionOverri
12
19
  trim: boolean;
13
20
  default: null;
14
21
  };
15
- declare const uniqueEmptiableString: (field: string, options?: SchemaOptionOverrides) => {
22
+ type UniqueEmptiableBase = {
16
23
  type: StringConstructor;
17
24
  index: {
18
25
  unique: boolean;
19
26
  partialFilterExpression: {
20
- [x: string]: {
27
+ [field: string]: {
21
28
  $type: string;
22
29
  $gt: string;
23
30
  };
@@ -26,5 +33,27 @@ declare const uniqueEmptiableString: (field: string, options?: SchemaOptionOverr
26
33
  trim: boolean;
27
34
  default: null;
28
35
  };
36
+ /**
37
+ * Partial-unique string field that allows any number of `null` values while
38
+ * still rejecting duplicate non-null strings (including `''`). The partial
39
+ * index only covers string-typed values (`{ [field]: { $type: 'string' } }`),
40
+ * so `null`/missing entries never conflict. Extra `options` are spread over
41
+ * the defaults and reflected in the return type.
42
+ *
43
+ * @example
44
+ * const userSchema = new Schema({ email: uniqueNullableString('email') });
45
+ */
46
+ declare const uniqueNullableString: <TOverrides extends SchemaOptionOverrides = Record<string, never>>(field: string, options?: TOverrides) => Omit<UniqueNullableBase, keyof TOverrides> & TOverrides;
47
+ /**
48
+ * Partial-unique string field that additionally ignores empty strings:
49
+ * both `null` and `''` can repeat, while duplicate non-empty strings are
50
+ * rejected. The partial index only covers strings longer than `''`
51
+ * (`{ [field]: { $type: 'string', $gt: '' } }`). Extra `options` are spread
52
+ * over the defaults and reflected in the return type.
53
+ *
54
+ * @example
55
+ * const userSchema = new Schema({ username: uniqueEmptiableString('username') });
56
+ */
57
+ declare const uniqueEmptiableString: <TOverrides extends SchemaOptionOverrides = Record<string, never>>(field: string, options?: TOverrides) => Omit<UniqueEmptiableBase, keyof TOverrides> & TOverrides;
29
58
 
30
- export { uniqueEmptiableString, uniqueNullableString };
59
+ export { type SchemaOptionOverrides, uniqueEmptiableString, uniqueNullableString };
package/schema.js CHANGED
@@ -24,23 +24,30 @@ __export(schema_exports, {
24
24
  uniqueNullableString: () => uniqueNullableString
25
25
  });
26
26
  module.exports = __toCommonJS(schema_exports);
27
- var uniqueNullableString = (field, options = {}) => ({
28
- type: String,
29
- index: { unique: true, partialFilterExpression: { [field]: { $type: "string" } } },
30
- trim: true,
31
- default: null,
32
- ...options
33
- });
34
- var uniqueEmptiableString = (field, options = {}) => ({
35
- type: String,
36
- index: {
37
- unique: true,
38
- partialFilterExpression: { [field]: { $type: "string", $gt: "" } }
39
- },
40
- trim: true,
41
- default: null,
42
- ...options
43
- });
27
+ var uniqueNullableString = (field, options) => (
28
+ // The runtime spread applies overrides over the defaults; the cast expresses
29
+ // that override-wins merge because TypeScript cannot narrow a generic spread.
30
+ {
31
+ type: String,
32
+ index: { unique: true, partialFilterExpression: { [field]: { $type: "string" } } },
33
+ trim: true,
34
+ default: null,
35
+ ...options
36
+ }
37
+ );
38
+ var uniqueEmptiableString = (field, options) => (
39
+ // Same override-wins spread contract as uniqueNullableString above.
40
+ {
41
+ type: String,
42
+ index: {
43
+ unique: true,
44
+ partialFilterExpression: { [field]: { $type: "string", $gt: "" } }
45
+ },
46
+ trim: true,
47
+ default: null,
48
+ ...options
49
+ }
50
+ );
44
51
  // Annotate the CommonJS export names for ESM import in node:
45
52
  0 && (module.exports = {
46
53
  uniqueEmptiableString,
package/schema.mjs CHANGED
@@ -1,21 +1,28 @@
1
1
  // src/schema.ts
2
- var uniqueNullableString = (field, options = {}) => ({
3
- type: String,
4
- index: { unique: true, partialFilterExpression: { [field]: { $type: "string" } } },
5
- trim: true,
6
- default: null,
7
- ...options
8
- });
9
- var uniqueEmptiableString = (field, options = {}) => ({
10
- type: String,
11
- index: {
12
- unique: true,
13
- partialFilterExpression: { [field]: { $type: "string", $gt: "" } }
14
- },
15
- trim: true,
16
- default: null,
17
- ...options
18
- });
2
+ var uniqueNullableString = (field, options) => (
3
+ // The runtime spread applies overrides over the defaults; the cast expresses
4
+ // that override-wins merge because TypeScript cannot narrow a generic spread.
5
+ {
6
+ type: String,
7
+ index: { unique: true, partialFilterExpression: { [field]: { $type: "string" } } },
8
+ trim: true,
9
+ default: null,
10
+ ...options
11
+ }
12
+ );
13
+ var uniqueEmptiableString = (field, options) => (
14
+ // Same override-wins spread contract as uniqueNullableString above.
15
+ {
16
+ type: String,
17
+ index: {
18
+ unique: true,
19
+ partialFilterExpression: { [field]: { $type: "string", $gt: "" } }
20
+ },
21
+ trim: true,
22
+ default: null,
23
+ ...options
24
+ }
25
+ );
19
26
  export {
20
27
  uniqueEmptiableString,
21
28
  uniqueNullableString