@pgpm/types 0.4.0 → 0.6.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/Makefile CHANGED
@@ -1,5 +1,5 @@
1
1
  EXTENSION = launchql-types
2
- DATA = sql/launchql-types--0.4.6.sql
2
+ DATA = sql/launchql-types--0.5.0.sql
3
3
 
4
4
  PG_CONFIG = pg_config
5
5
  PGXS := $(shell $(PG_CONFIG) --pgxs)
package/README.md CHANGED
@@ -2,4 +2,281 @@
2
2
 
3
3
  Core PostgreSQL data types with SQL scripts.
4
4
 
5
- Provides essential data types including attachment, email, hostname, image, multiple_select, single_select, upload, and url domains for PostgreSQL applications.
5
+ ## Overview
6
+
7
+ `@pgpm/types` provides a collection of validated PostgreSQL domain types for common data formats. These domains enforce data integrity at the database level through regex-based validation, ensuring that only properly formatted data is stored.
8
+
9
+ ## Features
10
+
11
+ - **email**: Case-insensitive email address validation
12
+ - **url**: HTTP/HTTPS URL validation
13
+ - **hostname**: Domain name validation
14
+ - **image**: JSON-based image metadata with URL and MIME type
15
+ - **attachment**: JSON-based file attachment metadata with URL and MIME type
16
+ - **upload**: File upload metadata
17
+ - **single_select**: Single selection field
18
+ - **multiple_select**: Multiple selection field
19
+
20
+ ## Installation
21
+
22
+ If you have `pgpm` installed:
23
+
24
+ ```bash
25
+ pgpm install @pgpm/types
26
+ pgpm deploy
27
+ ```
28
+
29
+ This is a quick way to get started. The sections below provide more detailed installation options.
30
+
31
+ ### Prerequisites
32
+
33
+ ```bash
34
+ # Install pgpm globally
35
+ npm install -g pgpm
36
+
37
+ # Start PostgreSQL
38
+ pgpm docker start
39
+
40
+ # Set environment variables
41
+ eval "$(pgpm env)"
42
+ ```
43
+
44
+ ### Deploy
45
+
46
+ #### Option 1: Deploy by installing with pgpm
47
+
48
+ ```bash
49
+ pgpm install @pgpm/types
50
+ pgpm deploy
51
+ ```
52
+
53
+ #### Option 2: Deploy from Package Directory
54
+
55
+ ```bash
56
+ cd packages/data-types/types
57
+ pgpm deploy --createdb
58
+ ```
59
+
60
+ #### Option 3: Deploy from Workspace Root
61
+
62
+ ```bash
63
+ # Install workspace dependencies
64
+ pnpm install
65
+
66
+ # Deploy with dependencies
67
+ pgpm deploy mydb1 --yes --createdb
68
+ ```
69
+
70
+ ## Usage
71
+
72
+ ### Creating Tables with Validated Types
73
+
74
+ ```sql
75
+ CREATE TABLE customers (
76
+ id serial PRIMARY KEY,
77
+ email email,
78
+ website url,
79
+ domain hostname,
80
+ profile_image image,
81
+ document attachment
82
+ );
83
+ ```
84
+
85
+ ### Email Domain
86
+
87
+ The `email` domain validates email addresses using a comprehensive regex pattern and stores them as case-insensitive text (`citext`).
88
+
89
+ ```sql
90
+ -- Valid emails
91
+ INSERT INTO customers (email) VALUES
92
+ ('user@example.com'),
93
+ ('john.doe@company.co.uk'),
94
+ ('support+tag@service.io');
95
+
96
+ -- Invalid email (will fail)
97
+ INSERT INTO customers (email) VALUES ('not-an-email');
98
+ -- ERROR: value for domain email violates check constraint
99
+ ```
100
+
101
+ **Validation Pattern**: RFC-compliant email format with support for special characters and subdomains.
102
+
103
+ ### URL Domain
104
+
105
+ The `url` domain validates HTTP and HTTPS URLs.
106
+
107
+ ```sql
108
+ -- Valid URLs
109
+ INSERT INTO customers (website) VALUES
110
+ ('http://example.com'),
111
+ ('https://www.example.com/path?query=value'),
112
+ ('http://foo.bar/path_(with)_parens');
113
+
114
+ -- Invalid URLs (will fail)
115
+ INSERT INTO customers (website) VALUES
116
+ ('ftp://example.com'), -- Only http/https allowed
117
+ ('example.com'), -- Missing protocol
118
+ ('http://'); -- Incomplete URL
119
+ ```
120
+
121
+ **Validation Pattern**: Requires `http://` or `https://` protocol and valid URL structure.
122
+
123
+ ### Hostname Domain
124
+
125
+ The `hostname` domain validates domain names without protocol or path.
126
+
127
+ ```sql
128
+ -- Valid hostnames
129
+ INSERT INTO customers (domain) VALUES
130
+ ('example.com'),
131
+ ('subdomain.example.com'),
132
+ ('my-site.co.uk');
133
+
134
+ -- Invalid hostnames (will fail)
135
+ INSERT INTO customers (domain) VALUES
136
+ ('http://example.com'), -- No protocol allowed
137
+ ('example.com/path'), -- No path allowed
138
+ ('invalid..domain.com'); -- Invalid format
139
+ ```
140
+
141
+ **Validation Pattern**: Standard domain name format with support for subdomains and hyphens.
142
+
143
+ ### Image and Attachment Domains
144
+
145
+ The `image` and `attachment` domains store JSON objects with URL and MIME type information.
146
+
147
+ ```sql
148
+ -- Valid image
149
+ INSERT INTO customers (profile_image) VALUES
150
+ ('{"url": "https://cdn.example.com/photo.jpg", "mime": "image/jpeg"}'::json);
151
+
152
+ -- Valid attachment
153
+ INSERT INTO customers (document) VALUES
154
+ ('{"url": "https://storage.example.com/file.pdf", "mime": "application/pdf"}'::json);
155
+ ```
156
+
157
+ **Structure**: Both domains expect JSON objects with `url` and `mime` properties.
158
+
159
+ ## Domain Types Reference
160
+
161
+ | Domain | Base Type | Description | Example |
162
+ |--------|-----------|-------------|---------|
163
+ | `email` | `citext` | Case-insensitive email address | `user@example.com` |
164
+ | `url` | `text` | HTTP/HTTPS URL | `https://example.com/path` |
165
+ | `hostname` | `text` | Domain name without protocol | `example.com` |
166
+ | `image` | `json` | Image metadata with URL and MIME | `{"url": "...", "mime": "image/jpeg"}` |
167
+ | `attachment` | `json` | File attachment metadata | `{"url": "...", "mime": "application/pdf"}` |
168
+ | `upload` | `text` | File upload identifier | Various formats |
169
+ | `single_select` | `text` | Single selection value | Text value |
170
+ | `multiple_select` | `text[]` | Multiple selection values | Array of text values |
171
+
172
+ ## Validation Benefits
173
+
174
+ Using domain types provides several advantages over plain text columns:
175
+
176
+ 1. **Data Integrity**: Invalid data is rejected at insert/update time
177
+ 2. **Self-Documenting**: Column types clearly indicate expected format
178
+ 3. **Consistent Validation**: Same rules applied across all tables
179
+ 4. **Database-Level Enforcement**: No reliance on application-level validation alone
180
+
181
+ ## Dependencies
182
+
183
+ - `@pgpm/verify`: Verification utilities for database objects
184
+ - PostgreSQL `citext` extension (for email domain)
185
+
186
+ ## Testing
187
+
188
+ ```bash
189
+ pnpm test
190
+ ```
191
+
192
+ The test suite validates:
193
+ - Email format validation (valid and invalid cases)
194
+ - URL format validation with extensive test cases
195
+ - Hostname format validation
196
+ - Image and attachment JSON structure validation
197
+
198
+ ## Development
199
+
200
+ See the [Development](#development) section below for information on working with this package.
201
+
202
+ ---
203
+
204
+ ## Development
205
+
206
+ ### **Before You Begin**
207
+
208
+ ```bash
209
+ # 1. Install pgpm
210
+ npm install -g pgpm
211
+
212
+ # 2. Start Postgres (Docker or local)
213
+ pgpm docker start
214
+
215
+ # 3. Load PG* environment variables (PGHOST, PGUSER, ...)
216
+ eval "$(pgpm env)"
217
+ ```
218
+
219
+ ---
220
+
221
+ ### **Starting a New Project**
222
+
223
+ ```bash
224
+ # 1. Create a workspace
225
+ pgpm init --workspace
226
+ cd my-app
227
+
228
+ # 2. Create your first module
229
+ pgpm init
230
+
231
+ # 3. Add a migration
232
+ pgpm add some_change
233
+
234
+ # 4. Deploy (auto-creates database)
235
+ pgpm deploy --createdb
236
+ ```
237
+
238
+ ---
239
+
240
+ ### **Working With an Existing Project**
241
+
242
+ ```bash
243
+ # 1. Clone and enter the project
244
+ git clone <repo> && cd <project>
245
+
246
+ # 2. Install dependencies
247
+ pnpm install
248
+
249
+ # 3. Deploy locally
250
+ pgpm deploy --createdb
251
+ ```
252
+
253
+ ---
254
+
255
+ ### **Testing a Module Inside a Workspace**
256
+
257
+ ```bash
258
+ # 1. Install workspace deps
259
+ pnpm install
260
+
261
+ # 2. Enter the module directory
262
+ cd packages/<some-module>
263
+
264
+ # 3. Run tests in watch mode
265
+ pnpm test:watch
266
+ ```
267
+
268
+ ## Related Tooling
269
+
270
+ * [pgpm](https://github.com/launchql/launchql/tree/main/packages/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
271
+ * [pgsql-test](https://github.com/launchql/launchql/tree/main/packages/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
272
+ * [supabase-test](https://github.com/launchql/launchql/tree/main/packages/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
273
+ * [graphile-test](https://github.com/launchql/launchql/tree/main/packages/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
274
+ * [pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
275
+ * [libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
276
+ * [pg-proto-parser](https://github.com/launchql/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
277
+
278
+ ## Disclaimer
279
+
280
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
281
+
282
+ No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
@@ -1,6 +1,6 @@
1
1
  # launchql-types extension
2
2
  comment = 'launchql-types extension'
3
- default_version = '0.4.6'
3
+ default_version = '0.5.0'
4
4
  module_pathname = '$libdir/launchql-types'
5
5
  requires = 'plpgsql,citext,launchql-verify'
6
6
  relocatable = false
package/package.json CHANGED
@@ -1,28 +1,28 @@
1
1
  {
2
2
  "name": "@pgpm/types",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Core PostgreSQL data types with deploy/verify/revert SQL scripts",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "scripts": {
9
- "bundle": "lql package",
9
+ "bundle": "pgpm package",
10
10
  "test": "jest",
11
11
  "test:watch": "jest --watch"
12
12
  },
13
13
  "dependencies": {
14
- "@pgpm/verify": "0.4.0"
14
+ "@pgpm/verify": "0.6.0"
15
15
  },
16
16
  "devDependencies": {
17
- "@launchql/cli": "^4.9.0"
17
+ "pgpm": "^0.2.0"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "https://github.com/launchql/extensions"
21
+ "url": "https://github.com/launchql/pgpm-modules"
22
22
  },
23
- "homepage": "https://github.com/launchql/extensions",
23
+ "homepage": "https://github.com/launchql/pgpm-modules",
24
24
  "bugs": {
25
- "url": "https://github.com/launchql/extensions/issues"
25
+ "url": "https://github.com/launchql/pgpm-modules/issues"
26
26
  },
27
- "gitHead": "cc9f52a335caa6e21ee7751b04b77c84ce6cb809"
27
+ "gitHead": "c7d0eae588d7a764b382a330c8b853b341b13fb2"
28
28
  }
package/sqitch.plan DELETED
@@ -1,13 +0,0 @@
1
- %syntax-version=1.0.0
2
- %project=launchql-types
3
- %uri=launchql-types
4
-
5
- schemas/public/schema 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/schema
6
- schemas/public/domains/attachment [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/attachment
7
- schemas/public/domains/email [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/email
8
- schemas/public/domains/hostname [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/hostname
9
- schemas/public/domains/image [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/image
10
- schemas/public/domains/multiple_select [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/multiple_select
11
- schemas/public/domains/single_select [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/single_select
12
- schemas/public/domains/upload [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/upload
13
- schemas/public/domains/url [schemas/public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/public/domains/url
File without changes