@pthm/melange 0.4.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,44 @@
1
+ # @pthm/melange
2
+
3
+ TypeScript client for Melange PostgreSQL authorization.
4
+
5
+ > **Note:** This package is a placeholder. The TypeScript runtime is not yet implemented.
6
+ > Use the Go runtime (`github.com/pthm/melange/melange`) for production workloads.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @pthm/melange
12
+ ```
13
+
14
+ ## Status
15
+
16
+ This package provides:
17
+ - Type definitions for authorization objects
18
+ - Placeholder Checker class (throws "not implemented")
19
+
20
+ The full implementation will include:
21
+ - `Checker` class for permission checks
22
+ - `Cache` for caching decisions
23
+ - Connection pooling support
24
+
25
+ ## Generated Client Code
26
+
27
+ You can generate type-safe client code from your schema using the melange CLI:
28
+
29
+ ```bash
30
+ melange generate client --runtime typescript --schema schema.fga --output ./src/authz/
31
+ ```
32
+
33
+ This generates:
34
+ - Type constants (`TYPE_USER`, `TYPE_REPOSITORY`)
35
+ - Relation constants (`REL_CAN_READ`, `REL_OWNER`)
36
+ - Factory functions (`user()`, `repository()`)
37
+
38
+ ## Contributing
39
+
40
+ See the [main repository](https://github.com/pthm/melange) for contribution guidelines.
41
+
42
+ ## License
43
+
44
+ MIT
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Melange TypeScript Checker
3
+ *
4
+ * This module will provide the Checker class for performing authorization checks.
5
+ * Currently a placeholder - implementation coming in a future release.
6
+ */
7
+ import type { MelangeObject, Relation, Decision } from './types.js';
8
+ /**
9
+ * Checker performs authorization checks against a PostgreSQL database.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { Checker } from '@pthm/melange';
14
+ * import { Pool } from 'pg';
15
+ *
16
+ * const pool = new Pool({ connectionString: process.env.DATABASE_URL });
17
+ * const checker = new Checker(pool);
18
+ *
19
+ * const decision = await checker.check(
20
+ * { type: 'user', id: '123' },
21
+ * 'can_read',
22
+ * { type: 'repository', id: '456' }
23
+ * );
24
+ * ```
25
+ */
26
+ export declare class Checker {
27
+ /**
28
+ * Creates a new Checker instance.
29
+ *
30
+ * @param db - A PostgreSQL client or pool with query capability
31
+ */
32
+ constructor(_db: unknown);
33
+ /**
34
+ * Check performs a permission check.
35
+ *
36
+ * @param subject - The subject requesting access
37
+ * @param relation - The relation to check
38
+ * @param object - The object being accessed
39
+ * @returns A Decision indicating whether access is allowed
40
+ */
41
+ check(_subject: MelangeObject, _relation: Relation, _object: MelangeObject): Promise<Decision>;
42
+ }
43
+ //# sourceMappingURL=checker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,OAAO;IAClB;;;;OAIG;gBACS,GAAG,EAAE,OAAO;IAOxB;;;;;;;OAOG;IACG,KAAK,CACT,QAAQ,EAAE,aAAa,EACvB,SAAS,EAAE,QAAQ,EACnB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,QAAQ,CAAC;CAGrB"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Melange TypeScript Checker
3
+ *
4
+ * This module will provide the Checker class for performing authorization checks.
5
+ * Currently a placeholder - implementation coming in a future release.
6
+ */
7
+ /**
8
+ * Checker performs authorization checks against a PostgreSQL database.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { Checker } from '@pthm/melange';
13
+ * import { Pool } from 'pg';
14
+ *
15
+ * const pool = new Pool({ connectionString: process.env.DATABASE_URL });
16
+ * const checker = new Checker(pool);
17
+ *
18
+ * const decision = await checker.check(
19
+ * { type: 'user', id: '123' },
20
+ * 'can_read',
21
+ * { type: 'repository', id: '456' }
22
+ * );
23
+ * ```
24
+ */
25
+ export class Checker {
26
+ /**
27
+ * Creates a new Checker instance.
28
+ *
29
+ * @param db - A PostgreSQL client or pool with query capability
30
+ */
31
+ constructor(_db) {
32
+ throw new Error('Melange TypeScript runtime is not yet implemented. ' +
33
+ 'Use the Go runtime (github.com/pthm/melange/melange) for now.');
34
+ }
35
+ /**
36
+ * Check performs a permission check.
37
+ *
38
+ * @param subject - The subject requesting access
39
+ * @param relation - The relation to check
40
+ * @param object - The object being accessed
41
+ * @returns A Decision indicating whether access is allowed
42
+ */
43
+ async check(_subject, _relation, _object) {
44
+ throw new Error('Not implemented');
45
+ }
46
+ }
47
+ //# sourceMappingURL=checker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checker.js","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,OAAO;IAClB;;;;OAIG;IACH,YAAY,GAAY;QACtB,MAAM,IAAI,KAAK,CACb,qDAAqD;YACrD,+DAA+D,CAChE,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,KAAK,CACT,QAAuB,EACvB,SAAmB,EACnB,OAAsB;QAEtB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @pthm/melange - TypeScript client for Melange PostgreSQL authorization
3
+ *
4
+ * Melange is an OpenFGA-compatible authorization library that runs entirely
5
+ * in PostgreSQL. This TypeScript client provides type-safe access to the
6
+ * authorization system.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ export { Checker } from './checker.js';
11
+ export type { ObjectType, Relation, MelangeObject, Decision, CheckRequest, } from './types.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EACV,UAAU,EACV,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,YAAY,GACb,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @pthm/melange - TypeScript client for Melange PostgreSQL authorization
3
+ *
4
+ * Melange is an OpenFGA-compatible authorization library that runs entirely
5
+ * in PostgreSQL. This TypeScript client provides type-safe access to the
6
+ * authorization system.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ export { Checker } from './checker.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Melange TypeScript Types
3
+ *
4
+ * This module provides type definitions for Melange authorization checks.
5
+ * Types are designed to match the Go runtime for cross-language consistency.
6
+ */
7
+ /**
8
+ * ObjectType represents an authorization object type (e.g., "user", "repository").
9
+ */
10
+ export type ObjectType = string;
11
+ /**
12
+ * Relation represents an authorization relation (e.g., "owner", "can_read").
13
+ */
14
+ export type Relation = string;
15
+ /**
16
+ * Object represents an authorization object with type and ID.
17
+ */
18
+ export interface MelangeObject {
19
+ readonly type: ObjectType;
20
+ readonly id: string;
21
+ }
22
+ /**
23
+ * Decision represents the result of a permission check.
24
+ */
25
+ export interface Decision {
26
+ readonly allowed: boolean;
27
+ }
28
+ /**
29
+ * CheckRequest represents a permission check request.
30
+ */
31
+ export interface CheckRequest {
32
+ readonly subject: MelangeObject;
33
+ readonly relation: Relation;
34
+ readonly object: MelangeObject;
35
+ }
36
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;CAChC"}
package/dist/types.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Melange TypeScript Types
3
+ *
4
+ * This module provides type definitions for Melange authorization checks.
5
+ * Types are designed to match the Go runtime for cross-language consistency.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@pthm/melange",
3
+ "version": "0.4.0",
4
+ "description": "TypeScript client for Melange PostgreSQL authorization",
5
+ "keywords": [
6
+ "authorization",
7
+ "fga",
8
+ "openfga",
9
+ "postgresql",
10
+ "melange"
11
+ ],
12
+ "author": "pthm",
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/pthm/melange.git",
17
+ "directory": "clients/typescript"
18
+ },
19
+ "type": "module",
20
+ "main": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js"
26
+ }
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md"
31
+ ],
32
+ "scripts": {
33
+ "build": "tsc",
34
+ "clean": "rm -rf dist",
35
+ "prepublishOnly": "npm run build"
36
+ },
37
+ "devDependencies": {
38
+ "typescript": "^5.0.0"
39
+ },
40
+ "engines": {
41
+ "node": ">=18"
42
+ }
43
+ }