graphile-meta-schema 0.2.4 → 0.2.6
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 +3 -1
- package/README.md +101 -4
- package/belongs-to.d.ts +3 -0
- package/belongs-to.js +37 -0
- package/esm/belongs-to.js +35 -0
- package/esm/has.js +36 -0
- package/esm/index.js +503 -0
- package/esm/many-to-many.js +81 -0
- package/esm/types.js +1 -0
- package/has.d.ts +3 -0
- package/has.js +38 -0
- package/index.d.ts +4 -0
- package/index.js +509 -0
- package/many-to-many.d.ts +3 -0
- package/many-to-many.js +83 -0
- package/package.json +28 -43
- package/types.d.ts +105 -0
- package/types.js +2 -0
- package/main/index.js +0 -496
- package/main/many-to-many.js +0 -124
- package/module/index.js +0 -629
- package/module/many-to-many.js +0 -79
package/LICENSE
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
|
|
4
|
+
Copyright (c) 2025 Hyperweb <developers@hyperweb.io>
|
|
5
|
+
Copyright (c) 2020-present, Interweb, Inc.
|
|
4
6
|
|
|
5
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
8
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
# graphile-meta-schema
|
|
1
|
+
# graphile-meta-schema
|
|
2
|
+
|
|
3
|
+
<p align="center" width="100%">
|
|
4
|
+
<img height="250" src="https://raw.githubusercontent.com/launchql/launchql/refs/heads/main/assets/outline-logo.svg" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center" width="100%">
|
|
8
|
+
<a href="https://github.com/launchql/launchql/actions/workflows/run-tests.yaml">
|
|
9
|
+
<img height="20" src="https://github.com/launchql/launchql/actions/workflows/run-tests.yaml/badge.svg" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/launchql/launchql/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
## Install
|
|
2
15
|
|
|
3
16
|
```sh
|
|
4
|
-
|
|
17
|
+
pnpm add graphile-meta-schema
|
|
5
18
|
```
|
|
6
19
|
|
|
7
|
-
##
|
|
20
|
+
## Example Query
|
|
8
21
|
|
|
9
22
|
```gql
|
|
10
23
|
query MetaQuery {
|
|
@@ -70,10 +83,94 @@ query MetaQuery {
|
|
|
70
83
|
}
|
|
71
84
|
```
|
|
72
85
|
|
|
73
|
-
##
|
|
86
|
+
## Testing
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
# requires a local Postgres with PostGIS available (defaults to postgres/password@localhost:5432)
|
|
90
|
+
pnpm --filter graphile-meta-schema test
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
If you want to explore the fixtures manually:
|
|
74
94
|
|
|
75
95
|
```sh
|
|
76
96
|
createdb metaschema_example
|
|
77
97
|
psql metaschema_example < sql/test.sql
|
|
78
98
|
psql metaschema_example < sql/types.sql
|
|
79
99
|
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Education and Tutorials
|
|
104
|
+
|
|
105
|
+
1. 🚀 [Quickstart: Getting Up and Running](https://launchql.com/learn/quickstart)
|
|
106
|
+
Get started with modular databases in minutes. Install prerequisites and deploy your first module.
|
|
107
|
+
|
|
108
|
+
2. 📦 [Modular PostgreSQL Development with Database Packages](https://launchql.com/learn/modular-postgres)
|
|
109
|
+
Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
|
|
110
|
+
|
|
111
|
+
3. ✏️ [Authoring Database Changes](https://launchql.com/learn/authoring-database-changes)
|
|
112
|
+
Master the workflow for adding, organizing, and managing database changes with pgpm.
|
|
113
|
+
|
|
114
|
+
4. 🧪 [End-to-End PostgreSQL Testing with TypeScript](https://launchql.com/learn/e2e-postgres-testing)
|
|
115
|
+
Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
|
|
116
|
+
|
|
117
|
+
5. ⚡ [Supabase Testing](https://launchql.com/learn/supabase)
|
|
118
|
+
Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.
|
|
119
|
+
|
|
120
|
+
6. 💧 [Drizzle ORM Testing](https://launchql.com/learn/drizzle-testing)
|
|
121
|
+
Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.
|
|
122
|
+
|
|
123
|
+
7. 🔧 [Troubleshooting](https://launchql.com/learn/troubleshooting)
|
|
124
|
+
Common issues and solutions for pgpm, PostgreSQL, and testing.
|
|
125
|
+
|
|
126
|
+
## Related LaunchQL Tooling
|
|
127
|
+
|
|
128
|
+
### 🧪 Testing
|
|
129
|
+
|
|
130
|
+
* [launchql/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.
|
|
131
|
+
* [launchql/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.
|
|
132
|
+
* [launchql/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.
|
|
133
|
+
* [launchql/pg-query-context](https://github.com/launchql/launchql/tree/main/packages/pg-query-context): **🔒 Session context injection** to add session-local context (e.g., `SET LOCAL`) into queries—ideal for setting `role`, `jwt.claims`, and other session settings.
|
|
134
|
+
|
|
135
|
+
### 🧠 Parsing & AST
|
|
136
|
+
|
|
137
|
+
* [launchql/pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
|
|
138
|
+
* [launchql/libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
|
|
139
|
+
* [launchql/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.
|
|
140
|
+
* [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
|
|
141
|
+
* [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
|
|
142
|
+
* [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
|
|
143
|
+
* [launchql/pg-ast](https://github.com/launchql/launchql/tree/main/packages/pg-ast): **🔍 Low-level AST tools** and transformations for Postgres query structures.
|
|
144
|
+
|
|
145
|
+
### 🚀 API & Dev Tools
|
|
146
|
+
|
|
147
|
+
* [launchql/server](https://github.com/launchql/launchql/tree/main/packages/server): **⚡ Express-based API server** powered by PostGraphile to expose a secure, scalable GraphQL API over your Postgres database.
|
|
148
|
+
* [launchql/explorer](https://github.com/launchql/launchql/tree/main/packages/explorer): **🔎 Visual API explorer** with GraphiQL for browsing across all databases and schemas—useful for debugging, documentation, and API prototyping.
|
|
149
|
+
|
|
150
|
+
### 🔁 Streaming & Uploads
|
|
151
|
+
|
|
152
|
+
* [launchql/s3-streamer](https://github.com/launchql/launchql/tree/main/packages/s3-streamer): **📤 Direct S3 streaming** for large files with support for metadata injection and content validation.
|
|
153
|
+
* [launchql/etag-hash](https://github.com/launchql/launchql/tree/main/packages/etag-hash): **🏷️ S3-compatible ETags** created by streaming and hashing file uploads in chunks.
|
|
154
|
+
* [launchql/etag-stream](https://github.com/launchql/launchql/tree/main/packages/etag-stream): **🔄 ETag computation** via Node stream transformer during upload or transfer.
|
|
155
|
+
* [launchql/uuid-hash](https://github.com/launchql/launchql/tree/main/packages/uuid-hash): **🆔 Deterministic UUIDs** generated from hashed content, great for deduplication and asset referencing.
|
|
156
|
+
* [launchql/uuid-stream](https://github.com/launchql/launchql/tree/main/packages/uuid-stream): **🌊 Streaming UUID generation** based on piped file content—ideal for upload pipelines.
|
|
157
|
+
* [launchql/upload-names](https://github.com/launchql/launchql/tree/main/packages/upload-names): **📂 Collision-resistant filenames** utility for structured and unique file names for uploads.
|
|
158
|
+
|
|
159
|
+
### 🧰 CLI & Codegen
|
|
160
|
+
|
|
161
|
+
* [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.
|
|
162
|
+
* [@launchql/cli](https://github.com/launchql/launchql/tree/main/packages/cli): **🖥️ Command-line toolkit** for managing LaunchQL projects—supports database scaffolding, migrations, seeding, code generation, and automation.
|
|
163
|
+
* [launchql/launchql-gen](https://github.com/launchql/launchql/tree/main/packages/launchql-gen): **✨ Auto-generated GraphQL** mutations and queries dynamically built from introspected schema data.
|
|
164
|
+
* [@launchql/query-builder](https://github.com/launchql/launchql/tree/main/packages/query-builder): **🏗️ SQL constructor** providing a robust TypeScript-based query builder for dynamic generation of `SELECT`, `INSERT`, `UPDATE`, `DELETE`, and stored procedure calls—supports advanced SQL features like `JOIN`, `GROUP BY`, and schema-qualified queries.
|
|
165
|
+
* [@launchql/query](https://github.com/launchql/launchql/tree/main/packages/query): **🧩 Fluent GraphQL builder** for PostGraphile schemas. ⚡ Schema-aware via introspection, 🧩 composable and ergonomic for building deeply nested queries.
|
|
166
|
+
|
|
167
|
+
## Credits
|
|
168
|
+
|
|
169
|
+
🛠 Built by LaunchQL — if you like our tools, please checkout and contribute to [our github ⚛️](https://github.com/launchql)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
## Disclaimer
|
|
173
|
+
|
|
174
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
175
|
+
|
|
176
|
+
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.
|
package/belongs-to.d.ts
ADDED
package/belongs-to.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getBelongsToRelations = (table, build) => {
|
|
4
|
+
const { pgIntrospectionResultsByKind: introspectionResultsByKind, inflection, pgOmit: omit } = build;
|
|
5
|
+
return table.constraints
|
|
6
|
+
.filter((constraint) => constraint.type === 'f')
|
|
7
|
+
.reduce((memo, constraint) => {
|
|
8
|
+
if (omit(constraint, 'read')) {
|
|
9
|
+
return memo;
|
|
10
|
+
}
|
|
11
|
+
const foreignTable = (constraint.foreignClassId !== undefined
|
|
12
|
+
? introspectionResultsByKind.classById[String(constraint.foreignClassId)]
|
|
13
|
+
: undefined) ?? constraint.foreignClass;
|
|
14
|
+
if (!foreignTable || omit(foreignTable, 'read')) {
|
|
15
|
+
return memo;
|
|
16
|
+
}
|
|
17
|
+
const keys = constraint.keyAttributes;
|
|
18
|
+
const foreignKeys = constraint.foreignKeyAttributes;
|
|
19
|
+
if (keys.some((key) => omit(key, 'read')) || foreignKeys.some((key) => omit(key, 'read'))) {
|
|
20
|
+
return memo;
|
|
21
|
+
}
|
|
22
|
+
const isUnique = table.constraints.some((c) => (c.type === 'p' || c.type === 'u') &&
|
|
23
|
+
c.keyAttributeNums.length === keys.length &&
|
|
24
|
+
c.keyAttributeNums.every((n, i) => keys[i].num === n));
|
|
25
|
+
const fieldName = inflection.singleRelationByKeys(keys, foreignTable, table, constraint);
|
|
26
|
+
return [
|
|
27
|
+
...memo,
|
|
28
|
+
{
|
|
29
|
+
references: foreignTable,
|
|
30
|
+
isUnique,
|
|
31
|
+
fieldName,
|
|
32
|
+
keys
|
|
33
|
+
}
|
|
34
|
+
];
|
|
35
|
+
}, []);
|
|
36
|
+
};
|
|
37
|
+
exports.default = getBelongsToRelations;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const getBelongsToRelations = (table, build) => {
|
|
2
|
+
const { pgIntrospectionResultsByKind: introspectionResultsByKind, inflection, pgOmit: omit } = build;
|
|
3
|
+
return table.constraints
|
|
4
|
+
.filter((constraint) => constraint.type === 'f')
|
|
5
|
+
.reduce((memo, constraint) => {
|
|
6
|
+
if (omit(constraint, 'read')) {
|
|
7
|
+
return memo;
|
|
8
|
+
}
|
|
9
|
+
const foreignTable = (constraint.foreignClassId !== undefined
|
|
10
|
+
? introspectionResultsByKind.classById[String(constraint.foreignClassId)]
|
|
11
|
+
: undefined) ?? constraint.foreignClass;
|
|
12
|
+
if (!foreignTable || omit(foreignTable, 'read')) {
|
|
13
|
+
return memo;
|
|
14
|
+
}
|
|
15
|
+
const keys = constraint.keyAttributes;
|
|
16
|
+
const foreignKeys = constraint.foreignKeyAttributes;
|
|
17
|
+
if (keys.some((key) => omit(key, 'read')) || foreignKeys.some((key) => omit(key, 'read'))) {
|
|
18
|
+
return memo;
|
|
19
|
+
}
|
|
20
|
+
const isUnique = table.constraints.some((c) => (c.type === 'p' || c.type === 'u') &&
|
|
21
|
+
c.keyAttributeNums.length === keys.length &&
|
|
22
|
+
c.keyAttributeNums.every((n, i) => keys[i].num === n));
|
|
23
|
+
const fieldName = inflection.singleRelationByKeys(keys, foreignTable, table, constraint);
|
|
24
|
+
return [
|
|
25
|
+
...memo,
|
|
26
|
+
{
|
|
27
|
+
references: foreignTable,
|
|
28
|
+
isUnique,
|
|
29
|
+
fieldName,
|
|
30
|
+
keys
|
|
31
|
+
}
|
|
32
|
+
];
|
|
33
|
+
}, []);
|
|
34
|
+
};
|
|
35
|
+
export default getBelongsToRelations;
|
package/esm/has.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const getHasRelations = (foreignTable, build) => {
|
|
2
|
+
const { pgIntrospectionResultsByKind: introspectionResultsByKind, inflection, pgOmit: omit } = build;
|
|
3
|
+
return foreignTable.foreignConstraints
|
|
4
|
+
.filter((constraint) => constraint.type === 'f')
|
|
5
|
+
.reduce((memo, constraint) => {
|
|
6
|
+
if (omit(constraint, 'read')) {
|
|
7
|
+
return memo;
|
|
8
|
+
}
|
|
9
|
+
const table = introspectionResultsByKind.classById[String(constraint.classId)] ?? constraint.foreignClass;
|
|
10
|
+
if (!table || omit(table, 'read')) {
|
|
11
|
+
return memo;
|
|
12
|
+
}
|
|
13
|
+
const keys = constraint.keyAttributes;
|
|
14
|
+
const foreignKeys = constraint.foreignKeyAttributes;
|
|
15
|
+
if (keys.some((key) => omit(key, 'read')) || foreignKeys.some((key) => omit(key, 'read'))) {
|
|
16
|
+
return memo;
|
|
17
|
+
}
|
|
18
|
+
const isUnique = table.constraints.some((c) => (c.type === 'p' || c.type === 'u') &&
|
|
19
|
+
c.keyAttributeNums.length === keys.length &&
|
|
20
|
+
c.keyAttributeNums.every((n, i) => keys[i].num === n));
|
|
21
|
+
const fieldName = isUnique
|
|
22
|
+
? inflection.singleRelationByKeysBackwards(keys, table, foreignTable, constraint)
|
|
23
|
+
: inflection.manyRelationByKeys(keys, table, foreignTable, constraint);
|
|
24
|
+
return [
|
|
25
|
+
...memo,
|
|
26
|
+
{
|
|
27
|
+
referencedBy: table,
|
|
28
|
+
isUnique,
|
|
29
|
+
fieldName,
|
|
30
|
+
type: isUnique ? 'hasOne' : 'hasMany',
|
|
31
|
+
keys
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
}, []);
|
|
35
|
+
};
|
|
36
|
+
export default getHasRelations;
|