@pi-ohm/core 0.6.4-dev.22269206811.1.0e8e307

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,9 @@
1
+ # @pi-ohm/core
2
+
3
+ Internal shared runtime primitives for pi-ohm packages.
4
+
5
+ Current module:
6
+
7
+ - `@pi-ohm/core/errors`
8
+ - `@pi-ohm/core/grammar`
9
+ - `@pi-ohm/core/paths`
@@ -0,0 +1,75 @@
1
+ import * as better_result0 from "better-result";
2
+ import { Result } from "better-result";
3
+
4
+ //#region src/errors.d.ts
5
+ type CoreErrorMeta = Record<string, unknown>;
6
+ declare const CoreValidationError_base: better_result0.TaggedErrorClass<"CoreValidationError", {
7
+ code: string;
8
+ message: string;
9
+ path?: string;
10
+ cause?: unknown;
11
+ meta?: CoreErrorMeta;
12
+ }>;
13
+ declare class CoreValidationError extends CoreValidationError_base {
14
+ constructor(args: {
15
+ code: string;
16
+ path?: string;
17
+ message?: string;
18
+ cause?: unknown;
19
+ meta?: CoreErrorMeta;
20
+ });
21
+ }
22
+ declare const CorePolicyError_base: better_result0.TaggedErrorClass<"CorePolicyError", {
23
+ code: string;
24
+ message: string;
25
+ action?: string;
26
+ cause?: unknown;
27
+ meta?: CoreErrorMeta;
28
+ }>;
29
+ declare class CorePolicyError extends CorePolicyError_base {
30
+ constructor(args: {
31
+ code: string;
32
+ action?: string;
33
+ message?: string;
34
+ cause?: unknown;
35
+ meta?: CoreErrorMeta;
36
+ });
37
+ }
38
+ declare const CoreRuntimeError_base: better_result0.TaggedErrorClass<"CoreRuntimeError", {
39
+ code: string;
40
+ message: string;
41
+ stage?: string;
42
+ cause?: unknown;
43
+ meta?: CoreErrorMeta;
44
+ }>;
45
+ declare class CoreRuntimeError extends CoreRuntimeError_base {
46
+ constructor(args: {
47
+ code: string;
48
+ stage?: string;
49
+ message?: string;
50
+ cause?: unknown;
51
+ meta?: CoreErrorMeta;
52
+ });
53
+ }
54
+ declare const CorePersistenceError_base: better_result0.TaggedErrorClass<"CorePersistenceError", {
55
+ code: string;
56
+ message: string;
57
+ resource?: string;
58
+ cause?: unknown;
59
+ meta?: CoreErrorMeta;
60
+ }>;
61
+ declare class CorePersistenceError extends CorePersistenceError_base {
62
+ constructor(args: {
63
+ code: string;
64
+ resource?: string;
65
+ message?: string;
66
+ cause?: unknown;
67
+ meta?: CoreErrorMeta;
68
+ });
69
+ }
70
+ type CoreError = CoreValidationError | CorePolicyError | CoreRuntimeError | CorePersistenceError;
71
+ type CoreResult<T, E extends CoreError = CoreError> = Result<T, E>;
72
+ declare function isCoreError(value: unknown): value is CoreError;
73
+ //#endregion
74
+ export { CoreError, CoreErrorMeta, CorePersistenceError, CorePolicyError, CoreResult, CoreRuntimeError, CoreValidationError, isCoreError };
75
+ //# sourceMappingURL=errors.d.ts.map
package/dist/errors.js ADDED
@@ -0,0 +1,63 @@
1
+ import { TaggedError } from "better-result";
2
+
3
+ //#region src/errors.ts
4
+ function messageFromCause(cause) {
5
+ if (cause instanceof Error && cause.message.trim().length > 0) return cause.message;
6
+ if (typeof cause === "string" && cause.trim().length > 0) return cause;
7
+ return String(cause);
8
+ }
9
+ var CoreValidationError = class extends TaggedError("CoreValidationError")() {
10
+ constructor(args) {
11
+ const derivedMessage = args.message ?? (args.cause ? `Validation failed (${args.code}): ${messageFromCause(args.cause)}` : `Validation failed (${args.code})`);
12
+ super({
13
+ code: args.code,
14
+ path: args.path,
15
+ cause: args.cause,
16
+ meta: args.meta,
17
+ message: derivedMessage
18
+ });
19
+ }
20
+ };
21
+ var CorePolicyError = class extends TaggedError("CorePolicyError")() {
22
+ constructor(args) {
23
+ const derivedMessage = args.message ?? (args.cause ? `Policy denied (${args.code}): ${messageFromCause(args.cause)}` : `Policy denied (${args.code})`);
24
+ super({
25
+ code: args.code,
26
+ action: args.action,
27
+ cause: args.cause,
28
+ meta: args.meta,
29
+ message: derivedMessage
30
+ });
31
+ }
32
+ };
33
+ var CoreRuntimeError = class extends TaggedError("CoreRuntimeError")() {
34
+ constructor(args) {
35
+ const derivedMessage = args.message ?? (args.cause ? `Runtime failure (${args.code}): ${messageFromCause(args.cause)}` : `Runtime failure (${args.code})`);
36
+ super({
37
+ code: args.code,
38
+ stage: args.stage,
39
+ cause: args.cause,
40
+ meta: args.meta,
41
+ message: derivedMessage
42
+ });
43
+ }
44
+ };
45
+ var CorePersistenceError = class extends TaggedError("CorePersistenceError")() {
46
+ constructor(args) {
47
+ const derivedMessage = args.message ?? (args.cause ? `Persistence failure (${args.code}): ${messageFromCause(args.cause)}` : `Persistence failure (${args.code})`);
48
+ super({
49
+ code: args.code,
50
+ resource: args.resource,
51
+ cause: args.cause,
52
+ meta: args.meta,
53
+ message: derivedMessage
54
+ });
55
+ }
56
+ };
57
+ function isCoreError(value) {
58
+ return CoreValidationError.is(value) || CorePolicyError.is(value) || CoreRuntimeError.is(value) || CorePersistenceError.is(value);
59
+ }
60
+
61
+ //#endregion
62
+ export { CorePersistenceError, CorePolicyError, CoreRuntimeError, CoreValidationError, isCoreError };
63
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { TaggedError, type Result } from \"better-result\";\n\nexport type CoreErrorMeta = Record<string, unknown>;\n\nfunction messageFromCause(cause: unknown): string {\n if (cause instanceof Error && cause.message.trim().length > 0) return cause.message;\n if (typeof cause === \"string\" && cause.trim().length > 0) return cause;\n return String(cause);\n}\n\nexport class CoreValidationError extends TaggedError(\"CoreValidationError\")<{\n code: string;\n message: string;\n path?: string;\n cause?: unknown;\n meta?: CoreErrorMeta;\n}>() {\n constructor(args: {\n code: string;\n path?: string;\n message?: string;\n cause?: unknown;\n meta?: CoreErrorMeta;\n }) {\n const derivedMessage =\n args.message ??\n (args.cause\n ? `Validation failed (${args.code}): ${messageFromCause(args.cause)}`\n : `Validation failed (${args.code})`);\n\n super({\n code: args.code,\n path: args.path,\n cause: args.cause,\n meta: args.meta,\n message: derivedMessage,\n });\n }\n}\n\nexport class CorePolicyError extends TaggedError(\"CorePolicyError\")<{\n code: string;\n message: string;\n action?: string;\n cause?: unknown;\n meta?: CoreErrorMeta;\n}>() {\n constructor(args: {\n code: string;\n action?: string;\n message?: string;\n cause?: unknown;\n meta?: CoreErrorMeta;\n }) {\n const derivedMessage =\n args.message ??\n (args.cause\n ? `Policy denied (${args.code}): ${messageFromCause(args.cause)}`\n : `Policy denied (${args.code})`);\n\n super({\n code: args.code,\n action: args.action,\n cause: args.cause,\n meta: args.meta,\n message: derivedMessage,\n });\n }\n}\n\nexport class CoreRuntimeError extends TaggedError(\"CoreRuntimeError\")<{\n code: string;\n message: string;\n stage?: string;\n cause?: unknown;\n meta?: CoreErrorMeta;\n}>() {\n constructor(args: {\n code: string;\n stage?: string;\n message?: string;\n cause?: unknown;\n meta?: CoreErrorMeta;\n }) {\n const derivedMessage =\n args.message ??\n (args.cause\n ? `Runtime failure (${args.code}): ${messageFromCause(args.cause)}`\n : `Runtime failure (${args.code})`);\n\n super({\n code: args.code,\n stage: args.stage,\n cause: args.cause,\n meta: args.meta,\n message: derivedMessage,\n });\n }\n}\n\nexport class CorePersistenceError extends TaggedError(\"CorePersistenceError\")<{\n code: string;\n message: string;\n resource?: string;\n cause?: unknown;\n meta?: CoreErrorMeta;\n}>() {\n constructor(args: {\n code: string;\n resource?: string;\n message?: string;\n cause?: unknown;\n meta?: CoreErrorMeta;\n }) {\n const derivedMessage =\n args.message ??\n (args.cause\n ? `Persistence failure (${args.code}): ${messageFromCause(args.cause)}`\n : `Persistence failure (${args.code})`);\n\n super({\n code: args.code,\n resource: args.resource,\n cause: args.cause,\n meta: args.meta,\n message: derivedMessage,\n });\n }\n}\n\nexport type CoreError =\n | CoreValidationError\n | CorePolicyError\n | CoreRuntimeError\n | CorePersistenceError;\n\nexport type CoreResult<T, E extends CoreError = CoreError> = Result<T, E>;\n\nexport function isCoreError(value: unknown): value is CoreError {\n return (\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ACH,YAAY,MAMT;EACD,MAAM,iBACJ,KAAK,YACJ,KAAK,QACF,wBAAwB,KAAK,KAAK,KAAK,iBAAiB,KAAK,MAAM,KACnE,wBAAwB,KAAK,KAAK;AAExC,QAAM;GACJ,MAAM,KAAK;GACX,UAAU,KAAK;GACf,OAAO,KAAK;GACZ,MAAM,KAAK;GACX,SAAS;GACV,CAAC;;;AAYN,SAAgB,YAAY,OAAoC;AAC9D,QACE,oBAAoB,GAAG,MAAM,IAC7B,gBAAgB,GAAG,MAAM,IACzB,iBAAiB,GAAG,MAAM,IAC1B,qBAAqB,GAAG,MAAM"}
@@ -0,0 +1,10 @@
1
+ //#region src/grammar.d.ts
2
+ declare function pluralSuffix(count: number): "" | "s";
3
+ declare function withCountNoun(input: {
4
+ readonly count: number;
5
+ readonly singular: string;
6
+ readonly plural?: string;
7
+ }): string;
8
+ //#endregion
9
+ export { pluralSuffix, withCountNoun };
10
+ //# sourceMappingURL=grammar.d.ts.map
@@ -0,0 +1,12 @@
1
+ //#region src/grammar.ts
2
+ function pluralSuffix(count) {
3
+ return count === 1 ? "" : "s";
4
+ }
5
+ function withCountNoun(input) {
6
+ const noun = input.plural ?? `${input.singular}${pluralSuffix(input.count)}`;
7
+ return `${input.count} ${noun}`;
8
+ }
9
+
10
+ //#endregion
11
+ export { pluralSuffix, withCountNoun };
12
+ //# sourceMappingURL=grammar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grammar.js","names":[],"sources":["../src/grammar.ts"],"sourcesContent":["export function pluralSuffix(count: number): \"\" | \"s\" {\n return count === 1 ? \"\" : \"s\";\n}\n\nexport function withCountNoun(input: {\n readonly count: number;\n readonly singular: string;\n readonly plural?: string;\n}): string {\n const noun = input.plural ?? `${input.singular}${pluralSuffix(input.count)}`;\n return `${input.count} ${noun}`;\n}\n"],"mappings":";AAAA,SAAgB,aAAa,OAAyB;AACpD,QAAO,UAAU,IAAI,KAAK;;AAG5B,SAAgB,cAAc,OAInB;CACT,MAAM,OAAO,MAAM,UAAU,GAAG,MAAM,WAAW,aAAa,MAAM,MAAM;AAC1E,QAAO,GAAG,MAAM,MAAM,GAAG"}
@@ -0,0 +1,9 @@
1
+ //#region src/paths.d.ts
2
+ interface ResolveOhmDataHomeInput {
3
+ readonly env?: NodeJS.ProcessEnv;
4
+ }
5
+ declare function resolveOhmDataHome(input?: ResolveOhmDataHomeInput): string;
6
+ declare function resolveOhmAgentDataHome(input?: ResolveOhmDataHomeInput): string;
7
+ //#endregion
8
+ export { ResolveOhmDataHomeInput, resolveOhmAgentDataHome, resolveOhmDataHome };
9
+ //# sourceMappingURL=paths.d.ts.map
package/dist/paths.js ADDED
@@ -0,0 +1,23 @@
1
+ import { homedir } from "node:os";
2
+ import { join } from "node:path";
3
+
4
+ //#region src/paths.ts
5
+ function readNonEmptyEnv(env, name) {
6
+ const raw = env[name];
7
+ if (!raw) return void 0;
8
+ const trimmed = raw.trim();
9
+ if (trimmed.length === 0) return void 0;
10
+ return trimmed;
11
+ }
12
+ function resolveOhmDataHome(input = {}) {
13
+ const xdgDataHome = readNonEmptyEnv(input.env ?? process.env, "XDG_DATA_HOME");
14
+ if (xdgDataHome) return join(xdgDataHome, "pi-ohm");
15
+ return join(homedir(), ".local", "share", "pi-ohm");
16
+ }
17
+ function resolveOhmAgentDataHome(input = {}) {
18
+ return join(resolveOhmDataHome(input), "agent");
19
+ }
20
+
21
+ //#endregion
22
+ export { resolveOhmAgentDataHome, resolveOhmDataHome };
23
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","names":[],"sources":["../src/paths.ts"],"sourcesContent":["import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\nexport interface ResolveOhmDataHomeInput {\n readonly env?: NodeJS.ProcessEnv;\n}\n\nfunction readNonEmptyEnv(env: NodeJS.ProcessEnv, name: string): string | undefined {\n const raw = env[name];\n if (!raw) return undefined;\n const trimmed = raw.trim();\n if (trimmed.length === 0) return undefined;\n return trimmed;\n}\n\nexport function resolveOhmDataHome(input: ResolveOhmDataHomeInput = {}): string {\n const env = input.env ?? process.env;\n const xdgDataHome = readNonEmptyEnv(env, \"XDG_DATA_HOME\");\n\n if (xdgDataHome) {\n return join(xdgDataHome, \"pi-ohm\");\n }\n\n return join(homedir(), \".local\", \"share\", \"pi-ohm\");\n}\n\nexport function resolveOhmAgentDataHome(input: ResolveOhmDataHomeInput = {}): string {\n return join(resolveOhmDataHome(input), \"agent\");\n}\n"],"mappings":";;;;AAOA,SAAS,gBAAgB,KAAwB,MAAkC;CACjF,MAAM,MAAM,IAAI;AAChB,KAAI,CAAC,IAAK,QAAO;CACjB,MAAM,UAAU,IAAI,MAAM;AAC1B,KAAI,QAAQ,WAAW,EAAG,QAAO;AACjC,QAAO;;AAGT,SAAgB,mBAAmB,QAAiC,EAAE,EAAU;CAE9E,MAAM,cAAc,gBADR,MAAM,OAAO,QAAQ,KACQ,gBAAgB;AAEzD,KAAI,YACF,QAAO,KAAK,aAAa,SAAS;AAGpC,QAAO,KAAK,SAAS,EAAE,UAAU,SAAS,SAAS;;AAGrD,SAAgB,wBAAwB,QAAiC,EAAE,EAAU;AACnF,QAAO,KAAK,mBAAmB,MAAM,EAAE,QAAQ"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@pi-ohm/core",
3
+ "version": "0.6.4-dev.22269206811.1.0e8e307",
4
+ "homepage": "https://github.com/pi-ohm/pi-ohm/tree/dev/packages/core#readme",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/pi-ohm/pi-ohm.git",
8
+ "directory": "packages/core"
9
+ },
10
+ "files": [
11
+ "dist/",
12
+ "README.md"
13
+ ],
14
+ "type": "module",
15
+ "sideEffects": false,
16
+ "exports": {
17
+ "./errors": {
18
+ "types": "./dist/errors.d.ts",
19
+ "default": "./dist/errors.js"
20
+ },
21
+ "./grammar": {
22
+ "types": "./dist/grammar.d.ts",
23
+ "default": "./dist/grammar.js"
24
+ },
25
+ "./paths": {
26
+ "types": "./dist/paths.d.ts",
27
+ "default": "./dist/paths.js"
28
+ }
29
+ },
30
+ "publishConfig": {
31
+ "access": "public",
32
+ "provenance": true
33
+ },
34
+ "dependencies": {
35
+ "better-result": "^2.6.0"
36
+ },
37
+ "tsdown": {
38
+ "entry": {
39
+ "errors": "src/errors.ts",
40
+ "grammar": "src/grammar.ts",
41
+ "paths": "src/paths.ts"
42
+ }
43
+ }
44
+ }