@sentzunhat/zacatl 0.0.22 → 0.0.24

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.
Files changed (53) hide show
  1. package/README.md +13 -7
  2. package/build/index.d.ts +1 -2
  3. package/build/index.d.ts.map +1 -1
  4. package/build/index.js +1 -2
  5. package/build/index.js.map +1 -1
  6. package/build/orm/mongoose.d.ts +3 -0
  7. package/build/orm/mongoose.d.ts.map +1 -0
  8. package/build/orm/mongoose.js +2 -0
  9. package/build/orm/mongoose.js.map +1 -0
  10. package/build/orm/sequelize.d.ts +3 -0
  11. package/build/orm/sequelize.d.ts.map +1 -0
  12. package/build/orm/sequelize.js +2 -0
  13. package/build/orm/sequelize.js.map +1 -0
  14. package/build/service/architecture/application/application.d.ts +1 -0
  15. package/build/service/architecture/application/application.d.ts.map +1 -1
  16. package/build/service/architecture/application/application.js +6 -1
  17. package/build/service/architecture/application/application.js.map +1 -1
  18. package/build/service/architecture/application/index.d.ts +1 -0
  19. package/build/service/architecture/application/index.d.ts.map +1 -1
  20. package/build/service/architecture/application/index.js +1 -0
  21. package/build/service/architecture/application/index.js.map +1 -1
  22. package/build/service/architecture/domain/domain.d.ts +1 -0
  23. package/build/service/architecture/domain/domain.d.ts.map +1 -1
  24. package/build/service/architecture/domain/domain.js +6 -1
  25. package/build/service/architecture/domain/domain.js.map +1 -1
  26. package/build/service/architecture/infrastructure/index.d.ts +0 -4
  27. package/build/service/architecture/infrastructure/index.d.ts.map +1 -1
  28. package/build/service/architecture/infrastructure/index.js +0 -2
  29. package/build/service/architecture/infrastructure/index.js.map +1 -1
  30. package/build/service/architecture/infrastructure/infrastructure.d.ts +1 -0
  31. package/build/service/architecture/infrastructure/infrastructure.d.ts.map +1 -1
  32. package/build/service/architecture/infrastructure/infrastructure.js +6 -1
  33. package/build/service/architecture/infrastructure/infrastructure.js.map +1 -1
  34. package/build/service/architecture/infrastructure/orm/adapter-loader.d.ts.map +1 -1
  35. package/build/service/architecture/infrastructure/orm/adapter-loader.js.map +1 -1
  36. package/build/service/architecture/infrastructure/repositories/abstract.d.ts.map +1 -1
  37. package/build/service/architecture/infrastructure/repositories/abstract.js.map +1 -1
  38. package/build/service/architecture/infrastructure/repositories/types.d.ts +2 -2
  39. package/build/service/architecture/infrastructure/repositories/types.d.ts.map +1 -1
  40. package/build/service/architecture/infrastructure/repositories/types.js.map +1 -1
  41. package/build/test/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +10 -2
  43. package/src/index.ts +6 -11
  44. package/src/orm/mongoose.ts +22 -0
  45. package/src/orm/sequelize.ts +14 -0
  46. package/src/service/architecture/application/application.ts +12 -3
  47. package/src/service/architecture/application/index.ts +1 -0
  48. package/src/service/architecture/domain/domain.ts +10 -1
  49. package/src/service/architecture/infrastructure/index.ts +0 -46
  50. package/src/service/architecture/infrastructure/infrastructure.ts +10 -1
  51. package/src/service/architecture/infrastructure/orm/adapter-loader.ts +2 -10
  52. package/src/service/architecture/infrastructure/repositories/abstract.ts +3 -14
  53. package/src/service/architecture/infrastructure/repositories/types.ts +3 -44
package/package.json CHANGED
@@ -4,13 +4,21 @@
4
4
  "main": "build/index.js",
5
5
  "module": "build/index.js",
6
6
  "types": "build/index.d.ts",
7
- "version": "0.0.22",
7
+ "version": "0.0.24",
8
8
  "packageManager": "npm@10.9.0",
9
9
  "exports": {
10
10
  ".": {
11
11
  "import": "./build/index.js",
12
12
  "types": "./build/index.d.ts"
13
13
  },
14
+ "./orm/mongoose": {
15
+ "import": "./build/orm/mongoose.js",
16
+ "types": "./build/orm/mongoose.d.ts"
17
+ },
18
+ "./orm/sequelize": {
19
+ "import": "./build/orm/sequelize.js",
20
+ "types": "./build/orm/sequelize.d.ts"
21
+ },
14
22
  "./infrastructure": {
15
23
  "import": "./build/service/architecture/infrastructure/repositories/abstract.js",
16
24
  "types": "./build/service/architecture/infrastructure/repositories/abstract.d.ts"
@@ -124,6 +132,7 @@
124
132
  "@vitest/coverage-istanbul": "^4.0.15",
125
133
  "eslint": "^9.39.1",
126
134
  "knip": "^5.71.0",
135
+ "mongodb-memory-server": "^10.4.1",
127
136
  "tsx": "^4.21.0",
128
137
  "typescript": "^5.9.3",
129
138
  "typescript-eslint": "^8.48.1",
@@ -164,7 +173,6 @@
164
173
  "i18n": "^0.15.3",
165
174
  "i18next": "^25.8.0",
166
175
  "js-yaml": "^4.1.1",
167
- "mongodb-memory-server": "^10.4.1",
168
176
  "mongoose": "^9.0.1",
169
177
  "pino": "^10.3.0",
170
178
  "pino-pretty": "^13.1.3",
package/src/index.ts CHANGED
@@ -10,10 +10,8 @@ export * from "./logs";
10
10
  export * from "./runtime";
11
11
  export * from "./localization";
12
12
 
13
- // Re-export infrastructure with ORM types
14
13
  export * from "./service/architecture/infrastructure";
15
14
 
16
- // Re-export server types for convenience
17
15
  export {
18
16
  ServerType,
19
17
  ServerVendor,
@@ -22,16 +20,13 @@ export {
22
20
  } from "./service/architecture/platform/server/server";
23
21
  export type { ConfigServer } from "./service/architecture/platform/server/server";
24
22
 
25
- // Re-export commonly used third-party packages
26
- export { container } from "tsyringe";
23
+ // Third-party integrations
24
+ export { container, singleton, inject } from "tsyringe";
27
25
  export type { DependencyContainer } from "tsyringe";
28
-
29
- // Re-export Zod for validation
30
26
  export { z } from "zod";
31
27
  export type { ZodSchema, ZodType, ZodError } from "zod";
32
28
 
33
- // Re-export ORMs (included as dependencies)
34
- export * from "./orm-exports";
35
-
36
- // Note: TypeScript utility types (Partial, Required, Readonly, etc.)
37
- // are globally available and don't need re-export
29
+ // ⚠️ ORM exports REMOVED from main package to prevent eager loading
30
+ // Use dedicated subpath imports instead:
31
+ // import { mongoose, Schema } from "@sentzunhat/zacatl/orm/mongoose"
32
+ // import { Sequelize, DataTypes } from "@sentzunhat/zacatl/orm/sequelize"
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Mongoose ORM exports
3
+ *
4
+ * @example Minimal bundle (tree-shakeable)
5
+ * import { mongoose, Schema } from "@sentzunhat/zacatl/orm/mongoose";
6
+ *
7
+ * @example Convenience (from main package)
8
+ * import { mongoose, Schema } from "@sentzunhat/zacatl";
9
+ */
10
+
11
+ export {
12
+ default as mongoose,
13
+ Mongoose,
14
+ Schema,
15
+ Model,
16
+ Document,
17
+ connect,
18
+ connection,
19
+ } from "mongoose";
20
+
21
+ // Type-only exports
22
+ export type { Model as MongooseModel } from "mongoose";
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Sequelize ORM exports
3
+ *
4
+ * @example Minimal bundle (tree-shakeable)
5
+ * import { Sequelize, DataTypes } from "@sentzunhat/zacatl/orm/sequelize";
6
+ *
7
+ * @example Convenience (from main package)
8
+ * import { Sequelize, DataTypes } from "@sentzunhat/zacatl";
9
+ */
10
+
11
+ export { Sequelize, Model as SequelizeModel, DataTypes, Op } from "sequelize";
12
+
13
+ // Type-only exports
14
+ export type { ModelStatic, Options as SequelizeOptions } from "sequelize";
@@ -18,6 +18,7 @@ export type ApplicationEntryPoints = {
18
18
 
19
19
  export type ConfigApplication = {
20
20
  entryPoints: ApplicationEntryPoints;
21
+ autoRegister?: boolean; // Auto-register on construction (default: false)
21
22
  };
22
23
 
23
24
  export class Application extends AbstractArchitecture {
@@ -36,6 +37,11 @@ export class Application extends AbstractArchitecture {
36
37
  });
37
38
 
38
39
  this.config = config;
40
+
41
+ // Auto-register if enabled (useful without Service)
42
+ if (config.autoRegister) {
43
+ this.registerRest();
44
+ }
39
45
  }
40
46
 
41
47
  /**
@@ -44,16 +50,19 @@ export class Application extends AbstractArchitecture {
44
50
  private registerRest(): void {
45
51
  this.registerAndStoreDependencies(
46
52
  this.config.entryPoints.rest.hookHandlers,
47
- this.hookHandlers
53
+ this.hookHandlers,
48
54
  );
49
55
 
50
56
  this.registerAndStoreDependencies(
51
57
  this.config.entryPoints.rest.routeHandlers,
52
- this.routeHandlers
58
+ this.routeHandlers,
53
59
  );
54
60
  }
55
61
 
56
62
  public start(): void {
57
- this.registerRest();
63
+ // Register if not already done
64
+ if (!this.config.autoRegister) {
65
+ this.registerRest();
66
+ }
58
67
  }
59
68
  }
@@ -1,2 +1,3 @@
1
1
  export * from "./entry-points";
2
2
  export * from "./application";
3
+ export * from "../../../dependency-injection";
@@ -4,6 +4,7 @@ import { container } from "tsyringe";
4
4
 
5
5
  export type ConfigDomain = {
6
6
  providers: Array<Constructor>;
7
+ autoRegister?: boolean; // Auto-register on construction (default: false)
7
8
  };
8
9
 
9
10
  export class Domain extends AbstractArchitecture {
@@ -14,10 +15,18 @@ export class Domain extends AbstractArchitecture {
14
15
  super();
15
16
 
16
17
  this.config = config;
18
+
19
+ // Auto-register if enabled (useful without Service)
20
+ if (config.autoRegister) {
21
+ this.registerDependencies(this.config.providers);
22
+ }
17
23
  }
18
24
 
19
25
  public async start(): Promise<void> {
20
- this.registerDependencies(this.config.providers);
26
+ // Register if not already done
27
+ if (!this.config.autoRegister) {
28
+ this.registerDependencies(this.config.providers);
29
+ }
21
30
 
22
31
  // Auto-start providers that implement the start method
23
32
  for (const ProviderClass of this.config.providers) {
@@ -1,48 +1,2 @@
1
1
  export * from "./repositories";
2
2
  export * from "./infrastructure";
3
-
4
- // Re-export Mongoose for user convenience
5
- // Users can import directly from @sentzunhat/zacatl instead of installing mongoose
6
- export {
7
- Schema,
8
- Model,
9
- Types,
10
- connect,
11
- connection,
12
- createConnection,
13
- } from "mongoose";
14
-
15
- export type {
16
- Document,
17
- SchemaDefinition,
18
- SchemaOptions,
19
- SchemaTypeOptions,
20
- Connection,
21
- Mongoose,
22
- ObjectId,
23
- UpdateQuery,
24
- QueryOptions,
25
- PopulateOptions,
26
- HydratedDocument,
27
- InferSchemaType,
28
- } from "mongoose";
29
-
30
- // Re-export Sequelize for user convenience
31
- // Users can import directly from @sentzunhat/zacatl instead of installing sequelize
32
- export { DataTypes, Sequelize, Model as SequelizeModelClass } from "sequelize";
33
-
34
- export type {
35
- ModelStatic,
36
- QueryInterface,
37
- Transaction,
38
- Options as SequelizeOptions,
39
- ModelAttributes,
40
- ModelOptions,
41
- FindOptions,
42
- CreateOptions,
43
- UpdateOptions,
44
- DestroyOptions,
45
- WhereOptions,
46
- Order,
47
- Includeable,
48
- } from "sequelize";
@@ -2,6 +2,7 @@ import { AbstractArchitecture, Constructor } from "../architecture";
2
2
 
3
3
  export type ConfigInfrastructure = {
4
4
  repositories: Array<Constructor>;
5
+ autoRegister?: boolean; // Auto-register on construction (default: false)
5
6
  };
6
7
 
7
8
  export class Infrastructure extends AbstractArchitecture {
@@ -11,9 +12,17 @@ export class Infrastructure extends AbstractArchitecture {
11
12
  super();
12
13
 
13
14
  this.config = config;
15
+
16
+ // Auto-register if enabled (useful without Service)
17
+ if (config.autoRegister) {
18
+ this.registerDependencies(this.config.repositories);
19
+ }
14
20
  }
15
21
 
16
22
  public start(): void {
17
- this.registerDependencies(this.config.repositories);
23
+ // Register if not already done
24
+ if (!this.config.autoRegister) {
25
+ this.registerDependencies(this.config.repositories);
26
+ }
18
27
  }
19
28
  }
@@ -5,15 +5,11 @@ import type {
5
5
  ORMAdapter,
6
6
  } from "../repositories/types";
7
7
 
8
- /**
9
- * Loads MongooseAdapter dynamically - only when needed
10
- * Throws helpful error if mongoose is not installed
11
- */
8
+ /** Lazy-loads MongooseAdapter when needed */
12
9
  export async function loadMongooseAdapter<D, I, O>(
13
10
  config: MongooseRepositoryConfig<D>,
14
11
  ): Promise<ORMAdapter<D, I, O>> {
15
12
  try {
16
- // Dynamic import - only loads when Mongoose is actually used
17
13
  const adapters = await import("./adapters/mongoose-adapter");
18
14
  return new adapters.MongooseAdapter<D, I, O>(config);
19
15
  } catch (error: any) {
@@ -29,15 +25,11 @@ export async function loadMongooseAdapter<D, I, O>(
29
25
  }
30
26
  }
31
27
 
32
- /**
33
- * Loads SequelizeAdapter dynamically - only when needed
34
- * Throws helpful error if sequelize is not installed
35
- */
28
+ /** Lazy-loads SequelizeAdapter when needed */
36
29
  export async function loadSequelizeAdapter<D extends Model, I, O>(
37
30
  config: SequelizeRepositoryConfig<D>,
38
31
  ): Promise<ORMAdapter<D, I, O>> {
39
32
  try {
40
- // Dynamic import - only loads when Sequelize is actually used
41
33
  const adapters = await import("./adapters/sequelize-adapter");
42
34
  return new adapters.SequelizeAdapter<D, I, O>(config);
43
35
  } catch (error: any) {
@@ -1,3 +1,4 @@
1
+ // Type-only imports prevent eager loading in ESM
1
2
  import type { Model as MongooseModel } from "mongoose";
2
3
  import type { Model, ModelStatic } from "sequelize";
3
4
  import {
@@ -15,18 +16,12 @@ import {
15
16
 
16
17
  export * from "./types";
17
18
 
18
- /**
19
- * Type guard to check if config is for Mongoose
20
- */
21
19
  const isMongooseConfig = <D>(
22
20
  config: BaseRepositoryConfig<D>,
23
21
  ): config is MongooseRepositoryConfig<D> => {
24
22
  return config.type === ORMType.Mongoose;
25
23
  };
26
24
 
27
- /**
28
- * Type guard to check if config is for Sequelize
29
- */
30
25
  const isSequelizeConfig = <D extends Model>(
31
26
  config: BaseRepositoryConfig<D>,
32
27
  ): config is SequelizeRepositoryConfig<D> => {
@@ -34,14 +29,8 @@ const isSequelizeConfig = <D extends Model>(
34
29
  };
35
30
 
36
31
  /**
37
- * BaseRepository - Abstract base class for all repositories
38
- *
39
- * Supports multiple ORMs (Mongoose, Sequelize) through adapter pattern.
40
- * Adapters are lazy-loaded - only the ORM you use gets imported.
41
- * This allows projects to install only one ORM without unused dependencies.
42
- *
43
- * Uses lazy initialization to support ESM dynamic imports while maintaining
44
- * backward compatibility with synchronous constructors.
32
+ * Abstract base repository supporting multiple ORMs via adapter pattern.
33
+ * Adapters are lazy-loaded for optimal bundle size.
45
34
  */
46
35
  export abstract class BaseRepository<D, I, O> implements Repository<D, I, O> {
47
36
  private adapter?: ORMAdapter<D, I, O>;
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  Document,
3
3
  Model as MongooseModel,
4
4
  Schema,
@@ -7,11 +7,8 @@ import {
7
7
  ObjectId,
8
8
  IfAny,
9
9
  } from "mongoose";
10
- import { Model as SequelizeModel, ModelStatic, Model } from "sequelize";
10
+ import type { Model as SequelizeModel, ModelStatic, Model } from "sequelize";
11
11
 
12
- /**
13
- * Enum for supported ORM types
14
- */
15
12
  export enum ORMType {
16
13
  Mongoose = "mongoose",
17
14
  Sequelize = "sequelize",
@@ -51,29 +48,17 @@ export type ToLeanInput<D, T> =
51
48
  | null
52
49
  | undefined;
53
50
 
54
- /**
55
- * Configuration for Mongoose-based repository
56
- * @template D - Database document type
57
- */
58
51
  export type MongooseRepositoryConfig<D = unknown> = {
59
52
  readonly type: ORMType.Mongoose;
60
53
  readonly name?: string;
61
54
  readonly schema: Schema<D>;
62
55
  };
63
56
 
64
- /**
65
- * Configuration for Sequelize-based repository
66
- * @template D - Sequelize Model type (must extend Model)
67
- */
68
57
  export type SequelizeRepositoryConfig<D extends Model = Model> = {
69
58
  readonly type: ORMType.Sequelize;
70
59
  readonly model: ModelStatic<D>;
71
60
  };
72
61
 
73
- /**
74
- * Discriminated union of all repository configuration types
75
- * @template D - Database/Model type
76
- */
77
62
  export type BaseRepositoryConfig<D = unknown> =
78
63
  | MongooseRepositoryConfig<D>
79
64
  | SequelizeRepositoryConfig<Model>;
@@ -88,38 +73,12 @@ export type Repository<D, I, O> = {
88
73
  delete(id: string): Promise<O | null>;
89
74
  };
90
75
 
91
- /**
92
- * ORM Adapter Interface - Defines the contract for ORM-specific implementations
93
- * This enables pluggable ORM support without circular dependencies
94
- */
76
+ /** ORM adapter interface for pluggable ORM implementations */
95
77
  export interface ORMAdapter<D, I, O> {
96
- /**
97
- * Get the underlying ORM model
98
- */
99
78
  readonly model: MongooseModel<D> | ModelStatic<any>;
100
-
101
- /**
102
- * Transform database entity to plain lean object
103
- */
104
79
  toLean(input: unknown): O | null;
105
-
106
- /**
107
- * Find entity by ID
108
- */
109
80
  findById(id: string): Promise<O | null>;
110
-
111
- /**
112
- * Create new entity
113
- */
114
81
  create(entity: I): Promise<O>;
115
-
116
- /**
117
- * Update existing entity
118
- */
119
82
  update(id: string, update: Partial<I>): Promise<O | null>;
120
-
121
- /**
122
- * Delete entity by ID
123
- */
124
83
  delete(id: string): Promise<O | null>;
125
84
  }