@hulla/db-postgres 0.0.0-stage → 0.2.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 Samuel Hulla
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,32 @@
1
- # Temporary Holding Version
1
+ # @hulla/db-postgres
2
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.
3
+ PostgreSQL application instances using shared `@hulla/db` schemas and execution.
4
+
5
+ ```ts
6
+ import { defineSchema, defineTable, v } from '@hulla/db'
7
+ import { postgres } from '@hulla/db-postgres'
8
+
9
+ const schema = defineSchema({ tasks: defineTable({ title: v.string() }) })
10
+ const db = postgres({ schema, url: process.env.DATABASE_URL, namespace: 'app' })
11
+ await db.insert('tasks', { title: 'A task' })
12
+ ```
13
+
14
+ Schema imports are inert; `postgres({...})` starts the instance. Optional `functions`
15
+ selects one handler barrel or build-time glob. Handlers use `ctx.db` and can be shared
16
+ between instances of the same schema. Optional `ready()`, `state`/`subscribe()` and
17
+ terminal `close()` expose lifecycle. Use `postgres.initialize({...})` for explicit
18
+ fresh provisioning. PostgreSQL cannot store device replicas.
19
+
20
+ `url` takes precedence over `DATABASE_URL`. Run `hulla-db dev ./db/server.ts` against
21
+ an exported initializer to start the development service. Without either URL, dev
22
+ starts and initializes its own persistent PostgreSQL; with a URL, it starts the
23
+ same service using that database. External databases require explicit `init` or
24
+ `migrate`. Invalid or unreachable URLs never fall back to managed storage.
25
+
26
+ Outside the development launcher, opening an instance needs `url` or `DATABASE_URL`;
27
+ the adapter never starts a PostgreSQL server. Generation prepares server-only
28
+ settings without opening the instance, and evaluates environment URLs at hosting
29
+ time. Deploy the generated directory along with the application.
30
+
31
+ This adapter currently delegates to the core PostgreSQL bridge. Complete native
32
+ asset relocation remains work. See [schema authoring and SQLite](https://github.com/hulladev/db/blob/main/docs/sqlite.md).
@@ -0,0 +1,12 @@
1
+ import type { DatabaseEngine, ConnectedDatabase, SchemaDefinition, FunctionSource, SourceConnection } from "@hulla/db";
2
+ import { type DatabaseOptions } from "@hulla/db/engine";
3
+ import type { SourcesOf } from "@hulla/db/internal/engine";
4
+ export interface PostgresConnection {
5
+ readonly url?: string | undefined;
6
+ readonly namespace?: string;
7
+ }
8
+ export type Connector = <S extends SchemaDefinition>(schema: S, connection: PostgresConnection, initialize: boolean) => Promise<ConnectedDatabase<S>>;
9
+ export declare function postgresDescriptor(connect: Connector): DatabaseEngine<"postgres", PostgresConnection>;
10
+ export declare function postgresFactory(connect: Connector): (<const S extends SchemaDefinition, const F extends FunctionSource | undefined = undefined, const R extends readonly SourceConnection<SourcesOf<S>>[] = readonly SourceConnection<SourcesOf<S>>[]>(options: DatabaseOptions<S, PostgresConnection, F, R>) => import("@hulla/db").Database<S, F>) & {
11
+ initialize: <const S extends SchemaDefinition, const F extends FunctionSource | undefined = undefined, const R extends readonly SourceConnection<SourcesOf<S>>[] = readonly SourceConnection<SourcesOf<S>>[]>(options: DatabaseOptions<S, PostgresConnection, F, R>) => import("@hulla/db").Database<S, F>;
12
+ };
@@ -0,0 +1,15 @@
1
+ import { createDatabase, registerDatabaseFactory } from "@hulla/db/engine";
2
+ export function postgresDescriptor(connect) {
3
+ return Object.freeze({ name: "postgres", replicaStorage: false,
4
+ connect: (schema, settings) => connect(schema, settings, false),
5
+ initialize: (schema, settings) => connect(schema, settings, true),
6
+ });
7
+ }
8
+ export function postgresFactory(connect) {
9
+ const engine = postgresDescriptor(connect);
10
+ const create = (options) => createDatabase(engine, options);
11
+ const initialize = (options) => createDatabase(engine, options, true);
12
+ registerDatabaseFactory(create, engine);
13
+ registerDatabaseFactory(initialize, engine);
14
+ return Object.assign(create, { initialize });
15
+ }
@@ -0,0 +1,4 @@
1
+ export type { PostgresConnection } from "./descriptor.ts";
2
+ export declare const postgres: (<const S extends import("@hulla/db").SchemaDefinition, const F extends import("@hulla/db").FunctionSource | undefined = undefined, const R extends readonly import("@hulla/db").SourceConnection<import("@hulla/db/internal/engine").SourcesOf<S>>[] = readonly import("@hulla/db").SourceConnection<import("@hulla/db/internal/engine").SourcesOf<S>>[]>(options: import("@hulla/db/engine").DatabaseOptions<S, import("./descriptor.ts").PostgresConnection, F, R>) => import("@hulla/db").Database<S, F>) & {
3
+ initialize: <const S extends import("@hulla/db").SchemaDefinition, const F extends import("@hulla/db").FunctionSource | undefined = undefined, const R extends readonly import("@hulla/db").SourceConnection<import("@hulla/db/internal/engine").SourcesOf<S>>[] = readonly import("@hulla/db").SourceConnection<import("@hulla/db/internal/engine").SourcesOf<S>>[]>(options: import("@hulla/db/engine").DatabaseOptions<S, import("./descriptor.ts").PostgresConnection, F, R>) => import("@hulla/db").Database<S, F>;
4
+ };
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import { postgresFactory } from "./descriptor.js";
2
+ export const postgres = postgresFactory(async (schema, settings, initialize) => {
3
+ const runtime = await import("@hulla/db/internal/postgres");
4
+ const connection = runtime.resolvePostgresConnection(settings);
5
+ if (initialize)
6
+ await runtime.initializeDatabase(schema, connection);
7
+ return runtime.createDatabase(schema, connection);
8
+ });
@@ -0,0 +1,5 @@
1
+ export type { PostgresConnection } from "./descriptor.ts";
2
+ /** Engine identity remains usable in browser schemas and restricted declarations. */
3
+ export declare const postgres: (<const S extends import("@hulla/db").SchemaDefinition, const F extends import("@hulla/db").FunctionSource | undefined = undefined, const R extends readonly import("@hulla/db").SourceConnection<import("@hulla/db/internal/engine").SourcesOf<S>>[] = readonly import("@hulla/db").SourceConnection<import("@hulla/db/internal/engine").SourcesOf<S>>[]>(options: import("@hulla/db/engine").DatabaseOptions<S, import("./descriptor.ts").PostgresConnection, F, R>) => import("@hulla/db").Database<S, F>) & {
4
+ initialize: <const S extends import("@hulla/db").SchemaDefinition, const F extends import("@hulla/db").FunctionSource | undefined = undefined, const R extends readonly import("@hulla/db").SourceConnection<import("@hulla/db/internal/engine").SourcesOf<S>>[] = readonly import("@hulla/db").SourceConnection<import("@hulla/db/internal/engine").SourcesOf<S>>[]>(options: import("@hulla/db/engine").DatabaseOptions<S, import("./descriptor.ts").PostgresConnection, F, R>) => import("@hulla/db").Database<S, F>;
5
+ };
package/dist/worker.js ADDED
@@ -0,0 +1,3 @@
1
+ import { postgresFactory } from "./descriptor.js";
2
+ /** Engine identity remains usable in browser schemas and restricted declarations. */
3
+ export const postgres = postgresFactory(async () => { throw new Error("PostgreSQL connections require a server runtime; use ctx.db inside database functions"); });
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@hulla/db-postgres",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "description": "PostgreSQL application instances for Hulla schemas and functions",
6
+ "exports": {
7
+ ".": {
8
+ "hulladb-worker": {
9
+ "types": "./dist/worker.d.ts",
10
+ "default": "./dist/worker.js"
11
+ },
12
+ "browser": {
13
+ "types": "./dist/worker.d.ts",
14
+ "default": "./dist/worker.js"
15
+ },
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "README.md",
23
+ "LICENSE"
24
+ ],
25
+ "peerDependencies": {
26
+ "@hulla/db": "^0.2.0"
27
+ },
28
+ "engines": {
29
+ "node": ">=22.18.0"
30
+ },
31
+ "license": "MIT",
32
+ "author": {
33
+ "name": "Samuel Hulla",
34
+ "url": "https://hulla.dev"
35
+ },
36
+ "homepage": "https://github.com/hulladev/db#readme",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/hulladev/db.git",
40
+ "directory": "packages/db-postgres"
41
+ },
42
+ "bugs": {
43
+ "url": "https://github.com/hulladev/db/issues"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public",
47
+ "registry": "https://registry.npmjs.org/"
48
+ }
49
+ }