@web-ts-toolkit/moo 0.4.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 +49 -13
- package/is.d.mts +7 -0
- package/is.d.ts +7 -0
- package/llms.txt +67 -0
- package/package.json +9 -6
package/README.md
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
# moo
|
|
1
|
+
# `@web-ts-toolkit/moo`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
This package includes:
|
|
6
|
-
|
|
7
|
-
- partial-index helpers for nullable or empty string fields
|
|
8
|
-
- an `isObjectId(...)` guard for strict ObjectId checks
|
|
9
|
-
- document plugins for model-bound helper functions and cascade deletes
|
|
3
|
+
Mongoose helpers for schema fields, ObjectId checks, and document plugins.
|
|
10
4
|
|
|
11
5
|
## Installation
|
|
12
6
|
|
|
13
7
|
```sh
|
|
14
|
-
|
|
8
|
+
pnpm add mongoose @web-ts-toolkit/moo
|
|
15
9
|
```
|
|
16
10
|
|
|
17
|
-
|
|
11
|
+
Peer dependencies:
|
|
18
12
|
|
|
19
|
-
-
|
|
20
|
-
- Use the Docusaurus site in `website` for the full examples.
|
|
13
|
+
- `mongoose >= 8`
|
|
21
14
|
|
|
22
|
-
##
|
|
15
|
+
## Highlights
|
|
16
|
+
|
|
17
|
+
- partial-index helpers for nullable or empty-string fields
|
|
18
|
+
- strict `isObjectId(...)` guard
|
|
19
|
+
- model-function plugin
|
|
20
|
+
- cascade-delete plugin
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
23
|
|
|
24
24
|
```ts
|
|
25
25
|
import { Schema } from 'mongoose';
|
|
@@ -30,3 +30,39 @@ const userSchema = new Schema({
|
|
|
30
30
|
username: uniqueEmptiableString('username'),
|
|
31
31
|
});
|
|
32
32
|
```
|
|
33
|
+
|
|
34
|
+
## Main Exports
|
|
35
|
+
|
|
36
|
+
Root entrypoint (`@web-ts-toolkit/moo`):
|
|
37
|
+
|
|
38
|
+
- schema helpers such as `uniqueNullableString(...)`
|
|
39
|
+
- `isObjectId(...)`
|
|
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
|
+
```
|
|
63
|
+
|
|
64
|
+
## Documentation
|
|
65
|
+
|
|
66
|
+
Full package documentation lives in `website/docs/packages/moo.md`.
|
|
67
|
+
|
|
68
|
+
- live docs: https://web-ts-toolkit.pages.dev/docs/packages/moo
|
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
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
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.6.0",
|
|
6
|
+
"sideEffects": false,
|
|
5
7
|
"keywords": [
|
|
6
8
|
"mongoose",
|
|
7
9
|
"mongodb",
|
|
8
10
|
"schema",
|
|
9
|
-
"
|
|
11
|
+
"plugins",
|
|
12
|
+
"objectid"
|
|
10
13
|
],
|
|
11
14
|
"main": "./index.js",
|
|
12
15
|
"module": "./index.mjs",
|
|
@@ -55,19 +58,19 @@
|
|
|
55
58
|
"default": "./plugins/model-function.js"
|
|
56
59
|
}
|
|
57
60
|
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=20"
|
|
63
|
+
},
|
|
58
64
|
"peerDependencies": {
|
|
59
65
|
"mongoose": ">=8.0.0"
|
|
60
66
|
},
|
|
61
67
|
"dependencies": {
|
|
62
|
-
"@web-ts-toolkit/utils": "0.
|
|
68
|
+
"@web-ts-toolkit/utils": "0.6.0"
|
|
63
69
|
},
|
|
64
70
|
"author": "Junmin Ahn",
|
|
65
71
|
"bugs": {
|
|
66
72
|
"url": "https://github.com/egose/web-ts-toolkit/issues"
|
|
67
73
|
},
|
|
68
|
-
"engines": {
|
|
69
|
-
"node": ">=20"
|
|
70
|
-
},
|
|
71
74
|
"license": "Apache-2.0",
|
|
72
75
|
"repository": {
|
|
73
76
|
"type": "git",
|