@sprucelabs/schema 25.4.148 → 25.5.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.
@@ -0,0 +1,7 @@
1
+ import AbstractSchemaTest from '../../AbstractSchemaTest';
2
+ export default class GettingFieldsOffASchemaTest extends AbstractSchemaTest {
3
+ protected static throwsWithNothingPassed(): Promise<void>;
4
+ protected static noFieldsThrows(): Promise<void>;
5
+ protected static getsBacksFields(): Promise<void>;
6
+ protected static getsBackMoreFields(): Promise<void>;
7
+ }
@@ -0,0 +1,88 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
16
+ import { test, assert } from '@sprucelabs/test';
17
+ import { errorAssertUtil } from '@sprucelabs/test-utils';
18
+ import { buildSchema } from '../../index.js';
19
+ import AbstractSchemaTest from '../../AbstractSchemaTest.js';
20
+ import getFields from '../../utilities/getFields.js';
21
+ const noFieldsSchema = buildSchema({
22
+ id: 'noField',
23
+ fields: {},
24
+ });
25
+ const withFieldsSchema = buildSchema({
26
+ id: 'withField',
27
+ fields: {
28
+ firstName: {
29
+ type: 'text',
30
+ },
31
+ },
32
+ });
33
+ const withManyFieldsSchema = buildSchema({
34
+ id: 'withManyField',
35
+ fields: {
36
+ firstName: {
37
+ type: 'text',
38
+ },
39
+ lastName: {
40
+ type: 'text',
41
+ },
42
+ },
43
+ });
44
+ export default class GettingFieldsOffASchemaTest extends AbstractSchemaTest {
45
+ static throwsWithNothingPassed() {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ //@ts-ignore
48
+ const err = assert.doesThrow(() => getFields());
49
+ errorAssertUtil.assertError(err, 'INVALID_PARAMETERS', {
50
+ parameters: ['schema'],
51
+ });
52
+ });
53
+ }
54
+ static noFieldsThrows() {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const err = assert.doesThrow(() => getFields(noFieldsSchema));
57
+ errorAssertUtil.assertError(err, 'INVALID_PARAMETERS', {
58
+ parameters: ['schema'],
59
+ });
60
+ });
61
+ }
62
+ static getsBacksFields() {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ const actual = getFields(withFieldsSchema);
65
+ assert.isEqualDeep(actual, ['firstName']);
66
+ assert.isExactType(true);
67
+ });
68
+ }
69
+ static getsBackMoreFields() {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const actual = getFields(withManyFieldsSchema);
72
+ assert.isEqualDeep(actual, ['firstName', 'lastName']);
73
+ assert.isExactType(true);
74
+ });
75
+ }
76
+ }
77
+ __decorate([
78
+ test()
79
+ ], GettingFieldsOffASchemaTest, "throwsWithNothingPassed", null);
80
+ __decorate([
81
+ test()
82
+ ], GettingFieldsOffASchemaTest, "noFieldsThrows", null);
83
+ __decorate([
84
+ test()
85
+ ], GettingFieldsOffASchemaTest, "getsBacksFields", null);
86
+ __decorate([
87
+ test()
88
+ ], GettingFieldsOffASchemaTest, "getsBackMoreFields", null);
@@ -25,6 +25,7 @@ export { default as validateSchema } from './utilities/validateSchema';
25
25
  export { default as isSchemaValid } from './utilities/isSchemaValid';
26
26
  export { default as areSchemasTheSame } from './utilities/areSchemasTheSame';
27
27
  export { default as formatPhoneNumber } from './utilities/formatPhoneNumber';
28
+ export { default as getFields } from './utilities/getFields';
28
29
  export { default as isIdWithVersion } from './utilities/isIdWithVersion';
29
30
  export { default as normalizeSchemaToIdWithVersion } from './utilities/normalizeSchemaToIdWithVersion';
30
31
  export * from './utilities/formatPhoneNumber';
@@ -39,6 +39,7 @@ export { default as validateSchema } from './utilities/validateSchema.js';
39
39
  export { default as isSchemaValid } from './utilities/isSchemaValid.js';
40
40
  export { default as areSchemasTheSame } from './utilities/areSchemasTheSame.js';
41
41
  export { default as formatPhoneNumber } from './utilities/formatPhoneNumber.js';
42
+ export { default as getFields } from './utilities/getFields.js';
42
43
  export { default as isIdWithVersion } from './utilities/isIdWithVersion.js';
43
44
  export { default as normalizeSchemaToIdWithVersion } from './utilities/normalizeSchemaToIdWithVersion.js';
44
45
  export * from './utilities/formatPhoneNumber.js';
@@ -0,0 +1,2 @@
1
+ import { Schema, SchemaFieldNames } from '..';
2
+ export default function getFields<S extends Schema>(schema: S): SchemaFieldNames<S>[];
@@ -0,0 +1,12 @@
1
+ import SpruceError from '../errors/SpruceError.js';
2
+ export default function getFields(schema) {
3
+ var _a;
4
+ const names = Object.keys((_a = schema === null || schema === void 0 ? void 0 : schema.fields) !== null && _a !== void 0 ? _a : {});
5
+ if (names.length === 0) {
6
+ throw new SpruceError({
7
+ code: 'INVALID_PARAMETERS',
8
+ parameters: ['schema'],
9
+ });
10
+ }
11
+ return names;
12
+ }
package/build/index.d.ts CHANGED
@@ -25,6 +25,7 @@ export { default as validateSchema } from './utilities/validateSchema';
25
25
  export { default as isSchemaValid } from './utilities/isSchemaValid';
26
26
  export { default as areSchemasTheSame } from './utilities/areSchemasTheSame';
27
27
  export { default as formatPhoneNumber } from './utilities/formatPhoneNumber';
28
+ export { default as getFields } from './utilities/getFields';
28
29
  export { default as isIdWithVersion } from './utilities/isIdWithVersion';
29
30
  export { default as normalizeSchemaToIdWithVersion } from './utilities/normalizeSchemaToIdWithVersion';
30
31
  export * from './utilities/formatPhoneNumber';
package/build/index.js CHANGED
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.mapFieldErrorsToParameterErrors = exports.assertOptions = exports.fieldRegistrations = exports.SchemaRegistry = exports.SchemaEntityFactory = exports.FieldFactory = exports.normalizeSchemaToIdWithVersion = exports.isIdWithVersion = exports.formatPhoneNumber = exports.areSchemasTheSame = exports.isSchemaValid = exports.validateSchema = exports.dropPrivateFields = exports.dropFields = exports.makeFieldsOptional = exports.areSchemaValuesValid = exports.normalizeSchemaValues = exports.validateSchemaValues = exports.defaultSchemaValues = exports.registerFieldType = exports.buildSchema = exports.buildErrorSchema = exports.SchemaError = exports.selectAssertUtil = exports.validationErrorAssertUtil = void 0;
16
+ exports.mapFieldErrorsToParameterErrors = exports.assertOptions = exports.fieldRegistrations = exports.SchemaRegistry = exports.SchemaEntityFactory = exports.FieldFactory = exports.normalizeSchemaToIdWithVersion = exports.isIdWithVersion = exports.getFields = exports.formatPhoneNumber = exports.areSchemasTheSame = exports.isSchemaValid = exports.validateSchema = exports.dropPrivateFields = exports.dropFields = exports.makeFieldsOptional = exports.areSchemaValuesValid = exports.normalizeSchemaValues = exports.validateSchemaValues = exports.defaultSchemaValues = exports.registerFieldType = exports.buildSchema = exports.buildErrorSchema = exports.SchemaError = exports.selectAssertUtil = exports.validationErrorAssertUtil = void 0;
17
17
  __exportStar(require("./StaticSchemaEntityImplementation"), exports);
18
18
  const addressField_addon_1 = __importDefault(require("./addons/addressField.addon"));
19
19
  const booleanField_addon_1 = __importDefault(require("./addons/booleanField.addon"));
@@ -72,6 +72,8 @@ var areSchemasTheSame_1 = require("./utilities/areSchemasTheSame");
72
72
  Object.defineProperty(exports, "areSchemasTheSame", { enumerable: true, get: function () { return __importDefault(areSchemasTheSame_1).default; } });
73
73
  var formatPhoneNumber_1 = require("./utilities/formatPhoneNumber");
74
74
  Object.defineProperty(exports, "formatPhoneNumber", { enumerable: true, get: function () { return __importDefault(formatPhoneNumber_1).default; } });
75
+ var getFields_1 = require("./utilities/getFields");
76
+ Object.defineProperty(exports, "getFields", { enumerable: true, get: function () { return __importDefault(getFields_1).default; } });
75
77
  var isIdWithVersion_1 = require("./utilities/isIdWithVersion");
76
78
  Object.defineProperty(exports, "isIdWithVersion", { enumerable: true, get: function () { return __importDefault(isIdWithVersion_1).default; } });
77
79
  var normalizeSchemaToIdWithVersion_1 = require("./utilities/normalizeSchemaToIdWithVersion");
@@ -0,0 +1,2 @@
1
+ import { Schema, SchemaFieldNames } from '..';
2
+ export default function getFields<S extends Schema>(schema: S): SchemaFieldNames<S>[];
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
7
+ function getFields(schema) {
8
+ var _a;
9
+ const names = Object.keys((_a = schema === null || schema === void 0 ? void 0 : schema.fields) !== null && _a !== void 0 ? _a : {});
10
+ if (names.length === 0) {
11
+ throw new SpruceError_1.default({
12
+ code: 'INVALID_PARAMETERS',
13
+ parameters: ['schema'],
14
+ });
15
+ }
16
+ return names;
17
+ }
18
+ exports.default = getFields;
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "!build/__tests__",
9
9
  "esm"
10
10
  ],
11
- "version": "25.4.148",
11
+ "version": "25.5.0",
12
12
  "main": "./build/index.js",
13
13
  "types": "./build/index.d.ts",
14
14
  "module": "./build/esm/index.js",
@@ -73,7 +73,7 @@
73
73
  "@sprucelabs/jest-sheets-reporter": "^1.2.290",
74
74
  "@sprucelabs/resolve-path-aliases": "^1.0.246",
75
75
  "@sprucelabs/semantic-release": "^4.0.8",
76
- "@sprucelabs/spruce-test-fixtures": "^19.1.6",
76
+ "@sprucelabs/spruce-test-fixtures": "^19.1.10",
77
77
  "@sprucelabs/test-utils": "^3.0.347",
78
78
  "@types/lodash": "^4.14.178",
79
79
  "@types/mime-db": "^1.43.1",