@bedrockio/model 0.21.1 → 0.21.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.21.2
2
+
3
+ - Export `loadDefinition` and readme updates.
4
+
1
5
  ## 0.21.1
2
6
 
3
7
  - Fixed issues with schema loading.
package/README.md CHANGED
@@ -6,6 +6,7 @@ Bedrock utilities for model creation.
6
6
  - [Dependencies](#dependencies)
7
7
  - [Usage](#usage)
8
8
  - [Schemas](#schemas)
9
+ - [Schema Comments](#schema-comments)
9
10
  - [Schema Extensions](#schema-extensions)
10
11
  - [Attributes](#attributes)
11
12
  - [Scopes](#scopes)
@@ -58,14 +59,13 @@ const { loadModelDir } = require('@bedrockio/model');
58
59
  model.exports = loadModelDir('path/to/definitions/');
59
60
  ```
60
61
 
61
- Models that need to be extended can use the `createSchema` method with the
62
- definition and add to the schema as needed:
62
+ Models that need to be extended can use the `loadSchema` method.
63
63
 
64
64
  ```js
65
65
  const mongoose = require('mongoose');
66
- const definition = require('./definitions/user.json');
66
+ const { loadSchema } = require('@bedrockio/model')
67
67
 
68
- const schema = createSchema(definition);
68
+ const schema = loadSchema('user');
69
69
 
70
70
  schema.virtual('name').get(function () {
71
71
  return [this.firstName, this.lastName].join(' ');
@@ -89,7 +89,7 @@ model.exports = {
89
89
  The `attributes` field of model definitions can be considered equivalent to
90
90
  Mongoose, but defined in JSON with extended features:
91
91
 
92
- ```js
92
+ ```jsonc
93
93
  {
94
94
  "attributes": {
95
95
  // Shortcut for the syntax below.
@@ -129,6 +129,21 @@ Links:
129
129
  - [Validation](#validation)
130
130
  - [Access Control](#access-control)
131
131
 
132
+
133
+ #### Schema Comments
134
+
135
+ Schemas may be `.jsonc` which will allow comments in definitions:
136
+
137
+ ```jsonc
138
+ // user.jsonc
139
+ {
140
+ "attributes": {
141
+ // User name
142
+ "name": "String",
143
+ }
144
+ }
145
+ ```
146
+
132
147
  ### Schema Extensions
133
148
 
134
149
  This module provides a number of extensions to assist schema creation outside
package/dist/cjs/load.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.loadDefinition = loadDefinition;
6
7
  exports.loadModel = loadModel;
7
8
  exports.loadModelDir = loadModelDir;
8
9
  exports.loadSchema = loadSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.21.1",
3
+ "version": "0.21.2",
4
4
  "description": "Bedrock utilities for model creation.",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/load.js CHANGED
@@ -64,7 +64,7 @@ export function loadSchema(name, dir) {
64
64
  const DEFINITION_DIR = 'src/models/definitions';
65
65
  const SCHEMA_EXTENSIONS = ['.json', '.jsonc'];
66
66
 
67
- function loadDefinition(name, dir) {
67
+ export function loadDefinition(name, dir) {
68
68
  const { filepath, ext } = resolvePath(name, dir);
69
69
  const content = fs.readFileSync(filepath, 'utf-8');
70
70
  return ext === '.jsonc' ? parseWithComments(content) : JSON.parse(content);
@@ -33,5 +33,6 @@ export function loadSchema(name: string, dir?: string): mongoose.Schema<any, mon
33
33
  }> & {
34
34
  __v: number;
35
35
  }>;
36
+ export function loadDefinition(name: any, dir: any): any;
36
37
  import mongoose from 'mongoose';
37
38
  //# sourceMappingURL=load.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/load.js"],"names":[],"mappings":"AAUA;;;;;GAKG;AACH,sCAJW,MAAM,QACN,MAAM,OAahB;AAED;;;;GAIG;AACH,kCAFW,MAAM,mBAoBhB;AAED;;;;GAIG;AACH,iCAHW,MAAM,QACN,MAAM;;;;;;;;;;;;;;;;GAKhB;qBAvDoB,UAAU"}
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/load.js"],"names":[],"mappings":"AAUA;;;;;GAKG;AACH,sCAJW,MAAM,QACN,MAAM,OAahB;AAED;;;;GAIG;AACH,kCAFW,MAAM,mBAoBhB;AAED;;;;GAIG;AACH,iCAHW,MAAM,QACN,MAAM;;;;;;;;;;;;;;;;GAKhB;AAKD,yDAIC;qBAhEoB,UAAU"}