@sprucelabs/schema 32.0.48 → 32.1.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.
@@ -1,7 +1,9 @@
1
1
  import { Schema } from '../schemas.static.types';
2
2
  export default class SchemaRegistry {
3
3
  private schemasById;
4
- private static instance;
4
+ private static instance?;
5
+ private shouldTrack;
6
+ constructor(shouldTrack?: boolean);
5
7
  static getInstance(): SchemaRegistry;
6
8
  trackSchema(schema: Schema): void;
7
9
  isTrackingSchema(id: string, version?: string, namespace?: string): boolean;
@@ -12,4 +14,5 @@ export default class SchemaRegistry {
12
14
  private getSchemaNotThrowing;
13
15
  private isTrackedById;
14
16
  forgetSchema(id: string, version?: string): void;
17
+ static reset(): void;
15
18
  }
@@ -1,16 +1,20 @@
1
1
  import SpruceError from '../errors/SpruceError.js';
2
2
  import validateSchema from '../utilities/validateSchema.js';
3
3
  export default class SchemaRegistry {
4
- constructor() {
4
+ constructor(shouldTrack = true) {
5
5
  this.schemasById = {};
6
+ this.shouldTrack = shouldTrack;
6
7
  }
7
8
  static getInstance() {
8
9
  if (!this.instance) {
9
- this.instance = new SchemaRegistry();
10
+ this.instance = new SchemaRegistry(process.env.SHOULD_USE_SCHEMA_REGISTRY !== 'false');
10
11
  }
11
12
  return this.instance;
12
13
  }
13
14
  trackSchema(schema) {
15
+ if (!this.shouldTrack) {
16
+ return;
17
+ }
14
18
  validateSchema(schema);
15
19
  const id = schema.id;
16
20
  if (!this.schemasById[id]) {
@@ -85,4 +89,7 @@ export default class SchemaRegistry {
85
89
  delete this.schemasById[id];
86
90
  }
87
91
  }
92
+ static reset() {
93
+ delete this.instance;
94
+ }
88
95
  }
@@ -1,7 +1,9 @@
1
1
  import { Schema } from '../schemas.static.types';
2
2
  export default class SchemaRegistry {
3
3
  private schemasById;
4
- private static instance;
4
+ private static instance?;
5
+ private shouldTrack;
6
+ constructor(shouldTrack?: boolean);
5
7
  static getInstance(): SchemaRegistry;
6
8
  trackSchema(schema: Schema): void;
7
9
  isTrackingSchema(id: string, version?: string, namespace?: string): boolean;
@@ -12,4 +14,5 @@ export default class SchemaRegistry {
12
14
  private getSchemaNotThrowing;
13
15
  private isTrackedById;
14
16
  forgetSchema(id: string, version?: string): void;
17
+ static reset(): void;
15
18
  }
@@ -6,16 +6,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
7
7
  const validateSchema_1 = __importDefault(require("../utilities/validateSchema"));
8
8
  class SchemaRegistry {
9
- constructor() {
9
+ constructor(shouldTrack = true) {
10
10
  this.schemasById = {};
11
+ this.shouldTrack = shouldTrack;
11
12
  }
12
13
  static getInstance() {
13
14
  if (!this.instance) {
14
- this.instance = new SchemaRegistry();
15
+ this.instance = new SchemaRegistry(process.env.SHOULD_USE_SCHEMA_REGISTRY !== 'false');
15
16
  }
16
17
  return this.instance;
17
18
  }
18
19
  trackSchema(schema) {
20
+ if (!this.shouldTrack) {
21
+ return;
22
+ }
19
23
  (0, validateSchema_1.default)(schema);
20
24
  const id = schema.id;
21
25
  if (!this.schemasById[id]) {
@@ -89,5 +93,8 @@ class SchemaRegistry {
89
93
  delete this.schemasById[id];
90
94
  }
91
95
  }
96
+ static reset() {
97
+ delete this.instance;
98
+ }
92
99
  }
93
100
  exports.default = SchemaRegistry;
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "!build/__tests__",
9
9
  "esm"
10
10
  ],
11
- "version": "32.0.48",
11
+ "version": "32.1.0",
12
12
  "main": "./build/index.js",
13
13
  "types": "./build/index.d.ts",
14
14
  "module": "./build/esm/index.js",