@astralibx/core 1.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 ADDED
@@ -0,0 +1,80 @@
1
+ # @astralibx/core
2
+
3
+ Shared foundation for all @astralibx packages -- base errors, types, and validation helpers.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @astralibx/core
9
+ ```
10
+
11
+ `zod` is included as a dependency -- no need to install it separately.
12
+
13
+ ## Quick Start
14
+
15
+ ```ts
16
+ import { z } from 'zod';
17
+ import {
18
+ AlxError,
19
+ createConfigValidator,
20
+ baseDbSchema,
21
+ loggerSchema,
22
+ } from '@astralibx/core';
23
+
24
+ // 1. Extend AlxError for your package
25
+ class QueueError extends AlxError {
26
+ constructor(message: string) {
27
+ super(message, 'QUEUE_ERROR');
28
+ this.name = 'QueueError';
29
+ }
30
+ }
31
+
32
+ // 2. Compose a config schema from core fragments + your own fields
33
+ const queueConfigSchema = z.object({
34
+ db: baseDbSchema,
35
+ logger: loggerSchema.optional(),
36
+ concurrency: z.number().int().positive().default(5),
37
+ });
38
+
39
+ // 3. Validate config -- throws ConfigValidationError on invalid input
40
+ const validate = createConfigValidator(queueConfigSchema);
41
+
42
+ validate({
43
+ db: { connection: mongoClient.db() },
44
+ concurrency: 10,
45
+ });
46
+ ```
47
+
48
+ ## What's Included
49
+
50
+ **Error classes**
51
+
52
+ - `AlxError` -- Base error for the ecosystem. Carries a `code` string.
53
+ - `ConfigValidationError` -- Thrown on invalid config. Adds a `field` property.
54
+
55
+ **Type contracts**
56
+
57
+ - `LogAdapter` -- Logger-agnostic interface (`info`, `warn`, `error` methods).
58
+ - `BaseDbConfig` -- Database connection + optional `collectionPrefix`.
59
+ - `BaseRedisConfig` -- Redis connection + optional `keyPrefix`.
60
+
61
+ **Zod schemas**
62
+
63
+ - `loggerSchema` -- Validates a `LogAdapter`-shaped object.
64
+ - `baseDbSchema` -- Validates `BaseDbConfig` (connection must be non-null).
65
+ - `baseRedisSchema` -- Validates `BaseRedisConfig` (connection must be non-null).
66
+
67
+ **Helpers**
68
+
69
+ - `createConfigValidator` -- Takes a Zod schema, returns a validate function that throws `ConfigValidationError` on failure.
70
+
71
+ ## Documentation
72
+
73
+ - [Error Classes](docs/errors.md) -- AlxError, ConfigValidationError, extending for your package
74
+ - [Type Contracts](docs/types.md) -- LogAdapter, BaseDbConfig, BaseRedisConfig
75
+ - [Validation](docs/validation.md) -- Zod schemas, createConfigValidator, composing schemas
76
+ - [Package Author Guide](docs/package-author-guide.md) -- Building new @astralibx packages on top of core
77
+
78
+ ## License
79
+
80
+ MIT
@@ -0,0 +1,61 @@
1
+ import { z, ZodSchema } from 'zod';
2
+
3
+ declare class AlxError extends Error {
4
+ readonly code: string;
5
+ constructor(message: string, code: string);
6
+ }
7
+ declare class ConfigValidationError extends AlxError {
8
+ readonly field: string;
9
+ constructor(message: string, field: string);
10
+ }
11
+
12
+ interface LogAdapter {
13
+ info: (msg: string, meta?: Record<string, unknown>) => void;
14
+ warn: (msg: string, meta?: Record<string, unknown>) => void;
15
+ error: (msg: string, meta?: Record<string, unknown>) => void;
16
+ }
17
+ interface BaseDbConfig {
18
+ connection: unknown;
19
+ collectionPrefix?: string;
20
+ }
21
+ interface BaseRedisConfig {
22
+ connection: unknown;
23
+ keyPrefix?: string;
24
+ }
25
+
26
+ declare const loggerSchema: z.ZodObject<{
27
+ info: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>;
28
+ warn: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>;
29
+ error: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>;
30
+ }, "strip", z.ZodTypeAny, {
31
+ info: (...args: unknown[]) => unknown;
32
+ warn: (...args: unknown[]) => unknown;
33
+ error: (...args: unknown[]) => unknown;
34
+ }, {
35
+ info: (...args: unknown[]) => unknown;
36
+ warn: (...args: unknown[]) => unknown;
37
+ error: (...args: unknown[]) => unknown;
38
+ }>;
39
+ declare const baseDbSchema: z.ZodObject<{
40
+ connection: z.ZodEffects<z.ZodAny, any, any>;
41
+ collectionPrefix: z.ZodOptional<z.ZodString>;
42
+ }, "strip", z.ZodTypeAny, {
43
+ connection?: any;
44
+ collectionPrefix?: string | undefined;
45
+ }, {
46
+ connection?: any;
47
+ collectionPrefix?: string | undefined;
48
+ }>;
49
+ declare const baseRedisSchema: z.ZodObject<{
50
+ connection: z.ZodEffects<z.ZodAny, any, any>;
51
+ keyPrefix: z.ZodOptional<z.ZodString>;
52
+ }, "strip", z.ZodTypeAny, {
53
+ connection?: any;
54
+ keyPrefix?: string | undefined;
55
+ }, {
56
+ connection?: any;
57
+ keyPrefix?: string | undefined;
58
+ }>;
59
+ declare function createConfigValidator(configSchema: ZodSchema, ErrorClass?: typeof ConfigValidationError): (raw: unknown) => void;
60
+
61
+ export { AlxError, type BaseDbConfig, type BaseRedisConfig, ConfigValidationError, type LogAdapter, baseDbSchema, baseRedisSchema, createConfigValidator, loggerSchema };
@@ -0,0 +1,61 @@
1
+ import { z, ZodSchema } from 'zod';
2
+
3
+ declare class AlxError extends Error {
4
+ readonly code: string;
5
+ constructor(message: string, code: string);
6
+ }
7
+ declare class ConfigValidationError extends AlxError {
8
+ readonly field: string;
9
+ constructor(message: string, field: string);
10
+ }
11
+
12
+ interface LogAdapter {
13
+ info: (msg: string, meta?: Record<string, unknown>) => void;
14
+ warn: (msg: string, meta?: Record<string, unknown>) => void;
15
+ error: (msg: string, meta?: Record<string, unknown>) => void;
16
+ }
17
+ interface BaseDbConfig {
18
+ connection: unknown;
19
+ collectionPrefix?: string;
20
+ }
21
+ interface BaseRedisConfig {
22
+ connection: unknown;
23
+ keyPrefix?: string;
24
+ }
25
+
26
+ declare const loggerSchema: z.ZodObject<{
27
+ info: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>;
28
+ warn: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>;
29
+ error: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>;
30
+ }, "strip", z.ZodTypeAny, {
31
+ info: (...args: unknown[]) => unknown;
32
+ warn: (...args: unknown[]) => unknown;
33
+ error: (...args: unknown[]) => unknown;
34
+ }, {
35
+ info: (...args: unknown[]) => unknown;
36
+ warn: (...args: unknown[]) => unknown;
37
+ error: (...args: unknown[]) => unknown;
38
+ }>;
39
+ declare const baseDbSchema: z.ZodObject<{
40
+ connection: z.ZodEffects<z.ZodAny, any, any>;
41
+ collectionPrefix: z.ZodOptional<z.ZodString>;
42
+ }, "strip", z.ZodTypeAny, {
43
+ connection?: any;
44
+ collectionPrefix?: string | undefined;
45
+ }, {
46
+ connection?: any;
47
+ collectionPrefix?: string | undefined;
48
+ }>;
49
+ declare const baseRedisSchema: z.ZodObject<{
50
+ connection: z.ZodEffects<z.ZodAny, any, any>;
51
+ keyPrefix: z.ZodOptional<z.ZodString>;
52
+ }, "strip", z.ZodTypeAny, {
53
+ connection?: any;
54
+ keyPrefix?: string | undefined;
55
+ }, {
56
+ connection?: any;
57
+ keyPrefix?: string | undefined;
58
+ }>;
59
+ declare function createConfigValidator(configSchema: ZodSchema, ErrorClass?: typeof ConfigValidationError): (raw: unknown) => void;
60
+
61
+ export { AlxError, type BaseDbConfig, type BaseRedisConfig, ConfigValidationError, type LogAdapter, baseDbSchema, baseRedisSchema, createConfigValidator, loggerSchema };
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ var zod = require('zod');
4
+
5
+ // src/errors.ts
6
+ var AlxError = class extends Error {
7
+ constructor(message, code) {
8
+ super(message);
9
+ this.code = code;
10
+ Object.setPrototypeOf(this, new.target.prototype);
11
+ this.name = "AlxError";
12
+ if (Error.captureStackTrace) {
13
+ Error.captureStackTrace(this, this.constructor);
14
+ }
15
+ }
16
+ };
17
+ var ConfigValidationError = class extends AlxError {
18
+ constructor(message, field) {
19
+ super(message, "CONFIG_VALIDATION_ERROR");
20
+ this.field = field;
21
+ Object.setPrototypeOf(this, new.target.prototype);
22
+ this.name = "ConfigValidationError";
23
+ }
24
+ };
25
+ var loggerSchema = zod.z.object({
26
+ info: zod.z.function(),
27
+ warn: zod.z.function(),
28
+ error: zod.z.function()
29
+ });
30
+ var baseDbSchema = zod.z.object({
31
+ connection: zod.z.any().refine((val) => val != null, "db.connection is required"),
32
+ collectionPrefix: zod.z.string().optional()
33
+ });
34
+ var baseRedisSchema = zod.z.object({
35
+ connection: zod.z.any().refine((val) => val != null, "redis.connection is required"),
36
+ keyPrefix: zod.z.string().optional()
37
+ });
38
+ function createConfigValidator(configSchema, ErrorClass = ConfigValidationError) {
39
+ return function validateConfig(raw) {
40
+ const result = configSchema.safeParse(raw);
41
+ if (!result.success) {
42
+ const issues = result.error.issues.map((i) => ` ${i.path.join(".")}: ${i.message}`).join("\n");
43
+ throw new ErrorClass(
44
+ `Invalid config:
45
+ ${issues}`,
46
+ result.error.issues[0]?.path.join(".") ?? ""
47
+ );
48
+ }
49
+ };
50
+ }
51
+
52
+ exports.AlxError = AlxError;
53
+ exports.ConfigValidationError = ConfigValidationError;
54
+ exports.baseDbSchema = baseDbSchema;
55
+ exports.baseRedisSchema = baseRedisSchema;
56
+ exports.createConfigValidator = createConfigValidator;
57
+ exports.loggerSchema = loggerSchema;
58
+ //# sourceMappingURL=index.js.map
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/validation.ts"],"names":["z"],"mappings":";;;;;AAAO,IAAM,QAAA,GAAN,cAAuB,KAAA,CAAM;AAAA,EAClC,WAAA,CAAY,SAAiC,IAAA,EAAc;AACzD,IAAA,KAAA,CAAM,OAAO,CAAA;AAD8B,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAE3C,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,GAAA,CAAA,MAAA,CAAW,SAAS,CAAA;AAChD,IAAA,IAAA,CAAK,IAA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AAA,MAAM,MAAA,GAAS,YAAA,CAAa,SAAA,CAAU,GAAG,CAAA;AACzC,IAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,MAAA,MAAM,SAAS,MAAA,CAAO,KAAA,CAAM,OACzB,GAAA,CAAI,CAAC,MAAM,CAAA,EAAA,EAAK,CAAA,CAAE,KAAK,IAAA,CAAK,GAAG,CAAC,CAAA,EAAA,EAAK,CAAA,CAAE,OAAO,CAAA,CAAE,CAAA,CAChD,KAAK,IAAI,CAAA;AACZ,MAAA,MAAM,IAAI,UAAA;AAAA,QACR,CAAA;AAAA,EAAoB,MAAM,CAAA,CAAA;AAAA,QAC1B,MAAA,CAAO,MAAM,MAAA,CAAO,CAAC,GAAG,IAAA,CAAK,IAAA,CAAK,GAAG,CAAA,IAAK;AAAA,OAC5C;AAAA,IACF;AAAA,EACF,CAAA;AACF","file":"index.js","sourcesContent":["export class AlxError extends Error {\n constructor(message: string, public readonly code: string) {\n super(message);\n Object.setPrototypeOf(this, new.target.prototype);\n this.name = 'AlxError';\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n}\n\nexport class ConfigValidationError extends AlxError {\n constructor(message: string, public readonly field: string) {\n super(message, 'CONFIG_VALIDATION_ERROR');\n Object.setPrototypeOf(this, new.target.prototype);\n this.name = 'ConfigValidationError';\n }\n}\n","import { z, type ZodSchema } from 'zod';\nimport { ConfigValidationError } from './errors';\n\nexport const loggerSchema = z.object({\n info: z.function(),\n warn: z.function(),\n error: z.function(),\n});\n\nexport const baseDbSchema = z.object({\n connection: z.any().refine((val) => val != null, 'db.connection is required'),\n collectionPrefix: z.string().optional(),\n});\n\nexport const baseRedisSchema = z.object({\n connection: z.any().refine((val) => val != null, 'redis.connection is required'),\n keyPrefix: z.string().optional(),\n});\n\nexport function createConfigValidator(\n configSchema: ZodSchema,\n ErrorClass: typeof ConfigValidationError = ConfigValidationError,\n): (raw: unknown) => void {\n return function validateConfig(raw: unknown): void {\n const result = configSchema.safeParse(raw);\n if (!result.success) {\n const issues = result.error.issues\n .map((i) => ` ${i.path.join('.')}: ${i.message}`)\n .join('\\n');\n throw new ErrorClass(\n `Invalid config:\\n${issues}`,\n result.error.issues[0]?.path.join('.') ?? '',\n );\n }\n };\n}\n"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,52 @@
1
+ import { z } from 'zod';
2
+
3
+ // src/errors.ts
4
+ var AlxError = class extends Error {
5
+ constructor(message, code) {
6
+ super(message);
7
+ this.code = code;
8
+ Object.setPrototypeOf(this, new.target.prototype);
9
+ this.name = "AlxError";
10
+ if (Error.captureStackTrace) {
11
+ Error.captureStackTrace(this, this.constructor);
12
+ }
13
+ }
14
+ };
15
+ var ConfigValidationError = class extends AlxError {
16
+ constructor(message, field) {
17
+ super(message, "CONFIG_VALIDATION_ERROR");
18
+ this.field = field;
19
+ Object.setPrototypeOf(this, new.target.prototype);
20
+ this.name = "ConfigValidationError";
21
+ }
22
+ };
23
+ var loggerSchema = z.object({
24
+ info: z.function(),
25
+ warn: z.function(),
26
+ error: z.function()
27
+ });
28
+ var baseDbSchema = z.object({
29
+ connection: z.any().refine((val) => val != null, "db.connection is required"),
30
+ collectionPrefix: z.string().optional()
31
+ });
32
+ var baseRedisSchema = z.object({
33
+ connection: z.any().refine((val) => val != null, "redis.connection is required"),
34
+ keyPrefix: z.string().optional()
35
+ });
36
+ function createConfigValidator(configSchema, ErrorClass = ConfigValidationError) {
37
+ return function validateConfig(raw) {
38
+ const result = configSchema.safeParse(raw);
39
+ if (!result.success) {
40
+ const issues = result.error.issues.map((i) => ` ${i.path.join(".")}: ${i.message}`).join("\n");
41
+ throw new ErrorClass(
42
+ `Invalid config:
43
+ ${issues}`,
44
+ result.error.issues[0]?.path.join(".") ?? ""
45
+ );
46
+ }
47
+ };
48
+ }
49
+
50
+ export { AlxError, ConfigValidationError, baseDbSchema, baseRedisSchema, createConfigValidator, loggerSchema };
51
+ //# sourceMappingURL=index.mjs.map
52
+ //# sourceMappingURL=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/B,CAAC;AAEM,IAAM,eAAA,GAAkB,EAAE,MAAA,CAAO;AAAA,EACtC,UAAA,EAAY,EAAE,GAAA,EAAI,CAAE,OAAO,CAAC,GAAA,KAAQ,GAAA,IAAO,IAAA,EAAM,8BAA8B,CAAA;AAAA,EAC/E,SAAA,EAAW,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AACxB,CAAC;AAEM,SAAS,qBAAA,CACd,YAAA,EACA,UAAA,GAA2C,qBAAA,EACnB;AACxB,EAAA,OAAO,SAAS,eAAe,GAAA,EAAoB;AACjD,IAAA,MAAM,MAAA,GAAS,YAAA,CAAa,SAAA,CAAU,GAAG,CAAA;AACzC,IAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,MAAA,MAAM,SAAS,MAAA,CAAO,KAAA,CAAM,OACzB,GAAA,CAAI,CAAC,MAAM,CAAA,EAAA,EAAK,CAAA,CAAE,KAAK,IAAA,CAAK,GAAG,CAAC,CAAA,EAAA,EAAK,CAAA,CAAE,OAAO,CAAA,CAAE,CAAA,CAChD,KAAK,IAAI,CAAA;AACZ,MAAA,MAAM,IAAI,UAAA;AAAA,QACR,CAAA;AAAA,EAAoB,MAAM,CAAA,CAAA;AAAA,QAC1B,MAAA,CAAO,MAAM,MAAA,CAAO,CAAC,GAAG,IAAA,CAAK,IAAA,CAAK,GAAG,CAAA,IAAK;AAAA,OAC5C;AAAA,IACF;AAAA,EACF,CAAA;AACF","file":"index.mjs","sourcesContent":["export class AlxError extends Error {\n constructor(message: string, public readonly code: string) {\n super(message);\n Object.setPrototypeOf(this, new.target.prototype);\n this.name = 'AlxError';\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n}\n\nexport class ConfigValidationError extends AlxError {\n constructor(message: string, public readonly field: string) {\n super(message, 'CONFIG_VALIDATION_ERROR');\n Object.setPrototypeOf(this, new.target.prototype);\n this.name = 'ConfigValidationError';\n }\n}\n","import { z, type ZodSchema } from 'zod';\nimport { ConfigValidationError } from './errors';\n\nexport const loggerSchema = z.object({\n info: z.function(),\n warn: z.function(),\n error: z.function(),\n});\n\nexport const baseDbSchema = z.object({\n connection: z.any().refine((val) => val != null, 'db.connection is required'),\n collectionPrefix: z.string().optional(),\n});\n\nexport const baseRedisSchema = z.object({\n connection: z.any().refine((val) => val != null, 'redis.connection is required'),\n keyPrefix: z.string().optional(),\n});\n\nexport function createConfigValidator(\n configSchema: ZodSchema,\n ErrorClass: typeof ConfigValidationError = ConfigValidationError,\n): (raw: unknown) => void {\n return function validateConfig(raw: unknown): void {\n const result = configSchema.safeParse(raw);\n if (!result.success) {\n const issues = result.error.issues\n .map((i) => ` ${i.path.join('.')}: ${i.message}`)\n .join('\\n');\n throw new ErrorClass(\n `Invalid config:\\n${issues}`,\n result.error.issues[0]?.path.join('.') ?? '',\n );\n }\n };\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@astralibx/core",
3
+ "version": "1.1.0",
4
+ "description": "Shared foundation for all @astralibx packages — base errors, types, and validation helpers",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.mts",
12
+ "default": "./dist/index.mjs"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsup",
25
+ "dev": "tsup --watch",
26
+ "test": "vitest run",
27
+ "test:watch": "vitest",
28
+ "test:coverage": "vitest run --coverage",
29
+ "lint": "eslint src/",
30
+ "prepublishOnly": "npm run build"
31
+ },
32
+ "keywords": [
33
+ "astralibx",
34
+ "core",
35
+ "errors",
36
+ "validation",
37
+ "zod"
38
+ ],
39
+ "license": "MIT",
40
+ "dependencies": {
41
+ "zod": "^3.23.0"
42
+ }
43
+ }