@web-ts-toolkit/moo 0.5.0 → 0.6.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/README.md CHANGED
@@ -33,9 +33,33 @@ const userSchema = new Schema({
33
33
 
34
34
  ## Main Exports
35
35
 
36
+ Root entrypoint (`@web-ts-toolkit/moo`):
37
+
36
38
  - schema helpers such as `uniqueNullableString(...)`
37
39
  - `isObjectId(...)`
38
- - plugins from `@web-ts-toolkit/moo/plugins`
40
+
41
+ Subpath entrypoints:
42
+
43
+ - `@web-ts-toolkit/moo/schema` — schema field helpers
44
+ - `@web-ts-toolkit/moo/is` — type guards such as `isObjectId(...)`
45
+ - `@web-ts-toolkit/moo/utils` — mongoose utilities
46
+ - `@web-ts-toolkit/moo/plugins` — plugin entrypoint
47
+ - `@web-ts-toolkit/moo/plugins/cascade-delete` — cascade-delete plugin
48
+ - `@web-ts-toolkit/moo/plugins/model-function` — model-function plugin
49
+
50
+ ### Subpath import example
51
+
52
+ ```ts
53
+ import { Schema } from 'mongoose';
54
+ import { uniqueEmptiableString } from '@web-ts-toolkit/moo';
55
+ import { cascadeDeletePlugin } from '@web-ts-toolkit/moo/plugins/cascade-delete';
56
+
57
+ const userSchema = new Schema({
58
+ email: uniqueEmptiableString('email'),
59
+ });
60
+
61
+ userSchema.plugin(cascadeDeletePlugin, { foreignKey: 'parentRef' });
62
+ ```
39
63
 
40
64
  ## Documentation
41
65
 
package/is.d.mts CHANGED
@@ -1,6 +1,13 @@
1
1
  import { Types } from 'mongoose';
2
2
 
3
3
  declare const ObjectId: typeof Types.ObjectId;
4
+ /**
5
+ * Type guard that returns `true` when `value` is a valid MongoDB ObjectId
6
+ * string or ObjectId instance.
7
+ *
8
+ * @example
9
+ * if (isObjectId(req.params.id)) { doSomething(); }
10
+ */
4
11
  declare function isObjectId(value: unknown): value is InstanceType<typeof ObjectId> | string;
5
12
 
6
13
  export { isObjectId };
package/is.d.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  import { Types } from 'mongoose';
2
2
 
3
3
  declare const ObjectId: typeof Types.ObjectId;
4
+ /**
5
+ * Type guard that returns `true` when `value` is a valid MongoDB ObjectId
6
+ * string or ObjectId instance.
7
+ *
8
+ * @example
9
+ * if (isObjectId(req.params.id)) { doSomething(); }
10
+ */
4
11
  declare function isObjectId(value: unknown): value is InstanceType<typeof ObjectId> | string;
5
12
 
6
13
  export { isObjectId };
package/llms.txt ADDED
@@ -0,0 +1,67 @@
1
+ # @web-ts-toolkit/moo
2
+
3
+ Mongoose helpers for schema fields, ObjectId checks, and document plugins.
4
+
5
+ ## Main Patterns
6
+
7
+ Partial-index schema fields:
8
+
9
+ ```ts
10
+ import { Schema } from 'mongoose';
11
+ import { uniqueEmptiableString, uniqueNullableString } from '@web-ts-toolkit/moo';
12
+
13
+ const userSchema = new Schema({
14
+ email: uniqueNullableString('email'),
15
+ username: uniqueEmptiableString('username'),
16
+ });
17
+ ```
18
+
19
+ Strict ObjectId guard:
20
+
21
+ ```ts
22
+ import { isObjectId } from '@web-ts-toolkit/moo';
23
+
24
+ if (isObjectId(req.params.id)) { doSomething(); }
25
+ ```
26
+
27
+ Cascade-delete plugin:
28
+
29
+ ```ts
30
+ import { cascadeDeletePlugin } from '@web-ts-toolkit/moo/plugins/cascade-delete';
31
+
32
+ userSchema.plugin(cascadeDeletePlugin, { foreignKey: 'parentRef' });
33
+ ```
34
+
35
+ Model-function plugin:
36
+
37
+ ```ts
38
+ import { modelFunctionPlugin } from '@web-ts-toolkit/moo/plugins/model-function';
39
+
40
+ userSchema.plugin(modelFunctionPlugin, {
41
+ fnName: 'fullName',
42
+ fn: (doc) => `${doc.name}`,
43
+ });
44
+
45
+ // static + instance methods `fullName` and `fullNameById` are now available on the model
46
+ ```
47
+
48
+ ## Gotchas
49
+
50
+ - peer dependency: `mongoose >= 8`
51
+ - root entrypoint exports schema helpers and `isObjectId`; plugins and utils live under subpaths
52
+ - `isObjectId(...)` is a strict guard: it rejects strings that `ObjectId.isValid` accepts but that don't round-trip back to the same string
53
+ - `uniqueNullableString`/`uniqueEmptiableString` return partial-index field definitions, not full schemas
54
+
55
+ ## Subpaths
56
+
57
+ - `@web-ts-toolkit/moo/is` — `isObjectId`
58
+ - `@web-ts-toolkit/moo/schema` — `uniqueNullableString`, `uniqueEmptiableString`
59
+ - `@web-ts-toolkit/moo/utils` — `isSchema`, `isObjectIdType`, `isReference`
60
+ - `@web-ts-toolkit/moo/plugins` — re-exports all plugins
61
+ - `@web-ts-toolkit/moo/plugins/cascade-delete` — `cascadeDeletePlugin`
62
+ - `@web-ts-toolkit/moo/plugins/model-function` — `modelFunctionPlugin`
63
+
64
+ ## Pointers
65
+
66
+ - README: installation, quickstart, main exports, subpath list
67
+ - website/docs/packages/moo.md: full documentation
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@web-ts-toolkit/moo",
3
3
  "description": "Mongoose helpers for schema fields, ObjectId checks, and document plugins",
4
4
  "homepage": "https://web-ts-toolkit.pages.dev/docs/packages/moo",
5
- "version": "0.5.0",
5
+ "version": "0.6.0",
6
6
  "sideEffects": false,
7
7
  "keywords": [
8
8
  "mongoose",
@@ -65,7 +65,7 @@
65
65
  "mongoose": ">=8.0.0"
66
66
  },
67
67
  "dependencies": {
68
- "@web-ts-toolkit/utils": "0.5.0"
68
+ "@web-ts-toolkit/utils": "0.6.0"
69
69
  },
70
70
  "author": "Junmin Ahn",
71
71
  "bugs": {