@pgpm/inflection 0.17.0 → 0.18.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/README.md CHANGED
@@ -297,7 +297,7 @@ SELECT slug FROM blog_posts;
297
297
 
298
298
  ## Integration Examples
299
299
 
300
- ### With @pgpm/metaschema-schema
300
+ ### With @pgpm/db-meta-schema
301
301
 
302
302
  Use inflection for schema introspection and code generation:
303
303
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  -- requires: schemas/inflection/schema
4
4
  -- requires: schemas/inflection/tables/inflection_rules/table
5
+ -- requires: schemas/inflection/procedures/should_skip_uncountable
5
6
 
6
7
  BEGIN;
7
8
 
@@ -12,6 +13,10 @@ DECLARE
12
13
  result record;
13
14
  matches text[];
14
15
  BEGIN
16
+ IF inflection.should_skip_uncountable(lower(str)) THEN
17
+ return str;
18
+ END IF;
19
+
15
20
  FOR result IN
16
21
  SELECT * FROM inflection.inflection_rules where type='plural'
17
22
  LOOP
@@ -2,6 +2,7 @@
2
2
 
3
3
  -- requires: schemas/inflection/schema
4
4
  -- requires: schemas/inflection/tables/inflection_rules/table
5
+ -- requires: schemas/inflection/procedures/should_skip_uncountable
5
6
 
6
7
  BEGIN;
7
8
 
@@ -12,6 +13,10 @@ DECLARE
12
13
  result record;
13
14
  matches text[];
14
15
  BEGIN
16
+ IF inflection.should_skip_uncountable(lower(str)) THEN
17
+ return str;
18
+ END IF;
19
+
15
20
  FOR result IN
16
21
  SELECT * FROM inflection.inflection_rules where type='singular'
17
22
  LOOP
@@ -7,11 +7,14 @@ BEGIN;
7
7
 
8
8
  INSERT INTO inflection.inflection_rules
9
9
  (type, test, replacement) VALUES
10
+ -- plural guards: already-plural words return as-is (NULL replacement)
10
11
  ('plural', '^(m|wom)en$', NULL),
11
12
  ('plural', '(pe)ople$', NULL),
12
13
  ('plural', '(child)ren$', NULL),
13
14
  ('plural', '([ti])a$', NULL),
14
15
  ('plural', '((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$', NULL),
16
+ ('plural', '(database)s$', NULL),
17
+ ('plural', '(drive)s$', NULL),
15
18
  ('plural', '(hi|ti)ves$', NULL),
16
19
  ('plural', '(curve)s$', NULL),
17
20
  ('plural', '([lr])ves$', NULL),
@@ -25,11 +28,12 @@ INSERT INTO inflection.inflection_rules
25
28
  ('plural', '(o)es$', NULL),
26
29
  ('plural', '(shoe)s$', NULL),
27
30
  ('plural', '(cris|ax|test)es$', NULL),
28
- ('plural', '(octop|vir)i$', NULL),
31
+ ('plural', '(octop|vir)uses$', NULL),
29
32
  ('plural', '(alias|canvas|status|campus)es$', NULL),
30
- ('plural', '^(summons)es$', NULL),
33
+ ('plural', '^(summons|bonus)es$', NULL),
31
34
  ('plural', '^(ox)en', NULL),
32
35
  ('plural', '(matr)ices$', NULL),
36
+ ('plural', '(vert|ind)ices$', NULL),
33
37
  ('plural', '^feet$', NULL),
34
38
  ('plural', '^teeth$', NULL),
35
39
  ('plural', '^geese$', NULL),
@@ -37,19 +41,22 @@ INSERT INTO inflection.inflection_rules
37
41
  ('plural', '^(whereas)es$', NULL),
38
42
  ('plural', '^(criteri)a$', NULL),
39
43
  ('plural', '^genera$', NULL),
44
+ -- plural replacement rules
40
45
  ('plural', '^(m|wom)an$', E'\\1en'),
41
46
  ('plural', '(pe)rson$', E'\\1ople'),
42
47
  ('plural', '(child)$', E'\\1ren'),
48
+ ('plural', '(drive)$', E'\\1s'),
43
49
  ('plural', '^(ox)$', E'\\1en'),
44
50
  ('plural', '(ax|test)is$', E'\\1es'),
45
- ('plural', '(octop|vir)us$', E'\\1i'),
51
+ ('plural', '(octop|vir)us$', E'\\1uses'),
46
52
  ('plural', '(alias|status|canvas|campus)$', E'\\1es'),
47
- ('plural', '^(summons)$', E'\\1es'),
53
+ ('plural', '^(summons|bonus)$', E'\\1es'),
48
54
  ('plural', '(bu)s$', E'\\1ses'),
49
55
  ('plural', '(buffal|tomat|potat)o$', E'\\1oes'),
50
56
  ('plural', '([ti])um$', E'\\1a'),
51
57
  ('plural', 'sis$', E'ses'),
52
58
  ('plural', '(?:([^f])fe|([lr])f)$', E'\\1\\2ves'),
59
+ ('plural', '^(focus)$', E'\\1es'),
53
60
  ('plural', '(hi|ti)ve$', E'\\1ves'),
54
61
  ('plural', '([^aeiouy]|qu)y$', E'\\1ies'),
55
62
  ('plural', '(matr)ix$', E'\\1ices'),
@@ -65,23 +72,27 @@ INSERT INTO inflection.inflection_rules
65
72
  ('plural', '^genus$', E'genera'),
66
73
  ('plural', 's$', E's'),
67
74
  ('plural', '$', E's'),
75
+ -- singular guards: already-singular words return as-is (NULL replacement)
68
76
  ('singular', '^(m|wom)an$', NULL),
69
77
  ('singular', '(pe)rson$', NULL),
70
78
  ('singular', '(child)$', NULL),
79
+ ('singular', '(drive)$', NULL),
71
80
  ('singular', '^(ox)$', NULL),
72
81
  ('singular', '(ax|test)is$', NULL),
73
82
  ('singular', '(octop|vir)us$', NULL),
74
83
  ('singular', '(alias|status|canvas|campus)$', NULL),
75
- ('singular', '^(summons)$', NULL),
84
+ ('singular', '^(summons|bonus)$', NULL),
76
85
  ('singular', '(bu)s$', NULL),
77
86
  ('singular', '(buffal|tomat|potat)o$', NULL),
78
87
  ('singular', '([ti])um$', NULL),
79
88
  ('singular', 'sis$', NULL),
80
89
  ('singular', '(?:([^f])fe|([lr])f)$', NULL),
90
+ ('singular', '^(focus)$', NULL),
81
91
  ('singular', '(hi|ti)ve$', NULL),
82
92
  ('singular', '([^aeiouy]|qu)y$', NULL),
83
93
  ('singular', '(x|ch|ss|sh)$', NULL),
84
94
  ('singular', '(matr)ix$', NULL),
95
+ ('singular', '(vert|ind)ex$', NULL),
85
96
  ('singular', '([m|l])ouse$', NULL),
86
97
  ('singular', '^foot$', NULL),
87
98
  ('singular', '^tooth$', NULL),
@@ -90,11 +101,19 @@ INSERT INTO inflection.inflection_rules
90
101
  ('singular', '^(whereas)$', NULL),
91
102
  ('singular', '^(criteri)on$', NULL),
92
103
  ('singular', '^genus$', NULL),
104
+ -- singular replacement rules
93
105
  ('singular', '^(m|wom)en$', E'\\1an'),
94
106
  ('singular', '(pe)ople$', E'\\1rson'),
95
107
  ('singular', '(child)ren$', E'\\1'),
108
+ ('singular', '(database)s$', E'\\1'),
109
+ ('singular', '(drive)s$', E'\\1'),
96
110
  ('singular', '^genera$', E'genus'),
97
111
  ('singular', '^(criteri)a$', E'\\1on'),
112
+ -- Latin suffix overrides (PostGraphile-compatible)
113
+ ('singular', '(schema)ta$', E'\\1'),
114
+ ('singular', '(phenomen)a$', E'\\1on'),
115
+ ('singular', '(memorand)a$', E'\\1um'),
116
+ ('singular', '(curricul)a$', E'\\1um'),
98
117
  ('singular', '([ti])a$', E'\\1um'),
99
118
  ('singular', '((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$', E'\\1\\2sis'),
100
119
  ('singular', '(hi|ti)ves$', E'\\1ve'),
@@ -111,9 +130,9 @@ INSERT INTO inflection.inflection_rules
111
130
  ('singular', '(o)es$', E'\\1'),
112
131
  ('singular', '(shoe)s$', E'\\1'),
113
132
  ('singular', '(cris|ax|test)es$', E'\\1is'),
114
- ('singular', '(octop|vir)i$', E'\\1us'),
133
+ ('singular', '(octop|vir)uses$', E'\\1us'),
115
134
  ('singular', '(alias|canvas|status|campus)es$', E'\\1'),
116
- ('singular', '^(summons)es$', E'\\1'),
135
+ ('singular', '^(summons|bonus)es$', E'\\1'),
117
136
  ('singular', '^(ox)en', E'\\1'),
118
137
  ('singular', '(matr)ices$', E'\\1ix'),
119
138
  ('singular', '(vert|ind)ices$', E'\\1ex'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgpm/inflection",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "String inflection utilities for PostgreSQL naming conventions",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "contributors": [
@@ -21,10 +21,10 @@
21
21
  "test:watch": "jest --watch"
22
22
  },
23
23
  "dependencies": {
24
- "@pgpm/verify": "0.17.0"
24
+ "@pgpm/verify": "0.18.0"
25
25
  },
26
26
  "devDependencies": {
27
- "pgpm": "^1.3.0"
27
+ "pgpm": "^4.2.3"
28
28
  },
29
29
  "repository": {
30
30
  "type": "git",
@@ -34,5 +34,5 @@
34
34
  "bugs": {
35
35
  "url": "https://github.com/constructive-io/pgpm-modules/issues"
36
36
  },
37
- "gitHead": "8eb8b9e3a6784fb45a3a9e86838f8417f061925c"
37
+ "gitHead": "8144027c7fab4956bcdebd736d04c0d4f57344bc"
38
38
  }
package/pgpm.plan CHANGED
@@ -11,10 +11,10 @@ schemas/inflection/procedures/camel [schemas/inflection/schema schemas/inflectio
11
11
  schemas/inflection/procedures/dashed [schemas/inflection/schema schemas/inflection/procedures/underscore] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/dashed
12
12
  schemas/inflection/procedures/pascal [schemas/inflection/schema schemas/inflection/procedures/camel] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/pascal
13
13
  schemas/inflection/tables/inflection_rules/table [schemas/inflection/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/tables/inflection_rules/table
14
- schemas/inflection/procedures/plural [schemas/inflection/schema schemas/inflection/tables/inflection_rules/table] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/plural
15
14
  schemas/inflection/procedures/uncountable_words [schemas/inflection/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/uncountable_words
16
15
  schemas/inflection/procedures/should_skip_uncountable [schemas/inflection/schema schemas/inflection/procedures/uncountable_words] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/should_skip_uncountable
17
- schemas/inflection/procedures/singular [schemas/inflection/schema schemas/inflection/tables/inflection_rules/table] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/singular
16
+ schemas/inflection/procedures/plural [schemas/inflection/schema schemas/inflection/tables/inflection_rules/table schemas/inflection/procedures/should_skip_uncountable] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/plural
17
+ schemas/inflection/procedures/singular [schemas/inflection/schema schemas/inflection/tables/inflection_rules/table schemas/inflection/procedures/should_skip_uncountable] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/singular
18
18
  schemas/inflection/procedures/slugify [schemas/inflection/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/slugify
19
19
  schemas/inflection/tables/inflection_rules/fixtures/1589249334312_fixture [schemas/inflection/schema schemas/inflection/tables/inflection_rules/table] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/tables/inflection_rules/fixtures/1589249334312_fixture
20
- schemas/inflection/tables/inflection_rules/indexes/inflection_rules_type_idx [schemas/inflection/schema schemas/inflection/tables/inflection_rules/table] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/tables/inflection_rules/indexes/inflection_rules_type_idx
20
+ schemas/inflection/tables/inflection_rules/indexes/inflection_rules_type_idx [schemas/inflection/schema schemas/inflection/tables/inflection_rules/table] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/tables/inflection_rules/indexes/inflection_rules_type_idx
@@ -242,6 +242,10 @@ DECLARE
242
242
  result record;
243
243
  matches text[];
244
244
  BEGIN
245
+ IF inflection.should_skip_uncountable(lower(str)) THEN
246
+ return str;
247
+ END IF;
248
+
245
249
  FOR result IN
246
250
  SELECT * FROM inflection.inflection_rules where type='plural'
247
251
  LOOP
@@ -272,6 +276,10 @@ DECLARE
272
276
  result record;
273
277
  matches text[];
274
278
  BEGIN
279
+ IF inflection.should_skip_uncountable(lower(str)) THEN
280
+ return str;
281
+ END IF;
282
+
275
283
  FOR result IN
276
284
  SELECT * FROM inflection.inflection_rules where type='singular'
277
285
  LOOP
@@ -334,11 +342,14 @@ INSERT INTO inflection.inflection_rules (
334
342
  test,
335
343
  replacement
336
344
  ) VALUES
345
+ -- plural guards: already-plural words return as-is (NULL replacement)
337
346
  ('plural', '^(m|wom)en$', NULL),
338
347
  ('plural', '(pe)ople$', NULL),
339
348
  ('plural', '(child)ren$', NULL),
340
349
  ('plural', '([ti])a$', NULL),
341
350
  ('plural', '((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$', NULL),
351
+ ('plural', '(database)s$', NULL),
352
+ ('plural', '(drive)s$', NULL),
342
353
  ('plural', '(hi|ti)ves$', NULL),
343
354
  ('plural', '(curve)s$', NULL),
344
355
  ('plural', '([lr])ves$', NULL),
@@ -352,11 +363,12 @@ INSERT INTO inflection.inflection_rules (
352
363
  ('plural', '(o)es$', NULL),
353
364
  ('plural', '(shoe)s$', NULL),
354
365
  ('plural', '(cris|ax|test)es$', NULL),
355
- ('plural', '(octop|vir)i$', NULL),
366
+ ('plural', '(octop|vir)uses$', NULL),
356
367
  ('plural', '(alias|canvas|status|campus)es$', NULL),
357
- ('plural', '^(summons)es$', NULL),
368
+ ('plural', '^(summons|bonus)es$', NULL),
358
369
  ('plural', '^(ox)en', NULL),
359
370
  ('plural', '(matr)ices$', NULL),
371
+ ('plural', '(vert|ind)ices$', NULL),
360
372
  ('plural', '^feet$', NULL),
361
373
  ('plural', '^teeth$', NULL),
362
374
  ('plural', '^geese$', NULL),
@@ -364,19 +376,22 @@ INSERT INTO inflection.inflection_rules (
364
376
  ('plural', '^(whereas)es$', NULL),
365
377
  ('plural', '^(criteri)a$', NULL),
366
378
  ('plural', '^genera$', NULL),
379
+ -- plural replacement rules
367
380
  ('plural', '^(m|wom)an$', E'\\1en'),
368
381
  ('plural', '(pe)rson$', E'\\1ople'),
369
382
  ('plural', '(child)$', E'\\1ren'),
383
+ ('plural', '(drive)$', E'\\1s'),
370
384
  ('plural', '^(ox)$', E'\\1en'),
371
385
  ('plural', '(ax|test)is$', E'\\1es'),
372
- ('plural', '(octop|vir)us$', E'\\1i'),
386
+ ('plural', '(octop|vir)us$', E'\\1uses'),
373
387
  ('plural', '(alias|status|canvas|campus)$', E'\\1es'),
374
- ('plural', '^(summons)$', E'\\1es'),
388
+ ('plural', '^(summons|bonus)$', E'\\1es'),
375
389
  ('plural', '(bu)s$', E'\\1ses'),
376
390
  ('plural', '(buffal|tomat|potat)o$', E'\\1oes'),
377
391
  ('plural', '([ti])um$', E'\\1a'),
378
392
  ('plural', 'sis$', 'ses'),
379
393
  ('plural', '(?:([^f])fe|([lr])f)$', E'\\1\\2ves'),
394
+ ('plural', '^(focus)$', E'\\1es'),
380
395
  ('plural', '(hi|ti)ve$', E'\\1ves'),
381
396
  ('plural', '([^aeiouy]|qu)y$', E'\\1ies'),
382
397
  ('plural', '(matr)ix$', E'\\1ices'),
@@ -392,23 +407,27 @@ INSERT INTO inflection.inflection_rules (
392
407
  ('plural', '^genus$', 'genera'),
393
408
  ('plural', 's$', 's'),
394
409
  ('plural', '$', 's'),
410
+ -- singular guards: already-singular words return as-is (NULL replacement)
395
411
  ('singular', '^(m|wom)an$', NULL),
396
412
  ('singular', '(pe)rson$', NULL),
397
413
  ('singular', '(child)$', NULL),
414
+ ('singular', '(drive)$', NULL),
398
415
  ('singular', '^(ox)$', NULL),
399
416
  ('singular', '(ax|test)is$', NULL),
400
417
  ('singular', '(octop|vir)us$', NULL),
401
418
  ('singular', '(alias|status|canvas|campus)$', NULL),
402
- ('singular', '^(summons)$', NULL),
419
+ ('singular', '^(summons|bonus)$', NULL),
403
420
  ('singular', '(bu)s$', NULL),
404
421
  ('singular', '(buffal|tomat|potat)o$', NULL),
405
422
  ('singular', '([ti])um$', NULL),
406
423
  ('singular', 'sis$', NULL),
407
424
  ('singular', '(?:([^f])fe|([lr])f)$', NULL),
425
+ ('singular', '^(focus)$', NULL),
408
426
  ('singular', '(hi|ti)ve$', NULL),
409
427
  ('singular', '([^aeiouy]|qu)y$', NULL),
410
428
  ('singular', '(x|ch|ss|sh)$', NULL),
411
429
  ('singular', '(matr)ix$', NULL),
430
+ ('singular', '(vert|ind)ex$', NULL),
412
431
  ('singular', '([m|l])ouse$', NULL),
413
432
  ('singular', '^foot$', NULL),
414
433
  ('singular', '^tooth$', NULL),
@@ -417,11 +436,19 @@ INSERT INTO inflection.inflection_rules (
417
436
  ('singular', '^(whereas)$', NULL),
418
437
  ('singular', '^(criteri)on$', NULL),
419
438
  ('singular', '^genus$', NULL),
439
+ -- singular replacement rules
420
440
  ('singular', '^(m|wom)en$', E'\\1an'),
421
441
  ('singular', '(pe)ople$', E'\\1rson'),
422
442
  ('singular', '(child)ren$', E'\\1'),
443
+ ('singular', '(database)s$', E'\\1'),
444
+ ('singular', '(drive)s$', E'\\1'),
423
445
  ('singular', '^genera$', 'genus'),
424
446
  ('singular', '^(criteri)a$', E'\\1on'),
447
+ -- Latin suffix overrides (PostGraphile-compatible)
448
+ ('singular', '(schema)ta$', E'\\1'),
449
+ ('singular', '(phenomen)a$', E'\\1on'),
450
+ ('singular', '(memorand)a$', E'\\1um'),
451
+ ('singular', '(curricul)a$', E'\\1um'),
425
452
  ('singular', '([ti])a$', E'\\1um'),
426
453
  ('singular', '((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$', E'\\1\\2sis'),
427
454
  ('singular', '(hi|ti)ves$', E'\\1ve'),
@@ -438,9 +465,9 @@ INSERT INTO inflection.inflection_rules (
438
465
  ('singular', '(o)es$', E'\\1'),
439
466
  ('singular', '(shoe)s$', E'\\1'),
440
467
  ('singular', '(cris|ax|test)es$', E'\\1is'),
441
- ('singular', '(octop|vir)i$', E'\\1us'),
468
+ ('singular', '(octop|vir)uses$', E'\\1us'),
442
469
  ('singular', '(alias|canvas|status|campus)es$', E'\\1'),
443
- ('singular', '^(summons)es$', E'\\1'),
470
+ ('singular', '^(summons|bonus)es$', E'\\1'),
444
471
  ('singular', '^(ox)en', E'\\1'),
445
472
  ('singular', '(matr)ices$', E'\\1ix'),
446
473
  ('singular', '(vert|ind)ices$', E'\\1ex'),
@@ -452,4 +479,4 @@ INSERT INTO inflection.inflection_rules (
452
479
  ('singular', 'ss$', 'ss'),
453
480
  ('singular', 's$', '');
454
481
 
455
- CREATE INDEX inflection_rules_type_idx ON inflection.inflection_rules (type);
482
+ CREATE INDEX inflection_rules_type_idx ON inflection.inflection_rules (type);