@bedrockio/model 0.2.2 → 0.2.3

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.
@@ -131,7 +131,7 @@ function applyValidation(schema, definition) {
131
131
  allowInclude: true,
132
132
  expandDotSyntax: true,
133
133
  unwindArrayFields: true,
134
- requireReadAccess: true,
134
+ requireSearchAccess: true,
135
135
  stripDeleted: !includeDeleted,
136
136
  appendSchema: (0, _search.searchValidation)({
137
137
  defaults,
@@ -297,7 +297,7 @@ function getSchemaForTypedef(typedef, options = {}) {
297
297
  if (options.allowSearch) {
298
298
  schema = getSearchSchema(schema, type);
299
299
  }
300
- if (typedef.readAccess && options.requireReadAccess) {
300
+ if (typedef.readAccess && options.requireSearchAccess) {
301
301
  schema = validateReadAccess(schema, typedef.readAccess, options);
302
302
  }
303
303
  if (typedef.writeAccess && options.requireWriteAccess) {
@@ -375,13 +375,13 @@ function isRequired(typedef, options) {
375
375
  }
376
376
  function isExcludedField(field, options) {
377
377
  if ((0, _utils.isSchemaTypedef)(field)) {
378
- const {
379
- requireWriteAccess
380
- } = options;
381
- return requireWriteAccess && field.writeAccess === 'none';
382
- } else {
383
- return false;
378
+ if (options.requireWriteAccess) {
379
+ return field.writeAccess === 'none';
380
+ } else if (options.requireSearchAccess) {
381
+ return field.readAccess === 'none' || field.readAccess === 'self';
382
+ }
384
383
  }
384
+ return false;
385
385
  }
386
386
  function validateReadAccess(schema, allowed, options) {
387
387
  return validateAccess('read', schema, allowed, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Bedrock utilities for model creation.",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/validation.js CHANGED
@@ -145,7 +145,7 @@ export function applyValidation(schema, definition) {
145
145
  allowInclude: true,
146
146
  expandDotSyntax: true,
147
147
  unwindArrayFields: true,
148
- requireReadAccess: true,
148
+ requireSearchAccess: true,
149
149
  stripDeleted: !includeDeleted,
150
150
  appendSchema: searchValidation({
151
151
  defaults,
@@ -314,7 +314,7 @@ function getSchemaForTypedef(typedef, options = {}) {
314
314
  if (options.allowSearch) {
315
315
  schema = getSearchSchema(schema, type);
316
316
  }
317
- if (typedef.readAccess && options.requireReadAccess) {
317
+ if (typedef.readAccess && options.requireSearchAccess) {
318
318
  schema = validateReadAccess(schema, typedef.readAccess, options);
319
319
  }
320
320
  if (typedef.writeAccess && options.requireWriteAccess) {
@@ -430,11 +430,13 @@ function isRequired(typedef, options) {
430
430
 
431
431
  function isExcludedField(field, options) {
432
432
  if (isSchemaTypedef(field)) {
433
- const { requireWriteAccess } = options;
434
- return requireWriteAccess && field.writeAccess === 'none';
435
- } else {
436
- return false;
433
+ if (options.requireWriteAccess) {
434
+ return field.writeAccess === 'none';
435
+ } else if (options.requireSearchAccess) {
436
+ return field.readAccess === 'none' || field.readAccess === 'self';
437
+ }
437
438
  }
439
+ return false;
438
440
  }
439
441
 
440
442
  function validateReadAccess(schema, allowed, options) {
package/types/load.d.ts CHANGED
@@ -4,7 +4,73 @@
4
4
  * @param {string} name
5
5
  * @returns mongoose.Model
6
6
  */
7
- export function loadModel(definition: object, name: string): any;
7
+ export function loadModel(definition: object, name: string): mongoose.Model<any, any, any, any, any, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, any, any, any, {
8
+ [x: string]: any;
9
+ }, {
10
+ autoIndex?: boolean;
11
+ autoCreate?: boolean;
12
+ bufferCommands?: boolean;
13
+ bufferTimeoutMS?: number;
14
+ capped?: number | boolean | {
15
+ size?: number;
16
+ max?: number;
17
+ autoIndexId?: boolean;
18
+ };
19
+ collation?: mongoose.mongo.CollationOptions;
20
+ collectionOptions?: mongoose.mongo.CreateCollectionOptions;
21
+ timeseries?: mongoose.mongo.TimeSeriesCollectionOptions;
22
+ expireAfterSeconds?: number;
23
+ expires?: string | number;
24
+ collection?: string;
25
+ discriminatorKey?: string;
26
+ excludeIndexes?: boolean;
27
+ id?: boolean;
28
+ _id?: boolean;
29
+ minimize?: boolean;
30
+ optimisticConcurrency?: boolean;
31
+ pluginTags?: string[];
32
+ read?: string;
33
+ writeConcern?: mongoose.mongo.WriteConcern;
34
+ safe?: boolean | {
35
+ w?: string | number;
36
+ wtimeout?: number;
37
+ j?: boolean;
38
+ };
39
+ shardKey?: Record<string, unknown>;
40
+ strict?: boolean | "throw";
41
+ strictQuery?: boolean | "throw";
42
+ toJSON: {
43
+ getters: boolean;
44
+ versionKey: boolean;
45
+ transform: (doc: any, ret: any, options: any) => void;
46
+ } | mongoose.ToObjectOptions<any>;
47
+ toObject: {
48
+ getters: boolean;
49
+ versionKey: boolean;
50
+ transform: (doc: any, ret: any, options: any) => void;
51
+ } | mongoose.ToObjectOptions<any>;
52
+ typeKey?: string;
53
+ validateBeforeSave?: boolean;
54
+ validateModifiedOnly?: boolean;
55
+ versionKey?: string | boolean;
56
+ selectPopulatedPaths?: boolean;
57
+ skipVersioning?: {
58
+ [key: string]: boolean;
59
+ };
60
+ storeSubdocValidationError?: boolean;
61
+ timestamps: boolean | mongoose.SchemaTimestampsConfig;
62
+ suppressReservedKeysWarning?: boolean;
63
+ statics?: {
64
+ [x: string]: any;
65
+ };
66
+ methods?: any;
67
+ query?: any;
68
+ castNonArrays?: boolean;
69
+ virtuals?: mongoose.SchemaOptionsVirtualsPropertyType<any, any, any>;
70
+ overwriteModels?: boolean;
71
+ }, any, any>> & {
72
+ [x: string]: any;
73
+ };
8
74
  /**
9
75
  * Loads all model definitions in the given directory.
10
76
  * Returns the full loaded model set.
@@ -1 +1 @@
1
- {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.js"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,sCAJW,MAAM,QACN,MAAM,OAahB;AAED;;;;GAIG;AACH,sCAFW,MAAM,mBAkBhB"}
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.js"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,sCAJW,MAAM,QACN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAahB;AAED;;;;GAIG;AACH,sCAFW,MAAM,mBAkBhB"}
package/types/schema.d.ts CHANGED
@@ -6,7 +6,9 @@
6
6
  * @param {mongoose.SchemaOptions} options
7
7
  * @returns mongoose.Schema
8
8
  */
9
- export function createSchema(definition: object, options?: mongoose.SchemaOptions): mongoose.Schema<any, mongoose.Model<any, any, any, any, any>, any, any, any, any, {
9
+ export function createSchema(definition: object, options?: mongoose.SchemaOptions): mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, any, any, any, {
10
+ [x: string]: any;
11
+ }, {
10
12
  autoIndex?: boolean;
11
13
  autoCreate?: boolean;
12
14
  bufferCommands?: boolean;
@@ -16,8 +18,9 @@ export function createSchema(definition: object, options?: mongoose.SchemaOption
16
18
  max?: number;
17
19
  autoIndexId?: boolean;
18
20
  };
19
- collation?: import("mongoose/node_modules/mongodb").CollationOptions;
20
- timeseries?: import("mongoose/node_modules/mongodb").TimeSeriesCollectionOptions;
21
+ collation?: mongoose.mongo.CollationOptions;
22
+ collectionOptions?: mongoose.mongo.CreateCollectionOptions;
23
+ timeseries?: mongoose.mongo.TimeSeriesCollectionOptions;
21
24
  expireAfterSeconds?: number;
22
25
  expires?: string | number;
23
26
  collection?: string;
@@ -29,7 +32,7 @@ export function createSchema(definition: object, options?: mongoose.SchemaOption
29
32
  optimisticConcurrency?: boolean;
30
33
  pluginTags?: string[];
31
34
  read?: string;
32
- writeConcern?: import("mongoose/node_modules/mongodb").WriteConcern;
35
+ writeConcern?: mongoose.mongo.WriteConcern;
33
36
  safe?: boolean | {
34
37
  w?: string | number;
35
38
  wtimeout?: number;
@@ -42,14 +45,15 @@ export function createSchema(definition: object, options?: mongoose.SchemaOption
42
45
  getters: boolean;
43
46
  versionKey: boolean;
44
47
  transform: (doc: any, ret: any, options: any) => void;
45
- } | mongoose.ToObjectOptions;
48
+ } | mongoose.ToObjectOptions<any>;
46
49
  toObject: {
47
50
  getters: boolean;
48
51
  versionKey: boolean;
49
52
  transform: (doc: any, ret: any, options: any) => void;
50
- } | mongoose.ToObjectOptions;
53
+ } | mongoose.ToObjectOptions<any>;
51
54
  typeKey?: string;
52
55
  validateBeforeSave?: boolean;
56
+ validateModifiedOnly?: boolean;
53
57
  versionKey?: string | boolean;
54
58
  selectPopulatedPaths?: boolean;
55
59
  skipVersioning?: {
@@ -57,14 +61,16 @@ export function createSchema(definition: object, options?: mongoose.SchemaOption
57
61
  };
58
62
  storeSubdocValidationError?: boolean;
59
63
  timestamps: boolean | mongoose.SchemaTimestampsConfig;
60
- supressReservedKeysWarning?: boolean;
61
- statics?: any;
64
+ suppressReservedKeysWarning?: boolean;
65
+ statics?: {
66
+ [x: string]: any;
67
+ };
62
68
  methods?: any;
63
69
  query?: any;
64
70
  castNonArrays?: boolean;
65
71
  virtuals?: mongoose.SchemaOptionsVirtualsPropertyType<any, any, any>;
66
72
  overwriteModels?: boolean;
67
- }, any>;
73
+ }, any, any>;
68
74
  export function normalizeAttributes(arg: any, path?: any[]): any;
69
75
  import mongoose from "mongoose";
70
76
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.js"],"names":[],"mappings":"AAoBA;;;;;;;GAOG;AACH,yCAJW,MAAM,YACN,SAAS,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAuChC;AAED,iEAsBC"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.js"],"names":[],"mappings":"AAoBA;;;;;;;GAOG;AACH,yCAJW,MAAM,YACN,SAAS,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAuChC;AAED,iEAsBC"}
@@ -5,7 +5,7 @@
5
5
  * [Link](https://github.com/bedrockio/model#testing)
6
6
  * @returns mongoose.Model
7
7
  */
8
- export function createTestModel(...args: any[]): mongoose.Model<any, unknown, unknown, unknown, any>;
8
+ export function createTestModel(...args: any[]): mongoose.Model<any, unknown, unknown, unknown, any, any>;
9
9
  export function getTestModelName(): string;
10
10
  import mongoose from "mongoose";
11
11
  //# sourceMappingURL=testing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.js"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,qGAiBC;AAED,2CAEC"}
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.js"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,0GAiBC;AAED,2CAEC"}
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"AAiFA,kDAEC;AAED,oEAkFC;AAsBD,wEAkBC;AAwRD;;;EAEC;AAED;;;EAOC;AAheD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQK"}
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.js"],"names":[],"mappings":"AAiFA,kDAEC;AAED,oEAkFC;AAsBD,wEAkBC;AA0RD;;;EAEC;AAED;;;EAOC;AAleD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQK"}