@constructive-io/graphql-codegen 2.23.0 → 2.23.2
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/cli/codegen/orm/input-types-generator.js +2 -2
- package/cli/codegen/utils.js +4 -4
- package/cli/introspect/index.d.ts +1 -1
- package/cli/introspect/index.js +4 -4
- package/cli/introspect/infer-tables.js +15 -15
- package/core/ast.js +4 -4
- package/core/query-builder.js +12 -12
- package/esm/cli/codegen/orm/input-types-generator.js +1 -1
- package/esm/cli/codegen/utils.js +1 -1
- package/esm/cli/introspect/index.d.ts +1 -1
- package/esm/cli/introspect/index.js +2 -2
- package/esm/cli/introspect/infer-tables.js +1 -1
- package/esm/core/ast.js +4 -4
- package/esm/core/query-builder.js +12 -12
- package/esm/generators/mutations.js +3 -3
- package/esm/generators/select.js +7 -7
- package/generators/mutations.js +3 -3
- package/generators/select.js +7 -7
- package/package.json +3 -3
- package/cli/introspect/pluralize.d.ts +0 -30
- package/cli/introspect/pluralize.js +0 -124
- package/esm/cli/introspect/pluralize.d.ts +0 -30
- package/esm/cli/introspect/pluralize.js +0 -83
|
@@ -5,7 +5,7 @@ exports.collectPayloadTypeNames = collectPayloadTypeNames;
|
|
|
5
5
|
exports.generateInputTypesFile = generateInputTypesFile;
|
|
6
6
|
const ts_ast_1 = require("../ts-ast");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
|
-
const
|
|
8
|
+
const inflekt_1 = require("inflekt");
|
|
9
9
|
const type_resolver_1 = require("../type-resolver");
|
|
10
10
|
const scalars_1 = require("../scalars");
|
|
11
11
|
// ============================================================================
|
|
@@ -283,7 +283,7 @@ function getRelatedOrderByName(tableName, tableByName) {
|
|
|
283
283
|
if (tableName.endsWith('ManyToMany')) {
|
|
284
284
|
return `${tableName}OrderBy`;
|
|
285
285
|
}
|
|
286
|
-
return `${(0,
|
|
286
|
+
return `${(0, inflekt_1.pluralize)(tableName)}OrderBy`;
|
|
287
287
|
}
|
|
288
288
|
function getRelatedFilterName(tableName, tableByName) {
|
|
289
289
|
const relatedTable = tableByName.get(tableName);
|
package/cli/codegen/utils.js
CHANGED
|
@@ -39,7 +39,7 @@ exports.getQueryKeyPrefix = getQueryKeyPrefix;
|
|
|
39
39
|
exports.getGeneratedFileHeader = getGeneratedFileHeader;
|
|
40
40
|
exports.indent = indent;
|
|
41
41
|
const scalars_1 = require("./scalars");
|
|
42
|
-
const
|
|
42
|
+
const inflekt_1 = require("inflekt");
|
|
43
43
|
// ============================================================================
|
|
44
44
|
// String manipulation
|
|
45
45
|
// ============================================================================
|
|
@@ -79,7 +79,7 @@ function getTableNames(table) {
|
|
|
79
79
|
const singularName = table.inflection?.tableFieldName || lcFirst(typeName);
|
|
80
80
|
const pluralName = table.query?.all ||
|
|
81
81
|
table.inflection?.allRows ||
|
|
82
|
-
lcFirst((0,
|
|
82
|
+
lcFirst((0, inflekt_1.pluralize)(typeName));
|
|
83
83
|
const pluralTypeName = ucFirst(pluralName);
|
|
84
84
|
return {
|
|
85
85
|
typeName,
|
|
@@ -170,7 +170,7 @@ function getDeleteMutationFileName(table) {
|
|
|
170
170
|
function getAllRowsQueryName(table) {
|
|
171
171
|
return (table.query?.all ||
|
|
172
172
|
table.inflection?.allRows ||
|
|
173
|
-
lcFirst((0,
|
|
173
|
+
lcFirst((0, inflekt_1.pluralize)(table.name)));
|
|
174
174
|
}
|
|
175
175
|
/**
|
|
176
176
|
* Get the GraphQL query name for fetching single row
|
|
@@ -211,7 +211,7 @@ function getFilterTypeName(table) {
|
|
|
211
211
|
* e.g., "CarsOrderBy", "AddressesOrderBy"
|
|
212
212
|
*/
|
|
213
213
|
function getOrderByTypeName(table) {
|
|
214
|
-
return table.inflection?.orderByType || `${(0,
|
|
214
|
+
return table.inflection?.orderByType || `${(0, inflekt_1.pluralize)(table.name)}OrderBy`;
|
|
215
215
|
}
|
|
216
216
|
/**
|
|
217
217
|
* Get PostGraphile Condition type name (simple equality filter)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { inferTablesFromIntrospection } from './infer-tables';
|
|
5
5
|
export type { InferTablesOptions } from './infer-tables';
|
|
6
|
-
export { singularize, pluralize } from '
|
|
6
|
+
export { singularize, pluralize } from 'inflekt';
|
|
7
7
|
export { createSchemaSource, validateSourceOptions, EndpointSchemaSource, FileSchemaSource, SchemaSourceError, } from './source';
|
|
8
8
|
export type { SchemaSource, SchemaSourceResult, CreateSchemaSourceOptions, } from './source';
|
|
9
9
|
export { fetchSchema } from './fetch-schema';
|
package/cli/introspect/index.js
CHANGED
|
@@ -7,10 +7,10 @@ exports.filterTables = exports.findTable = exports.getTableNames = exports.fetch
|
|
|
7
7
|
// Table inference from introspection
|
|
8
8
|
var infer_tables_1 = require("./infer-tables");
|
|
9
9
|
Object.defineProperty(exports, "inferTablesFromIntrospection", { enumerable: true, get: function () { return infer_tables_1.inferTablesFromIntrospection; } });
|
|
10
|
-
// Pluralization utilities
|
|
11
|
-
var
|
|
12
|
-
Object.defineProperty(exports, "singularize", { enumerable: true, get: function () { return
|
|
13
|
-
Object.defineProperty(exports, "pluralize", { enumerable: true, get: function () { return
|
|
10
|
+
// Pluralization utilities (from inflekt)
|
|
11
|
+
var inflekt_1 = require("inflekt");
|
|
12
|
+
Object.defineProperty(exports, "singularize", { enumerable: true, get: function () { return inflekt_1.singularize; } });
|
|
13
|
+
Object.defineProperty(exports, "pluralize", { enumerable: true, get: function () { return inflekt_1.pluralize; } });
|
|
14
14
|
// Schema sources
|
|
15
15
|
var source_1 = require("./source");
|
|
16
16
|
Object.defineProperty(exports, "createSchemaSource", { enumerable: true, get: function () { return source_1.createSchemaSource; } });
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.inferTablesFromIntrospection = inferTablesFromIntrospection;
|
|
4
4
|
const introspection_1 = require("../../types/introspection");
|
|
5
|
-
const
|
|
5
|
+
const inflekt_1 = require("inflekt");
|
|
6
6
|
// ============================================================================
|
|
7
7
|
// Pattern Matching Constants
|
|
8
8
|
// ============================================================================
|
|
@@ -115,7 +115,7 @@ function detectEntityTypes(types) {
|
|
|
115
115
|
const connectionMatch = type.name.match(PATTERNS.connection);
|
|
116
116
|
if (connectionMatch) {
|
|
117
117
|
const pluralName = connectionMatch[1]; // e.g., "Users" from "UsersConnection"
|
|
118
|
-
const singularName = (0,
|
|
118
|
+
const singularName = (0, inflekt_1.singularize)(pluralName); // e.g., "User"
|
|
119
119
|
// Verify the entity type actually exists
|
|
120
120
|
if (typeNames.has(singularName)) {
|
|
121
121
|
entityNames.add(singularName);
|
|
@@ -148,8 +148,8 @@ function buildCleanTable(entityName, entityType, typeMap, queryFields, mutationF
|
|
|
148
148
|
// Combine query operations with fallbacks for UI purposes
|
|
149
149
|
// (but hasRealOperation indicates if we should include this table)
|
|
150
150
|
const query = {
|
|
151
|
-
all: queryOps.all ?? (0,
|
|
152
|
-
one: queryOps.one ?? (0,
|
|
151
|
+
all: queryOps.all ?? (0, inflekt_1.lcFirst)((0, inflekt_1.pluralize)(entityName)),
|
|
152
|
+
one: queryOps.one ?? (0, inflekt_1.lcFirst)(entityName),
|
|
153
153
|
create: mutationOps.create ?? `create${entityName}`,
|
|
154
154
|
update: mutationOps.update,
|
|
155
155
|
delete: mutationOps.delete,
|
|
@@ -202,7 +202,7 @@ function extractEntityFields(entityType, typeMap) {
|
|
|
202
202
|
* Check if a type name is an entity type (has a corresponding Connection)
|
|
203
203
|
*/
|
|
204
204
|
function isEntityType(typeName, typeMap) {
|
|
205
|
-
const connectionName = `${(0,
|
|
205
|
+
const connectionName = `${(0, inflekt_1.pluralize)(typeName)}Connection`;
|
|
206
206
|
return typeMap.has(connectionName);
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
@@ -269,7 +269,7 @@ function inferHasManyOrManyToMany(field, connectionTypeName, typeMap) {
|
|
|
269
269
|
// Extract the related entity name from Connection type
|
|
270
270
|
const match = connectionTypeName.match(PATTERNS.connection);
|
|
271
271
|
const relatedPluralName = match ? match[1] : connectionTypeName;
|
|
272
|
-
const relatedEntityName = (0,
|
|
272
|
+
const relatedEntityName = (0, inflekt_1.singularize)(relatedPluralName);
|
|
273
273
|
// Check for manyToMany pattern in field name
|
|
274
274
|
const isManyToMany = field.name.includes('By') && field.name.includes('And');
|
|
275
275
|
if (isManyToMany) {
|
|
@@ -279,7 +279,7 @@ function inferHasManyOrManyToMany(field, connectionTypeName, typeMap) {
|
|
|
279
279
|
// e.g., "productsByOrderItemOrderIdAndProductId" → "products" → "Product"
|
|
280
280
|
const prefixMatch = field.name.match(/^([a-z]+)By/i);
|
|
281
281
|
const actualEntityName = prefixMatch
|
|
282
|
-
? (0,
|
|
282
|
+
? (0, inflekt_1.singularize)((0, inflekt_1.ucFirst)(prefixMatch[1]))
|
|
283
283
|
: relatedEntityName;
|
|
284
284
|
// Try to extract junction table from field name
|
|
285
285
|
// Pattern: {relatedEntities}By{JunctionTable}{Keys}
|
|
@@ -316,7 +316,7 @@ function inferHasManyOrManyToMany(field, connectionTypeName, typeMap) {
|
|
|
316
316
|
* - Single query: returns {EntityName} with id/nodeId arg (e.g., user → User)
|
|
317
317
|
*/
|
|
318
318
|
function matchQueryOperations(entityName, queryFields, typeMap) {
|
|
319
|
-
const pluralName = (0,
|
|
319
|
+
const pluralName = (0, inflekt_1.pluralize)(entityName);
|
|
320
320
|
const connectionTypeName = `${pluralName}Connection`;
|
|
321
321
|
let all = null;
|
|
322
322
|
let one = null;
|
|
@@ -327,7 +327,7 @@ function matchQueryOperations(entityName, queryFields, typeMap) {
|
|
|
327
327
|
// Match list query by return type (Connection)
|
|
328
328
|
if (returnTypeName === connectionTypeName) {
|
|
329
329
|
// Prefer the simple plural name, but accept any that returns the connection
|
|
330
|
-
if (!all || field.name === (0,
|
|
330
|
+
if (!all || field.name === (0, inflekt_1.lcFirst)(pluralName)) {
|
|
331
331
|
all = field.name;
|
|
332
332
|
}
|
|
333
333
|
}
|
|
@@ -338,7 +338,7 @@ function matchQueryOperations(entityName, queryFields, typeMap) {
|
|
|
338
338
|
arg.name.toLowerCase().endsWith('id'));
|
|
339
339
|
if (hasIdArg) {
|
|
340
340
|
// Prefer exact match (e.g., "user" for "User")
|
|
341
|
-
if (!one || field.name === (0,
|
|
341
|
+
if (!one || field.name === (0, inflekt_1.lcFirst)(entityName)) {
|
|
342
342
|
one = field.name;
|
|
343
343
|
}
|
|
344
344
|
}
|
|
@@ -448,9 +448,9 @@ function inferConstraints(entityName, typeMap) {
|
|
|
448
448
|
* Build inflection map from discovered types
|
|
449
449
|
*/
|
|
450
450
|
function buildInflection(entityName, typeMap) {
|
|
451
|
-
const pluralName = (0,
|
|
452
|
-
const singularFieldName = (0,
|
|
453
|
-
const pluralFieldName = (0,
|
|
451
|
+
const pluralName = (0, inflekt_1.pluralize)(entityName);
|
|
452
|
+
const singularFieldName = (0, inflekt_1.lcFirst)(entityName);
|
|
453
|
+
const pluralFieldName = (0, inflekt_1.lcFirst)(pluralName);
|
|
454
454
|
// Check which types actually exist in the schema
|
|
455
455
|
const hasFilter = typeMap.has(`${entityName}Filter`);
|
|
456
456
|
const hasPatch = typeMap.has(`${entityName}Patch`);
|
|
@@ -471,7 +471,7 @@ function buildInflection(entityName, typeMap) {
|
|
|
471
471
|
deleteByPrimaryKey: `delete${entityName}`,
|
|
472
472
|
deletePayloadType: `Delete${entityName}Payload`,
|
|
473
473
|
edge: `${pluralName}Edge`,
|
|
474
|
-
edgeField: (0,
|
|
474
|
+
edgeField: (0, inflekt_1.lcFirst)(pluralName),
|
|
475
475
|
enumType: `${entityName}Enum`,
|
|
476
476
|
filterType: hasFilter ? `${entityName}Filter` : null,
|
|
477
477
|
inputType: `${entityName}Input`,
|
|
@@ -523,7 +523,7 @@ function findOrderByType(entityName, pluralName, typeMap) {
|
|
|
523
523
|
const baseName = typeName.slice(0, -7); // Remove 'OrderBy'
|
|
524
524
|
// Check if singularizing the base name gives us the entity name
|
|
525
525
|
// e.g., 'Schemata' -> 'Schema', 'Users' -> 'User', 'Addresses' -> 'Address'
|
|
526
|
-
if ((0,
|
|
526
|
+
if ((0, inflekt_1.singularize)(baseName) === entityName) {
|
|
527
527
|
return typeName;
|
|
528
528
|
}
|
|
529
529
|
}
|
package/core/ast.js
CHANGED
|
@@ -36,7 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.deleteOne = exports.patchOne = exports.createOne = exports.getOne = exports.getMany = exports.getCount = exports.getAll = void 0;
|
|
37
37
|
exports.getSelections = getSelections;
|
|
38
38
|
const t = __importStar(require("gql-ast"));
|
|
39
|
-
const
|
|
39
|
+
const inflekt_1 = require("inflekt");
|
|
40
40
|
const custom_ast_1 = require("./custom-ast");
|
|
41
41
|
const NON_MUTABLE_PROPS = ['createdAt', 'createdBy', 'updatedAt', 'updatedBy'];
|
|
42
42
|
const objectToArray = (obj) => Object.keys(obj).map((k) => ({
|
|
@@ -320,7 +320,7 @@ const createOne = ({ mutationName, operationName, mutation, selection, }) => {
|
|
|
320
320
|
if (!mutation.properties?.input?.properties) {
|
|
321
321
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
322
322
|
}
|
|
323
|
-
const modelName =
|
|
323
|
+
const modelName = (0, inflekt_1.camelize)([(0, inflekt_1.singularize)(mutation.model)].join('_'), true);
|
|
324
324
|
const inputProperties = mutation.properties.input
|
|
325
325
|
.properties;
|
|
326
326
|
const modelProperties = inputProperties[modelName];
|
|
@@ -366,7 +366,7 @@ const patchOne = ({ mutationName, operationName, mutation, selection, }) => {
|
|
|
366
366
|
if (!mutation.properties?.input?.properties) {
|
|
367
367
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
368
368
|
}
|
|
369
|
-
const modelName =
|
|
369
|
+
const modelName = (0, inflekt_1.camelize)([(0, inflekt_1.singularize)(mutation.model)].join('_'), true);
|
|
370
370
|
const inputProperties = mutation.properties.input
|
|
371
371
|
.properties;
|
|
372
372
|
const patchProperties = inputProperties['patch'];
|
|
@@ -419,7 +419,7 @@ const deleteOne = ({ mutationName, operationName, mutation, }) => {
|
|
|
419
419
|
if (!mutation.properties?.input?.properties) {
|
|
420
420
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
421
421
|
}
|
|
422
|
-
const modelName =
|
|
422
|
+
const modelName = (0, inflekt_1.camelize)([(0, inflekt_1.singularize)(mutation.model)].join('_'), true);
|
|
423
423
|
const inputProperties = mutation.properties.input
|
|
424
424
|
.properties;
|
|
425
425
|
const deleteAttrs = objectToArray(inputProperties);
|
package/core/query-builder.js
CHANGED
|
@@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.QueryBuilder = exports.MetaObject = void 0;
|
|
37
37
|
const graphql_1 = require("graphql");
|
|
38
|
-
const
|
|
38
|
+
const inflekt_1 = require("inflekt");
|
|
39
39
|
const ast_1 = require("./ast");
|
|
40
40
|
const meta_object_1 = require("./meta-object");
|
|
41
41
|
exports.MetaObject = __importStar(require("./meta-object"));
|
|
@@ -124,13 +124,13 @@ class QueryBuilder {
|
|
|
124
124
|
const getInputName = (mutationType) => {
|
|
125
125
|
switch (mutationType) {
|
|
126
126
|
case 'delete': {
|
|
127
|
-
return `Delete${
|
|
127
|
+
return `Delete${(0, inflekt_1.camelize)(this._model)}Input`;
|
|
128
128
|
}
|
|
129
129
|
case 'create': {
|
|
130
|
-
return `Create${
|
|
130
|
+
return `Create${(0, inflekt_1.camelize)(this._model)}Input`;
|
|
131
131
|
}
|
|
132
132
|
case 'patch': {
|
|
133
|
-
return `Update${
|
|
133
|
+
return `Update${(0, inflekt_1.camelize)(this._model)}Input`;
|
|
134
134
|
}
|
|
135
135
|
default:
|
|
136
136
|
throw new Error('Unhandled mutation type' + mutationType);
|
|
@@ -159,7 +159,7 @@ class QueryBuilder {
|
|
|
159
159
|
getMany({ select } = {}) {
|
|
160
160
|
this._op = 'getMany';
|
|
161
161
|
this._key = this._findQuery();
|
|
162
|
-
this.queryName(
|
|
162
|
+
this.queryName((0, inflekt_1.camelize)(['get', (0, inflekt_1.underscore)(this._key), 'query'].join('_'), true));
|
|
163
163
|
const defn = this._introspection[this._key];
|
|
164
164
|
this.select(select);
|
|
165
165
|
this._ast = (0, ast_1.getMany)({
|
|
@@ -174,7 +174,7 @@ class QueryBuilder {
|
|
|
174
174
|
all({ select } = {}) {
|
|
175
175
|
this._op = 'getMany';
|
|
176
176
|
this._key = this._findQuery();
|
|
177
|
-
this.queryName(
|
|
177
|
+
this.queryName((0, inflekt_1.camelize)(['get', (0, inflekt_1.underscore)(this._key), 'query', 'all'].join('_'), true));
|
|
178
178
|
const defn = this._introspection[this._key];
|
|
179
179
|
this.select(select);
|
|
180
180
|
this._ast = (0, ast_1.getAll)({
|
|
@@ -188,7 +188,7 @@ class QueryBuilder {
|
|
|
188
188
|
count() {
|
|
189
189
|
this._op = 'getMany';
|
|
190
190
|
this._key = this._findQuery();
|
|
191
|
-
this.queryName(
|
|
191
|
+
this.queryName((0, inflekt_1.camelize)(['get', (0, inflekt_1.underscore)(this._key), 'count', 'query'].join('_'), true));
|
|
192
192
|
const defn = this._introspection[this._key];
|
|
193
193
|
this._ast = (0, ast_1.getCount)({
|
|
194
194
|
queryName: this._queryName,
|
|
@@ -200,7 +200,7 @@ class QueryBuilder {
|
|
|
200
200
|
getOne({ select } = {}) {
|
|
201
201
|
this._op = 'getOne';
|
|
202
202
|
this._key = this._findQuery();
|
|
203
|
-
this.queryName(
|
|
203
|
+
this.queryName((0, inflekt_1.camelize)(['get', (0, inflekt_1.underscore)(this._key), 'query'].join('_'), true));
|
|
204
204
|
const defn = this._introspection[this._key];
|
|
205
205
|
this.select(select);
|
|
206
206
|
this._ast = (0, ast_1.getOne)({
|
|
@@ -216,7 +216,7 @@ class QueryBuilder {
|
|
|
216
216
|
this._op = 'mutation';
|
|
217
217
|
this._mutation = 'create';
|
|
218
218
|
this._key = this._findMutation();
|
|
219
|
-
this.queryName(
|
|
219
|
+
this.queryName((0, inflekt_1.camelize)([(0, inflekt_1.underscore)(this._key), 'mutation'].join('_'), true));
|
|
220
220
|
const defn = this._introspection[this._key];
|
|
221
221
|
this.select(select);
|
|
222
222
|
this._ast = (0, ast_1.createOne)({
|
|
@@ -231,7 +231,7 @@ class QueryBuilder {
|
|
|
231
231
|
this._op = 'mutation';
|
|
232
232
|
this._mutation = 'delete';
|
|
233
233
|
this._key = this._findMutation();
|
|
234
|
-
this.queryName(
|
|
234
|
+
this.queryName((0, inflekt_1.camelize)([(0, inflekt_1.underscore)(this._key), 'mutation'].join('_'), true));
|
|
235
235
|
const defn = this._introspection[this._key];
|
|
236
236
|
this.select(select);
|
|
237
237
|
this._ast = (0, ast_1.deleteOne)({
|
|
@@ -245,7 +245,7 @@ class QueryBuilder {
|
|
|
245
245
|
this._op = 'mutation';
|
|
246
246
|
this._mutation = 'patch';
|
|
247
247
|
this._key = this._findMutation();
|
|
248
|
-
this.queryName(
|
|
248
|
+
this.queryName((0, inflekt_1.camelize)([(0, inflekt_1.underscore)(this._key), 'mutation'].join('_'), true));
|
|
249
249
|
const defn = this._introspection[this._key];
|
|
250
250
|
this.select(select);
|
|
251
251
|
this._ast = (0, ast_1.patchOne)({
|
|
@@ -408,5 +408,5 @@ function isRelationalField(fieldName, modelMeta) {
|
|
|
408
408
|
// Get getMany op name from model
|
|
409
409
|
// ie. UserSetting => userSettings
|
|
410
410
|
function modelNameToGetMany(model) {
|
|
411
|
-
return
|
|
411
|
+
return (0, inflekt_1.camelize)((0, inflekt_1.pluralize)((0, inflekt_1.underscore)(model)), true);
|
|
412
412
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createProject, createSourceFile, getMinimalFormattedOutput, createFileHeader, createInterface, createTypeAlias, addSectionComment, } from '../ts-ast';
|
|
2
2
|
import { getTableNames, getFilterTypeName, getConditionTypeName, getOrderByTypeName, isRelationField, } from '../utils';
|
|
3
|
-
import { pluralize } from '
|
|
3
|
+
import { pluralize } from 'inflekt';
|
|
4
4
|
import { getTypeBaseName } from '../type-resolver';
|
|
5
5
|
import { scalarToTsType, scalarToFilterType } from '../scalars';
|
|
6
6
|
// ============================================================================
|
package/esm/cli/codegen/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { scalarToTsType, scalarToFilterType } from './scalars';
|
|
2
|
-
import { pluralize } from '
|
|
2
|
+
import { pluralize } from 'inflekt';
|
|
3
3
|
// ============================================================================
|
|
4
4
|
// String manipulation
|
|
5
5
|
// ============================================================================
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { inferTablesFromIntrospection } from './infer-tables';
|
|
5
5
|
export type { InferTablesOptions } from './infer-tables';
|
|
6
|
-
export { singularize, pluralize } from '
|
|
6
|
+
export { singularize, pluralize } from 'inflekt';
|
|
7
7
|
export { createSchemaSource, validateSourceOptions, EndpointSchemaSource, FileSchemaSource, SchemaSourceError, } from './source';
|
|
8
8
|
export type { SchemaSource, SchemaSourceResult, CreateSchemaSourceOptions, } from './source';
|
|
9
9
|
export { fetchSchema } from './fetch-schema';
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
// Table inference from introspection
|
|
5
5
|
export { inferTablesFromIntrospection } from './infer-tables';
|
|
6
|
-
// Pluralization utilities
|
|
7
|
-
export { singularize, pluralize } from '
|
|
6
|
+
// Pluralization utilities (from inflekt)
|
|
7
|
+
export { singularize, pluralize } from 'inflekt';
|
|
8
8
|
// Schema sources
|
|
9
9
|
export { createSchemaSource, validateSourceOptions, EndpointSchemaSource, FileSchemaSource, SchemaSourceError, } from './source';
|
|
10
10
|
// Schema fetching (still used by watch mode)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { unwrapType, getBaseTypeName, isList } from '../../types/introspection';
|
|
2
|
-
import { singularize, pluralize, lcFirst, ucFirst } from '
|
|
2
|
+
import { singularize, pluralize, lcFirst, ucFirst } from 'inflekt';
|
|
3
3
|
// ============================================================================
|
|
4
4
|
// Pattern Matching Constants
|
|
5
5
|
// ============================================================================
|
package/esm/core/ast.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as t from 'gql-ast';
|
|
2
|
-
import
|
|
2
|
+
import { camelize, singularize } from 'inflekt';
|
|
3
3
|
import { getCustomAst } from './custom-ast';
|
|
4
4
|
const NON_MUTABLE_PROPS = ['createdAt', 'createdBy', 'updatedAt', 'updatedBy'];
|
|
5
5
|
const objectToArray = (obj) => Object.keys(obj).map((k) => ({
|
|
@@ -279,7 +279,7 @@ export const createOne = ({ mutationName, operationName, mutation, selection, })
|
|
|
279
279
|
if (!mutation.properties?.input?.properties) {
|
|
280
280
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
281
281
|
}
|
|
282
|
-
const modelName =
|
|
282
|
+
const modelName = camelize([singularize(mutation.model)].join('_'), true);
|
|
283
283
|
const inputProperties = mutation.properties.input
|
|
284
284
|
.properties;
|
|
285
285
|
const modelProperties = inputProperties[modelName];
|
|
@@ -324,7 +324,7 @@ export const patchOne = ({ mutationName, operationName, mutation, selection, })
|
|
|
324
324
|
if (!mutation.properties?.input?.properties) {
|
|
325
325
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
326
326
|
}
|
|
327
|
-
const modelName =
|
|
327
|
+
const modelName = camelize([singularize(mutation.model)].join('_'), true);
|
|
328
328
|
const inputProperties = mutation.properties.input
|
|
329
329
|
.properties;
|
|
330
330
|
const patchProperties = inputProperties['patch'];
|
|
@@ -376,7 +376,7 @@ export const deleteOne = ({ mutationName, operationName, mutation, }) => {
|
|
|
376
376
|
if (!mutation.properties?.input?.properties) {
|
|
377
377
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
378
378
|
}
|
|
379
|
-
const modelName =
|
|
379
|
+
const modelName = camelize([singularize(mutation.model)].join('_'), true);
|
|
380
380
|
const inputProperties = mutation.properties.input
|
|
381
381
|
.properties;
|
|
382
382
|
const deleteAttrs = objectToArray(inputProperties);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { print as gqlPrint } from 'graphql';
|
|
2
|
-
import
|
|
2
|
+
import { camelize, underscore, pluralize } from 'inflekt';
|
|
3
3
|
import { createOne, deleteOne, getAll, getCount, getMany, getOne, patchOne, } from './ast';
|
|
4
4
|
import { validateMetaObject } from './meta-object';
|
|
5
5
|
export * as MetaObject from './meta-object';
|
|
@@ -88,13 +88,13 @@ export class QueryBuilder {
|
|
|
88
88
|
const getInputName = (mutationType) => {
|
|
89
89
|
switch (mutationType) {
|
|
90
90
|
case 'delete': {
|
|
91
|
-
return `Delete${
|
|
91
|
+
return `Delete${camelize(this._model)}Input`;
|
|
92
92
|
}
|
|
93
93
|
case 'create': {
|
|
94
|
-
return `Create${
|
|
94
|
+
return `Create${camelize(this._model)}Input`;
|
|
95
95
|
}
|
|
96
96
|
case 'patch': {
|
|
97
|
-
return `Update${
|
|
97
|
+
return `Update${camelize(this._model)}Input`;
|
|
98
98
|
}
|
|
99
99
|
default:
|
|
100
100
|
throw new Error('Unhandled mutation type' + mutationType);
|
|
@@ -123,7 +123,7 @@ export class QueryBuilder {
|
|
|
123
123
|
getMany({ select } = {}) {
|
|
124
124
|
this._op = 'getMany';
|
|
125
125
|
this._key = this._findQuery();
|
|
126
|
-
this.queryName(
|
|
126
|
+
this.queryName(camelize(['get', underscore(this._key), 'query'].join('_'), true));
|
|
127
127
|
const defn = this._introspection[this._key];
|
|
128
128
|
this.select(select);
|
|
129
129
|
this._ast = getMany({
|
|
@@ -138,7 +138,7 @@ export class QueryBuilder {
|
|
|
138
138
|
all({ select } = {}) {
|
|
139
139
|
this._op = 'getMany';
|
|
140
140
|
this._key = this._findQuery();
|
|
141
|
-
this.queryName(
|
|
141
|
+
this.queryName(camelize(['get', underscore(this._key), 'query', 'all'].join('_'), true));
|
|
142
142
|
const defn = this._introspection[this._key];
|
|
143
143
|
this.select(select);
|
|
144
144
|
this._ast = getAll({
|
|
@@ -152,7 +152,7 @@ export class QueryBuilder {
|
|
|
152
152
|
count() {
|
|
153
153
|
this._op = 'getMany';
|
|
154
154
|
this._key = this._findQuery();
|
|
155
|
-
this.queryName(
|
|
155
|
+
this.queryName(camelize(['get', underscore(this._key), 'count', 'query'].join('_'), true));
|
|
156
156
|
const defn = this._introspection[this._key];
|
|
157
157
|
this._ast = getCount({
|
|
158
158
|
queryName: this._queryName,
|
|
@@ -164,7 +164,7 @@ export class QueryBuilder {
|
|
|
164
164
|
getOne({ select } = {}) {
|
|
165
165
|
this._op = 'getOne';
|
|
166
166
|
this._key = this._findQuery();
|
|
167
|
-
this.queryName(
|
|
167
|
+
this.queryName(camelize(['get', underscore(this._key), 'query'].join('_'), true));
|
|
168
168
|
const defn = this._introspection[this._key];
|
|
169
169
|
this.select(select);
|
|
170
170
|
this._ast = getOne({
|
|
@@ -180,7 +180,7 @@ export class QueryBuilder {
|
|
|
180
180
|
this._op = 'mutation';
|
|
181
181
|
this._mutation = 'create';
|
|
182
182
|
this._key = this._findMutation();
|
|
183
|
-
this.queryName(
|
|
183
|
+
this.queryName(camelize([underscore(this._key), 'mutation'].join('_'), true));
|
|
184
184
|
const defn = this._introspection[this._key];
|
|
185
185
|
this.select(select);
|
|
186
186
|
this._ast = createOne({
|
|
@@ -195,7 +195,7 @@ export class QueryBuilder {
|
|
|
195
195
|
this._op = 'mutation';
|
|
196
196
|
this._mutation = 'delete';
|
|
197
197
|
this._key = this._findMutation();
|
|
198
|
-
this.queryName(
|
|
198
|
+
this.queryName(camelize([underscore(this._key), 'mutation'].join('_'), true));
|
|
199
199
|
const defn = this._introspection[this._key];
|
|
200
200
|
this.select(select);
|
|
201
201
|
this._ast = deleteOne({
|
|
@@ -209,7 +209,7 @@ export class QueryBuilder {
|
|
|
209
209
|
this._op = 'mutation';
|
|
210
210
|
this._mutation = 'patch';
|
|
211
211
|
this._key = this._findMutation();
|
|
212
|
-
this.queryName(
|
|
212
|
+
this.queryName(camelize([underscore(this._key), 'mutation'].join('_'), true));
|
|
213
213
|
const defn = this._introspection[this._key];
|
|
214
214
|
this.select(select);
|
|
215
215
|
this._ast = patchOne({
|
|
@@ -371,5 +371,5 @@ function isRelationalField(fieldName, modelMeta) {
|
|
|
371
371
|
// Get getMany op name from model
|
|
372
372
|
// ie. UserSetting => userSettings
|
|
373
373
|
function modelNameToGetMany(model) {
|
|
374
|
-
return
|
|
374
|
+
return camelize(pluralize(underscore(model)), true);
|
|
375
375
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import * as t from 'gql-ast';
|
|
6
6
|
import { print } from 'graphql';
|
|
7
|
-
import
|
|
7
|
+
import { camelize } from 'inflekt';
|
|
8
8
|
import { TypedDocumentString } from '../client/typed-document';
|
|
9
9
|
import { getCustomAstForCleanField, requiresSubfieldSelection, } from '../core/custom-ast';
|
|
10
10
|
import { isRelationalField } from './field-selector';
|
|
@@ -32,7 +32,7 @@ function generateFieldSelections(table) {
|
|
|
32
32
|
*/
|
|
33
33
|
export function buildPostGraphileCreate(table, _allTables, _options = {}) {
|
|
34
34
|
const mutationName = `create${table.name}`;
|
|
35
|
-
const singularName =
|
|
35
|
+
const singularName = camelize(table.name, true);
|
|
36
36
|
// Create the variable definition for $input
|
|
37
37
|
const variableDefinitions = [
|
|
38
38
|
t.variableDefinition({
|
|
@@ -91,7 +91,7 @@ export function buildPostGraphileCreate(table, _allTables, _options = {}) {
|
|
|
91
91
|
*/
|
|
92
92
|
export function buildPostGraphileUpdate(table, _allTables, _options = {}) {
|
|
93
93
|
const mutationName = `update${table.name}`;
|
|
94
|
-
const singularName =
|
|
94
|
+
const singularName = camelize(table.name, true);
|
|
95
95
|
// Create the variable definition for $input
|
|
96
96
|
const variableDefinitions = [
|
|
97
97
|
t.variableDefinition({
|
package/esm/generators/select.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import * as t from 'gql-ast';
|
|
6
6
|
import { print } from 'graphql';
|
|
7
|
-
import
|
|
7
|
+
import { camelize, pluralize } from 'inflekt';
|
|
8
8
|
import { TypedDocumentString } from '../client/typed-document';
|
|
9
9
|
import { getCustomAstForCleanField, requiresSubfieldSelection, } from '../core/custom-ast';
|
|
10
10
|
import { QueryBuilder } from '../core/query-builder';
|
|
@@ -16,9 +16,9 @@ import { convertToSelectionOptions, isRelationalField } from './field-selector';
|
|
|
16
16
|
*/
|
|
17
17
|
export function toCamelCasePlural(tableName) {
|
|
18
18
|
// First convert to camelCase (lowercase first letter)
|
|
19
|
-
const camelCase =
|
|
19
|
+
const camelCase = camelize(tableName, true);
|
|
20
20
|
// Then pluralize properly
|
|
21
|
-
return
|
|
21
|
+
return pluralize(camelCase);
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Generate the PostGraphile OrderBy enum type name for a table
|
|
@@ -101,7 +101,7 @@ export function generateIntrospectionSchema(tables) {
|
|
|
101
101
|
properties: convertFieldsToProperties(table.fields),
|
|
102
102
|
};
|
|
103
103
|
// Add getOne query (by ID)
|
|
104
|
-
const singularName =
|
|
104
|
+
const singularName = camelize(modelName, true);
|
|
105
105
|
schema[singularName] = {
|
|
106
106
|
qtype: 'getOne',
|
|
107
107
|
model: modelName,
|
|
@@ -122,8 +122,8 @@ export function generateIntrospectionSchema(tables) {
|
|
|
122
122
|
isArray: false,
|
|
123
123
|
isArrayNotNull: false,
|
|
124
124
|
properties: {
|
|
125
|
-
[
|
|
126
|
-
name:
|
|
125
|
+
[camelize(modelName, true)]: {
|
|
126
|
+
name: camelize(modelName, true),
|
|
127
127
|
type: `${modelName}Input`,
|
|
128
128
|
isNotNull: true,
|
|
129
129
|
isArray: false,
|
|
@@ -549,7 +549,7 @@ function findRelatedTable(relationField, table, allTables) {
|
|
|
549
549
|
* Generate FindOne query AST directly from CleanTable
|
|
550
550
|
*/
|
|
551
551
|
function generateFindOneQueryAST(table) {
|
|
552
|
-
const singularName =
|
|
552
|
+
const singularName = camelize(table.name, true);
|
|
553
553
|
// Generate field selections (include all non-relational fields, including complex types)
|
|
554
554
|
const fieldSelections = table.fields
|
|
555
555
|
.filter((field) => !isRelationalField(field.name, table))
|
package/generators/mutations.js
CHANGED
|
@@ -42,7 +42,7 @@ exports.buildPostGraphileDelete = buildPostGraphileDelete;
|
|
|
42
42
|
*/
|
|
43
43
|
const t = __importStar(require("gql-ast"));
|
|
44
44
|
const graphql_1 = require("graphql");
|
|
45
|
-
const
|
|
45
|
+
const inflekt_1 = require("inflekt");
|
|
46
46
|
const typed_document_1 = require("../client/typed-document");
|
|
47
47
|
const custom_ast_1 = require("../core/custom-ast");
|
|
48
48
|
const field_selector_1 = require("./field-selector");
|
|
@@ -70,7 +70,7 @@ function generateFieldSelections(table) {
|
|
|
70
70
|
*/
|
|
71
71
|
function buildPostGraphileCreate(table, _allTables, _options = {}) {
|
|
72
72
|
const mutationName = `create${table.name}`;
|
|
73
|
-
const singularName =
|
|
73
|
+
const singularName = (0, inflekt_1.camelize)(table.name, true);
|
|
74
74
|
// Create the variable definition for $input
|
|
75
75
|
const variableDefinitions = [
|
|
76
76
|
t.variableDefinition({
|
|
@@ -129,7 +129,7 @@ function buildPostGraphileCreate(table, _allTables, _options = {}) {
|
|
|
129
129
|
*/
|
|
130
130
|
function buildPostGraphileUpdate(table, _allTables, _options = {}) {
|
|
131
131
|
const mutationName = `update${table.name}`;
|
|
132
|
-
const singularName =
|
|
132
|
+
const singularName = (0, inflekt_1.camelize)(table.name, true);
|
|
133
133
|
// Create the variable definition for $input
|
|
134
134
|
const variableDefinitions = [
|
|
135
135
|
t.variableDefinition({
|
package/generators/select.js
CHANGED
|
@@ -47,7 +47,7 @@ exports.buildCount = buildCount;
|
|
|
47
47
|
*/
|
|
48
48
|
const t = __importStar(require("gql-ast"));
|
|
49
49
|
const graphql_1 = require("graphql");
|
|
50
|
-
const
|
|
50
|
+
const inflekt_1 = require("inflekt");
|
|
51
51
|
const typed_document_1 = require("../client/typed-document");
|
|
52
52
|
const custom_ast_1 = require("../core/custom-ast");
|
|
53
53
|
const query_builder_1 = require("../core/query-builder");
|
|
@@ -59,9 +59,9 @@ const field_selector_1 = require("./field-selector");
|
|
|
59
59
|
*/
|
|
60
60
|
function toCamelCasePlural(tableName) {
|
|
61
61
|
// First convert to camelCase (lowercase first letter)
|
|
62
|
-
const camelCase =
|
|
62
|
+
const camelCase = (0, inflekt_1.camelize)(tableName, true);
|
|
63
63
|
// Then pluralize properly
|
|
64
|
-
return
|
|
64
|
+
return (0, inflekt_1.pluralize)(camelCase);
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Generate the PostGraphile OrderBy enum type name for a table
|
|
@@ -144,7 +144,7 @@ function generateIntrospectionSchema(tables) {
|
|
|
144
144
|
properties: convertFieldsToProperties(table.fields),
|
|
145
145
|
};
|
|
146
146
|
// Add getOne query (by ID)
|
|
147
|
-
const singularName =
|
|
147
|
+
const singularName = (0, inflekt_1.camelize)(modelName, true);
|
|
148
148
|
schema[singularName] = {
|
|
149
149
|
qtype: 'getOne',
|
|
150
150
|
model: modelName,
|
|
@@ -165,8 +165,8 @@ function generateIntrospectionSchema(tables) {
|
|
|
165
165
|
isArray: false,
|
|
166
166
|
isArrayNotNull: false,
|
|
167
167
|
properties: {
|
|
168
|
-
[
|
|
169
|
-
name:
|
|
168
|
+
[(0, inflekt_1.camelize)(modelName, true)]: {
|
|
169
|
+
name: (0, inflekt_1.camelize)(modelName, true),
|
|
170
170
|
type: `${modelName}Input`,
|
|
171
171
|
isNotNull: true,
|
|
172
172
|
isArray: false,
|
|
@@ -592,7 +592,7 @@ function findRelatedTable(relationField, table, allTables) {
|
|
|
592
592
|
* Generate FindOne query AST directly from CleanTable
|
|
593
593
|
*/
|
|
594
594
|
function generateFindOneQueryAST(table) {
|
|
595
|
-
const singularName =
|
|
595
|
+
const singularName = (0, inflekt_1.camelize)(table.name, true);
|
|
596
596
|
// Generate field selections (include all non-relational fields, including complex types)
|
|
597
597
|
const fieldSelections = table.fields
|
|
598
598
|
.filter((field) => !(0, field_selector_1.isRelationalField)(field.name, table))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/graphql-codegen",
|
|
3
|
-
"version": "2.23.
|
|
3
|
+
"version": "2.23.2",
|
|
4
4
|
"description": "CLI-based GraphQL SDK generator for PostGraphile endpoints with React Query hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"commander": "^12.1.0",
|
|
54
54
|
"gql-ast": "^2.4.6",
|
|
55
55
|
"graphql": "15.10.1",
|
|
56
|
-
"
|
|
56
|
+
"inflekt": "^0.2.0",
|
|
57
57
|
"jiti": "^2.6.1",
|
|
58
58
|
"prettier": "^3.7.4",
|
|
59
59
|
"ts-morph": "^27.0.2"
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"tsx": "^4.21.0",
|
|
82
82
|
"typescript": "^5.9.3"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "a56b001d06690989ca4c66c3bfd7d260c3649eea"
|
|
85
85
|
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert a word to its singular form
|
|
3
|
-
* @example "Users" → "User", "People" → "Person", "Schemata" → "Schema", "ApiSchemata" → "ApiSchema"
|
|
4
|
-
*/
|
|
5
|
-
export declare function singularize(word: string): string;
|
|
6
|
-
/**
|
|
7
|
-
* Convert a word to its plural form
|
|
8
|
-
* @example "User" → "Users", "Person" → "People"
|
|
9
|
-
*/
|
|
10
|
-
export declare function pluralize(word: string): string;
|
|
11
|
-
/**
|
|
12
|
-
* Convert PascalCase to camelCase
|
|
13
|
-
* @example "UserProfile" → "userProfile"
|
|
14
|
-
*/
|
|
15
|
-
export declare function lcFirst(str: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* Convert camelCase to PascalCase
|
|
18
|
-
* @example "userProfile" → "UserProfile"
|
|
19
|
-
*/
|
|
20
|
-
export declare function ucFirst(str: string): string;
|
|
21
|
-
/**
|
|
22
|
-
* Convert a plural PascalCase type name to singular camelCase field name
|
|
23
|
-
* @example "Users" → "user", "OrderItems" → "orderItem"
|
|
24
|
-
*/
|
|
25
|
-
export declare function toFieldName(pluralTypeName: string): string;
|
|
26
|
-
/**
|
|
27
|
-
* Convert a singular PascalCase type name to plural camelCase query name
|
|
28
|
-
* @example "User" → "users", "OrderItem" → "orderItems"
|
|
29
|
-
*/
|
|
30
|
-
export declare function toQueryName(singularTypeName: string): string;
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.singularize = singularize;
|
|
37
|
-
exports.pluralize = pluralize;
|
|
38
|
-
exports.lcFirst = lcFirst;
|
|
39
|
-
exports.ucFirst = ucFirst;
|
|
40
|
-
exports.toFieldName = toFieldName;
|
|
41
|
-
exports.toQueryName = toQueryName;
|
|
42
|
-
/**
|
|
43
|
-
* Pluralization utilities for inferring entity names from PostGraphile patterns
|
|
44
|
-
*
|
|
45
|
-
* Uses the 'inflection' package which is already a dependency of this package.
|
|
46
|
-
*/
|
|
47
|
-
const inflection = __importStar(require("inflection"));
|
|
48
|
-
/**
|
|
49
|
-
* Latin plural suffixes that inflection handles differently than PostGraphile.
|
|
50
|
-
*
|
|
51
|
-
* The inflection library correctly singularizes Latin words (schemata → schematum),
|
|
52
|
-
* but PostGraphile uses English-style naming (schemata → schema).
|
|
53
|
-
*
|
|
54
|
-
* Format: [pluralSuffix, singularSuffix]
|
|
55
|
-
*/
|
|
56
|
-
const LATIN_SUFFIX_OVERRIDES = [
|
|
57
|
-
// Common Latin plural endings
|
|
58
|
-
['schemata', 'schema'],
|
|
59
|
-
['criteria', 'criterion'],
|
|
60
|
-
['phenomena', 'phenomenon'],
|
|
61
|
-
['media', 'medium'],
|
|
62
|
-
['memoranda', 'memorandum'],
|
|
63
|
-
['strata', 'stratum'],
|
|
64
|
-
['curricula', 'curriculum'],
|
|
65
|
-
['data', 'datum'],
|
|
66
|
-
];
|
|
67
|
-
/**
|
|
68
|
-
* Convert a word to its singular form
|
|
69
|
-
* @example "Users" → "User", "People" → "Person", "Schemata" → "Schema", "ApiSchemata" → "ApiSchema"
|
|
70
|
-
*/
|
|
71
|
-
function singularize(word) {
|
|
72
|
-
// Check for Latin suffix overrides (handles compound words like "ApiSchemata")
|
|
73
|
-
const lowerWord = word.toLowerCase();
|
|
74
|
-
for (const [pluralSuffix, singularSuffix] of LATIN_SUFFIX_OVERRIDES) {
|
|
75
|
-
if (lowerWord.endsWith(pluralSuffix)) {
|
|
76
|
-
// Find where the suffix starts in the original word (preserving case)
|
|
77
|
-
const suffixStart = word.length - pluralSuffix.length;
|
|
78
|
-
const prefix = word.slice(0, suffixStart);
|
|
79
|
-
const originalSuffix = word.slice(suffixStart);
|
|
80
|
-
// Preserve the casing of the first letter of the suffix
|
|
81
|
-
const isUpperSuffix = originalSuffix[0] === originalSuffix[0].toUpperCase();
|
|
82
|
-
const newSuffix = isUpperSuffix
|
|
83
|
-
? singularSuffix.charAt(0).toUpperCase() + singularSuffix.slice(1)
|
|
84
|
-
: singularSuffix;
|
|
85
|
-
return prefix + newSuffix;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return inflection.singularize(word);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Convert a word to its plural form
|
|
92
|
-
* @example "User" → "Users", "Person" → "People"
|
|
93
|
-
*/
|
|
94
|
-
function pluralize(word) {
|
|
95
|
-
return inflection.pluralize(word);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Convert PascalCase to camelCase
|
|
99
|
-
* @example "UserProfile" → "userProfile"
|
|
100
|
-
*/
|
|
101
|
-
function lcFirst(str) {
|
|
102
|
-
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Convert camelCase to PascalCase
|
|
106
|
-
* @example "userProfile" → "UserProfile"
|
|
107
|
-
*/
|
|
108
|
-
function ucFirst(str) {
|
|
109
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Convert a plural PascalCase type name to singular camelCase field name
|
|
113
|
-
* @example "Users" → "user", "OrderItems" → "orderItem"
|
|
114
|
-
*/
|
|
115
|
-
function toFieldName(pluralTypeName) {
|
|
116
|
-
return lcFirst(singularize(pluralTypeName));
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Convert a singular PascalCase type name to plural camelCase query name
|
|
120
|
-
* @example "User" → "users", "OrderItem" → "orderItems"
|
|
121
|
-
*/
|
|
122
|
-
function toQueryName(singularTypeName) {
|
|
123
|
-
return lcFirst(pluralize(singularTypeName));
|
|
124
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert a word to its singular form
|
|
3
|
-
* @example "Users" → "User", "People" → "Person", "Schemata" → "Schema", "ApiSchemata" → "ApiSchema"
|
|
4
|
-
*/
|
|
5
|
-
export declare function singularize(word: string): string;
|
|
6
|
-
/**
|
|
7
|
-
* Convert a word to its plural form
|
|
8
|
-
* @example "User" → "Users", "Person" → "People"
|
|
9
|
-
*/
|
|
10
|
-
export declare function pluralize(word: string): string;
|
|
11
|
-
/**
|
|
12
|
-
* Convert PascalCase to camelCase
|
|
13
|
-
* @example "UserProfile" → "userProfile"
|
|
14
|
-
*/
|
|
15
|
-
export declare function lcFirst(str: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* Convert camelCase to PascalCase
|
|
18
|
-
* @example "userProfile" → "UserProfile"
|
|
19
|
-
*/
|
|
20
|
-
export declare function ucFirst(str: string): string;
|
|
21
|
-
/**
|
|
22
|
-
* Convert a plural PascalCase type name to singular camelCase field name
|
|
23
|
-
* @example "Users" → "user", "OrderItems" → "orderItem"
|
|
24
|
-
*/
|
|
25
|
-
export declare function toFieldName(pluralTypeName: string): string;
|
|
26
|
-
/**
|
|
27
|
-
* Convert a singular PascalCase type name to plural camelCase query name
|
|
28
|
-
* @example "User" → "users", "OrderItem" → "orderItems"
|
|
29
|
-
*/
|
|
30
|
-
export declare function toQueryName(singularTypeName: string): string;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pluralization utilities for inferring entity names from PostGraphile patterns
|
|
3
|
-
*
|
|
4
|
-
* Uses the 'inflection' package which is already a dependency of this package.
|
|
5
|
-
*/
|
|
6
|
-
import * as inflection from 'inflection';
|
|
7
|
-
/**
|
|
8
|
-
* Latin plural suffixes that inflection handles differently than PostGraphile.
|
|
9
|
-
*
|
|
10
|
-
* The inflection library correctly singularizes Latin words (schemata → schematum),
|
|
11
|
-
* but PostGraphile uses English-style naming (schemata → schema).
|
|
12
|
-
*
|
|
13
|
-
* Format: [pluralSuffix, singularSuffix]
|
|
14
|
-
*/
|
|
15
|
-
const LATIN_SUFFIX_OVERRIDES = [
|
|
16
|
-
// Common Latin plural endings
|
|
17
|
-
['schemata', 'schema'],
|
|
18
|
-
['criteria', 'criterion'],
|
|
19
|
-
['phenomena', 'phenomenon'],
|
|
20
|
-
['media', 'medium'],
|
|
21
|
-
['memoranda', 'memorandum'],
|
|
22
|
-
['strata', 'stratum'],
|
|
23
|
-
['curricula', 'curriculum'],
|
|
24
|
-
['data', 'datum'],
|
|
25
|
-
];
|
|
26
|
-
/**
|
|
27
|
-
* Convert a word to its singular form
|
|
28
|
-
* @example "Users" → "User", "People" → "Person", "Schemata" → "Schema", "ApiSchemata" → "ApiSchema"
|
|
29
|
-
*/
|
|
30
|
-
export function singularize(word) {
|
|
31
|
-
// Check for Latin suffix overrides (handles compound words like "ApiSchemata")
|
|
32
|
-
const lowerWord = word.toLowerCase();
|
|
33
|
-
for (const [pluralSuffix, singularSuffix] of LATIN_SUFFIX_OVERRIDES) {
|
|
34
|
-
if (lowerWord.endsWith(pluralSuffix)) {
|
|
35
|
-
// Find where the suffix starts in the original word (preserving case)
|
|
36
|
-
const suffixStart = word.length - pluralSuffix.length;
|
|
37
|
-
const prefix = word.slice(0, suffixStart);
|
|
38
|
-
const originalSuffix = word.slice(suffixStart);
|
|
39
|
-
// Preserve the casing of the first letter of the suffix
|
|
40
|
-
const isUpperSuffix = originalSuffix[0] === originalSuffix[0].toUpperCase();
|
|
41
|
-
const newSuffix = isUpperSuffix
|
|
42
|
-
? singularSuffix.charAt(0).toUpperCase() + singularSuffix.slice(1)
|
|
43
|
-
: singularSuffix;
|
|
44
|
-
return prefix + newSuffix;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return inflection.singularize(word);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Convert a word to its plural form
|
|
51
|
-
* @example "User" → "Users", "Person" → "People"
|
|
52
|
-
*/
|
|
53
|
-
export function pluralize(word) {
|
|
54
|
-
return inflection.pluralize(word);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Convert PascalCase to camelCase
|
|
58
|
-
* @example "UserProfile" → "userProfile"
|
|
59
|
-
*/
|
|
60
|
-
export function lcFirst(str) {
|
|
61
|
-
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Convert camelCase to PascalCase
|
|
65
|
-
* @example "userProfile" → "UserProfile"
|
|
66
|
-
*/
|
|
67
|
-
export function ucFirst(str) {
|
|
68
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Convert a plural PascalCase type name to singular camelCase field name
|
|
72
|
-
* @example "Users" → "user", "OrderItems" → "orderItem"
|
|
73
|
-
*/
|
|
74
|
-
export function toFieldName(pluralTypeName) {
|
|
75
|
-
return lcFirst(singularize(pluralTypeName));
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Convert a singular PascalCase type name to plural camelCase query name
|
|
79
|
-
* @example "User" → "users", "OrderItem" → "orderItems"
|
|
80
|
-
*/
|
|
81
|
-
export function toQueryName(singularTypeName) {
|
|
82
|
-
return lcFirst(pluralize(singularTypeName));
|
|
83
|
-
}
|