@domain-first/types 2.0.2 → 3.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/dist/entity.d.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import { type DeepReadonly } from './utils';
3
- export declare const defineEntity: <IdSchema extends StandardSchemaV1, ModelSchema extends StandardSchemaV1>(idSchema: IdSchema, modelSchema: ModelSchema | ((isCurrentEntity: (target: unknown) => boolean) => ModelSchema)) => (abstract new (id: StandardSchemaV1.InferInput<IdSchema>, model: StandardSchemaV1.InferInput<ModelSchema>) => {
3
+ export declare const defineEntity: <IdSchema extends StandardSchemaV1, ModelSchema extends StandardSchemaV1>(idSchema: IdSchema, modelSchema: ModelSchema) => (abstract new (id: StandardSchemaV1.InferInput<IdSchema>, model: StandardSchemaV1.InferInput<ModelSchema>) => {
4
+ get model(): DeepReadonly<StandardSchemaV1.InferOutput<ModelSchema>>;
5
+ get id(): DeepReadonly<StandardSchemaV1.InferOutput<IdSchema>>;
6
+ }) & {
7
+ readonly idSchema: IdSchema;
8
+ readonly modelSchema: ModelSchema;
9
+ };
10
+ export declare const defineRecursiveEntity: <IdSchema extends StandardSchemaV1, ModelSchema extends StandardSchemaV1>(idSchema: IdSchema, modelSchema: (isCurrentEntity: (target: unknown) => boolean) => ModelSchema) => (abstract new (id: StandardSchemaV1.InferInput<IdSchema>, model: StandardSchemaV1.InferInput<ModelSchema>) => {
4
11
  get model(): DeepReadonly<StandardSchemaV1.InferOutput<ModelSchema>>;
5
12
  get id(): DeepReadonly<StandardSchemaV1.InferOutput<IdSchema>>;
6
13
  }) & {
package/dist/index.cjs CHANGED
@@ -31,6 +31,8 @@ __webpack_require__.d(__webpack_exports__, {
31
31
  AsyncSchemaInSyncParsingError: ()=>AsyncSchemaInSyncParsingError,
32
32
  InvalidDataParsingError: ()=>InvalidDataParsingError,
33
33
  defineEntity: ()=>defineEntity,
34
+ defineRecursiveEntity: ()=>defineRecursiveEntity,
35
+ defineRecursiveValueObject: ()=>defineRecursiveValueObject,
34
36
  defineValueObject: ()=>defineValueObject
35
37
  });
36
38
  const errors_namespaceObject = require("@domain-first/errors");
@@ -52,14 +54,14 @@ function parseSync(schema, value) {
52
54
  });
53
55
  return result.value;
54
56
  }
55
- const defineEntity = (idSchema, modelSchema)=>{
57
+ const createEntity = (idSchema, getModelSchema)=>{
56
58
  const idSymbol = Symbol();
57
59
  const modelSymbol = Symbol();
58
60
  const classSymbol = Symbol();
59
61
  const isThisClass = (target)=>!!target && 'object' == typeof target && classSymbol in target;
60
62
  class Entity {
61
63
  static idSchema = idSchema;
62
- static modelSchema = 'function' == typeof modelSchema ? modelSchema(isThisClass) : modelSchema;
64
+ static modelSchema = getModelSchema(isThisClass);
63
65
  constructor(id, model){
64
66
  const parsedId = parseSync(Entity.idSchema, id);
65
67
  const parsedModelData = parseSync(Entity.modelSchema, model);
@@ -74,22 +76,22 @@ const defineEntity = (idSchema, modelSchema)=>{
74
76
  });
75
77
  }
76
78
  get model() {
77
- const thisWithSymbol = this;
78
- return thisWithSymbol[modelSymbol];
79
+ return this[modelSymbol];
79
80
  }
80
81
  get id() {
81
- const thisWithSymbol = this;
82
- return thisWithSymbol[idSymbol];
82
+ return this[idSymbol];
83
83
  }
84
84
  }
85
85
  return Entity;
86
86
  };
87
- const defineValueObject = (schema)=>{
87
+ const defineEntity = (idSchema, modelSchema)=>createEntity(idSchema, ()=>modelSchema);
88
+ const defineRecursiveEntity = (idSchema, modelSchema)=>createEntity(idSchema, modelSchema);
89
+ const createValueObject = (getSchema)=>{
88
90
  const modelSymbol = Symbol();
89
91
  const classSymbol = Symbol();
90
92
  const isThisClass = (target)=>!!target && 'object' == typeof target && classSymbol in target;
91
93
  class ValueObject {
92
- static schema = 'function' == typeof schema ? schema(isThisClass) : schema;
94
+ static schema = getSchema(isThisClass);
93
95
  constructor(data){
94
96
  const parsedData = parseSync(ValueObject.schema, data);
95
97
  Object.defineProperty(this, modelSymbol, {
@@ -106,14 +108,20 @@ const defineValueObject = (schema)=>{
106
108
  }
107
109
  return ValueObject;
108
110
  };
111
+ const defineValueObject = (schema)=>createValueObject(()=>schema);
112
+ const defineRecursiveValueObject = (schema)=>createValueObject(schema);
109
113
  exports.AsyncSchemaInSyncParsingError = __webpack_exports__.AsyncSchemaInSyncParsingError;
110
114
  exports.InvalidDataParsingError = __webpack_exports__.InvalidDataParsingError;
111
115
  exports.defineEntity = __webpack_exports__.defineEntity;
116
+ exports.defineRecursiveEntity = __webpack_exports__.defineRecursiveEntity;
117
+ exports.defineRecursiveValueObject = __webpack_exports__.defineRecursiveValueObject;
112
118
  exports.defineValueObject = __webpack_exports__.defineValueObject;
113
119
  for(var __rspack_i in __webpack_exports__)if (-1 === [
114
120
  "AsyncSchemaInSyncParsingError",
115
121
  "InvalidDataParsingError",
116
122
  "defineEntity",
123
+ "defineRecursiveEntity",
124
+ "defineRecursiveValueObject",
117
125
  "defineValueObject"
118
126
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
119
127
  Object.defineProperty(exports, '__esModule', {
package/dist/index.js CHANGED
@@ -17,14 +17,14 @@ function parseSync(schema, value) {
17
17
  });
18
18
  return result.value;
19
19
  }
20
- const defineEntity = (idSchema, modelSchema)=>{
20
+ const createEntity = (idSchema, getModelSchema)=>{
21
21
  const idSymbol = Symbol();
22
22
  const modelSymbol = Symbol();
23
23
  const classSymbol = Symbol();
24
24
  const isThisClass = (target)=>!!target && 'object' == typeof target && classSymbol in target;
25
25
  class Entity {
26
26
  static idSchema = idSchema;
27
- static modelSchema = 'function' == typeof modelSchema ? modelSchema(isThisClass) : modelSchema;
27
+ static modelSchema = getModelSchema(isThisClass);
28
28
  constructor(id, model){
29
29
  const parsedId = parseSync(Entity.idSchema, id);
30
30
  const parsedModelData = parseSync(Entity.modelSchema, model);
@@ -39,22 +39,22 @@ const defineEntity = (idSchema, modelSchema)=>{
39
39
  });
40
40
  }
41
41
  get model() {
42
- const thisWithSymbol = this;
43
- return thisWithSymbol[modelSymbol];
42
+ return this[modelSymbol];
44
43
  }
45
44
  get id() {
46
- const thisWithSymbol = this;
47
- return thisWithSymbol[idSymbol];
45
+ return this[idSymbol];
48
46
  }
49
47
  }
50
48
  return Entity;
51
49
  };
52
- const defineValueObject = (schema)=>{
50
+ const defineEntity = (idSchema, modelSchema)=>createEntity(idSchema, ()=>modelSchema);
51
+ const defineRecursiveEntity = (idSchema, modelSchema)=>createEntity(idSchema, modelSchema);
52
+ const createValueObject = (getSchema)=>{
53
53
  const modelSymbol = Symbol();
54
54
  const classSymbol = Symbol();
55
55
  const isThisClass = (target)=>!!target && 'object' == typeof target && classSymbol in target;
56
56
  class ValueObject {
57
- static schema = 'function' == typeof schema ? schema(isThisClass) : schema;
57
+ static schema = getSchema(isThisClass);
58
58
  constructor(data){
59
59
  const parsedData = parseSync(ValueObject.schema, data);
60
60
  Object.defineProperty(this, modelSymbol, {
@@ -71,4 +71,6 @@ const defineValueObject = (schema)=>{
71
71
  }
72
72
  return ValueObject;
73
73
  };
74
- export { AsyncSchemaInSyncParsingError, InvalidDataParsingError, defineEntity, defineValueObject };
74
+ const defineValueObject = (schema)=>createValueObject(()=>schema);
75
+ const defineRecursiveValueObject = (schema)=>createValueObject(schema);
76
+ export { AsyncSchemaInSyncParsingError, InvalidDataParsingError, defineEntity, defineRecursiveEntity, defineRecursiveValueObject, defineValueObject };
@@ -1,12 +1,17 @@
1
1
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import { type DeepReadonly } from './utils';
3
- export declare const defineValueObject: <Schema extends StandardSchemaV1>(schema: Schema | ((isCurrentValueObject: (target: unknown) => boolean) => Schema)) => (abstract new (data: StandardSchemaV1.InferInput<Schema>) => {
3
+ export declare const defineValueObject: <Schema extends StandardSchemaV1>(schema: Schema) => (abstract new (data: StandardSchemaV1.InferInput<Schema>) => {
4
+ get model(): DeepReadonly<StandardSchemaV1.InferOutput<Schema>>;
5
+ }) & {
6
+ readonly schema: Schema;
7
+ };
8
+ export declare const defineRecursiveValueObject: <Schema extends StandardSchemaV1>(schema: (isCurrentValueObject: (target: unknown) => boolean) => Schema) => (abstract new (data: StandardSchemaV1.InferInput<Schema>) => {
4
9
  get model(): DeepReadonly<StandardSchemaV1.InferOutput<Schema>>;
5
10
  }) & {
6
11
  readonly schema: Schema;
7
12
  };
8
13
  export type InferValueObjectSchema<T> = T extends {
9
- schema: StandardSchemaV1;
10
- } ? StandardSchemaV1.InferOutput<T['schema']> : T extends {
14
+ schema: infer S extends StandardSchemaV1;
15
+ } ? StandardSchemaV1.InferOutput<S> : T extends {
11
16
  model: infer M;
12
17
  } ? M : never;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "zod",
16
16
  "valibot"
17
17
  ],
18
- "version": "2.0.2",
18
+ "version": "3.0.0",
19
19
  "type": "module",
20
20
  "repository": {
21
21
  "type": "git",
@@ -53,6 +53,7 @@
53
53
  "@semantic-release/git": "^10.0.1",
54
54
  "@semantic-release/npm": "^13.1.5",
55
55
  "@types/node": "^24.13.2",
56
+ "arktype": "^2.2.3",
56
57
  "semantic-release": "^25.0.8",
57
58
  "typescript": "^6.0.3",
58
59
  "valibot": "^1.4.2",