graphile-simple-inflector 0.1.3 → 0.1.5
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 +89 -1
- package/esm/index.js +329 -0
- package/index.d.ts +13 -0
- package/package.json +9 -15
package/README.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# graphile-simple-inflector
|
|
2
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
|
+
|
|
3
14
|
Simplified naming inflector for Graphile/PostGraphile. It shortens common field names (e.g. `tableByNodeId` → `table`) and makes pluralization behave more predictably for numeric suffixes.
|
|
4
15
|
|
|
5
16
|
## Install
|
|
@@ -31,4 +42,81 @@ psql -U postgres -f sql/roles.sql postgres
|
|
|
31
42
|
pnpm test --filter graphile-simple-inflector
|
|
32
43
|
```
|
|
33
44
|
|
|
34
|
-
The included SQL under `sql/` matches the original package
|
|
45
|
+
The included SQL under `sql/` matches the original package's fixtures.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Education and Tutorials
|
|
50
|
+
|
|
51
|
+
1. 🚀 [Quickstart: Getting Up and Running](https://launchql.com/learn/quickstart)
|
|
52
|
+
Get started with modular databases in minutes. Install prerequisites and deploy your first module.
|
|
53
|
+
|
|
54
|
+
2. 📦 [Modular PostgreSQL Development with Database Packages](https://launchql.com/learn/modular-postgres)
|
|
55
|
+
Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
|
|
56
|
+
|
|
57
|
+
3. ✏️ [Authoring Database Changes](https://launchql.com/learn/authoring-database-changes)
|
|
58
|
+
Master the workflow for adding, organizing, and managing database changes with pgpm.
|
|
59
|
+
|
|
60
|
+
4. 🧪 [End-to-End PostgreSQL Testing with TypeScript](https://launchql.com/learn/e2e-postgres-testing)
|
|
61
|
+
Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
|
|
62
|
+
|
|
63
|
+
5. ⚡ [Supabase Testing](https://launchql.com/learn/supabase)
|
|
64
|
+
Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.
|
|
65
|
+
|
|
66
|
+
6. 💧 [Drizzle ORM Testing](https://launchql.com/learn/drizzle-testing)
|
|
67
|
+
Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.
|
|
68
|
+
|
|
69
|
+
7. 🔧 [Troubleshooting](https://launchql.com/learn/troubleshooting)
|
|
70
|
+
Common issues and solutions for pgpm, PostgreSQL, and testing.
|
|
71
|
+
|
|
72
|
+
## Related LaunchQL Tooling
|
|
73
|
+
|
|
74
|
+
### 🧪 Testing
|
|
75
|
+
|
|
76
|
+
* [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.
|
|
77
|
+
* [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.
|
|
78
|
+
* [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.
|
|
79
|
+
* [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.
|
|
80
|
+
|
|
81
|
+
### 🧠 Parsing & AST
|
|
82
|
+
|
|
83
|
+
* [launchql/pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
|
|
84
|
+
* [launchql/libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
|
|
85
|
+
* [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.
|
|
86
|
+
* [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
|
|
87
|
+
* [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
|
|
88
|
+
* [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
|
|
89
|
+
* [launchql/pg-ast](https://github.com/launchql/launchql/tree/main/packages/pg-ast): **🔍 Low-level AST tools** and transformations for Postgres query structures.
|
|
90
|
+
|
|
91
|
+
### 🚀 API & Dev Tools
|
|
92
|
+
|
|
93
|
+
* [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.
|
|
94
|
+
* [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.
|
|
95
|
+
|
|
96
|
+
### 🔁 Streaming & Uploads
|
|
97
|
+
|
|
98
|
+
* [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.
|
|
99
|
+
* [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.
|
|
100
|
+
* [launchql/etag-stream](https://github.com/launchql/launchql/tree/main/packages/etag-stream): **🔄 ETag computation** via Node stream transformer during upload or transfer.
|
|
101
|
+
* [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.
|
|
102
|
+
* [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.
|
|
103
|
+
* [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.
|
|
104
|
+
|
|
105
|
+
### 🧰 CLI & Codegen
|
|
106
|
+
|
|
107
|
+
* [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.
|
|
108
|
+
* [@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.
|
|
109
|
+
* [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.
|
|
110
|
+
* [@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.
|
|
111
|
+
* [@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.
|
|
112
|
+
|
|
113
|
+
## Credits
|
|
114
|
+
|
|
115
|
+
🛠 Built by LaunchQL — if you like our tools, please checkout and contribute to [our github ⚛️](https://github.com/launchql)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
## Disclaimer
|
|
119
|
+
|
|
120
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
121
|
+
|
|
122
|
+
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/esm/index.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
const fixCapitalisedPlural = (fn) => function capitalisedPlural(str) {
|
|
2
|
+
const original = fn.call(this, str);
|
|
3
|
+
return original.replace(/[0-9]S(?=[A-Z]|$)/g, (match) => match.toLowerCase());
|
|
4
|
+
};
|
|
5
|
+
const fixChangePlural = (fn) => function changePlural(str) {
|
|
6
|
+
const matches = str.match(/([A-Z]|_[a-z0-9])[a-z0-9]*_*$/);
|
|
7
|
+
const index = matches ? (matches.index ?? 0) + matches[1].length - 1 : 0;
|
|
8
|
+
const suffixMatches = str.match(/_*$/);
|
|
9
|
+
const suffixIndex = suffixMatches && suffixMatches.index !== undefined ? suffixMatches.index : str.length;
|
|
10
|
+
const prefix = str.slice(0, index);
|
|
11
|
+
const word = str.slice(index, suffixIndex);
|
|
12
|
+
const suffix = str.slice(suffixIndex);
|
|
13
|
+
return `${prefix}${fn.call(this, word)}${suffix}`;
|
|
14
|
+
};
|
|
15
|
+
const DEFAULT_NODE_ID = 'nodeId';
|
|
16
|
+
export const PgSimpleInflector = (builder, { pgSimpleCollections, pgOmitListSuffix, pgSimplifyPatch = true, pgSimplifyAllRows = true, pgShortPk = true, pgSimplifyMultikeyRelations = true, pgSimplifyOppositeBaseNames = true, nodeIdFieldName = DEFAULT_NODE_ID, } = {}) => {
|
|
17
|
+
const hasConnections = pgSimpleCollections !== 'only';
|
|
18
|
+
const hasSimpleCollections = pgSimpleCollections === 'only' || pgSimpleCollections === 'both';
|
|
19
|
+
if (hasSimpleCollections &&
|
|
20
|
+
!hasConnections &&
|
|
21
|
+
pgOmitListSuffix !== true &&
|
|
22
|
+
pgOmitListSuffix !== false) {
|
|
23
|
+
// eslint-disable-next-line no-console
|
|
24
|
+
console.warn('You can simplify the inflector further by adding `{graphileBuildOptions: {pgOmitListSuffix: true}}` to the options passed to PostGraphile, however be aware that doing so will mean that later enabling relay connections will be a breaking change. To dismiss this message, set `pgOmitListSuffix` to false instead.');
|
|
25
|
+
}
|
|
26
|
+
const connectionSuffix = pgOmitListSuffix ? '-connection' : '';
|
|
27
|
+
const ConnectionSuffix = pgOmitListSuffix ? 'Connection' : '';
|
|
28
|
+
const listSuffix = pgOmitListSuffix ? '' : '-list';
|
|
29
|
+
const ListSuffix = pgOmitListSuffix ? '' : 'List';
|
|
30
|
+
builder.hook('inflection', (oldInflection) => {
|
|
31
|
+
const inflection = {
|
|
32
|
+
...oldInflection,
|
|
33
|
+
/*
|
|
34
|
+
* This solves the issue with `blah-table1s` becoming `blahTable1S`
|
|
35
|
+
* (i.e. the capital S at the end) or `table1-connection becoming `Table1SConnection`
|
|
36
|
+
*/
|
|
37
|
+
camelCase: fixCapitalisedPlural(oldInflection.camelCase),
|
|
38
|
+
upperCamelCase: fixCapitalisedPlural(oldInflection.upperCamelCase),
|
|
39
|
+
/*
|
|
40
|
+
* Pluralize/singularize only supports single words, so only run
|
|
41
|
+
* on the final segment of a name.
|
|
42
|
+
*/
|
|
43
|
+
pluralize: fixChangePlural(oldInflection.pluralize),
|
|
44
|
+
singularize: fixChangePlural(oldInflection.singularize),
|
|
45
|
+
distinctPluralize(str) {
|
|
46
|
+
const singular = this.singularize(str);
|
|
47
|
+
const plural = this.pluralize(singular);
|
|
48
|
+
if (singular !== plural) {
|
|
49
|
+
return plural;
|
|
50
|
+
}
|
|
51
|
+
if (plural.endsWith('ch') ||
|
|
52
|
+
plural.endsWith('s') ||
|
|
53
|
+
plural.endsWith('sh') ||
|
|
54
|
+
plural.endsWith('x') ||
|
|
55
|
+
plural.endsWith('z')) {
|
|
56
|
+
return `${plural}es`;
|
|
57
|
+
}
|
|
58
|
+
else if (plural.endsWith('y')) {
|
|
59
|
+
return `${plural.slice(0, -1)}ies`;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return `${plural}s`;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
// Fix a naming bug
|
|
66
|
+
deletedNodeId(table) {
|
|
67
|
+
return this.camelCase(`deleted-${this.singularize(table.name)}-${nodeIdFieldName}`);
|
|
68
|
+
},
|
|
69
|
+
getBaseName(columnName) {
|
|
70
|
+
const matches = columnName.match(/^(.+?)(_row_id|_id|_uuid|_fk|_pk|RowId|Id|Uuid|UUID|Fk|Pk)$/);
|
|
71
|
+
if (matches) {
|
|
72
|
+
return matches[1];
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
},
|
|
76
|
+
baseNameMatches(baseName, otherName) {
|
|
77
|
+
const singularizedName = this.singularize(otherName);
|
|
78
|
+
return baseName === singularizedName;
|
|
79
|
+
},
|
|
80
|
+
baseNameMatchesAny(baseName, otherName) {
|
|
81
|
+
if (!baseName)
|
|
82
|
+
return false;
|
|
83
|
+
return this.singularize(baseName) === this.singularize(otherName);
|
|
84
|
+
},
|
|
85
|
+
/* This is a good method to override. */
|
|
86
|
+
getOppositeBaseName(baseName) {
|
|
87
|
+
return (pgSimplifyOppositeBaseNames &&
|
|
88
|
+
({
|
|
89
|
+
/*
|
|
90
|
+
* Changes to this list are breaking changes and will require a
|
|
91
|
+
* major version update, so we need to group as many together as
|
|
92
|
+
* possible! Rather than sending a PR, please look for an open
|
|
93
|
+
* issue called something like "Add more opposites" (if there isn't
|
|
94
|
+
* one then please open it) and add your suggestions to the GitHub
|
|
95
|
+
* comments.
|
|
96
|
+
*/
|
|
97
|
+
// NOTE: reason to be careful using this:
|
|
98
|
+
// field names to take into account this particular case (e.g. events with event.parent_id could not have parent OR child fields)
|
|
99
|
+
inviter: 'invitee',
|
|
100
|
+
parent: 'child',
|
|
101
|
+
child: 'parent',
|
|
102
|
+
owner: 'owned',
|
|
103
|
+
author: 'authored',
|
|
104
|
+
editor: 'edited',
|
|
105
|
+
reviewer: 'reviewed',
|
|
106
|
+
}[baseName ?? ''] || null));
|
|
107
|
+
},
|
|
108
|
+
getBaseNameFromKeys(detailedKeys) {
|
|
109
|
+
if (detailedKeys.length === 1) {
|
|
110
|
+
const key = detailedKeys[0];
|
|
111
|
+
const columnName = this._columnName(key);
|
|
112
|
+
return this.getBaseName?.(columnName) ?? null;
|
|
113
|
+
}
|
|
114
|
+
if (pgSimplifyMultikeyRelations) {
|
|
115
|
+
const columnNames = detailedKeys.map((key) => this._columnName(key));
|
|
116
|
+
const baseNames = columnNames.map((columnName) => this.getBaseName?.(columnName) ?? null);
|
|
117
|
+
// Check none are null
|
|
118
|
+
if (baseNames.every((n) => n)) {
|
|
119
|
+
return baseNames.join('-');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
},
|
|
124
|
+
...(pgSimplifyPatch
|
|
125
|
+
? {
|
|
126
|
+
patchField() {
|
|
127
|
+
return 'patch';
|
|
128
|
+
},
|
|
129
|
+
}
|
|
130
|
+
: {}),
|
|
131
|
+
...(pgSimplifyAllRows
|
|
132
|
+
? {
|
|
133
|
+
allRows(table) {
|
|
134
|
+
return this.camelCase(this.distinctPluralize(this._singularizedTableName(table)) + connectionSuffix);
|
|
135
|
+
},
|
|
136
|
+
allRowsSimple(table) {
|
|
137
|
+
return this.camelCase(this.distinctPluralize(this._singularizedTableName(table)) + listSuffix);
|
|
138
|
+
},
|
|
139
|
+
}
|
|
140
|
+
: {}),
|
|
141
|
+
computedColumn(pseudoColumnName, proc) {
|
|
142
|
+
return proc.tags.fieldName
|
|
143
|
+
? `${proc.tags.fieldName}${proc.returnsSet ? ConnectionSuffix : ''}`
|
|
144
|
+
: this.camelCase(pseudoColumnName + (proc.returnsSet ? connectionSuffix : ''));
|
|
145
|
+
},
|
|
146
|
+
computedColumnList(pseudoColumnName, proc) {
|
|
147
|
+
return proc.tags.fieldName
|
|
148
|
+
? `${proc.tags.fieldName}${ListSuffix}`
|
|
149
|
+
: this.camelCase(pseudoColumnName + listSuffix);
|
|
150
|
+
},
|
|
151
|
+
singleRelationByKeys(detailedKeys, table, _foreignTable, constraint) {
|
|
152
|
+
if (constraint.tags.fieldName) {
|
|
153
|
+
return constraint.tags.fieldName;
|
|
154
|
+
}
|
|
155
|
+
const baseName = this.getBaseNameFromKeys(detailedKeys);
|
|
156
|
+
if (constraint.classId === constraint.foreignClassId) {
|
|
157
|
+
if (baseName && this.baseNameMatchesAny?.(baseName, table.name)) {
|
|
158
|
+
return oldInflection.singleRelationByKeys(detailedKeys, table, _foreignTable, constraint);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (baseName) {
|
|
162
|
+
return this.camelCase(baseName);
|
|
163
|
+
}
|
|
164
|
+
if (this.baseNameMatches?.(baseName, table.name)) {
|
|
165
|
+
return this.camelCase(`${this._singularizedTableName(table)}`);
|
|
166
|
+
}
|
|
167
|
+
return oldInflection.singleRelationByKeys(detailedKeys, table, _foreignTable, constraint);
|
|
168
|
+
},
|
|
169
|
+
singleRelationByKeysBackwards(detailedKeys, table, foreignTable, constraint) {
|
|
170
|
+
if (constraint.tags.foreignSingleFieldName) {
|
|
171
|
+
return constraint.tags.foreignSingleFieldName;
|
|
172
|
+
}
|
|
173
|
+
if (constraint.tags.foreignFieldName) {
|
|
174
|
+
return constraint.tags.foreignFieldName;
|
|
175
|
+
}
|
|
176
|
+
const baseName = this.getBaseNameFromKeys(detailedKeys);
|
|
177
|
+
const oppositeBaseName = baseName && this.getOppositeBaseName?.(baseName);
|
|
178
|
+
if (oppositeBaseName) {
|
|
179
|
+
return this.camelCase(`${oppositeBaseName}-${this._singularizedTableName(table)}`);
|
|
180
|
+
}
|
|
181
|
+
if (baseName && this.baseNameMatches?.(baseName, foreignTable.name)) {
|
|
182
|
+
return this.camelCase(`${this._singularizedTableName(table)}`);
|
|
183
|
+
}
|
|
184
|
+
return oldInflection.singleRelationByKeysBackwards(detailedKeys, table, foreignTable, constraint);
|
|
185
|
+
},
|
|
186
|
+
_manyRelationByKeysBase(detailedKeys, table, foreignTable, constraint) {
|
|
187
|
+
const baseName = this.getBaseNameFromKeys(detailedKeys);
|
|
188
|
+
const oppositeBaseName = baseName && this.getOppositeBaseName?.(baseName);
|
|
189
|
+
if (constraint.classId === constraint.foreignClassId) {
|
|
190
|
+
if (baseName && this.baseNameMatches?.(baseName, table.name)) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (oppositeBaseName) {
|
|
195
|
+
return this.camelCase(`${oppositeBaseName}-${this.distinctPluralize(this._singularizedTableName(table))}`);
|
|
196
|
+
}
|
|
197
|
+
if (baseName && this.baseNameMatches?.(baseName, foreignTable.name)) {
|
|
198
|
+
return this.camelCase(`${this.distinctPluralize(this._singularizedTableName(table))}`);
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
},
|
|
202
|
+
manyRelationByKeys(detailedKeys, table, foreignTable, constraint) {
|
|
203
|
+
if (constraint.tags.foreignFieldName) {
|
|
204
|
+
if (constraint.tags.foreignSimpleFieldName) {
|
|
205
|
+
return constraint.tags.foreignFieldName;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
return `${constraint.tags.foreignFieldName}${ConnectionSuffix}`;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const base = this._manyRelationByKeysBase?.(detailedKeys, table, foreignTable, constraint);
|
|
212
|
+
if (base) {
|
|
213
|
+
return base + ConnectionSuffix;
|
|
214
|
+
}
|
|
215
|
+
return (oldInflection.manyRelationByKeys(detailedKeys, table, foreignTable, constraint) + ConnectionSuffix);
|
|
216
|
+
},
|
|
217
|
+
manyRelationByKeysSimple(detailedKeys, table, foreignTable, constraint) {
|
|
218
|
+
if (constraint.tags.foreignSimpleFieldName) {
|
|
219
|
+
return constraint.tags.foreignSimpleFieldName;
|
|
220
|
+
}
|
|
221
|
+
if (constraint.tags.foreignFieldName) {
|
|
222
|
+
return `${constraint.tags.foreignFieldName}${ListSuffix}`;
|
|
223
|
+
}
|
|
224
|
+
const base = this._manyRelationByKeysBase?.(detailedKeys, table, foreignTable, constraint);
|
|
225
|
+
if (base) {
|
|
226
|
+
return base + ListSuffix;
|
|
227
|
+
}
|
|
228
|
+
return (oldInflection.manyRelationByKeys(detailedKeys, table, foreignTable, constraint) + ListSuffix);
|
|
229
|
+
},
|
|
230
|
+
functionQueryName(proc) {
|
|
231
|
+
return this.camelCase(this._functionName(proc) + (proc.returnsSet ? connectionSuffix : ''));
|
|
232
|
+
},
|
|
233
|
+
functionQueryNameList(proc) {
|
|
234
|
+
return this.camelCase(this._functionName(proc) + listSuffix);
|
|
235
|
+
},
|
|
236
|
+
...(pgShortPk
|
|
237
|
+
? {
|
|
238
|
+
tableNode(table) {
|
|
239
|
+
return this.camelCase(`${this._singularizedTableName(table)}-by-${nodeIdFieldName}`);
|
|
240
|
+
},
|
|
241
|
+
rowByUniqueKeys(detailedKeys, table, constraint) {
|
|
242
|
+
if (constraint.tags.fieldName) {
|
|
243
|
+
return constraint.tags.fieldName;
|
|
244
|
+
}
|
|
245
|
+
if (constraint.type === 'p') {
|
|
246
|
+
// Primary key, shorten!
|
|
247
|
+
return this.camelCase(this._singularizedTableName(table));
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
return this.camelCase(`${this._singularizedTableName(table)}-by-${detailedKeys
|
|
251
|
+
.map((key) => this.column(key))
|
|
252
|
+
.join('-and-')}`);
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
updateByKeys(detailedKeys, table, constraint) {
|
|
256
|
+
if (constraint.tags.updateFieldName) {
|
|
257
|
+
return constraint.tags.updateFieldName;
|
|
258
|
+
}
|
|
259
|
+
if (constraint.type === 'p') {
|
|
260
|
+
// Primary key, shorten!
|
|
261
|
+
return this.camelCase(`update-${this._singularizedTableName(table)}`);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
return this.camelCase(`update-${this._singularizedTableName(table)}-by-${detailedKeys
|
|
265
|
+
.map((key) => this.column(key))
|
|
266
|
+
.join('-and-')}`);
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
deleteByKeys(detailedKeys, table, constraint) {
|
|
270
|
+
if (constraint.tags.deleteFieldName) {
|
|
271
|
+
return constraint.tags.deleteFieldName;
|
|
272
|
+
}
|
|
273
|
+
if (constraint.type === 'p') {
|
|
274
|
+
// Primary key, shorten!
|
|
275
|
+
return this.camelCase(`delete-${this._singularizedTableName(table)}`);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
return this.camelCase(`delete-${this._singularizedTableName(table)}-by-${detailedKeys
|
|
279
|
+
.map((key) => this.column(key))
|
|
280
|
+
.join('-and-')}`);
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
updateByKeysInputType(detailedKeys, table, constraint) {
|
|
284
|
+
if (constraint.tags.updateFieldName) {
|
|
285
|
+
return this.upperCamelCase(`${constraint.tags.updateFieldName}-input`);
|
|
286
|
+
}
|
|
287
|
+
if (constraint.type === 'p') {
|
|
288
|
+
// Primary key, shorten!
|
|
289
|
+
return this.upperCamelCase(`update-${this._singularizedTableName(table)}-input`);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
return this.upperCamelCase(`update-${this._singularizedTableName(table)}-by-${detailedKeys
|
|
293
|
+
.map((key) => this.column(key))
|
|
294
|
+
.join('-and-')}-input`);
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
deleteByKeysInputType(detailedKeys, table, constraint) {
|
|
298
|
+
if (constraint.tags.deleteFieldName) {
|
|
299
|
+
return this.upperCamelCase(`${constraint.tags.deleteFieldName}-input`);
|
|
300
|
+
}
|
|
301
|
+
if (constraint.type === 'p') {
|
|
302
|
+
// Primary key, shorten!
|
|
303
|
+
return this.upperCamelCase(`delete-${this._singularizedTableName(table)}-input`);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
return this.upperCamelCase(`delete-${this._singularizedTableName(table)}-by-${detailedKeys
|
|
307
|
+
.map((key) => this.column(key))
|
|
308
|
+
.join('-and-')}-input`);
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
updateNode(table) {
|
|
312
|
+
return this.camelCase(`update-${this._singularizedTableName(table)}-by-${nodeIdFieldName}`);
|
|
313
|
+
},
|
|
314
|
+
deleteNode(table) {
|
|
315
|
+
return this.camelCase(`delete-${this._singularizedTableName(table)}-by-${nodeIdFieldName}`);
|
|
316
|
+
},
|
|
317
|
+
updateNodeInputType(table) {
|
|
318
|
+
return this.upperCamelCase(`update-${this._singularizedTableName(table)}-by-${nodeIdFieldName}-input`);
|
|
319
|
+
},
|
|
320
|
+
deleteNodeInputType(table) {
|
|
321
|
+
return this.upperCamelCase(`delete-${this._singularizedTableName(table)}-by-${nodeIdFieldName}-input`);
|
|
322
|
+
},
|
|
323
|
+
}
|
|
324
|
+
: {}),
|
|
325
|
+
};
|
|
326
|
+
return inflection;
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
export default PgSimpleInflector;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Plugin } from 'graphile-build';
|
|
2
|
+
export interface PgSimpleInflectorOptions {
|
|
3
|
+
pgSimpleCollections?: 'only' | 'both';
|
|
4
|
+
pgOmitListSuffix?: boolean;
|
|
5
|
+
pgSimplifyPatch?: boolean;
|
|
6
|
+
pgSimplifyAllRows?: boolean;
|
|
7
|
+
pgShortPk?: boolean;
|
|
8
|
+
pgSimplifyMultikeyRelations?: boolean;
|
|
9
|
+
pgSimplifyOppositeBaseNames?: boolean;
|
|
10
|
+
nodeIdFieldName?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const PgSimpleInflector: Plugin;
|
|
13
|
+
export default PgSimpleInflector;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-simple-inflector",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Simple inflector plugin for Graphile/PostGraphile",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/launchql/launchql",
|
|
@@ -8,19 +8,12 @@
|
|
|
8
8
|
"main": "index.js",
|
|
9
9
|
"module": "esm/index.js",
|
|
10
10
|
"types": "index.d.ts",
|
|
11
|
-
"directories": {
|
|
12
|
-
"lib": "src",
|
|
13
|
-
"test": "__tests__"
|
|
14
|
-
},
|
|
15
|
-
"files": [
|
|
16
|
-
"dist"
|
|
17
|
-
],
|
|
18
11
|
"scripts": {
|
|
19
|
-
"
|
|
20
|
-
"
|
|
12
|
+
"clean": "makage clean",
|
|
13
|
+
"copy": "makage assets",
|
|
21
14
|
"prepack": "npm run build",
|
|
22
|
-
"build": "
|
|
23
|
-
"build:dev": "
|
|
15
|
+
"build": "makage build",
|
|
16
|
+
"build:dev": "makage build --dev",
|
|
24
17
|
"lint": "eslint . --fix",
|
|
25
18
|
"test": "jest",
|
|
26
19
|
"test:watch": "jest --watch"
|
|
@@ -46,12 +39,13 @@
|
|
|
46
39
|
"url": "https://github.com/launchql/launchql/issues"
|
|
47
40
|
},
|
|
48
41
|
"devDependencies": {
|
|
49
|
-
"graphile-test": "^2.8.
|
|
42
|
+
"graphile-test": "^2.8.6",
|
|
50
43
|
"graphql-tag": "2.12.6",
|
|
51
|
-
"
|
|
44
|
+
"makage": "^0.1.6",
|
|
45
|
+
"pgsql-test": "^2.14.9"
|
|
52
46
|
},
|
|
53
47
|
"dependencies": {
|
|
54
48
|
"graphile-build": "^4.14.1"
|
|
55
49
|
},
|
|
56
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "1da5f98bd18b47382b652e104cdc4db1b9ee79db"
|
|
57
51
|
}
|