cosa 9.0.0 → 10.0.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2024 Losant IoT, Inc.
3
+ Copyright (c) 2025 Losant IoT, Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/lib/array.js CHANGED
@@ -1,4 +1,4 @@
1
- import clone from 'clone';
1
+ import { clone } from 'omnibelt';
2
2
  import Immutable from './immutable.js';
3
3
 
4
4
  /**
package/lib/errors.js CHANGED
@@ -1,39 +1,48 @@
1
- import TypedError from 'error/typed.js';
2
- import WrappedError from 'error/wrapped.js';
3
-
4
- // http response code reference:
5
- // 400 BAD REQUEST 401 UNAUTHORIZED 402 PAYMENT REQUIRED
6
- // 403 FORBIDDEN 404 NOT FOUND 405 METHOD NOT ALLOWED
7
- // 406 NOT ACCEPTABLE 407 PROXY AUTHENTICATION REQUIRED 408 REQUEST TIMEOUT
8
- // 409 CONFLICT 410 GONE 411 LENGTH REQUIRED
9
- // 412 PRECONDITION FAILED 413 REQUEST ENTITY TOO LARGE 414 REQUEST URI TOO LONG
10
- // 415 UNSUPPORTED MEDIA TYPE 416 REQUEST RANGE NOT SATISFIABLE 417 EXPECTATION FAILED
11
- //
12
- // 500 INTERNAL SERVER ERROR 501 NOT IMPLEMENTED 502 BAD GATEWAY
13
- // 503 SERVICE UNAVAILABLE 504 GATEWAY TIMEOUT 505 HTTP VERSION NOT SUPPORTED
14
-
15
1
  /**
16
2
  * Custom errors.
17
3
  * @namespace errors
18
4
  */
5
+
6
+ const createError = (type) => {
7
+ const result = new Error();
8
+ result.name = `${type}Error`;
9
+
10
+ Object.defineProperty(result, 'type', {
11
+ value: type,
12
+ enumerable: true,
13
+ writable: true,
14
+ configurable: true
15
+ });
16
+
17
+ return result;
18
+ };
19
+
19
20
  export default {
20
21
 
21
22
  /**
22
23
  * Error used when an action results in a conflict between documents.
23
24
  */
24
- Conflict: TypedError({
25
- type: 'Conflict',
26
- message: 'Document conflict',
27
- statusCode: 409
28
- }),
25
+ Conflict: ({ message = 'Document conflict' }) => {
26
+ const result = createError('Conflict');
27
+ result.message = message;
28
+ result.statusCode = 409;
29
+ return result;
30
+ },
29
31
 
30
32
  /**
31
33
  * Error used when validation of a document fails.
32
34
  */
33
- Validation: WrappedError({
34
- type: 'Validation',
35
- message: '{origMessage}',
36
- statusCode: 400
37
- })
35
+ Validation: (cause) => {
36
+ const result = createError('Validation');
37
+ result.message = cause.message;
38
+ result.statusCode = 400;
39
+
40
+ Object.defineProperty(result, 'cause', {
41
+ value: cause,
42
+ configurable: true,
43
+ enumerable: false
44
+ });
38
45
 
46
+ return result;
47
+ }
39
48
  };
package/lib/immutable.js CHANGED
@@ -1,4 +1,4 @@
1
- import clone from 'clone';
1
+ import { clone } from 'omnibelt';
2
2
 
3
3
  const IMMUTABLE_TYPES = [ 'function', 'string', 'boolean', 'number', 'undefined' ];
4
4
 
package/lib/model.js CHANGED
@@ -3,12 +3,11 @@ import etag from 'etag';
3
3
  import _debug from 'debug';
4
4
  const debug = _debug('cosa:model');
5
5
  import objectPath from 'object-path';
6
- import clone from 'clone';
7
6
  import { ObjectId, BSON } from 'mongodb';
8
7
  import Cursor from './cursor.js';
9
8
  import errors from './errors.js';
10
9
  import {
11
- pathEq, complement, pick, omit, has, isEmpty, isPlainObject
10
+ pathEq, complement, pick, omit, has, isEmpty, isPlainObject, clone
12
11
  } from 'omnibelt';
13
12
  import { buildPropertySchema } from './utils.js';
14
13
  import Immutable from './immutable.js';
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "cosa",
3
- "version": "9.0.0",
3
+ "version": "10.0.0",
4
4
  "description": "Cosa Models for MongoDB",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
7
7
  "engines": {
8
- "node": ">=18",
8
+ "node": ">=20",
9
9
  "yarn": ">=1.2.1"
10
10
  },
11
11
  "scripts": {
12
- "lint": "esw . --ext .js",
12
+ "lint": "eslint . --ext .js",
13
13
  "lint:fix": "yarn lint --fix",
14
- "lint:watch": "yarn lint --watch",
15
14
  "lint:changed": "lint-staged",
16
15
  "reinstall": "rm -rf node_modules && yarn install",
17
16
  "test": "NODE_ENV='test' COSA_DB_URI='mongodb://localhost:27017/test' mocha",
@@ -20,7 +19,6 @@
20
19
  },
21
20
  "author": "Losant <hello@losant.com>",
22
21
  "license": "MIT",
23
-
24
22
  "bugs": {
25
23
  "url": "https://github.com/Losant/cosa/issues"
26
24
  },
@@ -29,34 +27,28 @@
29
27
  "url": "git+https://github.com/Losant/cosa.git"
30
28
  },
31
29
  "lint-staged": {
32
- "*.js": "esw"
30
+ "*.js": "eslint"
33
31
  },
34
32
  "files": [
35
33
  "lib"
36
34
  ],
37
35
  "dependencies": {
38
- "clone": "^2.1.2",
39
- "debug": "^4.3.6",
40
- "error": "^7.0.2",
36
+ "debug": "^4.4.1",
41
37
  "etag": "^1.8.1",
42
- "joi": "^17.13.3",
43
- "mongodb": "~6.8.0",
38
+ "joi": "^18.0.1",
39
+ "mongodb": "~6.18.0",
44
40
  "object-path": "^0.11.8",
45
41
  "omnibelt": "^4.0.0"
46
42
  },
47
43
  "devDependencies": {
48
- "@losant/eslint-config-losant": "^1.6.1",
44
+ "@losant/eslint-config-losant": "^2.0.1",
49
45
  "husky": "^9.1.5",
50
- "lint-staged": "~15.2.9",
51
- "chai": "^5.1.1",
52
- "chai-as-promised": "^8.0.0",
53
- "chai-datetime": "^1.8.0",
54
- "documentation": "^14.0.2",
55
- "mocha": "^10.7.3",
56
- "string-template": "^1.0.0"
57
- },
58
- "eslintConfig": {
59
- "extends": "@losant/eslint-config-losant/env/esm"
46
+ "lint-staged": "^16.1.5",
47
+ "chai": "^6.0.1",
48
+ "chai-as-promised": "^8.0.2",
49
+ "chai-datetime": "^1.8.1",
50
+ "documentation": "^14.0.3",
51
+ "mocha": "^11.7.1"
60
52
  },
61
53
  "mocha": {
62
54
  "require": "chai",
@@ -64,4 +56,4 @@
64
56
  "ui": "bdd",
65
57
  "check-leaks": true
66
58
  }
67
- }
59
+ }