@palmares/schemas 0.0.1
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/.turbo/turbo-build$colon$watch.log +424 -0
- package/.turbo/turbo-build.log +13 -0
- package/.turbo/turbo-build:watch.log +26 -0
- package/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/dist/cjs/src/adapter/fields/array.js +157 -0
- package/dist/cjs/src/adapter/fields/boolean.js +167 -0
- package/dist/cjs/src/adapter/fields/datetime.js +167 -0
- package/dist/cjs/src/adapter/fields/index.js +311 -0
- package/dist/cjs/src/adapter/fields/number.js +167 -0
- package/dist/cjs/src/adapter/fields/object.js +167 -0
- package/dist/cjs/src/adapter/fields/string.js +167 -0
- package/dist/cjs/src/adapter/fields/union.js +167 -0
- package/dist/cjs/src/adapter/index.js +198 -0
- package/dist/cjs/src/adapter/types.js +4 -0
- package/dist/cjs/src/compile.js +262 -0
- package/dist/cjs/src/conf.js +27 -0
- package/dist/cjs/src/constants.js +42 -0
- package/dist/cjs/src/domain.js +12 -0
- package/dist/cjs/src/exceptions.js +168 -0
- package/dist/cjs/src/index.js +365 -0
- package/dist/cjs/src/model.js +628 -0
- package/dist/cjs/src/parsers/convert-from-number.js +20 -0
- package/dist/cjs/src/parsers/convert-from-string.js +24 -0
- package/dist/cjs/src/parsers/index.js +25 -0
- package/dist/cjs/src/schema/array.js +890 -0
- package/dist/cjs/src/schema/boolean.js +826 -0
- package/dist/cjs/src/schema/datetime.js +778 -0
- package/dist/cjs/src/schema/index.js +17 -0
- package/dist/cjs/src/schema/number.js +960 -0
- package/dist/cjs/src/schema/object.js +999 -0
- package/dist/cjs/src/schema/schema.js +1788 -0
- package/dist/cjs/src/schema/string.js +948 -0
- package/dist/cjs/src/schema/types.js +4 -0
- package/dist/cjs/src/schema/union.js +952 -0
- package/dist/cjs/src/types.js +4 -0
- package/dist/cjs/src/utils.js +627 -0
- package/dist/cjs/src/validators/array.js +457 -0
- package/dist/cjs/src/validators/boolean.js +199 -0
- package/dist/cjs/src/validators/datetime.js +287 -0
- package/dist/cjs/src/validators/number.js +403 -0
- package/dist/cjs/src/validators/object.js +290 -0
- package/dist/cjs/src/validators/schema.js +318 -0
- package/dist/cjs/src/validators/string.js +439 -0
- package/dist/cjs/src/validators/types.js +4 -0
- package/dist/cjs/src/validators/union.js +232 -0
- package/dist/cjs/src/validators/utils.js +426 -0
- package/dist/cjs/tsconfig.types.tsbuildinfo +1 -0
- package/dist/cjs/types/adapter/fields/array.d.ts +20 -0
- package/dist/cjs/types/adapter/fields/array.d.ts.map +1 -0
- package/dist/cjs/types/adapter/fields/boolean.d.ts +25 -0
- package/dist/cjs/types/adapter/fields/boolean.d.ts.map +1 -0
- package/dist/cjs/types/adapter/fields/datetime.d.ts +25 -0
- package/dist/cjs/types/adapter/fields/datetime.d.ts.map +1 -0
- package/dist/cjs/types/adapter/fields/index.d.ts +31 -0
- package/dist/cjs/types/adapter/fields/index.d.ts.map +1 -0
- package/dist/cjs/types/adapter/fields/number.d.ts +25 -0
- package/dist/cjs/types/adapter/fields/number.d.ts.map +1 -0
- package/dist/cjs/types/adapter/fields/object.d.ts +25 -0
- package/dist/cjs/types/adapter/fields/object.d.ts.map +1 -0
- package/dist/cjs/types/adapter/fields/string.d.ts +25 -0
- package/dist/cjs/types/adapter/fields/string.d.ts.map +1 -0
- package/dist/cjs/types/adapter/fields/union.d.ts +25 -0
- package/dist/cjs/types/adapter/fields/union.d.ts.map +1 -0
- package/dist/cjs/types/adapter/index.d.ts +25 -0
- package/dist/cjs/types/adapter/index.d.ts.map +1 -0
- package/dist/cjs/types/adapter/types.d.ts +144 -0
- package/dist/cjs/types/adapter/types.d.ts.map +1 -0
- package/dist/cjs/types/compile.d.ts +3 -0
- package/dist/cjs/types/compile.d.ts.map +1 -0
- package/dist/cjs/types/conf.d.ts +16 -0
- package/dist/cjs/types/conf.d.ts.map +1 -0
- package/dist/cjs/types/constants.d.ts +6 -0
- package/dist/cjs/types/constants.d.ts.map +1 -0
- package/dist/cjs/types/domain.d.ts +21 -0
- package/dist/cjs/types/domain.d.ts.map +1 -0
- package/dist/cjs/types/exceptions.d.ts +13 -0
- package/dist/cjs/types/exceptions.d.ts.map +1 -0
- package/dist/cjs/types/index.d.ts +240 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/model.d.ts +136 -0
- package/dist/cjs/types/model.d.ts.map +1 -0
- package/dist/cjs/types/parsers/convert-from-number.d.ts +15 -0
- package/dist/cjs/types/parsers/convert-from-number.d.ts.map +1 -0
- package/dist/cjs/types/parsers/convert-from-string.d.ts +9 -0
- package/dist/cjs/types/parsers/convert-from-string.d.ts.map +1 -0
- package/dist/cjs/types/parsers/index.d.ts +3 -0
- package/dist/cjs/types/parsers/index.d.ts.map +1 -0
- package/dist/cjs/types/schema/array.d.ts +429 -0
- package/dist/cjs/types/schema/array.d.ts.map +1 -0
- package/dist/cjs/types/schema/boolean.d.ts +501 -0
- package/dist/cjs/types/schema/boolean.d.ts.map +1 -0
- package/dist/cjs/types/schema/datetime.d.ts +474 -0
- package/dist/cjs/types/schema/datetime.d.ts.map +1 -0
- package/dist/cjs/types/schema/index.d.ts +4 -0
- package/dist/cjs/types/schema/index.d.ts.map +1 -0
- package/dist/cjs/types/schema/number.d.ts +667 -0
- package/dist/cjs/types/schema/number.d.ts.map +1 -0
- package/dist/cjs/types/schema/object.d.ts +450 -0
- package/dist/cjs/types/schema/object.d.ts.map +1 -0
- package/dist/cjs/types/schema/schema.d.ts +646 -0
- package/dist/cjs/types/schema/schema.d.ts.map +1 -0
- package/dist/cjs/types/schema/string.d.ts +606 -0
- package/dist/cjs/types/schema/string.d.ts.map +1 -0
- package/dist/cjs/types/schema/types.d.ts +70 -0
- package/dist/cjs/types/schema/types.d.ts.map +1 -0
- package/dist/cjs/types/schema/union.d.ts +388 -0
- package/dist/cjs/types/schema/union.d.ts.map +1 -0
- package/dist/cjs/types/types.d.ts +11 -0
- package/dist/cjs/types/types.d.ts.map +1 -0
- package/dist/cjs/types/utils.d.ts +79 -0
- package/dist/cjs/types/utils.d.ts.map +1 -0
- package/dist/cjs/types/validators/array.d.ts +8 -0
- package/dist/cjs/types/validators/array.d.ts.map +1 -0
- package/dist/cjs/types/validators/boolean.d.ts +4 -0
- package/dist/cjs/types/validators/boolean.d.ts.map +1 -0
- package/dist/cjs/types/validators/datetime.d.ts +7 -0
- package/dist/cjs/types/validators/datetime.d.ts.map +1 -0
- package/dist/cjs/types/validators/number.d.ts +10 -0
- package/dist/cjs/types/validators/number.d.ts.map +1 -0
- package/dist/cjs/types/validators/object.d.ts +6 -0
- package/dist/cjs/types/validators/object.d.ts.map +1 -0
- package/dist/cjs/types/validators/schema.d.ts +10 -0
- package/dist/cjs/types/validators/schema.d.ts.map +1 -0
- package/dist/cjs/types/validators/string.d.ts +12 -0
- package/dist/cjs/types/validators/string.d.ts.map +1 -0
- package/dist/cjs/types/validators/types.d.ts +2 -0
- package/dist/cjs/types/validators/types.d.ts.map +1 -0
- package/dist/cjs/types/validators/union.d.ts +4 -0
- package/dist/cjs/types/validators/union.d.ts.map +1 -0
- package/dist/cjs/types/validators/utils.d.ts +83 -0
- package/dist/cjs/types/validators/utils.d.ts.map +1 -0
- package/dist/esm/src/adapter/fields/array.js +13 -0
- package/dist/esm/src/adapter/fields/boolean.js +20 -0
- package/dist/esm/src/adapter/fields/datetime.js +20 -0
- package/dist/esm/src/adapter/fields/index.js +37 -0
- package/dist/esm/src/adapter/fields/number.js +20 -0
- package/dist/esm/src/adapter/fields/object.js +20 -0
- package/dist/esm/src/adapter/fields/string.js +20 -0
- package/dist/esm/src/adapter/fields/union.js +20 -0
- package/dist/esm/src/adapter/index.js +18 -0
- package/dist/esm/src/adapter/types.js +1 -0
- package/dist/esm/src/compile.js +10 -0
- package/dist/esm/src/conf.js +19 -0
- package/dist/esm/src/constants.js +5 -0
- package/dist/esm/src/domain.js +2 -0
- package/dist/esm/src/exceptions.js +15 -0
- package/dist/esm/src/index.js +160 -0
- package/dist/esm/src/model.js +255 -0
- package/dist/esm/src/parsers/convert-from-number.js +8 -0
- package/dist/esm/src/parsers/convert-from-string.js +14 -0
- package/dist/esm/src/parsers/index.js +2 -0
- package/dist/esm/src/schema/array.js +403 -0
- package/dist/esm/src/schema/boolean.js +465 -0
- package/dist/esm/src/schema/datetime.js +423 -0
- package/dist/esm/src/schema/index.js +3 -0
- package/dist/esm/src/schema/number.js +592 -0
- package/dist/esm/src/schema/object.js +464 -0
- package/dist/esm/src/schema/schema.js +728 -0
- package/dist/esm/src/schema/string.js +579 -0
- package/dist/esm/src/schema/types.js +1 -0
- package/dist/esm/src/schema/union.js +388 -0
- package/dist/esm/src/types.js +1 -0
- package/dist/esm/src/utils.js +175 -0
- package/dist/esm/src/validators/array.js +135 -0
- package/dist/esm/src/validators/boolean.js +35 -0
- package/dist/esm/src/validators/datetime.js +85 -0
- package/dist/esm/src/validators/number.js +162 -0
- package/dist/esm/src/validators/object.js +38 -0
- package/dist/esm/src/validators/schema.js +114 -0
- package/dist/esm/src/validators/string.js +174 -0
- package/dist/esm/src/validators/types.js +1 -0
- package/dist/esm/src/validators/union.js +38 -0
- package/dist/esm/src/validators/utils.js +120 -0
- package/package.json +48 -0
- package/src/adapter/fields/array.ts +31 -0
- package/src/adapter/fields/boolean.ts +48 -0
- package/src/adapter/fields/datetime.ts +49 -0
- package/src/adapter/fields/index.ts +72 -0
- package/src/adapter/fields/number.ts +49 -0
- package/src/adapter/fields/object.ts +49 -0
- package/src/adapter/fields/string.ts +49 -0
- package/src/adapter/fields/union.ts +49 -0
- package/src/adapter/index.ts +34 -0
- package/src/adapter/types.ts +261 -0
- package/src/compile.ts +14 -0
- package/src/conf.ts +27 -0
- package/src/constants.ts +9 -0
- package/src/domain.ts +3 -0
- package/src/exceptions.ts +17 -0
- package/src/index.ts +338 -0
- package/src/model.ts +501 -0
- package/src/parsers/convert-from-number.ts +13 -0
- package/src/parsers/convert-from-string.ts +19 -0
- package/src/parsers/index.ts +2 -0
- package/src/schema/array.ts +633 -0
- package/src/schema/boolean.ts +700 -0
- package/src/schema/datetime.ts +613 -0
- package/src/schema/index.ts +5 -0
- package/src/schema/number.ts +885 -0
- package/src/schema/object.ts +699 -0
- package/src/schema/schema.ts +1093 -0
- package/src/schema/string.ts +807 -0
- package/src/schema/types.ts +126 -0
- package/src/schema/union.ts +596 -0
- package/src/types.ts +13 -0
- package/src/utils.ts +322 -0
- package/src/validators/array.ts +164 -0
- package/src/validators/boolean.ts +46 -0
- package/src/validators/datetime.ts +113 -0
- package/src/validators/number.ts +188 -0
- package/src/validators/object.ts +55 -0
- package/src/validators/schema.ts +134 -0
- package/src/validators/string.ts +215 -0
- package/src/validators/types.ts +1 -0
- package/src/validators/union.ts +52 -0
- package/src/validators/utils.ts +200 -0
- package/tsconfig.json +9 -0
- package/tsconfig.types.json +10 -0
@@ -0,0 +1,168 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
7
|
+
enumerable: true,
|
8
|
+
get: all[name]
|
9
|
+
});
|
10
|
+
}
|
11
|
+
_export(exports, {
|
12
|
+
NoAdapterFoundError: function() {
|
13
|
+
return NoAdapterFoundError;
|
14
|
+
},
|
15
|
+
SchemaAdapterNotImplementedError: function() {
|
16
|
+
return SchemaAdapterNotImplementedError;
|
17
|
+
},
|
18
|
+
TranslatableFieldNotImplementedError: function() {
|
19
|
+
return TranslatableFieldNotImplementedError;
|
20
|
+
}
|
21
|
+
});
|
22
|
+
function _assert_this_initialized(self) {
|
23
|
+
if (self === void 0) {
|
24
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
25
|
+
}
|
26
|
+
return self;
|
27
|
+
}
|
28
|
+
function _class_call_check(instance, Constructor) {
|
29
|
+
if (!(instance instanceof Constructor)) {
|
30
|
+
throw new TypeError("Cannot call a class as a function");
|
31
|
+
}
|
32
|
+
}
|
33
|
+
function _construct(Parent, args, Class) {
|
34
|
+
if (_is_native_reflect_construct()) {
|
35
|
+
_construct = Reflect.construct;
|
36
|
+
} else {
|
37
|
+
_construct = function construct(Parent, args, Class) {
|
38
|
+
var a = [
|
39
|
+
null
|
40
|
+
];
|
41
|
+
a.push.apply(a, args);
|
42
|
+
var Constructor = Function.bind.apply(Parent, a);
|
43
|
+
var instance = new Constructor();
|
44
|
+
if (Class) _set_prototype_of(instance, Class.prototype);
|
45
|
+
return instance;
|
46
|
+
};
|
47
|
+
}
|
48
|
+
return _construct.apply(null, arguments);
|
49
|
+
}
|
50
|
+
function _get_prototype_of(o) {
|
51
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
52
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
53
|
+
};
|
54
|
+
return _get_prototype_of(o);
|
55
|
+
}
|
56
|
+
function _inherits(subClass, superClass) {
|
57
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
58
|
+
throw new TypeError("Super expression must either be null or a function");
|
59
|
+
}
|
60
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
61
|
+
constructor: {
|
62
|
+
value: subClass,
|
63
|
+
writable: true,
|
64
|
+
configurable: true
|
65
|
+
}
|
66
|
+
});
|
67
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
68
|
+
}
|
69
|
+
function _is_native_function(fn) {
|
70
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
71
|
+
}
|
72
|
+
function _possible_constructor_return(self, call) {
|
73
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
74
|
+
return call;
|
75
|
+
}
|
76
|
+
return _assert_this_initialized(self);
|
77
|
+
}
|
78
|
+
function _set_prototype_of(o, p) {
|
79
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
80
|
+
o.__proto__ = p;
|
81
|
+
return o;
|
82
|
+
};
|
83
|
+
return _set_prototype_of(o, p);
|
84
|
+
}
|
85
|
+
function _type_of(obj) {
|
86
|
+
"@swc/helpers - typeof";
|
87
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
88
|
+
}
|
89
|
+
function _wrap_native_super(Class) {
|
90
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
91
|
+
_wrap_native_super = function wrapNativeSuper(Class) {
|
92
|
+
if (Class === null || !_is_native_function(Class)) return Class;
|
93
|
+
if (typeof Class !== "function") {
|
94
|
+
throw new TypeError("Super expression must either be null or a function");
|
95
|
+
}
|
96
|
+
if (typeof _cache !== "undefined") {
|
97
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
98
|
+
_cache.set(Class, Wrapper);
|
99
|
+
}
|
100
|
+
function Wrapper() {
|
101
|
+
return _construct(Class, arguments, _get_prototype_of(this).constructor);
|
102
|
+
}
|
103
|
+
Wrapper.prototype = Object.create(Class.prototype, {
|
104
|
+
constructor: {
|
105
|
+
value: Wrapper,
|
106
|
+
enumerable: false,
|
107
|
+
writable: true,
|
108
|
+
configurable: true
|
109
|
+
}
|
110
|
+
});
|
111
|
+
return _set_prototype_of(Wrapper, Class);
|
112
|
+
};
|
113
|
+
return _wrap_native_super(Class);
|
114
|
+
}
|
115
|
+
function _is_native_reflect_construct() {
|
116
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
117
|
+
if (Reflect.construct.sham) return false;
|
118
|
+
if (typeof Proxy === "function") return true;
|
119
|
+
try {
|
120
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
121
|
+
return true;
|
122
|
+
} catch (e) {
|
123
|
+
return false;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
function _create_super(Derived) {
|
127
|
+
var hasNativeReflectConstruct = _is_native_reflect_construct();
|
128
|
+
return function _createSuperInternal() {
|
129
|
+
var Super = _get_prototype_of(Derived), result;
|
130
|
+
if (hasNativeReflectConstruct) {
|
131
|
+
var NewTarget = _get_prototype_of(this).constructor;
|
132
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
133
|
+
} else {
|
134
|
+
result = Super.apply(this, arguments);
|
135
|
+
}
|
136
|
+
return _possible_constructor_return(this, result);
|
137
|
+
};
|
138
|
+
}
|
139
|
+
var SchemaAdapterNotImplementedError = /*#__PURE__*/ function(Error1) {
|
140
|
+
"use strict";
|
141
|
+
_inherits(SchemaAdapterNotImplementedError, Error1);
|
142
|
+
var _super = _create_super(SchemaAdapterNotImplementedError);
|
143
|
+
function SchemaAdapterNotImplementedError(args) {
|
144
|
+
_class_call_check(this, SchemaAdapterNotImplementedError);
|
145
|
+
return _super.call(this, "Schema adapter did not implement ".concat(args.functionName, " in ").concat(args.className));
|
146
|
+
}
|
147
|
+
return SchemaAdapterNotImplementedError;
|
148
|
+
}(_wrap_native_super(Error));
|
149
|
+
var NoAdapterFoundError = /*#__PURE__*/ function(Error1) {
|
150
|
+
"use strict";
|
151
|
+
_inherits(NoAdapterFoundError, Error1);
|
152
|
+
var _super = _create_super(NoAdapterFoundError);
|
153
|
+
function NoAdapterFoundError() {
|
154
|
+
_class_call_check(this, NoAdapterFoundError);
|
155
|
+
return _super.call(this, 'No adapter found, please define an adapter using setDefaultAdapter() before using any schema.');
|
156
|
+
}
|
157
|
+
return NoAdapterFoundError;
|
158
|
+
}(_wrap_native_super(Error));
|
159
|
+
var TranslatableFieldNotImplementedError = /*#__PURE__*/ function(Error1) {
|
160
|
+
"use strict";
|
161
|
+
_inherits(TranslatableFieldNotImplementedError, Error1);
|
162
|
+
var _super = _create_super(TranslatableFieldNotImplementedError);
|
163
|
+
function TranslatableFieldNotImplementedError(fieldName) {
|
164
|
+
_class_call_check(this, TranslatableFieldNotImplementedError);
|
165
|
+
return _super.call(this, "TranslatableField '".concat(fieldName, "' did not implement the 'schema' key on 'customAttributes'"));
|
166
|
+
}
|
167
|
+
return TranslatableFieldNotImplementedError;
|
168
|
+
}(_wrap_native_super(Error));
|
@@ -0,0 +1,365 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
7
|
+
enumerable: true,
|
8
|
+
get: all[name]
|
9
|
+
});
|
10
|
+
}
|
11
|
+
_export(exports, {
|
12
|
+
ArrayFieldAdapter: function() {
|
13
|
+
return _array1.default;
|
14
|
+
},
|
15
|
+
ArraySchema: function() {
|
16
|
+
return _array.default;
|
17
|
+
},
|
18
|
+
BooleanFieldAdapter: function() {
|
19
|
+
return _boolean1.default;
|
20
|
+
},
|
21
|
+
BooleanSchema: function() {
|
22
|
+
return _boolean.default;
|
23
|
+
},
|
24
|
+
DatetimeFieldAdapter: function() {
|
25
|
+
return _datetime1.default;
|
26
|
+
},
|
27
|
+
DatetimeSchema: function() {
|
28
|
+
return _datetime.default;
|
29
|
+
},
|
30
|
+
FieldAdapter: function() {
|
31
|
+
return _fields.default;
|
32
|
+
},
|
33
|
+
NumberAdapter: function() {
|
34
|
+
return _number1.default;
|
35
|
+
},
|
36
|
+
NumberSchema: function() {
|
37
|
+
return _number.default;
|
38
|
+
},
|
39
|
+
ObjectFieldAdapter: function() {
|
40
|
+
return _object1.default;
|
41
|
+
},
|
42
|
+
ObjectSchema: function() {
|
43
|
+
return _object.default;
|
44
|
+
},
|
45
|
+
Schema: function() {
|
46
|
+
return _schema.default;
|
47
|
+
},
|
48
|
+
SchemaAdapter: function() {
|
49
|
+
return _adapter.default;
|
50
|
+
},
|
51
|
+
StringFieldAdapter: function() {
|
52
|
+
return _string1.default;
|
53
|
+
},
|
54
|
+
StringSchema: function() {
|
55
|
+
return _string.default;
|
56
|
+
},
|
57
|
+
UnionFieldAdapter: function() {
|
58
|
+
return _union1.default;
|
59
|
+
},
|
60
|
+
UnionSchema: function() {
|
61
|
+
return _union.default;
|
62
|
+
},
|
63
|
+
array: function() {
|
64
|
+
return _array.array;
|
65
|
+
},
|
66
|
+
boolean: function() {
|
67
|
+
return _boolean.boolean;
|
68
|
+
},
|
69
|
+
compile: function() {
|
70
|
+
return _compile.default;
|
71
|
+
},
|
72
|
+
datetime: function() {
|
73
|
+
return _datetime.datetime;
|
74
|
+
},
|
75
|
+
default: function() {
|
76
|
+
return _domain.default;
|
77
|
+
},
|
78
|
+
getSchemasWithDefaultAdapter: function() {
|
79
|
+
return getSchemasWithDefaultAdapter;
|
80
|
+
},
|
81
|
+
modelSchema: function() {
|
82
|
+
return _model.modelSchema;
|
83
|
+
},
|
84
|
+
number: function() {
|
85
|
+
return _number.number;
|
86
|
+
},
|
87
|
+
object: function() {
|
88
|
+
return _object.object;
|
89
|
+
},
|
90
|
+
schema: function() {
|
91
|
+
return _schema.schema;
|
92
|
+
},
|
93
|
+
setDefaultAdapter: function() {
|
94
|
+
return _conf.setDefaultAdapter;
|
95
|
+
},
|
96
|
+
string: function() {
|
97
|
+
return _string.string;
|
98
|
+
},
|
99
|
+
union: function() {
|
100
|
+
return _union.union;
|
101
|
+
}
|
102
|
+
});
|
103
|
+
var _adapter = /*#__PURE__*/ _interop_require_default(require("./adapter"));
|
104
|
+
var _model = require("./model");
|
105
|
+
var _array = /*#__PURE__*/ _interop_require_wildcard(require("./schema/array"));
|
106
|
+
var _boolean = /*#__PURE__*/ _interop_require_wildcard(require("./schema/boolean"));
|
107
|
+
var _datetime = /*#__PURE__*/ _interop_require_wildcard(require("./schema/datetime"));
|
108
|
+
var _number = /*#__PURE__*/ _interop_require_wildcard(require("./schema/number"));
|
109
|
+
var _object = /*#__PURE__*/ _interop_require_wildcard(require("./schema/object"));
|
110
|
+
var _schema = /*#__PURE__*/ _interop_require_wildcard(require("./schema/schema"));
|
111
|
+
var _string = /*#__PURE__*/ _interop_require_wildcard(require("./schema/string"));
|
112
|
+
var _union = /*#__PURE__*/ _interop_require_wildcard(require("./schema/union"));
|
113
|
+
var _domain = /*#__PURE__*/ _interop_require_default(require("./domain"));
|
114
|
+
var _fields = /*#__PURE__*/ _interop_require_default(require("./adapter/fields"));
|
115
|
+
var _number1 = /*#__PURE__*/ _interop_require_default(require("./adapter/fields/number"));
|
116
|
+
var _object1 = /*#__PURE__*/ _interop_require_default(require("./adapter/fields/object"));
|
117
|
+
var _union1 = /*#__PURE__*/ _interop_require_default(require("./adapter/fields/union"));
|
118
|
+
var _string1 = /*#__PURE__*/ _interop_require_default(require("./adapter/fields/string"));
|
119
|
+
var _array1 = /*#__PURE__*/ _interop_require_default(require("./adapter/fields/array"));
|
120
|
+
var _boolean1 = /*#__PURE__*/ _interop_require_default(require("./adapter/fields/boolean"));
|
121
|
+
var _datetime1 = /*#__PURE__*/ _interop_require_default(require("./adapter/fields/datetime"));
|
122
|
+
var _conf = require("./conf");
|
123
|
+
_export_star(require("./adapter/types"), exports);
|
124
|
+
_export_star(require("./schema"), exports);
|
125
|
+
var _compile = /*#__PURE__*/ _interop_require_default(require("./compile"));
|
126
|
+
function _array_like_to_array(arr, len) {
|
127
|
+
if (len == null || len > arr.length) len = arr.length;
|
128
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
129
|
+
return arr2;
|
130
|
+
}
|
131
|
+
function _array_without_holes(arr) {
|
132
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
133
|
+
}
|
134
|
+
function _export_star(from, to) {
|
135
|
+
Object.keys(from).forEach(function(k) {
|
136
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
137
|
+
Object.defineProperty(to, k, {
|
138
|
+
enumerable: true,
|
139
|
+
get: function() {
|
140
|
+
return from[k];
|
141
|
+
}
|
142
|
+
});
|
143
|
+
}
|
144
|
+
});
|
145
|
+
return from;
|
146
|
+
}
|
147
|
+
function _interop_require_default(obj) {
|
148
|
+
return obj && obj.__esModule ? obj : {
|
149
|
+
default: obj
|
150
|
+
};
|
151
|
+
}
|
152
|
+
function _getRequireWildcardCache(nodeInterop) {
|
153
|
+
if (typeof WeakMap !== "function") return null;
|
154
|
+
var cacheBabelInterop = new WeakMap();
|
155
|
+
var cacheNodeInterop = new WeakMap();
|
156
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
157
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
158
|
+
})(nodeInterop);
|
159
|
+
}
|
160
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
161
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
162
|
+
return obj;
|
163
|
+
}
|
164
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
165
|
+
return {
|
166
|
+
default: obj
|
167
|
+
};
|
168
|
+
}
|
169
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
170
|
+
if (cache && cache.has(obj)) {
|
171
|
+
return cache.get(obj);
|
172
|
+
}
|
173
|
+
var newObj = {
|
174
|
+
__proto__: null
|
175
|
+
};
|
176
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
177
|
+
for(var key in obj){
|
178
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
179
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
180
|
+
if (desc && (desc.get || desc.set)) {
|
181
|
+
Object.defineProperty(newObj, key, desc);
|
182
|
+
} else {
|
183
|
+
newObj[key] = obj[key];
|
184
|
+
}
|
185
|
+
}
|
186
|
+
}
|
187
|
+
newObj.default = obj;
|
188
|
+
if (cache) {
|
189
|
+
cache.set(obj, newObj);
|
190
|
+
}
|
191
|
+
return newObj;
|
192
|
+
}
|
193
|
+
function _iterable_to_array(iter) {
|
194
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
195
|
+
}
|
196
|
+
function _non_iterable_spread() {
|
197
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
198
|
+
}
|
199
|
+
function _to_consumable_array(arr) {
|
200
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
201
|
+
}
|
202
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
203
|
+
if (!o) return;
|
204
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
205
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
206
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
207
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
208
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
209
|
+
}
|
210
|
+
function getSchemasWithDefaultAdapter() {
|
211
|
+
return {
|
212
|
+
number: function() {
|
213
|
+
return _number.default.new();
|
214
|
+
},
|
215
|
+
string: function() {
|
216
|
+
return _string.default.new();
|
217
|
+
},
|
218
|
+
array: function() {
|
219
|
+
for(var _len = arguments.length, schemas = new Array(_len), _key = 0; _key < _len; _key++){
|
220
|
+
schemas[_key] = arguments[_key];
|
221
|
+
}
|
222
|
+
return _array.array.apply(void 0, _to_consumable_array(schemas));
|
223
|
+
},
|
224
|
+
boolean: function() {
|
225
|
+
return _boolean.default.new();
|
226
|
+
},
|
227
|
+
object: function(data) {
|
228
|
+
return _object.default.new(data);
|
229
|
+
},
|
230
|
+
union: function() {
|
231
|
+
for(var _len = arguments.length, schemas = new Array(_len), _key = 0; _key < _len; _key++){
|
232
|
+
schemas[_key] = arguments[_key];
|
233
|
+
}
|
234
|
+
return _union.default.new(schemas);
|
235
|
+
},
|
236
|
+
datetime: function() {
|
237
|
+
return _datetime.default.new();
|
238
|
+
},
|
239
|
+
/**
|
240
|
+
* Different from other models, this function is a factory function that returns either an ObjectSchema or an ArraySchema.
|
241
|
+
* The idea is to build the schema of a model dynamically based on its fields.
|
242
|
+
*
|
243
|
+
* Another feature is that it can automatically add the foreign key relation to the schema, but for that you need to define
|
244
|
+
* the fields of the related model in the fields object.
|
245
|
+
*
|
246
|
+
* For example: A User model have a field `companyId` that is a ForeignKeyField to the Company model. The `relationName`
|
247
|
+
* is the direct relation from the User model to the Company model, and the `relatedName` is the reverse relation from the
|
248
|
+
* Company model to the User model. If you define the fieldName as either the relatedName or the relationName it will fetch
|
249
|
+
* the data automatically.
|
250
|
+
*
|
251
|
+
* **Important**: We build the schema dynamically but also lazily, if you don't try to parse or validate the schema, it won't be built.
|
252
|
+
* After the first time it's built, it's cached and never built again.
|
253
|
+
*
|
254
|
+
* **Important 2**: If you want to use the automatic relation feature, you need to define guarantee that the foreignKey field fieldName
|
255
|
+
* exists on `show` array, or that it doesn't exist on `omit` array.
|
256
|
+
*
|
257
|
+
* Like: `{ options: { show: ['id', 'name', 'companyId'] }}` or `{ options: { omit: ['id'] }}` it **will work**.
|
258
|
+
*
|
259
|
+
* If you do `{ options: { show: ['id', 'name'] }}` or `{ options: { omit: ['companyId']} }` it **won't work**.
|
260
|
+
*
|
261
|
+
* **Important 3**: If you want to return an array instead of an object, you need to pass the `many` option as true.
|
262
|
+
*
|
263
|
+
* @example
|
264
|
+
* ```typescript
|
265
|
+
* import { auto, choice, foreignKey, Model, define } from '@palmares/databases';
|
266
|
+
* import * as p from '@palmares/schemas';
|
267
|
+
*
|
268
|
+
* const Company = define('Company', {
|
269
|
+
* fields: {
|
270
|
+
* id: auto(),
|
271
|
+
* name: text(),
|
272
|
+
* },
|
273
|
+
* options: {
|
274
|
+
* tableName: 'company',
|
275
|
+
* }
|
276
|
+
* });
|
277
|
+
*
|
278
|
+
* class User extends Model<User>() {
|
279
|
+
* fields = {
|
280
|
+
* id: auto(),
|
281
|
+
* type: choice({ choices: ['user', 'admin'] }),
|
282
|
+
* companyId: foreignKey({
|
283
|
+
* relatedTo: Company,
|
284
|
+
* relationName: 'company',
|
285
|
+
* relatedName: 'usersOfCompany',
|
286
|
+
* toField: 'id',
|
287
|
+
* onDelete: 'CASCADE',
|
288
|
+
* }),
|
289
|
+
* }
|
290
|
+
*
|
291
|
+
* options = {
|
292
|
+
* tableName: 'user',
|
293
|
+
* }
|
294
|
+
* }
|
295
|
+
*
|
296
|
+
* const userSchema = p.modelSchema(User, {
|
297
|
+
* fields: {
|
298
|
+
* company: p.modelSchema(Company).optional({ outputOnly: true });
|
299
|
+
* },
|
300
|
+
* show: ['type', 'companyId']
|
301
|
+
* });
|
302
|
+
*
|
303
|
+
* const companySchema = p.modelSchema(Company, {
|
304
|
+
* fields: {
|
305
|
+
* usersOfCompany: p.modelSchema(User, { many: true }).optional({ outputOnly: true });
|
306
|
+
* },
|
307
|
+
* show: ['id', 'type']
|
308
|
+
* });
|
309
|
+
*```
|
310
|
+
* @param model - The model that you want to build the schema from.
|
311
|
+
* @param options - The options to build the schema.
|
312
|
+
* @param options.ignoreExtraneousFields - If you want to ignore extraneous fields set this to true.
|
313
|
+
* @param options.engineInstance - What engine instance you want to use to fetch the data. Defaults to the first one.
|
314
|
+
* @param options.fields - Extra fields that you want to add to the schema. If it has the same name as the model field,
|
315
|
+
* We will not create a schema for that field and use the one you have defined here.
|
316
|
+
* @param options.omit - Fields that you want to omit from the schema. If that is defined, we ignore `show` option.
|
317
|
+
* @param options.show - Fields that you want to show on the schema. If that is defined, we ignore `omit` option.
|
318
|
+
* @param options.many - If you want to return an array instead of an object, set this to true. With that we create
|
319
|
+
* an ArraySchema instead of an ObjectSchema.
|
320
|
+
*
|
321
|
+
* @returns - If you pass the `many` option as true, we return an ArraySchema, otherwise we return an ObjectSchema.
|
322
|
+
*/ modelSchema: function(model, options) {
|
323
|
+
return (0, _model.modelSchema)(model, options);
|
324
|
+
}
|
325
|
+
};
|
326
|
+
} /*
|
327
|
+
export class User extends Model<User>() {
|
328
|
+
fields = {
|
329
|
+
id: AutoField.new(),
|
330
|
+
uuid: UuidField.new({
|
331
|
+
autoGenerate: true
|
332
|
+
}),
|
333
|
+
name: CharField.new({ maxLength: 255, dbIndex: true, allowNull: true }),
|
334
|
+
age: IntegerField.new({ dbIndex: true }),
|
335
|
+
userType: EnumField.new({ choices: ['admin', 'user'], defaultValue: 'admin' }),
|
336
|
+
price: DecimalField.new({ maxDigits: 5, decimalPlaces: 2, allowNull: true }),
|
337
|
+
isActive: BooleanField.new({ defaultValue: true }),
|
338
|
+
companyId: ForeignKeyField.new({
|
339
|
+
onDelete: ON_DELETE.CASCADE,
|
340
|
+
relatedName: 'usersOfCompany',
|
341
|
+
relationName: 'company',
|
342
|
+
toField: 'id',
|
343
|
+
relatedTo: Company
|
344
|
+
}),
|
345
|
+
updatedAt: DateField.new({ autoNow: true }),
|
346
|
+
createdAt: DateField.new({ autoNowAdd: true }),
|
347
|
+
}
|
348
|
+
|
349
|
+
options: ModelOptionsType<User> = {
|
350
|
+
tableName: 'users',
|
351
|
+
}
|
352
|
+
}
|
353
|
+
|
354
|
+
export class Company extends Model<Company>() {
|
355
|
+
fields = {
|
356
|
+
id: AutoField.new(),
|
357
|
+
name: CharField.new({ maxLength: 255 }),
|
358
|
+
address: CharField.new({ maxLength: 255, allowNull: true }),
|
359
|
+
}
|
360
|
+
|
361
|
+
options: ModelOptionsType<Company> = {
|
362
|
+
tableName: 'companies',
|
363
|
+
}
|
364
|
+
}
|
365
|
+
*/
|