refactor: the npm package moves to pgmorbac-node
This repository is the SQL extension only. @crudy/pgmorbac is published from pgmorbac-node, which packs the SQL of each signed release.
This commit is contained in:
@@ -20,6 +20,3 @@ Thumbs.db
|
|||||||
node_modules/
|
node_modules/
|
||||||
dist/
|
dist/
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
|
||||||
# npm package build output (scripts/build-package-sql.mjs)
|
|
||||||
/sql/
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
## [1.0.0] - 2026-07-25
|
## [1.0.0] - 2026-07-25
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- npm package `@crudy/pgmorbac`: the install and upgrade scripts with `extensionSql()`, `upgradeScripts()`, `version` and `sqlDir`
|
|
||||||
- First stable release of the Multi-OrBAC PostgreSQL extension
|
- First stable release of the Multi-OrBAC PostgreSQL extension
|
||||||
- Complete Multi-OrBAC implementation based on CNRS research paper
|
- Complete Multi-OrBAC implementation based on CNRS research paper
|
||||||
- Core features:
|
- Core features:
|
||||||
|
|||||||
@@ -79,21 +79,11 @@ psql -d mydb -c "CREATE EXTENSION pgmorbac;"
|
|||||||
|
|
||||||
### From Node.js (npm)
|
### From Node.js (npm)
|
||||||
|
|
||||||
`@crudy/pgmorbac` ships the same install and upgrade scripts for projects that
|
[`@crudy/pgmorbac`](https://www.npmjs.com/package/@crudy/pgmorbac) ships the
|
||||||
apply SQL through a migration runner instead of `CREATE EXTENSION`:
|
install and upgrade scripts of each signed release for Node projects and migration
|
||||||
|
runners, and [`@crudy/pgmorbac-fastify`](https://www.npmjs.com/package/@crudy/pgmorbac-fastify)
|
||||||
```bash
|
adds Fastify helpers on top. Sources: [pgmorbac-node](https://github.com/crudylabs/pgmorbac-node),
|
||||||
npm install @crudy/pgmorbac
|
[pgmorbac-fastify](https://github.com/crudylabs/pgmorbac-fastify).
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
import { extensionSql, upgradeScripts, version, sqlDir } from '@crudy/pgmorbac';
|
|
||||||
|
|
||||||
await client.query(extensionSql()); // pgmorbac--<version>.sql
|
|
||||||
for (const u of upgradeScripts()) { // pgmorbac--<from>--<to>.sql, in order
|
|
||||||
await client.query(u.sql);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
|
|||||||
+3
-9
@@ -9,7 +9,6 @@ pgmorbac/
|
|||||||
├── tools/ # Build and test scripts
|
├── tools/ # Build and test scripts
|
||||||
├── docs/ # Documentation
|
├── docs/ # Documentation
|
||||||
├── pgmorbac.control # Version source of truth
|
├── pgmorbac.control # Version source of truth
|
||||||
├── index.js, index.d.ts # npm package loader (@crudy/pgmorbac)
|
|
||||||
├── pgmorbac.sql # Generated (git-ignored)
|
├── pgmorbac.sql # Generated (git-ignored)
|
||||||
└── Makefile # Build automation
|
└── Makefile # Build automation
|
||||||
```
|
```
|
||||||
@@ -57,7 +56,7 @@ dropdb mytest
|
|||||||
|
|
||||||
## Release Process
|
## Release Process
|
||||||
|
|
||||||
1. `./tools/bump_version.sh X.Y.Z` (control file, META.json, package.json, README)
|
1. `./tools/bump_version.sh X.Y.Z` (control file, META.json, README)
|
||||||
2. Update `CHANGELOG.md`
|
2. Update `CHANGELOG.md`
|
||||||
3. Run `make build` and `make check`
|
3. Run `make build` and `make check`
|
||||||
4. Commit and tag:
|
4. Commit and tag:
|
||||||
@@ -76,13 +75,8 @@ PGMORBAC_RELEASE_KEY=<path to the Ed25519 key> GITEA_URL=https://git.villains.fr
|
|||||||
GITEA_REPO=crudy/pgmorbac GITEA_TOKEN=<token> npm run release
|
GITEA_REPO=crudy/pgmorbac GITEA_TOKEN=<token> npm run release
|
||||||
```
|
```
|
||||||
|
|
||||||
6. npm package `@crudy/pgmorbac` (the SQL is built from `src/` on prepack). Publish
|
6. The npm package `@crudy/pgmorbac` is released from the `pgmorbac-node`
|
||||||
the same version to the local Verdaccio, for crudy development, and to npmjs:
|
repository, which packs the SQL of this signed release.
|
||||||
|
|
||||||
```bash
|
|
||||||
npm publish --registry http://localhost:4873
|
|
||||||
npm publish --registry https://registry.npmjs.org
|
|
||||||
```
|
|
||||||
|
|
||||||
## Makefile Targets
|
## Makefile Targets
|
||||||
|
|
||||||
|
|||||||
Vendored
-16
@@ -1,16 +0,0 @@
|
|||||||
/** Absolute path to pgmorbac.control. */
|
|
||||||
export declare const controlFile: string;
|
|
||||||
/** Absolute path to the directory holding the install and upgrade scripts. */
|
|
||||||
export declare const sqlDir: string;
|
|
||||||
/** The extension version (default_version in pgmorbac.control). */
|
|
||||||
export declare const version: string;
|
|
||||||
/** The install script pgmorbac--<version>.sql, as CREATE EXTENSION would run it. */
|
|
||||||
export declare function extensionSql(): string;
|
|
||||||
export interface UpgradeScript {
|
|
||||||
from: string;
|
|
||||||
to: string;
|
|
||||||
filename: string;
|
|
||||||
sql: string;
|
|
||||||
}
|
|
||||||
/** Upgrade scripts pgmorbac--<from>--<to>.sql, in version order. */
|
|
||||||
export declare function upgradeScripts(): UpgradeScript[];
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import { readFileSync, readdirSync } from 'node:fs';
|
|
||||||
import { fileURLToPath } from 'node:url';
|
|
||||||
import { dirname, join } from 'node:path';
|
|
||||||
|
|
||||||
const root = dirname(fileURLToPath(import.meta.url));
|
|
||||||
|
|
||||||
export const controlFile = join(root, 'pgmorbac.control');
|
|
||||||
export const sqlDir = join(root, 'sql');
|
|
||||||
|
|
||||||
const control = readFileSync(controlFile, 'utf8').match(/default_version\s*=\s*'([^']+)'/);
|
|
||||||
if (!control) throw new Error('[pgmorbac] pgmorbac.control has no default_version');
|
|
||||||
export const version = control[1];
|
|
||||||
|
|
||||||
/** The install script pgmorbac--<version>.sql, as CREATE EXTENSION would run it. */
|
|
||||||
export function extensionSql() {
|
|
||||||
return readFileSync(join(sqlDir, `pgmorbac--${version}.sql`), 'utf8');
|
|
||||||
}
|
|
||||||
|
|
||||||
const semver = (v) => v.split('.').map(Number);
|
|
||||||
const byFrom = (a, b) => {
|
|
||||||
const [x, y] = [semver(a.from), semver(b.from)];
|
|
||||||
return x[0] - y[0] || x[1] - y[1] || x[2] - y[2];
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Upgrade scripts pgmorbac--<from>--<to>.sql, in version order. */
|
|
||||||
export function upgradeScripts() {
|
|
||||||
return readdirSync(sqlDir)
|
|
||||||
.map((filename) => ({ filename, m: /^pgmorbac--(\d+\.\d+\.\d+)--(\d+\.\d+\.\d+)\.sql$/.exec(filename) }))
|
|
||||||
.filter(({ m }) => m)
|
|
||||||
.map(({ filename, m }) => ({ from: m[1], to: m[2], filename, sql: readFileSync(join(sqlDir, filename), 'utf8') }))
|
|
||||||
.sort(byFrom);
|
|
||||||
}
|
|
||||||
+3
-48
@@ -1,58 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@crudy/pgmorbac",
|
"name": "pgmorbac-release-tools",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "Multi-OrBAC for PostgreSQL: the pgmorbac extension SQL, packaged for Node.js projects and migration runners",
|
"description": "Release tooling for the pgmorbac PostgreSQL extension (build + sign + publish the PGXN distribution).",
|
||||||
"keywords": [
|
|
||||||
"pgmorbac",
|
|
||||||
"morbac",
|
|
||||||
"orbac",
|
|
||||||
"rbac",
|
|
||||||
"authorization",
|
|
||||||
"access-control",
|
|
||||||
"postgresql",
|
|
||||||
"postgresql-extension",
|
|
||||||
"row-level-security",
|
|
||||||
"multi-tenant"
|
|
||||||
],
|
|
||||||
"author": "Marc Villain",
|
|
||||||
"license": "MIT",
|
|
||||||
"homepage": "https://pgmorbac.crudy.fr",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/crudylabs/pgmorbac.git"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/crudylabs/pgmorbac/issues"
|
|
||||||
},
|
|
||||||
"exports": {
|
|
||||||
".": {
|
|
||||||
"types": "./index.d.ts",
|
|
||||||
"default": "./index.js"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"main": "./index.js",
|
|
||||||
"types": "./index.d.ts",
|
|
||||||
"files": [
|
|
||||||
"index.js",
|
|
||||||
"index.d.ts",
|
|
||||||
"sql",
|
|
||||||
"pgmorbac.control",
|
|
||||||
"README.md",
|
|
||||||
"CHANGELOG.md",
|
|
||||||
"LICENSE"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
},
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepack": "node scripts/build-package-sql.mjs",
|
|
||||||
"dist": "node scripts/build-dist.mjs",
|
"dist": "node scripts/build-dist.mjs",
|
||||||
"release": "node scripts/build-dist.mjs && node scripts/gitea-release.mjs"
|
"release": "node scripts/build-dist.mjs && node scripts/gitea-release.mjs"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
|
||||||
"access": "public"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"jose": "^5"
|
"jose": "^5"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
// Builds sql/ for the npm package: the install script from src/ (tools/build.sh)
|
|
||||||
// plus any upgrade scripts. Runs on prepack; sql/ is never committed.
|
|
||||||
import { execFileSync } from 'node:child_process';
|
|
||||||
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync } from 'node:fs';
|
|
||||||
import { dirname, join } from 'node:path';
|
|
||||||
import { fileURLToPath } from 'node:url';
|
|
||||||
|
|
||||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
||||||
const control = readFileSync(join(root, 'pgmorbac.control'), 'utf8').match(/default_version\s*=\s*'([^']+)'/);
|
|
||||||
if (!control) throw new Error('pgmorbac.control has no default_version');
|
|
||||||
const version = control[1];
|
|
||||||
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
||||||
if (pkg.version !== version) throw new Error(`package.json ${pkg.version} != pgmorbac.control ${version}`);
|
|
||||||
|
|
||||||
const sqlDir = join(root, 'sql');
|
|
||||||
rmSync(sqlDir, { recursive: true, force: true });
|
|
||||||
mkdirSync(sqlDir);
|
|
||||||
execFileSync(join(root, 'tools', 'build.sh'), ['src', join(sqlDir, `pgmorbac--${version}.sql`)], { cwd: root, stdio: 'inherit' });
|
|
||||||
const upgrades = join(root, 'src', 'upgrades');
|
|
||||||
if (existsSync(upgrades)) {
|
|
||||||
for (const f of readdirSync(upgrades).filter((n) => n.endsWith('.sql'))) copyFileSync(join(upgrades, f), join(sqlDir, f));
|
|
||||||
}
|
|
||||||
@@ -46,11 +46,6 @@ sed -i.bak \
|
|||||||
"$META_FILE"
|
"$META_FILE"
|
||||||
echo " Updated $META_FILE"
|
echo " Updated $META_FILE"
|
||||||
|
|
||||||
# --- package.json (the @crudy/pgmorbac npm package) ---
|
|
||||||
PACKAGE_FILE="$ROOT_DIR/package.json"
|
|
||||||
sed -i.bak "s/\"version\": \"$OLD_VERSION\"/\"version\": \"$NEW_VERSION\"/" "$PACKAGE_FILE"
|
|
||||||
echo " Updated $PACKAGE_FILE"
|
|
||||||
|
|
||||||
# --- README.md (hardcoded version references in manual install section) ---
|
# --- README.md (hardcoded version references in manual install section) ---
|
||||||
sed -i.bak \
|
sed -i.bak \
|
||||||
-e "s/pgmorbac--$OLD_VERSION\.sql/pgmorbac--$NEW_VERSION.sql/g" \
|
-e "s/pgmorbac--$OLD_VERSION\.sql/pgmorbac--$NEW_VERSION.sql/g" \
|
||||||
|
|||||||
Reference in New Issue
Block a user