@archeon-ts/core 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Archeon contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,51 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # @archeon-ts/core
2
+
3
+ Framework-neutral operation runtime for TypeScript applications.
4
+
5
+ > **Status:** pre-release 0.x software. The public API may change before 1.0.0.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @archeon-ts/core
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```ts
16
+ import { createApplication, defineModule, defineOperation } from "@archeon-ts/core";
17
+
18
+ type Services = {
19
+ greetings: { say(name: string): string };
20
+ };
21
+
22
+ const greet = defineOperation<Services>()({
23
+ name: "greetings.say",
24
+ input: {
25
+ parse(value: unknown) {
26
+ if (typeof value !== "string") throw new TypeError("Expected a string");
27
+ return value;
28
+ },
29
+ },
30
+ execute: ({ input, context }) => context.services.greetings.say(input),
31
+ });
32
+
33
+ const app = createApplication({
34
+ modules: [defineModule({ name: "greetings", operations: { greet } })],
35
+ services: { greetings: { say: (name) => `Hello, ${name}!` } },
36
+ });
37
+
38
+ const result = await app.execute("greetings.say", "Archeon");
39
+ console.log(result);
40
+ ```
41
+
42
+ ## Core principles
43
+
44
+ - Operations have stable names and explicit execution contracts.
45
+ - Input parsing is optional and uses a framework-neutral `parse(unknown)` contract.
46
+ - Application services are provided by the application.
47
+ - Per-invocation request context is passed separately from services.
48
+ - Parser and handler errors propagate from core; map them at the transport boundary.
49
+ - Core does not provide authentication, authorization, database access, rate limiting, or a validation library.
50
+
51
+ See the [repository](https://github.com/Ndmaz/Archeon), [getting started guide](https://github.com/Ndmaz/Archeon/blob/main/docs/guides/getting-started.md), and [architecture decisions](https://github.com/Ndmaz/Archeon/tree/main/docs/adr).
@@ -0,0 +1,35 @@
1
+ import type { ModuleDefinition } from "./module.js";
2
+ import type { OperationDefinition } from "./operation.js";
3
+ type AnyOperation = OperationDefinition<any, any, any, any, any>;
4
+ type AnyModule = ModuleDefinition<any, Record<string, AnyOperation>>;
5
+ type ServicesOfModule<TModule> = OperationsOf<TModule> extends infer TOperation ? TOperation extends OperationDefinition<infer TServices, any, any, any, any> ? TServices : never : never;
6
+ type UnionToIntersection<T> = (T extends unknown ? (value: T) => void : never) extends (value: infer TIntersection) => void ? TIntersection : never;
7
+ type ServicesRequiredByModules<TModules extends readonly AnyModule[]> = UnionToIntersection<ServicesOfModule<TModules[number]>>;
8
+ type OperationsOf<TModule> = TModule extends {
9
+ readonly operations: infer TOperations;
10
+ } ? TOperations[keyof TOperations] : never;
11
+ type OperationsOfModules<TModules extends readonly AnyModule[]> = OperationsOf<TModules[number]>;
12
+ type RequestContextOf<TOperation> = TOperation extends OperationDefinition<any, any, any, any, infer TRequestContext> ? TRequestContext : never;
13
+ type RequestContextRequiredByModules<TModules extends readonly AnyModule[]> = UnionToIntersection<RequestContextOf<OperationsOfModules<TModules>>>;
14
+ type OperationName<TModules extends readonly AnyModule[]> = OperationsOfModules<TModules> extends infer TOperation ? TOperation extends {
15
+ readonly name: infer TName extends string;
16
+ } ? TName : never : never;
17
+ type OutputForName<TModules extends readonly AnyModule[], TName extends string> = OperationsOfModules<TModules> extends infer TOperation ? TOperation extends OperationDefinition<any, any, infer TOutput> ? TOperation["name"] extends TName ? TOutput : never : never : never;
18
+ export interface ExecutionPlan {
19
+ readonly operationName: string;
20
+ readonly invoke: (input: unknown, services: unknown, request: unknown) => Promise<unknown>;
21
+ }
22
+ export interface ApplicationOptions<TModules extends readonly AnyModule[]> {
23
+ readonly modules: TModules;
24
+ readonly services: ServicesRequiredByModules<TModules>;
25
+ }
26
+ export interface ArcheonApplication<TServices, TModules extends readonly AnyModule[], TRequestContext = unknown> {
27
+ readonly modules: readonly string[];
28
+ readonly operationNames: readonly OperationName<TModules>[];
29
+ execute<TName extends OperationName<TModules>>(operationName: TName, input: unknown, execution?: {
30
+ readonly request?: TRequestContext;
31
+ }): Promise<Awaited<OutputForName<TModules, TName>>>;
32
+ }
33
+ export declare function createApplication<const TModules extends readonly AnyModule[]>(options: ApplicationOptions<TModules>): ArcheonApplication<ServicesRequiredByModules<TModules>, TModules, RequestContextRequiredByModules<TModules>>;
34
+ export {};
35
+ //# sourceMappingURL=application.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAS1D,KAAK,YAAY,GAAG,mBAAmB,CAAC,GAA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5D,OAAO,CAAC,KAAK,SAAS,aAAa,CAAC,QAAQ,CAAC,EAC3C,aAAa,EAAE,KAAK,EACpB,KAAK,EAAE,OAAO,EACd,SAAS,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,CAAA;KAAE,GACjD,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;CACrD;AAID,wBAAgB,iBAAiB,CAC/B,KAAK,CAAC,QAAQ,SAAS,SAAS,SAAS,EAAE,EAE3C,OAAO,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GACpC,kBAAkB,CACnB,yBAAyB,CAAC,QAAQ,CAAC,EACnC,QAAQ,EACR,+BAA+B,CAAC,QAAQ,CAAC,CAC1C,CA+EA"}
@@ -0,0 +1,72 @@
1
+ import { DuplicateModuleError, DuplicateOperationError, InvalidOperationNameError, InvalidModuleDefinitionError, UnknownOperationError, } from "./errors.js";
2
+ const OPERATION_NAME = /^[a-z0-9]+(?:[.-][a-z0-9]+)*(?:-[a-z0-9]+)*$/;
3
+ export function createApplication(options) {
4
+ const moduleNames = new Set();
5
+ const plans = new Map();
6
+ // Capture application-scoped services once; later mutation of the options
7
+ // object must not change the dependencies used by an existing application.
8
+ const services = options.services;
9
+ if (!Array.isArray(options.modules)) {
10
+ throw new InvalidModuleDefinitionError("Application modules must be an array.");
11
+ }
12
+ for (const module of options.modules) {
13
+ if (typeof module !== "object" ||
14
+ module === null ||
15
+ typeof module.name !== "string" ||
16
+ !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(module.name) ||
17
+ typeof module.operations !== "object" ||
18
+ module.operations === null ||
19
+ Array.isArray(module.operations)) {
20
+ throw new InvalidModuleDefinitionError("Each module must have a valid slug name and an operations object.");
21
+ }
22
+ if (moduleNames.has(module.name))
23
+ throw new DuplicateModuleError(module.name);
24
+ moduleNames.add(module.name);
25
+ for (const operation of Object.values(module.operations)) {
26
+ if (typeof operation !== "object" ||
27
+ operation === null ||
28
+ typeof operation.name !== "string" ||
29
+ typeof operation.execute !== "function" ||
30
+ (operation.input !== undefined &&
31
+ (typeof operation.input !== "object" ||
32
+ operation.input === null ||
33
+ typeof operation.input.parse !== "function"))) {
34
+ throw new InvalidModuleDefinitionError(`Module "${module.name}" contains a malformed operation definition.`);
35
+ }
36
+ if (!OPERATION_NAME.test(operation.name)) {
37
+ throw new InvalidOperationNameError(operation.name);
38
+ }
39
+ if (plans.has(operation.name))
40
+ throw new DuplicateOperationError(operation.name);
41
+ const plan = Object.freeze({
42
+ operationName: operation.name,
43
+ invoke: async (input, services, request) => {
44
+ const parsedInput = operation.input
45
+ ? await operation.input.parse(input)
46
+ : input;
47
+ return await operation.execute({
48
+ input: parsedInput,
49
+ context: Object.freeze({
50
+ services: services,
51
+ request,
52
+ }),
53
+ });
54
+ },
55
+ });
56
+ plans.set(operation.name, plan);
57
+ }
58
+ }
59
+ const operationNames = Object.freeze([...plans.keys()]);
60
+ const registeredModules = Object.freeze([...moduleNames]);
61
+ return Object.freeze({
62
+ modules: registeredModules,
63
+ operationNames,
64
+ async execute(operationName, input, execution) {
65
+ const plan = plans.get(operationName);
66
+ if (!plan)
67
+ throw new UnknownOperationError(operationName);
68
+ return (await plan.invoke(input, services, execution?.request));
69
+ },
70
+ });
71
+ }
72
+ //# sourceMappingURL=application.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,EACzB,4BAA4B,EAC5B,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAyErB,MAAM,cAAc,GAAG,8CAA8C,CAAC;AAEtE,MAAM,UAAU,iBAAiB,CAG/B,OAAqC;IAMrC,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;IACtC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC/C,0EAA0E;IAC1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,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,OAAO,EAAE,iBAAiB;QAC1B,cAAc;QACd,KAAK,CAAC,OAAO,CACX,aAAoB,EACpB,KAAc,EACd,SAA4E;YAE5E,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YACtC,IAAI,CAAC,IAAI;gBAAE,MAAM,IAAI,qBAAqB,CAAC,aAAa,CAAC,CAAC;YAC1D,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAA4C,CAAC;QAC7G,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ModuleDefinition } from \"./module.js\";\r\nimport type { OperationDefinition } from \"./operation.js\";\r\nimport {\r\n DuplicateModuleError,\r\n DuplicateOperationError,\r\n InvalidOperationNameError,\r\n InvalidModuleDefinitionError,\r\n UnknownOperationError,\r\n} from \"./errors.js\";\r\n\r\ntype AnyOperation = OperationDefinition<any, any, any, any, any>;\r\ntype AnyModule = ModuleDefinition<any, Record<string, AnyOperation>>;\r\n// Derive requirements from the operations themselves so copies/spreads retain them.\r\ntype ServicesOfModule<TModule> =\r\n OperationsOf<TModule> extends infer TOperation\r\n ? TOperation extends OperationDefinition<infer TServices, any, any, any, any>\r\n ? TServices\r\n : never\r\n : never;\r\ntype UnionToIntersection<T> =\r\n (T extends unknown ? (value: T) => void : never) extends\r\n (value: infer TIntersection) => void ? TIntersection : never;\r\ntype ServicesRequiredByModules<TModules extends readonly AnyModule[]> =\r\n UnionToIntersection<ServicesOfModule<TModules[number]>>;\r\n\r\ntype OperationsOf<TModule> =\r\n TModule extends { readonly operations: infer TOperations }\r\n ? TOperations[keyof TOperations]\r\n : never;\r\n\r\ntype OperationsOfModules<TModules extends readonly AnyModule[]> =\r\n OperationsOf<TModules[number]>;\r\ntype RequestContextOf<TOperation> =\r\n TOperation extends OperationDefinition<any, any, any, any, infer TRequestContext>\r\n ? TRequestContext\r\n : never;\r\ntype RequestContextRequiredByModules<TModules extends readonly AnyModule[]> =\r\n UnionToIntersection<RequestContextOf<OperationsOfModules<TModules>>>;\r\n\r\ntype OperationName<TModules extends readonly AnyModule[]> =\r\n OperationsOfModules<TModules> extends infer TOperation\r\n ? TOperation extends { readonly name: infer TName extends string }\r\n ? TName\r\n : never\r\n : never;\r\n\r\ntype OutputForName<\r\n TModules extends readonly AnyModule[],\r\n TName extends string,\r\n> = OperationsOfModules<TModules> extends infer TOperation\r\n ? TOperation extends OperationDefinition<any, any, infer TOutput>\r\n ? TOperation[\"name\"] extends TName\r\n ? TOutput\r\n : never\r\n : never\r\n : never;\r\n\r\nexport interface ExecutionPlan {\r\n readonly operationName: string;\r\n readonly invoke: (input: unknown, services: unknown, request: unknown) => Promise<unknown>;\r\n}\r\n\r\nexport interface ApplicationOptions<TModules extends readonly AnyModule[]> {\r\n readonly modules: TModules;\r\n readonly services: ServicesRequiredByModules<TModules>;\r\n}\r\n\r\nexport interface ArcheonApplication<\r\n TServices,\r\n TModules extends readonly AnyModule[],\r\n TRequestContext = unknown,\r\n> {\r\n readonly modules: readonly string[];\r\n readonly operationNames: readonly OperationName<TModules>[];\r\n execute<TName extends OperationName<TModules>>(\r\n operationName: TName,\r\n input: unknown,\r\n execution?: { readonly request?: TRequestContext },\r\n ): Promise<Awaited<OutputForName<TModules, TName>>>;\r\n}\r\n\r\nconst OPERATION_NAME = /^[a-z0-9]+(?:[.-][a-z0-9]+)*(?:-[a-z0-9]+)*$/;\r\n\r\nexport function createApplication<\r\n const TModules extends readonly AnyModule[],\r\n>(\r\n options: ApplicationOptions<TModules>,\r\n): ArcheonApplication<\r\n ServicesRequiredByModules<TModules>,\r\n TModules,\r\n RequestContextRequiredByModules<TModules>\r\n> {\r\n const moduleNames = new Set<string>();\r\n const plans = new Map<string, ExecutionPlan>();\r\n // Capture application-scoped services once; later mutation of the options\r\n // object must not change the dependencies used by an existing application.\r\n const services = options.services;\r\n\r\n if (!Array.isArray(options.modules)) {\r\n throw new InvalidModuleDefinitionError(\"Application modules must be an array.\");\r\n }\r\n\r\n for (const module of options.modules) {\r\n if (\r\n typeof module !== \"object\" ||\r\n module === null ||\r\n typeof module.name !== \"string\" ||\r\n !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(module.name) ||\r\n typeof module.operations !== \"object\" ||\r\n module.operations === null ||\r\n Array.isArray(module.operations)\r\n ) {\r\n throw new InvalidModuleDefinitionError(\"Each module must have a valid slug name and an operations object.\");\r\n }\r\n if (moduleNames.has(module.name)) throw new DuplicateModuleError(module.name);\r\n moduleNames.add(module.name);\r\n\r\n for (const operation of Object.values(module.operations) as OperationDefinition<ServicesRequiredByModules<TModules>, any, any>[]) {\r\n if (\r\n typeof operation !== \"object\" ||\r\n operation === null ||\r\n typeof operation.name !== \"string\" ||\r\n typeof operation.execute !== \"function\" ||\r\n (operation.input !== undefined &&\r\n (typeof operation.input !== \"object\" ||\r\n operation.input === null ||\r\n typeof operation.input.parse !== \"function\"))\r\n ) {\r\n throw new InvalidModuleDefinitionError(`Module \"${module.name}\" contains a malformed operation definition.`);\r\n }\r\n if (!OPERATION_NAME.test(operation.name)) {\r\n throw new InvalidOperationNameError(operation.name);\r\n }\r\n if (plans.has(operation.name)) throw new DuplicateOperationError(operation.name);\r\n\r\n const plan: ExecutionPlan = Object.freeze({\r\n operationName: operation.name,\r\n invoke: async (input: unknown, services: unknown, request: unknown): Promise<unknown> => {\r\n const parsedInput = operation.input\r\n ? await operation.input.parse(input)\r\n : input;\r\n return await operation.execute({\r\n input: parsedInput,\r\n context: Object.freeze({\r\n services: services as ServicesRequiredByModules<TModules>,\r\n request,\r\n }),\r\n });\r\n },\r\n });\r\n plans.set(operation.name, plan);\r\n }\r\n }\r\n\r\n const operationNames = Object.freeze([...plans.keys()]) as readonly OperationName<TModules>[];\r\n const registeredModules = Object.freeze([...moduleNames]);\r\n\r\n return Object.freeze({\r\n modules: registeredModules,\r\n operationNames,\r\n async execute<TName extends OperationName<TModules>>(\r\n operationName: TName,\r\n input: unknown,\r\n execution?: { readonly request?: RequestContextRequiredByModules<TModules> },\r\n ): Promise<Awaited<OutputForName<TModules, TName>>> {\r\n const plan = plans.get(operationName);\r\n if (!plan) throw new UnknownOperationError(operationName);\r\n return (await plan.invoke(input, services, execution?.request)) as Awaited<OutputForName<TModules, TName>>;\r\n },\r\n });\r\n}\r\n"]}
@@ -0,0 +1,20 @@
1
+ export declare class ArcheonError extends Error {
2
+ readonly code: string;
3
+ constructor(code: string, message: string, options?: ErrorOptions);
4
+ }
5
+ export declare class DuplicateModuleError extends ArcheonError {
6
+ constructor(name: string);
7
+ }
8
+ export declare class DuplicateOperationError extends ArcheonError {
9
+ constructor(name: string);
10
+ }
11
+ export declare class UnknownOperationError extends ArcheonError {
12
+ constructor(name: string);
13
+ }
14
+ export declare class InvalidOperationNameError extends ArcheonError {
15
+ constructor(name: string);
16
+ }
17
+ export declare class InvalidModuleDefinitionError extends ArcheonError {
18
+ constructor(message: string);
19
+ }
20
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAKlE;AAED,qBAAa,oBAAqB,SAAQ,YAAY;gBACxC,IAAI,EAAE,MAAM;CAGzB;AAED,qBAAa,uBAAwB,SAAQ,YAAY;gBAC3C,IAAI,EAAE,MAAM;CAGzB;AAED,qBAAa,qBAAsB,SAAQ,YAAY;gBACzC,IAAI,EAAE,MAAM;CAGzB;AAED,qBAAa,yBAA0B,SAAQ,YAAY;gBAC7C,IAAI,EAAE,MAAM;CAGzB;AAED,qBAAa,4BAA6B,SAAQ,YAAY;gBAChD,OAAO,EAAE,MAAM;CAG5B"}
package/dist/errors.js ADDED
@@ -0,0 +1,34 @@
1
+ export class ArcheonError extends Error {
2
+ code;
3
+ constructor(code, message, options) {
4
+ super(message, options);
5
+ this.name = new.target.name;
6
+ this.code = code;
7
+ }
8
+ }
9
+ export class DuplicateModuleError extends ArcheonError {
10
+ constructor(name) {
11
+ super("DUPLICATE_MODULE", `A module named "${name}" is already registered.`);
12
+ }
13
+ }
14
+ export class DuplicateOperationError extends ArcheonError {
15
+ constructor(name) {
16
+ super("DUPLICATE_OPERATION", `An operation named "${name}" is already registered.`);
17
+ }
18
+ }
19
+ export class UnknownOperationError extends ArcheonError {
20
+ constructor(name) {
21
+ super("UNKNOWN_OPERATION", `No operation named "${name}" is registered.`);
22
+ }
23
+ }
24
+ export class InvalidOperationNameError extends ArcheonError {
25
+ constructor(name) {
26
+ super("INVALID_OPERATION_NAME", `Invalid operation name: "${name}".`);
27
+ }
28
+ }
29
+ export class InvalidModuleDefinitionError extends ArcheonError {
30
+ constructor(message) {
31
+ super("INVALID_MODULE_DEFINITION", message);
32
+ }
33
+ }
34
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,CAAS;IAEtB,YAAY,IAAY,EAAE,OAAe,EAAE,OAAsB;QAC/D,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,MAAM,OAAO,oBAAqB,SAAQ,YAAY;IACpD,YAAY,IAAY;QACtB,KAAK,CAAC,kBAAkB,EAAE,mBAAmB,IAAI,0BAA0B,CAAC,CAAC;IAC/E,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,YAAY;IACvD,YAAY,IAAY;QACtB,KAAK,CAAC,qBAAqB,EAAE,uBAAuB,IAAI,0BAA0B,CAAC,CAAC;IACtF,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,YAAY;IACrD,YAAY,IAAY;QACtB,KAAK,CAAC,mBAAmB,EAAE,uBAAuB,IAAI,kBAAkB,CAAC,CAAC;IAC5E,CAAC;CACF;AAED,MAAM,OAAO,yBAA0B,SAAQ,YAAY;IACzD,YAAY,IAAY;QACtB,KAAK,CAAC,wBAAwB,EAAE,4BAA4B,IAAI,IAAI,CAAC,CAAC;IACxE,CAAC;CACF;AAED,MAAM,OAAO,4BAA6B,SAAQ,YAAY;IAC5D,YAAY,OAAe;QACzB,KAAK,CAAC,2BAA2B,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF","sourcesContent":["export class ArcheonError extends Error {\r\n readonly code: string;\r\n\r\n constructor(code: string, message: string, options?: ErrorOptions) {\r\n super(message, options);\r\n this.name = new.target.name;\r\n this.code = code;\r\n }\r\n}\r\n\r\nexport class DuplicateModuleError extends ArcheonError {\r\n constructor(name: string) {\r\n super(\"DUPLICATE_MODULE\", `A module named \"${name}\" is already registered.`);\r\n }\r\n}\r\n\r\nexport class DuplicateOperationError extends ArcheonError {\r\n constructor(name: string) {\r\n super(\"DUPLICATE_OPERATION\", `An operation named \"${name}\" is already registered.`);\r\n }\r\n}\r\n\r\nexport class UnknownOperationError extends ArcheonError {\r\n constructor(name: string) {\r\n super(\"UNKNOWN_OPERATION\", `No operation named \"${name}\" is registered.`);\r\n }\r\n}\r\n\r\nexport class InvalidOperationNameError extends ArcheonError {\r\n constructor(name: string) {\r\n super(\"INVALID_OPERATION_NAME\", `Invalid operation name: \"${name}\".`);\r\n }\r\n}\r\n\r\nexport class InvalidModuleDefinitionError extends ArcheonError {\r\n constructor(message: string) {\r\n super(\"INVALID_MODULE_DEFINITION\", message);\r\n }\r\n}\r\n"]}
@@ -0,0 +1,8 @@
1
+ export { ArcheonError, DuplicateModuleError, DuplicateOperationError, InvalidOperationNameError, InvalidModuleDefinitionError, UnknownOperationError, } from "./errors.js";
2
+ export { createApplication } from "./application.js";
3
+ export type { ArcheonApplication, ExecutionPlan } from "./application.js";
4
+ export { defineModule } from "./module.js";
5
+ export type { ModuleDefinition } from "./module.js";
6
+ export { defineOperation } from "./operation.js";
7
+ export type { ExecutionContext, InputParser, OperationArguments, OperationBuilder, OperationDefinition, } from "./operation.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,EACzB,4BAA4B,EAC5B,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,YAAY,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { ArcheonError, DuplicateModuleError, DuplicateOperationError, InvalidOperationNameError, InvalidModuleDefinitionError, UnknownOperationError, } from "./errors.js";
2
+ export { createApplication } from "./application.js";
3
+ export { defineModule } from "./module.js";
4
+ export { defineOperation } from "./operation.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,EACzB,4BAA4B,EAC5B,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export {\r\n ArcheonError,\r\n DuplicateModuleError,\r\n DuplicateOperationError,\r\n InvalidOperationNameError,\r\n InvalidModuleDefinitionError,\r\n UnknownOperationError,\r\n} from \"./errors.js\";\r\nexport { createApplication } from \"./application.js\";\r\nexport type { ArcheonApplication, ExecutionPlan } from \"./application.js\";\r\nexport { defineModule } from \"./module.js\";\r\nexport type { ModuleDefinition } from \"./module.js\";\r\nexport { defineOperation } from \"./operation.js\";\r\nexport type {\r\n ExecutionContext,\r\n InputParser,\r\n OperationArguments,\r\n OperationBuilder,\r\n OperationDefinition,\r\n} from \"./operation.js\";\r\n"]}
@@ -0,0 +1,13 @@
1
+ import type { OperationDefinition } from "./operation.js";
2
+ type AnyOperation = OperationDefinition<any, any, any, any, any>;
3
+ type ServicesOf<TOperation> = TOperation extends OperationDefinition<infer TServices, any, any> ? TServices : never;
4
+ export interface ModuleDefinition<TServices, TOperations extends Record<string, AnyOperation> = Record<string, AnyOperation>> {
5
+ readonly name: string;
6
+ readonly operations: TOperations;
7
+ }
8
+ export declare function defineModule<TOperations extends Record<string, AnyOperation>>(definition: {
9
+ readonly name: string;
10
+ readonly operations: TOperations;
11
+ }): ModuleDefinition<ServicesOf<TOperations[keyof TOperations]>, TOperations>;
12
+ export {};
13
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,KAAK,YAAY,GAAG,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAEjE,KAAK,UAAU,CAAC,UAAU,IACxB,UAAU,SAAS,mBAAmB,CAAC,MAAM,SAAS,EAAE,GAAG,EAAE,GAAG,CAAC,GAC7D,SAAS,GACT,KAAK,CAAC;AAEZ,MAAM,WAAW,gBAAgB,CAC/B,SAAS,EACT,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IAE/E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC;CAClC;AAED,wBAAgB,YAAY,CAC1B,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAChD,UAAU,EAAE;IACZ,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC;CAClC,GAAG,gBAAgB,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,CAc5E"}
package/dist/module.js ADDED
@@ -0,0 +1,11 @@
1
+ export function defineModule(definition) {
2
+ if (typeof definition.name !== "string" ||
3
+ !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(definition.name)) {
4
+ throw new TypeError("Module name must be a lowercase slug using letters, digits, and internal hyphens.");
5
+ }
6
+ return Object.freeze({
7
+ name: definition.name,
8
+ operations: Object.freeze({ ...definition.operations }),
9
+ });
10
+ }
11
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAiBA,MAAM,UAAU,YAAY,CAE1B,UAGD;IACC,IACE,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ;QACnC,CAAC,4BAA4B,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EACnD,CAAC;QACD,MAAM,IAAI,SAAS,CACjB,mFAAmF,CACpF,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,UAAU,CAAC,UAAU,EAAE,CAAC;KACxD,CAA8E,CAAC;AAClF,CAAC","sourcesContent":["import type { OperationDefinition } from \"./operation.js\";\r\n\r\ntype AnyOperation = OperationDefinition<any, any, any, any, any>;\r\n\r\ntype ServicesOf<TOperation> =\r\n TOperation extends OperationDefinition<infer TServices, any, any>\r\n ? TServices\r\n : never;\r\n\r\nexport interface ModuleDefinition<\r\n TServices,\r\n TOperations extends Record<string, AnyOperation> = Record<string, AnyOperation>,\r\n> {\r\n readonly name: string;\r\n readonly operations: TOperations;\r\n}\r\n\r\nexport function defineModule<\r\n TOperations extends Record<string, AnyOperation>,\r\n>(definition: {\r\n readonly name: string;\r\n readonly operations: TOperations;\r\n}): ModuleDefinition<ServicesOf<TOperations[keyof TOperations]>, TOperations> {\r\n if (\r\n typeof definition.name !== \"string\" ||\r\n !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(definition.name)\r\n ) {\r\n throw new TypeError(\r\n \"Module name must be a lowercase slug using letters, digits, and internal hyphens.\",\r\n );\r\n }\r\n\r\n return Object.freeze({\r\n name: definition.name,\r\n operations: Object.freeze({ ...definition.operations }),\r\n }) as ModuleDefinition<ServicesOf<TOperations[keyof TOperations]>, TOperations>;\r\n}\r\n"]}
@@ -0,0 +1,32 @@
1
+ export interface InputParser<TInput> {
2
+ parse(input: unknown): TInput | Promise<TInput>;
3
+ }
4
+ export interface ExecutionContext<TServices, TRequestContext = unknown> {
5
+ readonly services: TServices;
6
+ readonly request: TRequestContext | undefined;
7
+ }
8
+ export interface OperationArguments<TInput, TServices, TRequestContext = unknown> {
9
+ readonly input: TInput;
10
+ readonly context: ExecutionContext<TServices, TRequestContext>;
11
+ }
12
+ export interface OperationDefinition<TServices, TInput = unknown, TOutput = unknown, TName extends string = string, TRequestContext = unknown> {
13
+ readonly name: TName;
14
+ readonly input?: InputParser<TInput>;
15
+ readonly execute: (args: OperationArguments<TInput, TServices, TRequestContext>) => TOutput | Promise<TOutput>;
16
+ }
17
+ type OperationWithParser<TServices, TInput, TOutput, TName extends string, TRequestContext> = {
18
+ readonly name: TName;
19
+ readonly input: InputParser<TInput>;
20
+ readonly execute: (args: OperationArguments<TInput, TServices, TRequestContext>) => TOutput | Promise<TOutput>;
21
+ };
22
+ type OperationWithoutParser<TServices, TOutput, TName extends string, TRequestContext> = {
23
+ readonly name: TName;
24
+ readonly execute: (args: OperationArguments<unknown, TServices, TRequestContext>) => TOutput | Promise<TOutput>;
25
+ };
26
+ export interface OperationBuilder<TServices, TRequestContext = unknown> {
27
+ <TInput, TOutput, const TName extends string>(definition: OperationWithParser<TServices, TInput, TOutput, TName, TRequestContext>): OperationDefinition<TServices, TInput, TOutput, TName, TRequestContext>;
28
+ <TOutput, const TName extends string>(definition: OperationWithoutParser<TServices, TOutput, TName, TRequestContext>): OperationDefinition<TServices, unknown, TOutput, TName, TRequestContext>;
29
+ }
30
+ export declare function defineOperation<TServices, TRequestContext = unknown>(): OperationBuilder<TServices, TRequestContext>;
31
+ export {};
32
+ //# sourceMappingURL=operation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../src/operation.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW,CAAC,MAAM;IACjC,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,gBAAgB,CAAC,SAAS,EAAE,eAAe,GAAG,OAAO;IACpE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,SAAS,CAAC;CAC/C;AAED,MAAM,WA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;CACjC,CAAC;AAEF,MAAM,WAAW,gBAAgB,CAAC,SAAS,EAAE,eAAe,GAAG,OAAO;IACpE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,SAAS,MAAM,EAC1C,UAAU,EAAE,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,GAClF,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;IAC3E,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,SAAS,MAAM,EAClC,UAAU,EAAE,sBAAsB,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,GAC7E,mBAAmB,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;CAC7E;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,eAAe,GAAG,OAAO,KAAK,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAC,CAYpH"}
@@ -0,0 +1,12 @@
1
+ import { InvalidOperationNameError } from "./errors.js";
2
+ export function defineOperation() {
3
+ return ((definition) => {
4
+ const name = definition.name;
5
+ if (typeof name !== "string" ||
6
+ !/^[a-z0-9]+(?:[.-][a-z0-9]+)*(?:-[a-z0-9]+)*$/.test(name)) {
7
+ throw new InvalidOperationNameError(String(name));
8
+ }
9
+ return Object.freeze({ ...definition });
10
+ });
11
+ }
12
+ //# sourceMappingURL=operation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../src/operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AA4DxD,MAAM,UAAU,eAAe;IAC7B,OAAO,CAAC,CAAC,UAAqF,EAAE,EAAE;QAChG,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;QAC7B,IACE,OAAO,IAAI,KAAK,QAAQ;YACxB,CAAC,8CAA8C,CAAC,IAAI,CAAC,IAAI,CAAC,EAC1D,CAAC;YACD,MAAM,IAAI,yBAAyB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACpD,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC;IAC1C,CAAC,CAAiD,CAAC;AACrD,CAAC","sourcesContent":["import { InvalidOperationNameError } from \"./errors.js\";\r\n\r\nexport interface InputParser<TInput> {\r\n parse(input: unknown): TInput | Promise<TInput>;\r\n}\r\n\r\nexport interface ExecutionContext<TServices, TRequestContext = unknown> {\r\n readonly services: TServices;\r\n readonly request: TRequestContext | undefined;\r\n}\r\n\r\nexport interface OperationArguments<TInput, TServices, TRequestContext = unknown> {\r\n readonly input: TInput;\r\n readonly context: ExecutionContext<TServices, TRequestContext>;\r\n}\r\n\r\nexport interface OperationDefinition<\r\n TServices,\r\n TInput = unknown,\r\n TOutput = unknown,\r\n TName extends string = string,\r\n TRequestContext = unknown,\r\n> {\r\n readonly name: TName;\r\n readonly input?: InputParser<TInput>;\r\n readonly execute: (\r\n args: OperationArguments<TInput, TServices, TRequestContext>,\r\n ) => TOutput | Promise<TOutput>;\r\n}\r\n\r\ntype OperationWithParser<\r\n TServices,\r\n TInput,\r\n TOutput,\r\n TName extends string,\r\n TRequestContext,\r\n> = {\r\n readonly name: TName;\r\n readonly input: InputParser<TInput>;\r\n readonly execute: (\r\n args: OperationArguments<TInput, TServices, TRequestContext>,\r\n ) => TOutput | Promise<TOutput>;\r\n};\r\n\r\ntype OperationWithoutParser<TServices, TOutput, TName extends string, TRequestContext> = {\r\n readonly name: TName;\r\n readonly execute: (\r\n args: OperationArguments<unknown, TServices, TRequestContext>,\r\n ) => TOutput | Promise<TOutput>;\r\n};\r\n\r\nexport interface OperationBuilder<TServices, TRequestContext = unknown> {\r\n <TInput, TOutput, const TName extends string>(\r\n definition: OperationWithParser<TServices, TInput, TOutput, TName, TRequestContext>,\r\n ): OperationDefinition<TServices, TInput, TOutput, TName, TRequestContext>;\r\n <TOutput, const TName extends string>(\r\n definition: OperationWithoutParser<TServices, TOutput, TName, TRequestContext>,\r\n ): OperationDefinition<TServices, unknown, TOutput, TName, TRequestContext>;\r\n}\r\n\r\nexport function defineOperation<TServices, TRequestContext = unknown>(): OperationBuilder<TServices, TRequestContext> {\r\n return ((definition: OperationDefinition<TServices, unknown, unknown, string, TRequestContext>) => {\r\n const name = definition.name;\r\n if (\r\n typeof name !== \"string\" ||\r\n !/^[a-z0-9]+(?:[.-][a-z0-9]+)*(?:-[a-z0-9]+)*$/.test(name)\r\n ) {\r\n throw new InvalidOperationNameError(String(name));\r\n }\r\n\r\n return Object.freeze({ ...definition });\r\n }) as OperationBuilder<TServices, TRequestContext>;\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "@archeon-ts/core",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Framework-neutral operation runtime for TypeScript applications",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "devDependencies": {
18
+ "typescript": "^5.9.3",
19
+ "vitest": "^3.2.4"
20
+ },
21
+ "license": "MIT",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/Ndmaz/Archeon.git",
25
+ "directory": "packages/core"
26
+ },
27
+ "homepage": "https://github.com/Ndmaz/Archeon#readme",
28
+ "bugs": {
29
+ "url": "https://github.com/Ndmaz/Archeon/issues"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "scripts": {
35
+ "build": "tsc -p tsconfig.json",
36
+ "typecheck": "tsc --noEmit -p tsconfig.test.json",
37
+ "test": "vitest run"
38
+ }
6
39
  }