@longzai-intelligence/shared-kernel 0.0.1 → 0.0.3

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/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`zod`);var t=class{_id;_props;_events=[];constructor(e,t){this._id=e,this._props=t}get id(){return this._id}get props(){return this._props}updateProps(e,t){this._props[e]=t}addEvent(e){this._events.push(e)}pullEvents(){let e=[...this._events];return this._events=[],e}hasEvents(){return this._events.length>0}equals(e){return this._id===e._id}},n=class extends t{_version=1;_isDirty=!1;get version(){return this._version}get isDirty(){return this._isDirty}markAsDirty(){this._isDirty=!0,this._version++}},r=class{static TYPE;eventId;occurredAt;traceContext;constructor(e,t){this.eventId=e,this.occurredAt=new Date,this.traceContext=t}toJSON(){return{eventId:this.eventId,type:this.type,occurredAt:this.occurredAt.toISOString(),traceContext:this.traceContext}}},i=class extends r{type=`entity:created`;constructor(e,t,n){super(e),this.entityType=t,this.entityId=n}toJSON(){return{...super.toJSON(),entityType:this.entityType,entityId:this.entityId}}},a=class extends r{type=`entity:updated`;constructor(e,t,n,r){super(e),this.entityType=t,this.entityId=n,this.changes=r}toJSON(){return{...super.toJSON(),entityType:this.entityType,entityId:this.entityId,changes:this.changes}}},o=class extends r{type=`entity:deleted`;constructor(e,t,n){super(e),this.entityType=t,this.entityId=n}toJSON(){return{...super.toJSON(),entityType:this.entityType,entityId:this.entityId}}},s=class extends Error{constructor(e,t=`DOMAIN_ERROR`,n){super(e),this.code=t,this.context=n,this.name=`DomainError`}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}},c=class extends s{constructor(e,t,n){super(e,`VALIDATION_ERROR`,{field:t,value:n}),this.field=t,this.value=n,this.name=`ValidationError`}},l=class extends s{constructor(e,t){super(e,`BUSINESS_RULE_ERROR`,{rule:t}),this.name=`BusinessRuleError`}},u=class extends s{constructor(e,t){super(`${e} 未找到: ${t}`,`ENTITY_NOT_FOUND`,{entityType:e,entityId:t}),this.entityType=e,this.entityId=t,this.name=`EntityNotFoundError`}},d=class extends s{constructor(e,t,n){super(e,`REPOSITORY_ERROR`,n),this.cause=t,this.name=`RepositoryError`}toJSON(){return{...super.toJSON(),cause:this.cause?.message}}},f=class extends s{constructor(e=`并发冲突,请重试`){super(e,`CONCURRENCY_ERROR`),this.name=`ConcurrencyError`}},p=class extends s{constructor(e,t){super(`无权限执行操作: ${t} on ${e}`,`PERMISSION_DENIED`,{resource:e,action:t}),this.resource=e,this.action=t,this.name=`PermissionDeniedError`}},m=class extends s{constructor(e,t){super(e,`CONFIGURATION_ERROR`,{key:t}),this.key=t,this.name=`ConfigurationError`}},h=class extends s{constructor(e,t,n){super(t,`EXTERNAL_SERVICE_ERROR`,{service:e}),this.service=e,this.name=`ExternalServiceError`,n&&(this.cause=n)}};function g(e){return e instanceof s?e:e instanceof Error?new d(e.message,e):new d(String(e))}function _(e,t,n){(n?t.withOperation(n):t).error(e.message,e,{code:e.code,name:e.name,context:e.context})}function v(e){return[`CONCURRENCY_ERROR`,`EXTERNAL_SERVICE_ERROR`].includes(e.code)}function y(e){return[`VALIDATION_ERROR`,`BUSINESS_RULE_ERROR`,`ENTITY_NOT_FOUND`,`PERMISSION_DENIED`].includes(e.code)}function b(e){return e instanceof c}function x(e){return e instanceof l}function S(e){return e instanceof u}function C(e){return e instanceof d}function w(e){return e instanceof f}function T(e){return e instanceof p}function E(e){return e instanceof m}function D(e){return e instanceof h}const O=Symbol(`UnitOfWork`);var k=class{_value;constructor(e){this._value=Object.freeze(e)}get value(){return this._value}valueOf(){return this._value}toString(){return String(this._value)}},A=class e extends k{constructor(e){super(e)}static fromString(t){if(!t||t.trim().length===0)throw Error(`实体 ID 不能为空`);return new e(t)}equals(e){return this._value===e._value}},j=class e extends k{constructor(e){super(e)}static now(){return new e(Date.now())}static fromDate(t){return new e(t.getTime())}static fromMillis(t){return new e(t)}toDate(){return new Date(this._value)}equals(e){return this._value===e._value}},M=class e extends k{constructor(e){super(e)}static initial(){return new e(0)}static fromNumber(t){if(!Number.isInteger(t)||t<0)throw Error(`版本号必须是非负整数`);return new e(t)}increment(){return new e(this._value+1)}equals(e){return this._value===e._value}isInitial(){return this._value===0}};let N=function(e){return e.LOCAL=`local`,e.PENDING=`pending`,e.SYNCED=`synced`,e.CONFLICT=`conflict`,e}({});var P=class e extends k{constructor(e){super(e)}static local(){return new e(N.LOCAL)}static pending(){return new e(N.PENDING)}static synced(){return new e(N.SYNCED)}static conflict(){return new e(N.CONFLICT)}static fromString(t){switch(t){case`local`:return e.local();case`pending`:return e.pending();case`synced`:return e.synced();case`conflict`:return e.conflict();default:throw Error(`未知的同步状态: ${t}`)}}needsSync(){return this._value===N.LOCAL||this._value===N.PENDING}equals(e){return this._value===e._value}},F=class{isSuccess=!0;isFailure=!1;constructor(e){this.value=e}map(e){return L(e(this.value))}flatMap(e){return e(this.value)}mapError(e){return L(this.value)}getOrElse(e){return this.value}match(e){return e.success(this.value)}},I=class{isSuccess=!1;isFailure=!0;constructor(e){this.error=e}map(e){return R(this.error)}flatMap(e){return R(this.error)}mapError(e){return R(e(this.error))}getOrElse(e){return e}match(e){return e.failure(this.error)}};function L(e){return new F(e)}function R(e){return new I(e)}function z(e){let t=[];for(let n of e){if(n.isFailure)return R(n.error);t.push(n.value)}return L(t)}function B(e){return e.isSuccess}function V(e){return e.isFailure}function H(e){if(e.isFailure)throw g(e.error);return e.value}const U=e.z.string().uuid(`无效的UUID格式`),W=U,G=e.z.number().int().positive(),K=e.z.number().int().nonnegative(),q=e.z.enum([`create`,`update`,`delete`]),J=e.z.enum([`local-wins`,`remote-wins`,`merge`,`manual`]),Y=e.z.object({id:e.z.string(),type:e.z.string()}),X=e.z.object({start:e.z.coerce.date(),end:e.z.coerce.date()}),Z=e.z.object({id:e.z.string(),type:e.z.string(),version:K,data:e.z.record(e.z.string(),e.z.unknown()),timestamp:G}),Q=e.z.object({entityId:e.z.string(),entityType:e.z.string(),changeType:q,data:e.z.record(e.z.string(),e.z.unknown()).optional(),timestamp:G,version:K}),$=e.z.object({id:e.z.string(),entityType:e.z.string(),entityId:e.z.string(),localVersion:K,remoteVersion:K,localData:e.z.record(e.z.string(),e.z.unknown()),remoteData:e.z.record(e.z.string(),e.z.unknown()),conflictedAt:G}),ee=e.z.object({conflictId:e.z.string(),strategy:J,resolvedData:e.z.record(e.z.string(),e.z.unknown()),resolvedAt:G});exports.AggregateRoot=n,exports.AggregateRootEntity=n,exports.BusinessRuleError=l,exports.ChangeTypeSchema=q,exports.ConcurrencyError=f,exports.ConfigurationError=m,exports.ConflictDataSchema=$,exports.ConflictResolutionSchema=ee,exports.ConflictResolutionStrategySchema=J,exports.DomainError=s,exports.DomainEvent=r,exports.Entity=t,exports.EntityChangeSchema=Q,exports.EntityCreatedEvent=i,exports.EntityDeletedEvent=o,exports.EntityIdSchema=W,exports.EntityIdVO=A,exports.EntityNotFoundError=u,exports.EntityUpdatedEvent=a,exports.ExternalServiceError=h,exports.Failure=I,exports.IdReferenceSchema=Y,exports.PermissionDeniedError=p,exports.RepositoryError=d,exports.Success=F,exports.SyncDataSchema=Z,exports.SyncStatus=N,exports.SyncStatusVO=P,exports.TimeRangeSchema=X,exports.TimestampSchema=G,exports.TimestampVO=j,exports.UNIT_OF_WORK_TOKEN=O,exports.UuidSchema=U,exports.ValidationError=c,exports.ValueObject=k,exports.VersionSchema=K,exports.VersionVO=M,exports.combine=z,exports.failure=R,exports.isBusinessRuleError=x,exports.isClientError=y,exports.isConcurrencyError=w,exports.isConfigurationError=E,exports.isEntityNotFoundError=S,exports.isExternalServiceError=D,exports.isFailure=V,exports.isPermissionDeniedError=T,exports.isRepositoryError=C,exports.isRetryableError=v,exports.isSuccess=B,exports.isValidationError=b,exports.logError=_,exports.success=L,exports.toDomainError=g,exports.unwrapResult=H;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`zod`);var t=class{_id;_props;_events=[];constructor(e,t){this._id=e,this._props=t}get id(){return this._id}get props(){return this._props}updateProps(e,t){this._props[e]=t}addEvent(e){this._events.push(e)}pullEvents(){let e=[...this._events];return this._events=[],e}hasEvents(){return this._events.length>0}equals(e){return this._id===e._id}},n=class extends t{_version=1;_isDirty=!1;get version(){return this._version}get isDirty(){return this._isDirty}markAsDirty(){this._isDirty=!0,this._version++}},r=class{static TYPE;eventId;occurredAt;traceContext;constructor(e,t){this.eventId=e,this.occurredAt=new Date,this.traceContext=t}toJSON(){return{eventId:this.eventId,type:this.type,occurredAt:this.occurredAt.toISOString(),traceContext:this.traceContext}}},i=class extends r{type=`entity:created`;constructor(e,t,n){super(e),this.entityType=t,this.entityId=n}toJSON(){return{...super.toJSON(),entityType:this.entityType,entityId:this.entityId}}},a=class extends r{type=`entity:updated`;constructor(e,t,n,r){super(e),this.entityType=t,this.entityId=n,this.changes=r}toJSON(){return{...super.toJSON(),entityType:this.entityType,entityId:this.entityId,changes:this.changes}}},o=class extends r{type=`entity:deleted`;constructor(e,t,n){super(e),this.entityType=t,this.entityId=n}toJSON(){return{...super.toJSON(),entityType:this.entityType,entityId:this.entityId}}};const s=Symbol(`UnitOfWork`);var c=class{_value;constructor(e){this._value=Object.freeze(e)}get value(){return this._value}valueOf(){return this._value}toString(){return String(this._value)}},l=class extends Error{constructor(e,t=`DOMAIN_ERROR`,n){super(e),this.code=t,this.context=n,this.name=`DomainError`}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}},u=class extends l{constructor(e,t,n){super(e,`VALIDATION_ERROR`,{field:t,value:n}),this.field=t,this.value=n,this.name=`ValidationError`}},d=class extends l{constructor(e,t,n){super(e,`REPOSITORY_ERROR`,n),this.cause=t,this.name=`RepositoryError`}toJSON(){return{...super.toJSON(),cause:this.cause?.message}}};function f(e){return e instanceof l?e:e instanceof Error?new d(e.message,e):new d(String(e))}var p=class{isSuccess=!0;isFailure=!1;constructor(e){this.value=e}map(e){return h(e(this.value))}flatMap(e){return e(this.value)}mapError(e){return h(this.value)}getOrElse(e){return this.value}match(e){return e.success(this.value)}},m=class{isSuccess=!1;isFailure=!0;constructor(e){this.error=e}map(e){return g(this.error)}flatMap(e){return g(this.error)}mapError(e){return g(e(this.error))}getOrElse(e){return e}match(e){return e.failure(this.error)}};function h(e){return new p(e)}function g(e){return new m(e)}function _(e){let t=[];for(let n of e){if(n.isFailure)return g(n.error);t.push(n.value)}return h(t)}function v(e){return e.isSuccess}function y(e){return e.isFailure}function b(e){if(e.isFailure)throw f(e.error);return e.value}var x=class e extends c{static UUID_V4_REGEX=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;constructor(e){super(e)}static fromUUID(t){return!t||t.trim().length===0?g(new u(`实体 ID 不能为空`,`id`,t)):this.UUID_V4_REGEX.test(t)?h(new e(t)):g(new u(`无效的 UUID 格式`,`id`,t))}static generate(){return new e(crypto.randomUUID())}static fromString(t){if(!t||t.trim().length===0)throw Error(`实体 ID 不能为空`);return new e(t)}equals(e){return this._value===e._value}},S=class e extends c{constructor(e){super(e)}static now(){return new e(Date.now())}static fromDate(t){return new e(t.getTime())}static fromMillis(t){return new e(t)}toDate(){return new Date(this._value)}equals(e){return this._value===e._value}},C=class e extends c{constructor(e){super(e)}static initial(){return new e(0)}static fromNumber(t){if(!Number.isInteger(t)||t<0)throw Error(`版本号必须是非负整数`);return new e(t)}increment(){return new e(this._value+1)}equals(e){return this._value===e._value}isInitial(){return this._value===0}};let w=function(e){return e.LOCAL=`local`,e.PENDING=`pending`,e.SYNCED=`synced`,e.CONFLICT=`conflict`,e}({});var T=class e extends c{constructor(e){super(e)}static local(){return new e(w.LOCAL)}static pending(){return new e(w.PENDING)}static synced(){return new e(w.SYNCED)}static conflict(){return new e(w.CONFLICT)}static fromString(t){switch(t){case`local`:return e.local();case`pending`:return e.pending();case`synced`:return e.synced();case`conflict`:return e.conflict();default:throw Error(`未知的同步状态: ${t}`)}}needsSync(){return this._value===w.LOCAL||this._value===w.PENDING}equals(e){return this._value===e._value}};const E=e.z.number().int().positive(),D=e.z.number().int().nonnegative(),O=e.z.enum([`create`,`update`,`delete`]),k=e.z.enum([`local-wins`,`remote-wins`,`merge`,`manual`]),A=e.z.object({id:e.z.string(),type:e.z.string()}),j=e.z.object({start:e.z.coerce.date(),end:e.z.coerce.date()}),M=e.z.object({id:e.z.string(),type:e.z.string(),version:D,data:e.z.record(e.z.string(),e.z.unknown()),timestamp:E}),N=e.z.object({entityId:e.z.string(),entityType:e.z.string(),changeType:O,data:e.z.record(e.z.string(),e.z.unknown()).optional(),timestamp:E,version:D}),P=e.z.object({id:e.z.string(),entityType:e.z.string(),entityId:e.z.string(),localVersion:D,remoteVersion:D,localData:e.z.record(e.z.string(),e.z.unknown()),remoteData:e.z.record(e.z.string(),e.z.unknown()),conflictedAt:E}),F=e.z.object({conflictId:e.z.string(),strategy:k,resolvedData:e.z.record(e.z.string(),e.z.unknown()),resolvedAt:E});exports.AggregateRoot=n,exports.AggregateRootEntity=n,exports.ChangeTypeSchema=O,exports.ConflictDataSchema=P,exports.ConflictResolutionSchema=F,exports.ConflictResolutionStrategySchema=k,exports.DomainEvent=r,exports.Entity=t,exports.EntityChangeSchema=N,exports.EntityCreatedEvent=i,exports.EntityDeletedEvent=o,exports.EntityIdVO=x,exports.EntityUpdatedEvent=a,exports.Failure=m,exports.IdReferenceSchema=A,exports.Success=p,exports.SyncDataSchema=M,exports.SyncStatus=w,exports.SyncStatusVO=T,exports.TimeRangeSchema=j,exports.TimestampSchema=E,exports.TimestampVO=S,exports.UNIT_OF_WORK_TOKEN=s,exports.ValueObject=c,exports.VersionSchema=D,exports.VersionVO=C,exports.combine=_,exports.failure=g,exports.isFailure=y,exports.isSuccess=v,exports.success=h,exports.unwrapResult=b;
package/dist/index.d.cts CHANGED
@@ -94,81 +94,6 @@ type TracingContextManager = {
94
94
  runWithChildSpan<T>(fn: () => T): T;
95
95
  };
96
96
  //#endregion
97
- //#region src/domain/exception/domain-exception.errors.d.ts
98
- declare abstract class DomainError extends Error {
99
- readonly code: string;
100
- readonly context?: Record<string, unknown> | undefined;
101
- constructor(message: string, code?: string, context?: Record<string, unknown> | undefined);
102
- toJSON(): object;
103
- }
104
- declare class ValidationError extends DomainError {
105
- readonly field?: string | undefined;
106
- readonly value?: unknown | undefined;
107
- constructor(message: string, field?: string | undefined, value?: unknown | undefined);
108
- }
109
- declare class BusinessRuleError extends DomainError {
110
- constructor(message: string, rule?: string);
111
- }
112
- declare class EntityNotFoundError extends DomainError {
113
- readonly entityType: string;
114
- readonly entityId: string;
115
- constructor(entityType: string, entityId: string);
116
- }
117
- declare class RepositoryError extends DomainError {
118
- readonly cause?: Error | undefined;
119
- constructor(message: string, cause?: Error | undefined, context?: Record<string, unknown>);
120
- toJSON(): object;
121
- }
122
- declare class ConcurrencyError extends DomainError {
123
- constructor(message?: string);
124
- }
125
- declare class PermissionDeniedError extends DomainError {
126
- readonly resource: string;
127
- readonly action: string;
128
- constructor(resource: string, action: string);
129
- }
130
- declare class ConfigurationError extends DomainError {
131
- readonly key?: string | undefined;
132
- constructor(message: string, key?: string | undefined);
133
- }
134
- declare class ExternalServiceError extends DomainError {
135
- readonly service: string;
136
- constructor(service: string, message: string, cause?: Error);
137
- }
138
- //#endregion
139
- //#region ../logger/core/dist/index.d.mts
140
- //#endregion
141
- //#region src/tracing/context.types.d.ts
142
- type TraceContext$1 = {
143
- traceId: string;
144
- spanId: string;
145
- parentSpanId?: string;
146
- };
147
- //#endregion
148
- //#region src/log/logger.types.d.ts
149
- type Logger = {
150
- debug(message: string, metadata?: Record<string, unknown>): void;
151
- info(message: string, metadata?: Record<string, unknown>): void;
152
- warn(message: string, metadata?: Record<string, unknown>): void;
153
- error(message: string, error?: Error, metadata?: Record<string, unknown>): void;
154
- withOperation(operation: string): Logger;
155
- withTrace(trace: TraceContext$1): Logger;
156
- };
157
- //#endregion
158
- //#region src/domain/exception/error-utils.d.ts
159
- declare function toDomainError(error: unknown): DomainError;
160
- declare function logError(error: DomainError, logger: Logger, operation?: string): void;
161
- declare function isRetryableError(error: DomainError): boolean;
162
- declare function isClientError(error: DomainError): boolean;
163
- declare function isValidationError(error: DomainError): error is ValidationError;
164
- declare function isBusinessRuleError(error: DomainError): error is BusinessRuleError;
165
- declare function isEntityNotFoundError(error: DomainError): error is EntityNotFoundError;
166
- declare function isRepositoryError(error: DomainError): error is RepositoryError;
167
- declare function isConcurrencyError(error: DomainError): error is ConcurrencyError;
168
- declare function isPermissionDeniedError(error: DomainError): error is PermissionDeniedError;
169
- declare function isConfigurationError(error: DomainError): error is ConfigurationError;
170
- declare function isExternalServiceError(error: DomainError): error is ExternalServiceError;
171
- //#endregion
172
97
  //#region src/domain/repositories/repository.types.d.ts
173
98
  type PaginationParams = {
174
99
  page: number;
@@ -192,6 +117,19 @@ type Repository<T extends Entity<unknown>> = {
192
117
  exists(id: string): Promise<boolean>;
193
118
  };
194
119
  //#endregion
120
+ //#region src/domain/exception/domain-exception.errors.d.ts
121
+ declare abstract class DomainError extends Error {
122
+ readonly code: string;
123
+ readonly context?: Record<string, unknown> | undefined;
124
+ constructor(message: string, code?: string, context?: Record<string, unknown> | undefined);
125
+ toJSON(): object;
126
+ }
127
+ declare class ValidationError extends DomainError {
128
+ readonly field?: string | undefined;
129
+ readonly value?: unknown | undefined;
130
+ constructor(message: string, field?: string | undefined, value?: unknown | undefined);
131
+ }
132
+ //#endregion
195
133
  //#region src/domain/result/result.types.d.ts
196
134
  type MapFunction<T, U> = (value: T) => U;
197
135
  type FlatMapFunction<T, U, E> = (value: T) => Result<U, E>;
@@ -251,7 +189,10 @@ declare abstract class ValueObject<T> {
251
189
  //#endregion
252
190
  //#region src/domain/value-object/entity-id.vo.d.ts
253
191
  declare class EntityIdVO extends ValueObject<string> {
192
+ private static readonly UUID_V4_REGEX;
254
193
  private constructor();
194
+ static fromUUID(value: string): Result<EntityIdVO, ValidationError>;
195
+ static generate(): EntityIdVO;
255
196
  static fromString(value: string): EntityIdVO;
256
197
  equals(other: EntityIdVO): boolean;
257
198
  }
@@ -337,8 +278,6 @@ type Reference = {
337
278
  };
338
279
  //#endregion
339
280
  //#region src/domain/schemas/common.schema.d.ts
340
- declare const UuidSchema: z.ZodString;
341
- declare const EntityIdSchema: z.ZodString;
342
281
  declare const TimestampSchema: z.ZodNumber;
343
282
  declare const VersionSchema: z.ZodNumber;
344
283
  declare const ChangeTypeSchema: z.ZodEnum<{
@@ -400,11 +339,9 @@ declare const ConflictResolutionSchema: z.ZodObject<{
400
339
  resolvedData: z.ZodRecord<z.ZodString, z.ZodUnknown>;
401
340
  resolvedAt: z.ZodNumber;
402
341
  }, z.core.$strip>;
403
- type Uuid = z.infer<typeof UuidSchema>;
404
- type EntityId = z.infer<typeof EntityIdSchema>;
405
342
  type Timestamp = z.infer<typeof TimestampSchema>;
406
343
  type Version = z.infer<typeof VersionSchema>;
407
344
  type ChangeType = z.infer<typeof ChangeTypeSchema>;
408
345
  type IdReference = z.infer<typeof IdReferenceSchema>;
409
346
  //#endregion
410
- export { AggregateRootEntity as AggregateRoot, AggregateRootEntity, BusinessRuleError, type ChangeType, ChangeTypeSchema, ConcurrencyError, ConfigurationError, type ConflictData, ConflictDataSchema, type ConflictResolution, ConflictResolutionSchema, type ConflictResolutionStrategy, ConflictResolutionStrategySchema, DomainError, DomainEvent, type DomainEventConstructor, type DomainEventHandler, Entity, type EntityChange, EntityChangeSchema, EntityCreatedEvent, EntityDeletedEvent, type EntityId, EntityIdSchema, EntityIdVO, EntityNotFoundError, EntityUpdatedEvent, type EventConstructor, ExternalServiceError, Failure, type IdReference, IdReferenceSchema, PermissionDeniedError, type QueryOptions, type Reference, type Repository, RepositoryError, type Result, type SortParams, Success, type SyncData, SyncDataSchema, SyncStatus, SyncStatusVO, type TimeRange, TimeRangeSchema, type Timestamp, TimestampSchema, TimestampVO, type TraceContext, type TracingContextManager, UNIT_OF_WORK_TOKEN, type UnitOfWork, type Uuid, UuidSchema, ValidationError, ValueObject, type Version, VersionSchema, VersionVO, combine, failure, isBusinessRuleError, isClientError, isConcurrencyError, isConfigurationError, isEntityNotFoundError, isExternalServiceError, isFailure, isPermissionDeniedError, isRepositoryError, isRetryableError, isSuccess, isValidationError, logError, success, toDomainError, unwrapResult };
347
+ export { AggregateRootEntity as AggregateRoot, AggregateRootEntity, type ChangeType, ChangeTypeSchema, type ConflictData, ConflictDataSchema, type ConflictResolution, ConflictResolutionSchema, type ConflictResolutionStrategy, ConflictResolutionStrategySchema, DomainEvent, type DomainEventConstructor, type DomainEventHandler, Entity, type EntityChange, EntityChangeSchema, EntityCreatedEvent, EntityDeletedEvent, EntityIdVO, EntityUpdatedEvent, type EventConstructor, Failure, type IdReference, IdReferenceSchema, type QueryOptions, type Reference, type Repository, type Result, type SortParams, Success, type SyncData, SyncDataSchema, SyncStatus, SyncStatusVO, type TimeRange, TimeRangeSchema, type Timestamp, TimestampSchema, TimestampVO, type TraceContext, type TracingContextManager, UNIT_OF_WORK_TOKEN, type UnitOfWork, ValueObject, type Version, VersionSchema, VersionVO, combine, failure, isFailure, isSuccess, success, unwrapResult };
package/dist/index.d.mts CHANGED
@@ -94,81 +94,6 @@ type TracingContextManager = {
94
94
  runWithChildSpan<T>(fn: () => T): T;
95
95
  };
96
96
  //#endregion
97
- //#region src/domain/exception/domain-exception.errors.d.ts
98
- declare abstract class DomainError extends Error {
99
- readonly code: string;
100
- readonly context?: Record<string, unknown> | undefined;
101
- constructor(message: string, code?: string, context?: Record<string, unknown> | undefined);
102
- toJSON(): object;
103
- }
104
- declare class ValidationError extends DomainError {
105
- readonly field?: string | undefined;
106
- readonly value?: unknown | undefined;
107
- constructor(message: string, field?: string | undefined, value?: unknown | undefined);
108
- }
109
- declare class BusinessRuleError extends DomainError {
110
- constructor(message: string, rule?: string);
111
- }
112
- declare class EntityNotFoundError extends DomainError {
113
- readonly entityType: string;
114
- readonly entityId: string;
115
- constructor(entityType: string, entityId: string);
116
- }
117
- declare class RepositoryError extends DomainError {
118
- readonly cause?: Error | undefined;
119
- constructor(message: string, cause?: Error | undefined, context?: Record<string, unknown>);
120
- toJSON(): object;
121
- }
122
- declare class ConcurrencyError extends DomainError {
123
- constructor(message?: string);
124
- }
125
- declare class PermissionDeniedError extends DomainError {
126
- readonly resource: string;
127
- readonly action: string;
128
- constructor(resource: string, action: string);
129
- }
130
- declare class ConfigurationError extends DomainError {
131
- readonly key?: string | undefined;
132
- constructor(message: string, key?: string | undefined);
133
- }
134
- declare class ExternalServiceError extends DomainError {
135
- readonly service: string;
136
- constructor(service: string, message: string, cause?: Error);
137
- }
138
- //#endregion
139
- //#region ../logger/core/dist/index.d.mts
140
- //#endregion
141
- //#region src/tracing/context.types.d.ts
142
- type TraceContext$1 = {
143
- traceId: string;
144
- spanId: string;
145
- parentSpanId?: string;
146
- };
147
- //#endregion
148
- //#region src/log/logger.types.d.ts
149
- type Logger = {
150
- debug(message: string, metadata?: Record<string, unknown>): void;
151
- info(message: string, metadata?: Record<string, unknown>): void;
152
- warn(message: string, metadata?: Record<string, unknown>): void;
153
- error(message: string, error?: Error, metadata?: Record<string, unknown>): void;
154
- withOperation(operation: string): Logger;
155
- withTrace(trace: TraceContext$1): Logger;
156
- };
157
- //#endregion
158
- //#region src/domain/exception/error-utils.d.ts
159
- declare function toDomainError(error: unknown): DomainError;
160
- declare function logError(error: DomainError, logger: Logger, operation?: string): void;
161
- declare function isRetryableError(error: DomainError): boolean;
162
- declare function isClientError(error: DomainError): boolean;
163
- declare function isValidationError(error: DomainError): error is ValidationError;
164
- declare function isBusinessRuleError(error: DomainError): error is BusinessRuleError;
165
- declare function isEntityNotFoundError(error: DomainError): error is EntityNotFoundError;
166
- declare function isRepositoryError(error: DomainError): error is RepositoryError;
167
- declare function isConcurrencyError(error: DomainError): error is ConcurrencyError;
168
- declare function isPermissionDeniedError(error: DomainError): error is PermissionDeniedError;
169
- declare function isConfigurationError(error: DomainError): error is ConfigurationError;
170
- declare function isExternalServiceError(error: DomainError): error is ExternalServiceError;
171
- //#endregion
172
97
  //#region src/domain/repositories/repository.types.d.ts
173
98
  type PaginationParams = {
174
99
  page: number;
@@ -192,6 +117,19 @@ type Repository<T extends Entity<unknown>> = {
192
117
  exists(id: string): Promise<boolean>;
193
118
  };
194
119
  //#endregion
120
+ //#region src/domain/exception/domain-exception.errors.d.ts
121
+ declare abstract class DomainError extends Error {
122
+ readonly code: string;
123
+ readonly context?: Record<string, unknown> | undefined;
124
+ constructor(message: string, code?: string, context?: Record<string, unknown> | undefined);
125
+ toJSON(): object;
126
+ }
127
+ declare class ValidationError extends DomainError {
128
+ readonly field?: string | undefined;
129
+ readonly value?: unknown | undefined;
130
+ constructor(message: string, field?: string | undefined, value?: unknown | undefined);
131
+ }
132
+ //#endregion
195
133
  //#region src/domain/result/result.types.d.ts
196
134
  type MapFunction<T, U> = (value: T) => U;
197
135
  type FlatMapFunction<T, U, E> = (value: T) => Result<U, E>;
@@ -251,7 +189,10 @@ declare abstract class ValueObject<T> {
251
189
  //#endregion
252
190
  //#region src/domain/value-object/entity-id.vo.d.ts
253
191
  declare class EntityIdVO extends ValueObject<string> {
192
+ private static readonly UUID_V4_REGEX;
254
193
  private constructor();
194
+ static fromUUID(value: string): Result<EntityIdVO, ValidationError>;
195
+ static generate(): EntityIdVO;
255
196
  static fromString(value: string): EntityIdVO;
256
197
  equals(other: EntityIdVO): boolean;
257
198
  }
@@ -337,8 +278,6 @@ type Reference = {
337
278
  };
338
279
  //#endregion
339
280
  //#region src/domain/schemas/common.schema.d.ts
340
- declare const UuidSchema: z.ZodString;
341
- declare const EntityIdSchema: z.ZodString;
342
281
  declare const TimestampSchema: z.ZodNumber;
343
282
  declare const VersionSchema: z.ZodNumber;
344
283
  declare const ChangeTypeSchema: z.ZodEnum<{
@@ -400,11 +339,9 @@ declare const ConflictResolutionSchema: z.ZodObject<{
400
339
  resolvedData: z.ZodRecord<z.ZodString, z.ZodUnknown>;
401
340
  resolvedAt: z.ZodNumber;
402
341
  }, z.core.$strip>;
403
- type Uuid = z.infer<typeof UuidSchema>;
404
- type EntityId = z.infer<typeof EntityIdSchema>;
405
342
  type Timestamp = z.infer<typeof TimestampSchema>;
406
343
  type Version = z.infer<typeof VersionSchema>;
407
344
  type ChangeType = z.infer<typeof ChangeTypeSchema>;
408
345
  type IdReference = z.infer<typeof IdReferenceSchema>;
409
346
  //#endregion
410
- export { AggregateRootEntity as AggregateRoot, AggregateRootEntity, BusinessRuleError, type ChangeType, ChangeTypeSchema, ConcurrencyError, ConfigurationError, type ConflictData, ConflictDataSchema, type ConflictResolution, ConflictResolutionSchema, type ConflictResolutionStrategy, ConflictResolutionStrategySchema, DomainError, DomainEvent, type DomainEventConstructor, type DomainEventHandler, Entity, type EntityChange, EntityChangeSchema, EntityCreatedEvent, EntityDeletedEvent, type EntityId, EntityIdSchema, EntityIdVO, EntityNotFoundError, EntityUpdatedEvent, type EventConstructor, ExternalServiceError, Failure, type IdReference, IdReferenceSchema, PermissionDeniedError, type QueryOptions, type Reference, type Repository, RepositoryError, type Result, type SortParams, Success, type SyncData, SyncDataSchema, SyncStatus, SyncStatusVO, type TimeRange, TimeRangeSchema, type Timestamp, TimestampSchema, TimestampVO, type TraceContext, type TracingContextManager, UNIT_OF_WORK_TOKEN, type UnitOfWork, type Uuid, UuidSchema, ValidationError, ValueObject, type Version, VersionSchema, VersionVO, combine, failure, isBusinessRuleError, isClientError, isConcurrencyError, isConfigurationError, isEntityNotFoundError, isExternalServiceError, isFailure, isPermissionDeniedError, isRepositoryError, isRetryableError, isSuccess, isValidationError, logError, success, toDomainError, unwrapResult };
347
+ export { AggregateRootEntity as AggregateRoot, AggregateRootEntity, type ChangeType, ChangeTypeSchema, type ConflictData, ConflictDataSchema, type ConflictResolution, ConflictResolutionSchema, type ConflictResolutionStrategy, ConflictResolutionStrategySchema, DomainEvent, type DomainEventConstructor, type DomainEventHandler, Entity, type EntityChange, EntityChangeSchema, EntityCreatedEvent, EntityDeletedEvent, EntityIdVO, EntityUpdatedEvent, type EventConstructor, Failure, type IdReference, IdReferenceSchema, type QueryOptions, type Reference, type Repository, type Result, type SortParams, Success, type SyncData, SyncDataSchema, SyncStatus, SyncStatusVO, type TimeRange, TimeRangeSchema, type Timestamp, TimestampSchema, TimestampVO, type TraceContext, type TracingContextManager, UNIT_OF_WORK_TOKEN, type UnitOfWork, ValueObject, type Version, VersionSchema, VersionVO, combine, failure, isFailure, isSuccess, success, unwrapResult };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{z as e}from"zod";var t=class{_id;_props;_events=[];constructor(e,t){this._id=e,this._props=t}get id(){return this._id}get props(){return this._props}updateProps(e,t){this._props[e]=t}addEvent(e){this._events.push(e)}pullEvents(){let e=[...this._events];return this._events=[],e}hasEvents(){return this._events.length>0}equals(e){return this._id===e._id}},n=class extends t{_version=1;_isDirty=!1;get version(){return this._version}get isDirty(){return this._isDirty}markAsDirty(){this._isDirty=!0,this._version++}},r=class{static TYPE;eventId;occurredAt;traceContext;constructor(e,t){this.eventId=e,this.occurredAt=new Date,this.traceContext=t}toJSON(){return{eventId:this.eventId,type:this.type,occurredAt:this.occurredAt.toISOString(),traceContext:this.traceContext}}},i=class extends r{type=`entity:created`;constructor(e,t,n){super(e),this.entityType=t,this.entityId=n}toJSON(){return{...super.toJSON(),entityType:this.entityType,entityId:this.entityId}}},a=class extends r{type=`entity:updated`;constructor(e,t,n,r){super(e),this.entityType=t,this.entityId=n,this.changes=r}toJSON(){return{...super.toJSON(),entityType:this.entityType,entityId:this.entityId,changes:this.changes}}},o=class extends r{type=`entity:deleted`;constructor(e,t,n){super(e),this.entityType=t,this.entityId=n}toJSON(){return{...super.toJSON(),entityType:this.entityType,entityId:this.entityId}}},s=class extends Error{constructor(e,t=`DOMAIN_ERROR`,n){super(e),this.code=t,this.context=n,this.name=`DomainError`}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}},c=class extends s{constructor(e,t,n){super(e,`VALIDATION_ERROR`,{field:t,value:n}),this.field=t,this.value=n,this.name=`ValidationError`}},l=class extends s{constructor(e,t){super(e,`BUSINESS_RULE_ERROR`,{rule:t}),this.name=`BusinessRuleError`}},u=class extends s{constructor(e,t){super(`${e} 未找到: ${t}`,`ENTITY_NOT_FOUND`,{entityType:e,entityId:t}),this.entityType=e,this.entityId=t,this.name=`EntityNotFoundError`}},d=class extends s{constructor(e,t,n){super(e,`REPOSITORY_ERROR`,n),this.cause=t,this.name=`RepositoryError`}toJSON(){return{...super.toJSON(),cause:this.cause?.message}}},f=class extends s{constructor(e=`并发冲突,请重试`){super(e,`CONCURRENCY_ERROR`),this.name=`ConcurrencyError`}},p=class extends s{constructor(e,t){super(`无权限执行操作: ${t} on ${e}`,`PERMISSION_DENIED`,{resource:e,action:t}),this.resource=e,this.action=t,this.name=`PermissionDeniedError`}},m=class extends s{constructor(e,t){super(e,`CONFIGURATION_ERROR`,{key:t}),this.key=t,this.name=`ConfigurationError`}},h=class extends s{constructor(e,t,n){super(t,`EXTERNAL_SERVICE_ERROR`,{service:e}),this.service=e,this.name=`ExternalServiceError`,n&&(this.cause=n)}};function g(e){return e instanceof s?e:e instanceof Error?new d(e.message,e):new d(String(e))}function _(e,t,n){(n?t.withOperation(n):t).error(e.message,e,{code:e.code,name:e.name,context:e.context})}function v(e){return[`CONCURRENCY_ERROR`,`EXTERNAL_SERVICE_ERROR`].includes(e.code)}function y(e){return[`VALIDATION_ERROR`,`BUSINESS_RULE_ERROR`,`ENTITY_NOT_FOUND`,`PERMISSION_DENIED`].includes(e.code)}function b(e){return e instanceof c}function x(e){return e instanceof l}function S(e){return e instanceof u}function C(e){return e instanceof d}function w(e){return e instanceof f}function T(e){return e instanceof p}function E(e){return e instanceof m}function D(e){return e instanceof h}const O=Symbol(`UnitOfWork`);var k=class{_value;constructor(e){this._value=Object.freeze(e)}get value(){return this._value}valueOf(){return this._value}toString(){return String(this._value)}},A=class e extends k{constructor(e){super(e)}static fromString(t){if(!t||t.trim().length===0)throw Error(`实体 ID 不能为空`);return new e(t)}equals(e){return this._value===e._value}},j=class e extends k{constructor(e){super(e)}static now(){return new e(Date.now())}static fromDate(t){return new e(t.getTime())}static fromMillis(t){return new e(t)}toDate(){return new Date(this._value)}equals(e){return this._value===e._value}},M=class e extends k{constructor(e){super(e)}static initial(){return new e(0)}static fromNumber(t){if(!Number.isInteger(t)||t<0)throw Error(`版本号必须是非负整数`);return new e(t)}increment(){return new e(this._value+1)}equals(e){return this._value===e._value}isInitial(){return this._value===0}};let N=function(e){return e.LOCAL=`local`,e.PENDING=`pending`,e.SYNCED=`synced`,e.CONFLICT=`conflict`,e}({});var P=class e extends k{constructor(e){super(e)}static local(){return new e(N.LOCAL)}static pending(){return new e(N.PENDING)}static synced(){return new e(N.SYNCED)}static conflict(){return new e(N.CONFLICT)}static fromString(t){switch(t){case`local`:return e.local();case`pending`:return e.pending();case`synced`:return e.synced();case`conflict`:return e.conflict();default:throw Error(`未知的同步状态: ${t}`)}}needsSync(){return this._value===N.LOCAL||this._value===N.PENDING}equals(e){return this._value===e._value}},F=class{isSuccess=!0;isFailure=!1;constructor(e){this.value=e}map(e){return L(e(this.value))}flatMap(e){return e(this.value)}mapError(e){return L(this.value)}getOrElse(e){return this.value}match(e){return e.success(this.value)}},I=class{isSuccess=!1;isFailure=!0;constructor(e){this.error=e}map(e){return R(this.error)}flatMap(e){return R(this.error)}mapError(e){return R(e(this.error))}getOrElse(e){return e}match(e){return e.failure(this.error)}};function L(e){return new F(e)}function R(e){return new I(e)}function z(e){let t=[];for(let n of e){if(n.isFailure)return R(n.error);t.push(n.value)}return L(t)}function B(e){return e.isSuccess}function V(e){return e.isFailure}function H(e){if(e.isFailure)throw g(e.error);return e.value}const U=e.string().uuid(`无效的UUID格式`),W=U,G=e.number().int().positive(),K=e.number().int().nonnegative(),q=e.enum([`create`,`update`,`delete`]),J=e.enum([`local-wins`,`remote-wins`,`merge`,`manual`]),Y=e.object({id:e.string(),type:e.string()}),X=e.object({start:e.coerce.date(),end:e.coerce.date()}),Z=e.object({id:e.string(),type:e.string(),version:K,data:e.record(e.string(),e.unknown()),timestamp:G}),Q=e.object({entityId:e.string(),entityType:e.string(),changeType:q,data:e.record(e.string(),e.unknown()).optional(),timestamp:G,version:K}),$=e.object({id:e.string(),entityType:e.string(),entityId:e.string(),localVersion:K,remoteVersion:K,localData:e.record(e.string(),e.unknown()),remoteData:e.record(e.string(),e.unknown()),conflictedAt:G}),ee=e.object({conflictId:e.string(),strategy:J,resolvedData:e.record(e.string(),e.unknown()),resolvedAt:G});export{n as AggregateRoot,n as AggregateRootEntity,l as BusinessRuleError,q as ChangeTypeSchema,f as ConcurrencyError,m as ConfigurationError,$ as ConflictDataSchema,ee as ConflictResolutionSchema,J as ConflictResolutionStrategySchema,s as DomainError,r as DomainEvent,t as Entity,Q as EntityChangeSchema,i as EntityCreatedEvent,o as EntityDeletedEvent,W as EntityIdSchema,A as EntityIdVO,u as EntityNotFoundError,a as EntityUpdatedEvent,h as ExternalServiceError,I as Failure,Y as IdReferenceSchema,p as PermissionDeniedError,d as RepositoryError,F as Success,Z as SyncDataSchema,N as SyncStatus,P as SyncStatusVO,X as TimeRangeSchema,G as TimestampSchema,j as TimestampVO,O as UNIT_OF_WORK_TOKEN,U as UuidSchema,c as ValidationError,k as ValueObject,K as VersionSchema,M as VersionVO,z as combine,R as failure,x as isBusinessRuleError,y as isClientError,w as isConcurrencyError,E as isConfigurationError,S as isEntityNotFoundError,D as isExternalServiceError,V as isFailure,T as isPermissionDeniedError,C as isRepositoryError,v as isRetryableError,B as isSuccess,b as isValidationError,_ as logError,L as success,g as toDomainError,H as unwrapResult};
1
+ import{z as e}from"zod";var t=class{_id;_props;_events=[];constructor(e,t){this._id=e,this._props=t}get id(){return this._id}get props(){return this._props}updateProps(e,t){this._props[e]=t}addEvent(e){this._events.push(e)}pullEvents(){let e=[...this._events];return this._events=[],e}hasEvents(){return this._events.length>0}equals(e){return this._id===e._id}},n=class extends t{_version=1;_isDirty=!1;get version(){return this._version}get isDirty(){return this._isDirty}markAsDirty(){this._isDirty=!0,this._version++}},r=class{static TYPE;eventId;occurredAt;traceContext;constructor(e,t){this.eventId=e,this.occurredAt=new Date,this.traceContext=t}toJSON(){return{eventId:this.eventId,type:this.type,occurredAt:this.occurredAt.toISOString(),traceContext:this.traceContext}}},i=class extends r{type=`entity:created`;constructor(e,t,n){super(e),this.entityType=t,this.entityId=n}toJSON(){return{...super.toJSON(),entityType:this.entityType,entityId:this.entityId}}},a=class extends r{type=`entity:updated`;constructor(e,t,n,r){super(e),this.entityType=t,this.entityId=n,this.changes=r}toJSON(){return{...super.toJSON(),entityType:this.entityType,entityId:this.entityId,changes:this.changes}}},o=class extends r{type=`entity:deleted`;constructor(e,t,n){super(e),this.entityType=t,this.entityId=n}toJSON(){return{...super.toJSON(),entityType:this.entityType,entityId:this.entityId}}};const s=Symbol(`UnitOfWork`);var c=class{_value;constructor(e){this._value=Object.freeze(e)}get value(){return this._value}valueOf(){return this._value}toString(){return String(this._value)}},l=class extends Error{constructor(e,t=`DOMAIN_ERROR`,n){super(e),this.code=t,this.context=n,this.name=`DomainError`}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}},u=class extends l{constructor(e,t,n){super(e,`VALIDATION_ERROR`,{field:t,value:n}),this.field=t,this.value=n,this.name=`ValidationError`}},d=class extends l{constructor(e,t,n){super(e,`REPOSITORY_ERROR`,n),this.cause=t,this.name=`RepositoryError`}toJSON(){return{...super.toJSON(),cause:this.cause?.message}}};function f(e){return e instanceof l?e:e instanceof Error?new d(e.message,e):new d(String(e))}var p=class{isSuccess=!0;isFailure=!1;constructor(e){this.value=e}map(e){return h(e(this.value))}flatMap(e){return e(this.value)}mapError(e){return h(this.value)}getOrElse(e){return this.value}match(e){return e.success(this.value)}},m=class{isSuccess=!1;isFailure=!0;constructor(e){this.error=e}map(e){return g(this.error)}flatMap(e){return g(this.error)}mapError(e){return g(e(this.error))}getOrElse(e){return e}match(e){return e.failure(this.error)}};function h(e){return new p(e)}function g(e){return new m(e)}function _(e){let t=[];for(let n of e){if(n.isFailure)return g(n.error);t.push(n.value)}return h(t)}function v(e){return e.isSuccess}function y(e){return e.isFailure}function b(e){if(e.isFailure)throw f(e.error);return e.value}var x=class e extends c{static UUID_V4_REGEX=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;constructor(e){super(e)}static fromUUID(t){return!t||t.trim().length===0?g(new u(`实体 ID 不能为空`,`id`,t)):this.UUID_V4_REGEX.test(t)?h(new e(t)):g(new u(`无效的 UUID 格式`,`id`,t))}static generate(){return new e(crypto.randomUUID())}static fromString(t){if(!t||t.trim().length===0)throw Error(`实体 ID 不能为空`);return new e(t)}equals(e){return this._value===e._value}},S=class e extends c{constructor(e){super(e)}static now(){return new e(Date.now())}static fromDate(t){return new e(t.getTime())}static fromMillis(t){return new e(t)}toDate(){return new Date(this._value)}equals(e){return this._value===e._value}},C=class e extends c{constructor(e){super(e)}static initial(){return new e(0)}static fromNumber(t){if(!Number.isInteger(t)||t<0)throw Error(`版本号必须是非负整数`);return new e(t)}increment(){return new e(this._value+1)}equals(e){return this._value===e._value}isInitial(){return this._value===0}};let w=function(e){return e.LOCAL=`local`,e.PENDING=`pending`,e.SYNCED=`synced`,e.CONFLICT=`conflict`,e}({});var T=class e extends c{constructor(e){super(e)}static local(){return new e(w.LOCAL)}static pending(){return new e(w.PENDING)}static synced(){return new e(w.SYNCED)}static conflict(){return new e(w.CONFLICT)}static fromString(t){switch(t){case`local`:return e.local();case`pending`:return e.pending();case`synced`:return e.synced();case`conflict`:return e.conflict();default:throw Error(`未知的同步状态: ${t}`)}}needsSync(){return this._value===w.LOCAL||this._value===w.PENDING}equals(e){return this._value===e._value}};const E=e.number().int().positive(),D=e.number().int().nonnegative(),O=e.enum([`create`,`update`,`delete`]),k=e.enum([`local-wins`,`remote-wins`,`merge`,`manual`]),A=e.object({id:e.string(),type:e.string()}),j=e.object({start:e.coerce.date(),end:e.coerce.date()}),M=e.object({id:e.string(),type:e.string(),version:D,data:e.record(e.string(),e.unknown()),timestamp:E}),N=e.object({entityId:e.string(),entityType:e.string(),changeType:O,data:e.record(e.string(),e.unknown()).optional(),timestamp:E,version:D}),P=e.object({id:e.string(),entityType:e.string(),entityId:e.string(),localVersion:D,remoteVersion:D,localData:e.record(e.string(),e.unknown()),remoteData:e.record(e.string(),e.unknown()),conflictedAt:E}),F=e.object({conflictId:e.string(),strategy:k,resolvedData:e.record(e.string(),e.unknown()),resolvedAt:E});export{n as AggregateRoot,n as AggregateRootEntity,O as ChangeTypeSchema,P as ConflictDataSchema,F as ConflictResolutionSchema,k as ConflictResolutionStrategySchema,r as DomainEvent,t as Entity,N as EntityChangeSchema,i as EntityCreatedEvent,o as EntityDeletedEvent,x as EntityIdVO,a as EntityUpdatedEvent,m as Failure,A as IdReferenceSchema,p as Success,M as SyncDataSchema,w as SyncStatus,T as SyncStatusVO,j as TimeRangeSchema,E as TimestampSchema,S as TimestampVO,s as UNIT_OF_WORK_TOKEN,c as ValueObject,D as VersionSchema,C as VersionVO,_ as combine,g as failure,y as isFailure,v as isSuccess,h as success,b as unwrapResult};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence/shared-kernel",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.mts",
6
6
  "main": "./dist/index.cjs",
@@ -31,7 +31,8 @@
31
31
  "typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
32
32
  "typecheck:app": "tsc --noEmit -p tsconfig/app.json",
33
33
  "typecheck:node": "tsc --noEmit -p tsconfig/node.json",
34
- "typecheck:test": "tsc --noEmit -p tsconfig/test.json"
34
+ "typecheck:test": "tsc --noEmit -p tsconfig/test.json",
35
+ "upgrade-deps": "ncu -u"
35
36
  },
36
37
  "dependencies": {
37
38
  "reflect-metadata": "^0.2.2",
@@ -45,7 +46,7 @@
45
46
  "rimraf": "^6.1.3",
46
47
  "typescript": "^6.0.2",
47
48
  "vitest": "^4.1.3",
48
- "@longzai-intelligence/eslint-preset-library": "0.0.3",
49
+ "@longzai-intelligence/eslint-preset-library": "0.0.5",
49
50
  "@longzai-intelligence/vitest-config": "0.0.3",
50
51
  "@longzai-intelligence/typescript-config": "0.0.2",
51
52
  "tsdown": "^0.21.7",