simplentity 0.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.
- package/README.md +60 -0
- package/dist/bun/entity.d.ts +42 -0
- package/dist/bun/field.d.ts +35 -0
- package/dist/bun/index.d.ts +3 -0
- package/dist/bun/index.js +2 -0
- package/dist/cjs/entity.cjs +77 -0
- package/dist/cjs/entity.d.ts +42 -0
- package/dist/cjs/field.cjs +59 -0
- package/dist/cjs/field.d.ts +35 -0
- package/dist/cjs/fields/boolean.cjs +68 -0
- package/dist/cjs/fields/date.cjs +68 -0
- package/dist/cjs/fields/index.cjs +95 -0
- package/dist/cjs/fields/number.cjs +68 -0
- package/dist/cjs/fields/string.cjs +68 -0
- package/dist/cjs/index.cjs +147 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/entity.d.ts +42 -0
- package/dist/entity.js +52 -0
- package/dist/field.d.ts +35 -0
- package/dist/field.js +34 -0
- package/dist/fields/boolean.d.ts +8 -0
- package/dist/fields/boolean.js +41 -0
- package/dist/fields/date.d.ts +8 -0
- package/dist/fields/date.js +41 -0
- package/dist/fields/index.d.ts +5 -0
- package/dist/fields/index.js +65 -0
- package/dist/fields/number.d.ts +8 -0
- package/dist/fields/number.js +41 -0
- package/dist/fields/string.d.ts +8 -0
- package/dist/fields/string.js +41 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +116 -0
- package/package.json +34 -0
package/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# simplentity
|
2
|
+
|
3
|
+
The simplentity is a simple typed entity library.
|
4
|
+
It provides the implementation of type-safe entities and manipulation.
|
5
|
+
|
6
|
+
> [!NOTE]
|
7
|
+
> I created the library to learn TypeScript and the type system for me.
|
8
|
+
> So, it may not be suitable for production use.
|
9
|
+
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
Coming soon...
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
```typescript
|
17
|
+
import {entity, number, string, boolean} from 'simplentity';
|
18
|
+
|
19
|
+
// Define a user entity
|
20
|
+
class User extends entity({
|
21
|
+
id: string().defaultFn(() => randomUUID()), // randomUUID is a third-party library. Not included.
|
22
|
+
name: string(),
|
23
|
+
age: number().notRequired(),
|
24
|
+
isActive: boolean().default(true),
|
25
|
+
}) {
|
26
|
+
activate(): void {
|
27
|
+
// You can get suggestions for the properties of the entity.
|
28
|
+
this.set('isActive', true);
|
29
|
+
}
|
30
|
+
|
31
|
+
deactivate(): void {
|
32
|
+
this.set('isActive', false);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
// Properties that have NotRequired or Default(Fn) are optional.
|
37
|
+
// If a property has a default value, it is automatically assigned to the property when you create the entity instance.
|
38
|
+
const user = new User({
|
39
|
+
name: 'John Doe',
|
40
|
+
})
|
41
|
+
/*
|
42
|
+
{
|
43
|
+
id: 'd02daa87-3984-4c6f-be9b-a13a478354b5',
|
44
|
+
name: 'John Doe',
|
45
|
+
isActive: true,
|
46
|
+
}
|
47
|
+
*/
|
48
|
+
|
49
|
+
// You can get property values via the get method.
|
50
|
+
// Of course, you can get suggestions for the properties of the entity.
|
51
|
+
const name = user.get('name'); // 'John Doe'
|
52
|
+
```
|
53
|
+
|
54
|
+
## Todo
|
55
|
+
- [ ] Add more built-in types
|
56
|
+
- [ ] Validation
|
57
|
+
- [ ] JSON serialization
|
58
|
+
- [ ] Custom field types
|
59
|
+
- [ ] Custom field validation
|
60
|
+
- [ ] Custom field serialization
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import type { Field } from "./field.ts";
|
2
|
+
type EntityConfig = {
|
3
|
+
[key: string]: Field<unknown>;
|
4
|
+
};
|
5
|
+
type EntityConfigTypeResolver<T extends EntityConfig> = {
|
6
|
+
[K in keyof T]: T[K]["_"]["notRequired"] extends true ? FieldTypeResolver<T[K]> | undefined : FieldTypeResolver<T[K]>;
|
7
|
+
};
|
8
|
+
type RequiredFieldKeys<T extends EntityConfig> = {
|
9
|
+
[K in keyof T]: T[K]["_"]["notRequired"] extends true ? never : T[K]["_"]["hasDefault"] extends true ? never : K;
|
10
|
+
}[keyof T];
|
11
|
+
type FieldTypeResolver<T> = T extends Field<infer U> ? U : never;
|
12
|
+
type EntityPropInputResolver<T extends EntityConfig> = {
|
13
|
+
[K in RequiredFieldKeys<T>]: FieldTypeResolver<T[K]>;
|
14
|
+
} & {
|
15
|
+
[K in keyof Omit<T, RequiredFieldKeys<T>>]?: FieldTypeResolver<T[K]>;
|
16
|
+
};
|
17
|
+
/**
|
18
|
+
* Create an entity class with the given fields
|
19
|
+
* @param fields
|
20
|
+
*/
|
21
|
+
export declare const entity: <Config extends EntityConfig>(fields: Config) => {
|
22
|
+
new (props: EntityPropInputResolver<Config>): {
|
23
|
+
readonly "__#1@#entityConfig": Config;
|
24
|
+
"__#1@#props": EntityConfigTypeResolver<Config>;
|
25
|
+
/**
|
26
|
+
* Get the value of the field by key
|
27
|
+
* @param key
|
28
|
+
*/
|
29
|
+
get<K extends keyof Config>(key: K): EntityConfigTypeResolver<Config>[K];
|
30
|
+
/**
|
31
|
+
* Set the value of the field by key
|
32
|
+
*
|
33
|
+
* WARNING: This method should be called only from the methods of the entity.
|
34
|
+
* Its accessor should be protected but TypeScript declaration does not allow protected methods in exported classes.
|
35
|
+
* @param key
|
36
|
+
* @param value
|
37
|
+
*/
|
38
|
+
set<K extends keyof Config>(key: K, value: EntityConfigTypeResolver<Config>[K]): void;
|
39
|
+
toJSON(): EntityConfigTypeResolver<Config>;
|
40
|
+
};
|
41
|
+
};
|
42
|
+
export {};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
type FieldConfig<T> = {
|
2
|
+
notRequired: boolean;
|
3
|
+
hasDefault: boolean;
|
4
|
+
data: T;
|
5
|
+
};
|
6
|
+
type FieldRuntimeConfig<T> = {
|
7
|
+
notRequired: boolean;
|
8
|
+
hasDefault: boolean;
|
9
|
+
default: T | undefined;
|
10
|
+
defaultFn?: () => T;
|
11
|
+
};
|
12
|
+
interface ConfigurableFieldBase<T> {
|
13
|
+
_: FieldConfig<T>;
|
14
|
+
}
|
15
|
+
type NotRequired<T extends ConfigurableFieldBase<unknown>> = T & {
|
16
|
+
_: {
|
17
|
+
notRequired: true;
|
18
|
+
};
|
19
|
+
};
|
20
|
+
type HasDefault<T extends ConfigurableFieldBase<unknown>> = T & {
|
21
|
+
_: {
|
22
|
+
hasDefault: true;
|
23
|
+
};
|
24
|
+
};
|
25
|
+
export declare abstract class Field<T> implements ConfigurableFieldBase<T> {
|
26
|
+
_: FieldConfig<T>;
|
27
|
+
protected config: FieldRuntimeConfig<T>;
|
28
|
+
constructor();
|
29
|
+
notRequired(): NotRequired<this>;
|
30
|
+
default(value: T): HasDefault<this>;
|
31
|
+
defaultFn(fn: () => T): HasDefault<this>;
|
32
|
+
getConfig(): FieldRuntimeConfig<T>;
|
33
|
+
getDefaultValue(): T | undefined;
|
34
|
+
}
|
35
|
+
export {};
|
@@ -0,0 +1,2 @@
|
|
1
|
+
// @bun
|
2
|
+
class f{#u;#t;constructor(t,o){this.#u=o,Object.freeze(this.#u),this.#t=Object.entries(o).reduce((e,[n,a])=>{let r=t[n]??a.getDefaultValue();if(a.getConfig().hasDefault&&r===void 0)throw new Error(`The field "${n}" has a default value but undefined was provided.`);return e[n]=r,e},{})}get(t){return this.#t[t]}set(t,o){this.#t[t]=o}toJSON(){return this.#t}}var R=(t)=>{return class extends f{constructor(o){super(o,t)}}};class u{config;constructor(){this.config={notRequired:!1,hasDefault:!1,default:void 0}}notRequired(){return this.config.notRequired=!0,this}default(t){return this.config.default=t,this.config.hasDefault=!0,this}defaultFn(t){return this.config.defaultFn=t,this.config.hasDefault=!0,this}getConfig(){return this.config}getDefaultValue(){return this.config.default??this.config.defaultFn?.()}}class i extends u{}var s=()=>{return new i};class h extends u{}var T=()=>{return new h};class g extends u{}var m=()=>{return new g};class d extends u{}var l=()=>{return new d};export{l as string,m as number,R as entity,T as date,s as boolean};
|
@@ -0,0 +1,77 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
|
20
|
+
// src/entity.ts
|
21
|
+
var entity_exports = {};
|
22
|
+
__export(entity_exports, {
|
23
|
+
entity: () => entity
|
24
|
+
});
|
25
|
+
module.exports = __toCommonJS(entity_exports);
|
26
|
+
var Entity = class {
|
27
|
+
#entityConfig;
|
28
|
+
#props;
|
29
|
+
constructor(props, entityConfig) {
|
30
|
+
this.#entityConfig = entityConfig;
|
31
|
+
Object.freeze(this.#entityConfig);
|
32
|
+
this.#props = Object.entries(entityConfig).reduce(
|
33
|
+
(acc, [key, field]) => {
|
34
|
+
const value = props[key] ?? field.getDefaultValue();
|
35
|
+
if (field.getConfig().hasDefault && value === void 0) {
|
36
|
+
throw new Error(`The field "${key}" has a default value but undefined was provided.`);
|
37
|
+
}
|
38
|
+
acc[key] = value;
|
39
|
+
return acc;
|
40
|
+
},
|
41
|
+
{}
|
42
|
+
);
|
43
|
+
}
|
44
|
+
/**
|
45
|
+
* Get the value of the field by key
|
46
|
+
* @param key
|
47
|
+
*/
|
48
|
+
get(key) {
|
49
|
+
return this.#props[key];
|
50
|
+
}
|
51
|
+
/**
|
52
|
+
* Set the value of the field by key
|
53
|
+
*
|
54
|
+
* WARNING: This method should be called only from the methods of the entity.
|
55
|
+
* Its accessor should be protected but TypeScript declaration does not allow protected methods in exported classes.
|
56
|
+
* @param key
|
57
|
+
* @param value
|
58
|
+
*/
|
59
|
+
set(key, value) {
|
60
|
+
this.#props[key] = value;
|
61
|
+
}
|
62
|
+
// biome-ignore lint/style/useNamingConvention: toJSON is a name to be used in JSON.stringify
|
63
|
+
toJSON() {
|
64
|
+
return this.#props;
|
65
|
+
}
|
66
|
+
};
|
67
|
+
var entity = (fields) => {
|
68
|
+
return class extends Entity {
|
69
|
+
constructor(props) {
|
70
|
+
super(props, fields);
|
71
|
+
}
|
72
|
+
};
|
73
|
+
};
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
75
|
+
0 && (module.exports = {
|
76
|
+
entity
|
77
|
+
});
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import type { Field } from "./field.ts";
|
2
|
+
type EntityConfig = {
|
3
|
+
[key: string]: Field<unknown>;
|
4
|
+
};
|
5
|
+
type EntityConfigTypeResolver<T extends EntityConfig> = {
|
6
|
+
[K in keyof T]: T[K]["_"]["notRequired"] extends true ? FieldTypeResolver<T[K]> | undefined : FieldTypeResolver<T[K]>;
|
7
|
+
};
|
8
|
+
type RequiredFieldKeys<T extends EntityConfig> = {
|
9
|
+
[K in keyof T]: T[K]["_"]["notRequired"] extends true ? never : T[K]["_"]["hasDefault"] extends true ? never : K;
|
10
|
+
}[keyof T];
|
11
|
+
type FieldTypeResolver<T> = T extends Field<infer U> ? U : never;
|
12
|
+
type EntityPropInputResolver<T extends EntityConfig> = {
|
13
|
+
[K in RequiredFieldKeys<T>]: FieldTypeResolver<T[K]>;
|
14
|
+
} & {
|
15
|
+
[K in keyof Omit<T, RequiredFieldKeys<T>>]?: FieldTypeResolver<T[K]>;
|
16
|
+
};
|
17
|
+
/**
|
18
|
+
* Create an entity class with the given fields
|
19
|
+
* @param fields
|
20
|
+
*/
|
21
|
+
export declare const entity: <Config extends EntityConfig>(fields: Config) => {
|
22
|
+
new (props: EntityPropInputResolver<Config>): {
|
23
|
+
readonly "__#1@#entityConfig": Config;
|
24
|
+
"__#1@#props": EntityConfigTypeResolver<Config>;
|
25
|
+
/**
|
26
|
+
* Get the value of the field by key
|
27
|
+
* @param key
|
28
|
+
*/
|
29
|
+
get<K extends keyof Config>(key: K): EntityConfigTypeResolver<Config>[K];
|
30
|
+
/**
|
31
|
+
* Set the value of the field by key
|
32
|
+
*
|
33
|
+
* WARNING: This method should be called only from the methods of the entity.
|
34
|
+
* Its accessor should be protected but TypeScript declaration does not allow protected methods in exported classes.
|
35
|
+
* @param key
|
36
|
+
* @param value
|
37
|
+
*/
|
38
|
+
set<K extends keyof Config>(key: K, value: EntityConfigTypeResolver<Config>[K]): void;
|
39
|
+
toJSON(): EntityConfigTypeResolver<Config>;
|
40
|
+
};
|
41
|
+
};
|
42
|
+
export {};
|
@@ -0,0 +1,59 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
|
20
|
+
// src/field.ts
|
21
|
+
var field_exports = {};
|
22
|
+
__export(field_exports, {
|
23
|
+
Field: () => Field
|
24
|
+
});
|
25
|
+
module.exports = __toCommonJS(field_exports);
|
26
|
+
var Field = class {
|
27
|
+
config;
|
28
|
+
constructor() {
|
29
|
+
this.config = {
|
30
|
+
notRequired: false,
|
31
|
+
hasDefault: false,
|
32
|
+
default: void 0
|
33
|
+
};
|
34
|
+
}
|
35
|
+
notRequired() {
|
36
|
+
this.config.notRequired = true;
|
37
|
+
return this;
|
38
|
+
}
|
39
|
+
default(value) {
|
40
|
+
this.config.default = value;
|
41
|
+
this.config.hasDefault = true;
|
42
|
+
return this;
|
43
|
+
}
|
44
|
+
defaultFn(fn) {
|
45
|
+
this.config.defaultFn = fn;
|
46
|
+
this.config.hasDefault = true;
|
47
|
+
return this;
|
48
|
+
}
|
49
|
+
getConfig() {
|
50
|
+
return this.config;
|
51
|
+
}
|
52
|
+
getDefaultValue() {
|
53
|
+
return this.config.default ?? this.config.defaultFn?.();
|
54
|
+
}
|
55
|
+
};
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
57
|
+
0 && (module.exports = {
|
58
|
+
Field
|
59
|
+
});
|
@@ -0,0 +1,35 @@
|
|
1
|
+
type FieldConfig<T> = {
|
2
|
+
notRequired: boolean;
|
3
|
+
hasDefault: boolean;
|
4
|
+
data: T;
|
5
|
+
};
|
6
|
+
type FieldRuntimeConfig<T> = {
|
7
|
+
notRequired: boolean;
|
8
|
+
hasDefault: boolean;
|
9
|
+
default: T | undefined;
|
10
|
+
defaultFn?: () => T;
|
11
|
+
};
|
12
|
+
interface ConfigurableFieldBase<T> {
|
13
|
+
_: FieldConfig<T>;
|
14
|
+
}
|
15
|
+
type NotRequired<T extends ConfigurableFieldBase<unknown>> = T & {
|
16
|
+
_: {
|
17
|
+
notRequired: true;
|
18
|
+
};
|
19
|
+
};
|
20
|
+
type HasDefault<T extends ConfigurableFieldBase<unknown>> = T & {
|
21
|
+
_: {
|
22
|
+
hasDefault: true;
|
23
|
+
};
|
24
|
+
};
|
25
|
+
export declare abstract class Field<T> implements ConfigurableFieldBase<T> {
|
26
|
+
_: FieldConfig<T>;
|
27
|
+
protected config: FieldRuntimeConfig<T>;
|
28
|
+
constructor();
|
29
|
+
notRequired(): NotRequired<this>;
|
30
|
+
default(value: T): HasDefault<this>;
|
31
|
+
defaultFn(fn: () => T): HasDefault<this>;
|
32
|
+
getConfig(): FieldRuntimeConfig<T>;
|
33
|
+
getDefaultValue(): T | undefined;
|
34
|
+
}
|
35
|
+
export {};
|
@@ -0,0 +1,68 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
|
20
|
+
// src/fields/boolean.ts
|
21
|
+
var boolean_exports = {};
|
22
|
+
__export(boolean_exports, {
|
23
|
+
boolean: () => boolean
|
24
|
+
});
|
25
|
+
module.exports = __toCommonJS(boolean_exports);
|
26
|
+
|
27
|
+
// src/field.ts
|
28
|
+
var Field = class {
|
29
|
+
config;
|
30
|
+
constructor() {
|
31
|
+
this.config = {
|
32
|
+
notRequired: false,
|
33
|
+
hasDefault: false,
|
34
|
+
default: void 0
|
35
|
+
};
|
36
|
+
}
|
37
|
+
notRequired() {
|
38
|
+
this.config.notRequired = true;
|
39
|
+
return this;
|
40
|
+
}
|
41
|
+
default(value) {
|
42
|
+
this.config.default = value;
|
43
|
+
this.config.hasDefault = true;
|
44
|
+
return this;
|
45
|
+
}
|
46
|
+
defaultFn(fn) {
|
47
|
+
this.config.defaultFn = fn;
|
48
|
+
this.config.hasDefault = true;
|
49
|
+
return this;
|
50
|
+
}
|
51
|
+
getConfig() {
|
52
|
+
return this.config;
|
53
|
+
}
|
54
|
+
getDefaultValue() {
|
55
|
+
return this.config.default ?? this.config.defaultFn?.();
|
56
|
+
}
|
57
|
+
};
|
58
|
+
|
59
|
+
// src/fields/boolean.ts
|
60
|
+
var BooleanField = class extends Field {
|
61
|
+
};
|
62
|
+
var boolean = () => {
|
63
|
+
return new BooleanField();
|
64
|
+
};
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
66
|
+
0 && (module.exports = {
|
67
|
+
boolean
|
68
|
+
});
|
@@ -0,0 +1,68 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
|
20
|
+
// src/fields/date.ts
|
21
|
+
var date_exports = {};
|
22
|
+
__export(date_exports, {
|
23
|
+
date: () => date
|
24
|
+
});
|
25
|
+
module.exports = __toCommonJS(date_exports);
|
26
|
+
|
27
|
+
// src/field.ts
|
28
|
+
var Field = class {
|
29
|
+
config;
|
30
|
+
constructor() {
|
31
|
+
this.config = {
|
32
|
+
notRequired: false,
|
33
|
+
hasDefault: false,
|
34
|
+
default: void 0
|
35
|
+
};
|
36
|
+
}
|
37
|
+
notRequired() {
|
38
|
+
this.config.notRequired = true;
|
39
|
+
return this;
|
40
|
+
}
|
41
|
+
default(value) {
|
42
|
+
this.config.default = value;
|
43
|
+
this.config.hasDefault = true;
|
44
|
+
return this;
|
45
|
+
}
|
46
|
+
defaultFn(fn) {
|
47
|
+
this.config.defaultFn = fn;
|
48
|
+
this.config.hasDefault = true;
|
49
|
+
return this;
|
50
|
+
}
|
51
|
+
getConfig() {
|
52
|
+
return this.config;
|
53
|
+
}
|
54
|
+
getDefaultValue() {
|
55
|
+
return this.config.default ?? this.config.defaultFn?.();
|
56
|
+
}
|
57
|
+
};
|
58
|
+
|
59
|
+
// src/fields/date.ts
|
60
|
+
var DateField = class extends Field {
|
61
|
+
};
|
62
|
+
var date = () => {
|
63
|
+
return new DateField();
|
64
|
+
};
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
66
|
+
0 && (module.exports = {
|
67
|
+
date
|
68
|
+
});
|
@@ -0,0 +1,95 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
|
20
|
+
// src/fields/index.ts
|
21
|
+
var fields_exports = {};
|
22
|
+
__export(fields_exports, {
|
23
|
+
boolean: () => boolean,
|
24
|
+
date: () => date,
|
25
|
+
number: () => number,
|
26
|
+
string: () => string
|
27
|
+
});
|
28
|
+
module.exports = __toCommonJS(fields_exports);
|
29
|
+
|
30
|
+
// src/field.ts
|
31
|
+
var Field = class {
|
32
|
+
config;
|
33
|
+
constructor() {
|
34
|
+
this.config = {
|
35
|
+
notRequired: false,
|
36
|
+
hasDefault: false,
|
37
|
+
default: void 0
|
38
|
+
};
|
39
|
+
}
|
40
|
+
notRequired() {
|
41
|
+
this.config.notRequired = true;
|
42
|
+
return this;
|
43
|
+
}
|
44
|
+
default(value) {
|
45
|
+
this.config.default = value;
|
46
|
+
this.config.hasDefault = true;
|
47
|
+
return this;
|
48
|
+
}
|
49
|
+
defaultFn(fn) {
|
50
|
+
this.config.defaultFn = fn;
|
51
|
+
this.config.hasDefault = true;
|
52
|
+
return this;
|
53
|
+
}
|
54
|
+
getConfig() {
|
55
|
+
return this.config;
|
56
|
+
}
|
57
|
+
getDefaultValue() {
|
58
|
+
return this.config.default ?? this.config.defaultFn?.();
|
59
|
+
}
|
60
|
+
};
|
61
|
+
|
62
|
+
// src/fields/boolean.ts
|
63
|
+
var BooleanField = class extends Field {
|
64
|
+
};
|
65
|
+
var boolean = () => {
|
66
|
+
return new BooleanField();
|
67
|
+
};
|
68
|
+
|
69
|
+
// src/fields/date.ts
|
70
|
+
var DateField = class extends Field {
|
71
|
+
};
|
72
|
+
var date = () => {
|
73
|
+
return new DateField();
|
74
|
+
};
|
75
|
+
|
76
|
+
// src/fields/number.ts
|
77
|
+
var NumberField = class extends Field {
|
78
|
+
};
|
79
|
+
var number = () => {
|
80
|
+
return new NumberField();
|
81
|
+
};
|
82
|
+
|
83
|
+
// src/fields/string.ts
|
84
|
+
var StringField = class extends Field {
|
85
|
+
};
|
86
|
+
var string = () => {
|
87
|
+
return new StringField();
|
88
|
+
};
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
90
|
+
0 && (module.exports = {
|
91
|
+
boolean,
|
92
|
+
date,
|
93
|
+
number,
|
94
|
+
string
|
95
|
+
});
|
@@ -0,0 +1,68 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
|
20
|
+
// src/fields/number.ts
|
21
|
+
var number_exports = {};
|
22
|
+
__export(number_exports, {
|
23
|
+
number: () => number
|
24
|
+
});
|
25
|
+
module.exports = __toCommonJS(number_exports);
|
26
|
+
|
27
|
+
// src/field.ts
|
28
|
+
var Field = class {
|
29
|
+
config;
|
30
|
+
constructor() {
|
31
|
+
this.config = {
|
32
|
+
notRequired: false,
|
33
|
+
hasDefault: false,
|
34
|
+
default: void 0
|
35
|
+
};
|
36
|
+
}
|
37
|
+
notRequired() {
|
38
|
+
this.config.notRequired = true;
|
39
|
+
return this;
|
40
|
+
}
|
41
|
+
default(value) {
|
42
|
+
this.config.default = value;
|
43
|
+
this.config.hasDefault = true;
|
44
|
+
return this;
|
45
|
+
}
|
46
|
+
defaultFn(fn) {
|
47
|
+
this.config.defaultFn = fn;
|
48
|
+
this.config.hasDefault = true;
|
49
|
+
return this;
|
50
|
+
}
|
51
|
+
getConfig() {
|
52
|
+
return this.config;
|
53
|
+
}
|
54
|
+
getDefaultValue() {
|
55
|
+
return this.config.default ?? this.config.defaultFn?.();
|
56
|
+
}
|
57
|
+
};
|
58
|
+
|
59
|
+
// src/fields/number.ts
|
60
|
+
var NumberField = class extends Field {
|
61
|
+
};
|
62
|
+
var number = () => {
|
63
|
+
return new NumberField();
|
64
|
+
};
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
66
|
+
0 && (module.exports = {
|
67
|
+
number
|
68
|
+
});
|