@danielfgray/pg-sourcerer 0.1.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.
Files changed (145) hide show
  1. package/dist/cli.d.ts +3 -0
  2. package/dist/cli.d.ts.map +1 -0
  3. package/dist/cli.js +104 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/config.d.ts +133 -0
  6. package/dist/config.d.ts.map +1 -0
  7. package/dist/config.js +47 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/errors.d.ts +129 -0
  10. package/dist/errors.d.ts.map +1 -0
  11. package/dist/errors.js +41 -0
  12. package/dist/errors.js.map +1 -0
  13. package/dist/generate.d.ts +75 -0
  14. package/dist/generate.d.ts.map +1 -0
  15. package/dist/generate.js +183 -0
  16. package/dist/generate.js.map +1 -0
  17. package/dist/index.d.ts +35 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +62 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/init.d.ts +4 -0
  22. package/dist/init.d.ts.map +1 -0
  23. package/dist/init.js +229 -0
  24. package/dist/init.js.map +1 -0
  25. package/dist/ir/index.d.ts +7 -0
  26. package/dist/ir/index.d.ts.map +1 -0
  27. package/dist/ir/index.js +7 -0
  28. package/dist/ir/index.js.map +1 -0
  29. package/dist/ir/relation-graph.d.ts +113 -0
  30. package/dist/ir/relation-graph.d.ts.map +1 -0
  31. package/dist/ir/relation-graph.js +232 -0
  32. package/dist/ir/relation-graph.js.map +1 -0
  33. package/dist/ir/semantic-ir.d.ts +448 -0
  34. package/dist/ir/semantic-ir.d.ts.map +1 -0
  35. package/dist/ir/semantic-ir.js +138 -0
  36. package/dist/ir/semantic-ir.js.map +1 -0
  37. package/dist/ir/smart-tags.d.ts +24 -0
  38. package/dist/ir/smart-tags.d.ts.map +1 -0
  39. package/dist/ir/smart-tags.js +30 -0
  40. package/dist/ir/smart-tags.js.map +1 -0
  41. package/dist/lib/conjure.d.ts +431 -0
  42. package/dist/lib/conjure.d.ts.map +1 -0
  43. package/dist/lib/conjure.js +697 -0
  44. package/dist/lib/conjure.js.map +1 -0
  45. package/dist/lib/field-utils.d.ts +61 -0
  46. package/dist/lib/field-utils.d.ts.map +1 -0
  47. package/dist/lib/field-utils.js +132 -0
  48. package/dist/lib/field-utils.js.map +1 -0
  49. package/dist/lib/hex.d.ts +117 -0
  50. package/dist/lib/hex.d.ts.map +1 -0
  51. package/dist/lib/hex.js +185 -0
  52. package/dist/lib/hex.js.map +1 -0
  53. package/dist/plugins/arktype.d.ts +11 -0
  54. package/dist/plugins/arktype.d.ts.map +1 -0
  55. package/dist/plugins/arktype.js +207 -0
  56. package/dist/plugins/arktype.js.map +1 -0
  57. package/dist/plugins/effect-model.d.ts +10 -0
  58. package/dist/plugins/effect-model.d.ts.map +1 -0
  59. package/dist/plugins/effect-model.js +261 -0
  60. package/dist/plugins/effect-model.js.map +1 -0
  61. package/dist/plugins/kysely-queries.d.ts +7 -0
  62. package/dist/plugins/kysely-queries.d.ts.map +1 -0
  63. package/dist/plugins/kysely-queries.js +380 -0
  64. package/dist/plugins/kysely-queries.js.map +1 -0
  65. package/dist/plugins/sql-queries.d.ts +6 -0
  66. package/dist/plugins/sql-queries.d.ts.map +1 -0
  67. package/dist/plugins/sql-queries.js +249 -0
  68. package/dist/plugins/sql-queries.js.map +1 -0
  69. package/dist/plugins/types.d.ts +18 -0
  70. package/dist/plugins/types.d.ts.map +1 -0
  71. package/dist/plugins/types.js +263 -0
  72. package/dist/plugins/types.js.map +1 -0
  73. package/dist/plugins/zod.d.ts +11 -0
  74. package/dist/plugins/zod.d.ts.map +1 -0
  75. package/dist/plugins/zod.js +180 -0
  76. package/dist/plugins/zod.js.map +1 -0
  77. package/dist/services/artifact-store.d.ts +55 -0
  78. package/dist/services/artifact-store.d.ts.map +1 -0
  79. package/dist/services/artifact-store.js +51 -0
  80. package/dist/services/artifact-store.js.map +1 -0
  81. package/dist/services/config-loader.d.ts +45 -0
  82. package/dist/services/config-loader.d.ts.map +1 -0
  83. package/dist/services/config-loader.js +113 -0
  84. package/dist/services/config-loader.js.map +1 -0
  85. package/dist/services/emissions.d.ts +89 -0
  86. package/dist/services/emissions.d.ts.map +1 -0
  87. package/dist/services/emissions.js +194 -0
  88. package/dist/services/emissions.js.map +1 -0
  89. package/dist/services/file-builder.d.ts +81 -0
  90. package/dist/services/file-builder.d.ts.map +1 -0
  91. package/dist/services/file-builder.js +112 -0
  92. package/dist/services/file-builder.js.map +1 -0
  93. package/dist/services/file-writer.d.ts +57 -0
  94. package/dist/services/file-writer.d.ts.map +1 -0
  95. package/dist/services/file-writer.js +76 -0
  96. package/dist/services/file-writer.js.map +1 -0
  97. package/dist/services/inflection.d.ts +227 -0
  98. package/dist/services/inflection.d.ts.map +1 -0
  99. package/dist/services/inflection.js +350 -0
  100. package/dist/services/inflection.js.map +1 -0
  101. package/dist/services/introspection.d.ts +46 -0
  102. package/dist/services/introspection.d.ts.map +1 -0
  103. package/dist/services/introspection.js +99 -0
  104. package/dist/services/introspection.js.map +1 -0
  105. package/dist/services/ir-builder.d.ts +46 -0
  106. package/dist/services/ir-builder.d.ts.map +1 -0
  107. package/dist/services/ir-builder.js +923 -0
  108. package/dist/services/ir-builder.js.map +1 -0
  109. package/dist/services/ir.d.ts +28 -0
  110. package/dist/services/ir.d.ts.map +1 -0
  111. package/dist/services/ir.js +25 -0
  112. package/dist/services/ir.js.map +1 -0
  113. package/dist/services/pg-types.d.ts +197 -0
  114. package/dist/services/pg-types.d.ts.map +1 -0
  115. package/dist/services/pg-types.js +274 -0
  116. package/dist/services/pg-types.js.map +1 -0
  117. package/dist/services/plugin-meta.d.ts +33 -0
  118. package/dist/services/plugin-meta.d.ts.map +1 -0
  119. package/dist/services/plugin-meta.js +24 -0
  120. package/dist/services/plugin-meta.js.map +1 -0
  121. package/dist/services/plugin-runner.d.ts +52 -0
  122. package/dist/services/plugin-runner.d.ts.map +1 -0
  123. package/dist/services/plugin-runner.js +182 -0
  124. package/dist/services/plugin-runner.js.map +1 -0
  125. package/dist/services/plugin.d.ts +286 -0
  126. package/dist/services/plugin.d.ts.map +1 -0
  127. package/dist/services/plugin.js +132 -0
  128. package/dist/services/plugin.js.map +1 -0
  129. package/dist/services/smart-tags-parser.d.ts +37 -0
  130. package/dist/services/smart-tags-parser.d.ts.map +1 -0
  131. package/dist/services/smart-tags-parser.js +79 -0
  132. package/dist/services/smart-tags-parser.js.map +1 -0
  133. package/dist/services/symbols.d.ts +85 -0
  134. package/dist/services/symbols.d.ts.map +1 -0
  135. package/dist/services/symbols.js +128 -0
  136. package/dist/services/symbols.js.map +1 -0
  137. package/dist/services/type-hints.d.ts +62 -0
  138. package/dist/services/type-hints.d.ts.map +1 -0
  139. package/dist/services/type-hints.js +117 -0
  140. package/dist/services/type-hints.js.map +1 -0
  141. package/dist/testing.d.ts +77 -0
  142. package/dist/testing.d.ts.map +1 -0
  143. package/dist/testing.js +84 -0
  144. package/dist/testing.js.map +1 -0
  145. package/package.json +74 -0
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Core Inflection Service - naming transformations
3
+ *
4
+ * Provides configurable naming conventions for entities, fields, enums, etc.
5
+ * Users configure with simple string→string functions that compose naturally.
6
+ */
7
+ import { Context, Layer } from "effect";
8
+ import type { PgAttribute, PgClass, PgProc, PgType } from "@pg-sourcerer/pg-introspection";
9
+ import type { SmartTags, ShapeKind } from "../ir/index.js";
10
+ /**
11
+ * Inflection helper functions for use in configuration.
12
+ *
13
+ * Users can compose these in their config:
14
+ * @example
15
+ * ```typescript
16
+ * import { inflect } from "pg-sourcerer"
17
+ *
18
+ * const config = {
19
+ * inflection: {
20
+ * entityName: (name) => inflect.pascalCase(inflect.singularize(name)),
21
+ * fieldName: inflect.camelCase,
22
+ * }
23
+ * }
24
+ * ```
25
+ */
26
+ export declare const inflect: {
27
+ /** Convert snake_case to camelCase */
28
+ readonly camelCase: (self: string) => string;
29
+ /** Convert snake_case to PascalCase */
30
+ readonly pascalCase: (self: string) => string;
31
+ /** Convert camelCase to snake_case */
32
+ readonly snakeCase: (self: string) => string;
33
+ /** Singularize a word (users → user) */
34
+ readonly singularize: (word: string) => string;
35
+ /** Pluralize a word (user → users) */
36
+ readonly pluralize: (word: string) => string;
37
+ /** Capitalize first letter */
38
+ readonly capitalize: <T extends string>(self: T) => Capitalize<T>;
39
+ /** Uncapitalize first letter */
40
+ readonly uncapitalize: <T extends string>(self: T) => Uncapitalize<T>;
41
+ /** Convert to lowercase */
42
+ readonly lowercase: (s: string) => string;
43
+ /** Convert to uppercase */
44
+ readonly uppercase: (s: string) => string;
45
+ };
46
+ /**
47
+ * Core inflection interface - shared naming transformations
48
+ */
49
+ export interface CoreInflection {
50
+ readonly camelCase: (text: string) => string;
51
+ readonly pascalCase: (text: string) => string;
52
+ readonly pluralize: (text: string) => string;
53
+ readonly singularize: (text: string) => string;
54
+ readonly safeIdentifier: (text: string) => string;
55
+ readonly entityName: (pgClass: PgClass, tags: SmartTags) => string;
56
+ readonly shapeName: (entityName: string, kind: ShapeKind) => string;
57
+ readonly fieldName: (pgAttribute: PgAttribute, tags: SmartTags) => string;
58
+ readonly enumName: (pgType: PgType, tags: SmartTags) => string;
59
+ readonly enumValueName: (value: string) => string;
60
+ readonly relationName: (name: string) => string;
61
+ readonly functionName: (pgProc: PgProc, tags: SmartTags) => string;
62
+ }
63
+ declare const Inflection_base: Context.TagClass<Inflection, "Inflection", CoreInflection>;
64
+ /** Service tag */
65
+ export declare class Inflection extends Inflection_base {
66
+ }
67
+ /**
68
+ * A simple string→string transform function.
69
+ */
70
+ export type TransformFn = (input: string) => string;
71
+ /**
72
+ * Configuration for customizing inflection behavior.
73
+ *
74
+ * Each property is an optional function that transforms a name.
75
+ * If undefined, the identity function is used (name preserved as-is).
76
+ * Smart tags (@name) always take precedence over configured transforms.
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * import { inflect } from "pg-sourcerer"
81
+ *
82
+ * const config: InflectionConfig = {
83
+ * // users → User
84
+ * entityName: (name) => inflect.pascalCase(inflect.singularize(name)),
85
+ *
86
+ * // created_at → createdAt
87
+ * fieldName: inflect.camelCase,
88
+ *
89
+ * // user_status → UserStatus
90
+ * enumName: inflect.pascalCase,
91
+ *
92
+ * // row → Row
93
+ * shapeSuffix: inflect.capitalize,
94
+ * }
95
+ * ```
96
+ */
97
+ export interface InflectionConfig {
98
+ /**
99
+ * Transform table/view name → entity name.
100
+ * Default: identity (preserve table name)
101
+ */
102
+ readonly entityName?: TransformFn;
103
+ /**
104
+ * Transform column name → field name.
105
+ * Default: identity (preserve column name)
106
+ */
107
+ readonly fieldName?: TransformFn;
108
+ /**
109
+ * Transform PostgreSQL enum type name → TypeScript enum name.
110
+ * Default: identity (preserve type name)
111
+ */
112
+ readonly enumName?: TransformFn;
113
+ /**
114
+ * Transform enum values.
115
+ * Default: identity (preserve value)
116
+ */
117
+ readonly enumValue?: TransformFn;
118
+ /**
119
+ * Transform shape kind suffix.
120
+ * Default: identity ("row", "insert", etc.)
121
+ */
122
+ readonly shapeSuffix?: TransformFn;
123
+ /**
124
+ * Transform relation names.
125
+ * Default: identity (preserve name)
126
+ */
127
+ readonly relationName?: TransformFn;
128
+ /**
129
+ * Transform function name.
130
+ * Default: "{name}_{argCount}" for overload disambiguation
131
+ */
132
+ readonly functionName?: TransformFn;
133
+ }
134
+ /**
135
+ * Default inflection implementation.
136
+ * Preserves PostgreSQL names as-is (identity transforms).
137
+ */
138
+ export declare const defaultInflection: CoreInflection;
139
+ /**
140
+ * Create a CoreInflection instance with optional configuration.
141
+ *
142
+ * Smart tags (@name) always take precedence over configured transforms.
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * import { inflect } from "pg-sourcerer"
147
+ *
148
+ * // Use defaults (identity - preserve names)
149
+ * const inflection = createInflection()
150
+ *
151
+ * // Common JS/TS conventions
152
+ * const inflection = createInflection({
153
+ * entityName: (name) => inflect.pascalCase(inflect.singularize(name)),
154
+ * fieldName: inflect.camelCase,
155
+ * enumName: inflect.pascalCase,
156
+ * shapeSuffix: inflect.capitalize,
157
+ * })
158
+ * ```
159
+ */
160
+ export declare function createInflection(config?: InflectionConfig): CoreInflection;
161
+ /**
162
+ * Create an Effect Layer that provides inflection with optional configuration.
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * import { inflect } from "pg-sourcerer"
167
+ *
168
+ * // Default layer (identity transforms)
169
+ * const layer = makeInflectionLayer()
170
+ *
171
+ * // Configured layer
172
+ * const layer = makeInflectionLayer({
173
+ * entityName: (name) => inflect.pascalCase(inflect.singularize(name)),
174
+ * fieldName: inflect.camelCase,
175
+ * })
176
+ * ```
177
+ */
178
+ export declare function makeInflectionLayer(config?: InflectionConfig): Layer.Layer<Inflection>;
179
+ /** Default inflection layer (identity - no transforms) */
180
+ export declare const InflectionLive: Layer.Layer<Inflection, never, never>;
181
+ /**
182
+ * Classic inflection config - matches the "opinionated" defaults of many ORMs:
183
+ * - Entity names: singularize + PascalCase (users → User)
184
+ * - Field names: camelCase (created_at → createdAt)
185
+ * - Enum names: PascalCase (user_status → UserStatus)
186
+ * - Shape suffixes: capitalize (row → Row)
187
+ * - Relation names: camelCase
188
+ */
189
+ export declare const classicInflectionConfig: InflectionConfig;
190
+ /** Classic inflection layer - applies traditional ORM naming conventions */
191
+ export declare const ClassicInflectionLive: Layer.Layer<Inflection, never, never>;
192
+ /**
193
+ * Compose plugin inflection defaults with user-configured inflection.
194
+ *
195
+ * Plugin defaults are applied first, then user config refines the result.
196
+ * This allows plugins to set baseline conventions while users can customize.
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * // Plugin wants PascalCase
201
+ * const pluginDefaults = { entityName: inflect.pascalCase }
202
+ *
203
+ * // User wants singular names
204
+ * const userConfig = { entityName: inflect.singularize }
205
+ *
206
+ * // Composed: "users" → "Users" → "User"
207
+ * const composed = composeInflectionConfigs(pluginDefaults, userConfig)
208
+ * ```
209
+ *
210
+ * @param pluginDefaults - Plugin's baseline inflection (applied first)
211
+ * @param userConfig - User's refinement config (applied second)
212
+ * @returns Merged InflectionConfig with composed functions
213
+ */
214
+ export declare function composeInflectionConfigs(pluginDefaults: InflectionConfig | undefined, userConfig: InflectionConfig | undefined): InflectionConfig;
215
+ /**
216
+ * Compose a CoreInflection with plugin defaults.
217
+ *
218
+ * This is used by PluginRunner to merge plugin's inflectionDefaults
219
+ * with the user's configured inflection.
220
+ *
221
+ * @param baseInflection - The user's CoreInflection instance
222
+ * @param pluginDefaults - Plugin's default transforms to apply first
223
+ * @returns New CoreInflection with composed behavior
224
+ */
225
+ export declare function composeInflection(baseInflection: CoreInflection, pluginDefaults: InflectionConfig | undefined): CoreInflection;
226
+ export {};
227
+ //# sourceMappingURL=inflection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inflection.d.ts","sourceRoot":"","sources":["../../src/services/inflection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAiB,MAAM,QAAQ,CAAA;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAA;AAC1F,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAiE1D;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,OAAO;IAClB,sCAAsC;;IAEtC,uCAAuC;;IAEvC,sCAAsC;;IAEtC,wCAAwC;iCA3Cf,MAAM,KAAG,MAAM;IA6CxC,sCAAsC;+BAhEf,MAAM,KAAG,MAAM;IAkEtC,8BAA8B;;IAE9B,gCAAgC;;IAEhC,2BAA2B;4BACZ,MAAM;IACrB,2BAA2B;4BACZ,MAAM;CACb,CAAA;AAMV;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IAC5C,QAAQ,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA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CAAC,QAAQ,CAAC,EAAE,WAAW,CAAA;IAE/B;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,WAAW,CAAA;IAEhC;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAA;IAElC;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,WAAW,CAAA;IAEnC;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,WAAW,CAAA;CACpC;AAMD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,cAgB/B,CAAA;AASD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAuC1E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAEtF;AAMD,0DAA0D;AAC1D,eAAO,MAAM,cAAc,uCAAwB,CAAA;AAEnD;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,EAAE,gBAMrC,CAAA;AAED,4EAA4E;AAC5E,eAAO,MAAM,qBAAqB,uCAA+C,CAAA;AAmBjF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,wBAAwB,CACtC,cAAc,EAAE,gBAAgB,GAAG,SAAS,EAC5C,UAAU,EAAE,gBAAgB,GAAG,SAAS,GACvC,gBAAgB,CAgBlB;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,gBAAgB,GAAG,SAAS,GAC3C,cAAc,CAsEhB"}
@@ -0,0 +1,350 @@
1
+ /**
2
+ * Core Inflection Service - naming transformations
3
+ *
4
+ * Provides configurable naming conventions for entities, fields, enums, etc.
5
+ * Users configure with simple string→string functions that compose naturally.
6
+ */
7
+ import { Context, Layer, String as Str } from "effect";
8
+ // ============================================================================
9
+ // Reserved Words
10
+ // ============================================================================
11
+ const RESERVED_WORDS = new Set([
12
+ // TypeScript/JavaScript reserved
13
+ "break", "case", "catch", "class", "const", "continue", "debugger", "default",
14
+ "delete", "do", "else", "enum", "export", "extends", "false", "finally", "for",
15
+ "function", "if", "import", "in", "instanceof", "new", "null", "return", "super",
16
+ "switch", "this", "throw", "true", "try", "typeof", "var", "void", "while", "with",
17
+ "yield", "let", "static", "implements", "interface", "package", "private",
18
+ "protected", "public", "abstract", "as", "async", "await", "constructor", "declare",
19
+ "get", "is", "module", "namespace", "never", "readonly", "require", "number",
20
+ "object", "set", "string", "symbol", "type", "undefined", "unique", "unknown",
21
+ "from", "global", "keyof", "of", "infer", "any", "boolean", "bigint",
22
+ ]);
23
+ // ============================================================================
24
+ // Inflection Helper Functions
25
+ // ============================================================================
26
+ /**
27
+ * Simple pluralization (naive, covers common cases)
28
+ */
29
+ const pluralize = (word) => {
30
+ if (word.endsWith("s") ||
31
+ word.endsWith("x") ||
32
+ word.endsWith("z") ||
33
+ word.endsWith("ch") ||
34
+ word.endsWith("sh")) {
35
+ return word + "es";
36
+ }
37
+ if (word.endsWith("y") && !/[aeiou]y$/i.test(word)) {
38
+ return word.slice(0, -1) + "ies";
39
+ }
40
+ return word + "s";
41
+ };
42
+ /**
43
+ * Simple singularization (naive, covers common cases)
44
+ */
45
+ const singularize = (word) => {
46
+ if (word.endsWith("ies") && word.length > 3) {
47
+ return word.slice(0, -3) + "y";
48
+ }
49
+ if (word.endsWith("es") &&
50
+ (word.endsWith("sses") ||
51
+ word.endsWith("xes") ||
52
+ word.endsWith("zes") ||
53
+ word.endsWith("ches") ||
54
+ word.endsWith("shes"))) {
55
+ return word.slice(0, -2);
56
+ }
57
+ if (word.endsWith("s") && !word.endsWith("ss") && word.length > 1) {
58
+ return word.slice(0, -1);
59
+ }
60
+ return word;
61
+ };
62
+ /**
63
+ * Inflection helper functions for use in configuration.
64
+ *
65
+ * Users can compose these in their config:
66
+ * @example
67
+ * ```typescript
68
+ * import { inflect } from "pg-sourcerer"
69
+ *
70
+ * const config = {
71
+ * inflection: {
72
+ * entityName: (name) => inflect.pascalCase(inflect.singularize(name)),
73
+ * fieldName: inflect.camelCase,
74
+ * }
75
+ * }
76
+ * ```
77
+ */
78
+ export const inflect = {
79
+ /** Convert snake_case to camelCase */
80
+ camelCase: Str.snakeToCamel,
81
+ /** Convert snake_case to PascalCase */
82
+ pascalCase: Str.snakeToPascal,
83
+ /** Convert camelCase to snake_case */
84
+ snakeCase: Str.camelToSnake,
85
+ /** Singularize a word (users → user) */
86
+ singularize,
87
+ /** Pluralize a word (user → users) */
88
+ pluralize,
89
+ /** Capitalize first letter */
90
+ capitalize: Str.capitalize,
91
+ /** Uncapitalize first letter */
92
+ uncapitalize: Str.uncapitalize,
93
+ /** Convert to lowercase */
94
+ lowercase: (s) => s.toLowerCase(),
95
+ /** Convert to uppercase */
96
+ uppercase: (s) => s.toUpperCase(),
97
+ };
98
+ /** Service tag */
99
+ export class Inflection extends Context.Tag("Inflection")() {
100
+ }
101
+ // ============================================================================
102
+ // Default Inflection (identity - no transforms)
103
+ // ============================================================================
104
+ /**
105
+ * Default inflection implementation.
106
+ * Preserves PostgreSQL names as-is (identity transforms).
107
+ */
108
+ export const defaultInflection = {
109
+ // Primitive transforms (always available)
110
+ camelCase: inflect.camelCase,
111
+ pascalCase: inflect.pascalCase,
112
+ pluralize: inflect.pluralize,
113
+ singularize: inflect.singularize,
114
+ safeIdentifier: (text) => (RESERVED_WORDS.has(text) ? text + "_" : text),
115
+ // Configurable transforms (default to identity)
116
+ entityName: (pgClass, tags) => tags.name ?? pgClass.relname,
117
+ shapeName: (entityName, kind) => kind === "row" ? entityName : entityName + kind,
118
+ fieldName: (pgAttribute, tags) => tags.name ?? pgAttribute.attname,
119
+ enumName: (pgType, tags) => tags.name ?? pgType.typname,
120
+ enumValueName: (value) => value,
121
+ relationName: (name) => name,
122
+ functionName: (pgProc, tags) => tags.name ?? `${pgProc.proname}_${pgProc.pronargs}`,
123
+ };
124
+ // ============================================================================
125
+ // Factory Functions
126
+ // ============================================================================
127
+ /** Identity function - returns input unchanged */
128
+ const identity = (s) => s;
129
+ /**
130
+ * Create a CoreInflection instance with optional configuration.
131
+ *
132
+ * Smart tags (@name) always take precedence over configured transforms.
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * import { inflect } from "pg-sourcerer"
137
+ *
138
+ * // Use defaults (identity - preserve names)
139
+ * const inflection = createInflection()
140
+ *
141
+ * // Common JS/TS conventions
142
+ * const inflection = createInflection({
143
+ * entityName: (name) => inflect.pascalCase(inflect.singularize(name)),
144
+ * fieldName: inflect.camelCase,
145
+ * enumName: inflect.pascalCase,
146
+ * shapeSuffix: inflect.capitalize,
147
+ * })
148
+ * ```
149
+ */
150
+ export function createInflection(config) {
151
+ if (!config)
152
+ return defaultInflection;
153
+ const entityFn = config.entityName ?? identity;
154
+ const fieldFn = config.fieldName ?? identity;
155
+ const enumNameFn = config.enumName ?? identity;
156
+ const enumValueFn = config.enumValue ?? identity;
157
+ const shapeSuffixFn = config.shapeSuffix ?? identity;
158
+ const relationFn = config.relationName ?? identity;
159
+ const functionFn = config.functionName ?? identity;
160
+ return {
161
+ // Primitive transforms unchanged
162
+ camelCase: defaultInflection.camelCase,
163
+ pascalCase: defaultInflection.pascalCase,
164
+ pluralize: defaultInflection.pluralize,
165
+ singularize: defaultInflection.singularize,
166
+ safeIdentifier: defaultInflection.safeIdentifier,
167
+ // Configurable transforms (smart tags take precedence)
168
+ entityName: (pgClass, tags) => tags.name ?? entityFn(pgClass.relname),
169
+ shapeName: (entityName, kind) => kind === "row" ? entityName : entityName + shapeSuffixFn(kind),
170
+ fieldName: (pgAttribute, tags) => tags.name ?? fieldFn(pgAttribute.attname),
171
+ enumName: (pgType, tags) => tags.name ?? enumNameFn(pgType.typname),
172
+ enumValueName: (value) => enumValueFn(value),
173
+ relationName: (name) => relationFn(name),
174
+ functionName: (pgProc, tags) => tags.name ?? functionFn(`${pgProc.proname}_${pgProc.pronargs}`),
175
+ };
176
+ }
177
+ /**
178
+ * Create an Effect Layer that provides inflection with optional configuration.
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * import { inflect } from "pg-sourcerer"
183
+ *
184
+ * // Default layer (identity transforms)
185
+ * const layer = makeInflectionLayer()
186
+ *
187
+ * // Configured layer
188
+ * const layer = makeInflectionLayer({
189
+ * entityName: (name) => inflect.pascalCase(inflect.singularize(name)),
190
+ * fieldName: inflect.camelCase,
191
+ * })
192
+ * ```
193
+ */
194
+ export function makeInflectionLayer(config) {
195
+ return Layer.succeed(Inflection, createInflection(config));
196
+ }
197
+ // ============================================================================
198
+ // Convenience Exports
199
+ // ============================================================================
200
+ /** Default inflection layer (identity - no transforms) */
201
+ export const InflectionLive = makeInflectionLayer();
202
+ /**
203
+ * Classic inflection config - matches the "opinionated" defaults of many ORMs:
204
+ * - Entity names: singularize + PascalCase (users → User)
205
+ * - Field names: camelCase (created_at → createdAt)
206
+ * - Enum names: PascalCase (user_status → UserStatus)
207
+ * - Shape suffixes: capitalize (row → Row)
208
+ * - Relation names: camelCase
209
+ */
210
+ export const classicInflectionConfig = {
211
+ entityName: (name) => inflect.pascalCase(inflect.singularize(name)),
212
+ fieldName: inflect.camelCase,
213
+ enumName: inflect.pascalCase,
214
+ shapeSuffix: inflect.capitalize,
215
+ relationName: inflect.camelCase,
216
+ };
217
+ /** Classic inflection layer - applies traditional ORM naming conventions */
218
+ export const ClassicInflectionLive = makeInflectionLayer(classicInflectionConfig);
219
+ // ============================================================================
220
+ // Inflection Composition
221
+ // ============================================================================
222
+ /**
223
+ * Compose two transform functions: plugin runs first, then user refines.
224
+ */
225
+ const composeFns = (pluginFn, userFn) => {
226
+ if (!pluginFn && !userFn)
227
+ return undefined;
228
+ if (!pluginFn)
229
+ return userFn;
230
+ if (!userFn)
231
+ return pluginFn;
232
+ return (name) => userFn(pluginFn(name));
233
+ };
234
+ /**
235
+ * Compose plugin inflection defaults with user-configured inflection.
236
+ *
237
+ * Plugin defaults are applied first, then user config refines the result.
238
+ * This allows plugins to set baseline conventions while users can customize.
239
+ *
240
+ * @example
241
+ * ```typescript
242
+ * // Plugin wants PascalCase
243
+ * const pluginDefaults = { entityName: inflect.pascalCase }
244
+ *
245
+ * // User wants singular names
246
+ * const userConfig = { entityName: inflect.singularize }
247
+ *
248
+ * // Composed: "users" → "Users" → "User"
249
+ * const composed = composeInflectionConfigs(pluginDefaults, userConfig)
250
+ * ```
251
+ *
252
+ * @param pluginDefaults - Plugin's baseline inflection (applied first)
253
+ * @param userConfig - User's refinement config (applied second)
254
+ * @returns Merged InflectionConfig with composed functions
255
+ */
256
+ export function composeInflectionConfigs(pluginDefaults, userConfig) {
257
+ if (!pluginDefaults && !userConfig)
258
+ return {};
259
+ if (!pluginDefaults)
260
+ return userConfig;
261
+ if (!userConfig)
262
+ return pluginDefaults;
263
+ return Object.fromEntries(Object.entries({
264
+ entityName: composeFns(pluginDefaults.entityName, userConfig.entityName),
265
+ fieldName: composeFns(pluginDefaults.fieldName, userConfig.fieldName),
266
+ enumName: composeFns(pluginDefaults.enumName, userConfig.enumName),
267
+ enumValue: composeFns(pluginDefaults.enumValue, userConfig.enumValue),
268
+ shapeSuffix: composeFns(pluginDefaults.shapeSuffix, userConfig.shapeSuffix),
269
+ relationName: composeFns(pluginDefaults.relationName, userConfig.relationName),
270
+ functionName: composeFns(pluginDefaults.functionName, userConfig.functionName),
271
+ }).filter(([, v]) => v !== undefined));
272
+ }
273
+ /**
274
+ * Compose a CoreInflection with plugin defaults.
275
+ *
276
+ * This is used by PluginRunner to merge plugin's inflectionDefaults
277
+ * with the user's configured inflection.
278
+ *
279
+ * @param baseInflection - The user's CoreInflection instance
280
+ * @param pluginDefaults - Plugin's default transforms to apply first
281
+ * @returns New CoreInflection with composed behavior
282
+ */
283
+ export function composeInflection(baseInflection, pluginDefaults) {
284
+ if (!pluginDefaults)
285
+ return baseInflection;
286
+ const entityFn = pluginDefaults.entityName;
287
+ const fieldFn = pluginDefaults.fieldName;
288
+ const enumNameFn = pluginDefaults.enumName;
289
+ const enumValueFn = pluginDefaults.enumValue;
290
+ const shapeSuffixFn = pluginDefaults.shapeSuffix;
291
+ const relationFn = pluginDefaults.relationName;
292
+ const functionFn = pluginDefaults.functionName;
293
+ // If no transforms defined, return base unchanged
294
+ if (!entityFn && !fieldFn && !enumNameFn && !enumValueFn && !shapeSuffixFn && !relationFn && !functionFn) {
295
+ return baseInflection;
296
+ }
297
+ return {
298
+ // Primitive transforms unchanged
299
+ camelCase: baseInflection.camelCase,
300
+ pascalCase: baseInflection.pascalCase,
301
+ pluralize: baseInflection.pluralize,
302
+ singularize: baseInflection.singularize,
303
+ safeIdentifier: baseInflection.safeIdentifier,
304
+ // Compose: plugin transforms first, then base transforms
305
+ entityName: (pgClass, tags) => {
306
+ if (tags.name)
307
+ return tags.name;
308
+ const afterPlugin = entityFn ? entityFn(pgClass.relname) : pgClass.relname;
309
+ // Now apply base inflection's transform to the result
310
+ // We simulate this by calling base with a fake pgClass that has the transformed name
311
+ return baseInflection.entityName({ ...pgClass, relname: afterPlugin }, {});
312
+ },
313
+ shapeName: (entityName, kind) => {
314
+ if (kind === "row")
315
+ return entityName;
316
+ const afterPlugin = shapeSuffixFn ? shapeSuffixFn(kind) : kind;
317
+ // Base's shapeName concatenates, so we need to handle carefully
318
+ // Actually base just does: entityName + kind, so we transform kind first
319
+ return entityName + afterPlugin;
320
+ },
321
+ fieldName: (pgAttribute, tags) => {
322
+ if (tags.name)
323
+ return tags.name;
324
+ const afterPlugin = fieldFn ? fieldFn(pgAttribute.attname) : pgAttribute.attname;
325
+ return baseInflection.fieldName({ ...pgAttribute, attname: afterPlugin }, {});
326
+ },
327
+ enumName: (pgType, tags) => {
328
+ if (tags.name)
329
+ return tags.name;
330
+ const afterPlugin = enumNameFn ? enumNameFn(pgType.typname) : pgType.typname;
331
+ return baseInflection.enumName({ ...pgType, typname: afterPlugin }, {});
332
+ },
333
+ enumValueName: (value) => {
334
+ const afterPlugin = enumValueFn ? enumValueFn(value) : value;
335
+ return baseInflection.enumValueName(afterPlugin);
336
+ },
337
+ relationName: (name) => {
338
+ const afterPlugin = relationFn ? relationFn(name) : name;
339
+ return baseInflection.relationName(afterPlugin);
340
+ },
341
+ functionName: (pgProc, tags) => {
342
+ if (tags.name)
343
+ return tags.name;
344
+ const baseName = `${pgProc.proname}_${pgProc.pronargs}`;
345
+ const afterPlugin = functionFn ? functionFn(baseName) : baseName;
346
+ return baseInflection.functionName({ ...pgProc, proname: afterPlugin }, {});
347
+ },
348
+ };
349
+ }
350
+ //# sourceMappingURL=inflection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inflection.js","sourceRoot":"","sources":["../../src/services/inflection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,GAAG,EAAE,MAAM,QAAQ,CAAA;AAItD,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,iCAAiC;IACjC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS;IAC7E,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK;IAC9E,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO;IAChF,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAClF,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS;IACzE,WAAW,EAAE,Q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CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAA;QACzE,CAAC;QAED,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;YACvB,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;YAC5D,OAAO,cAAc,CAAC,aAAa,CAAC,WAAW,CAAC,CAAA;QAClD,CAAC;QAED,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE;YACrB,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;YACxD,OAAO,cAAc,CAAC,YAAY,CAAC,WAAW,CAAC,CAAA;QACjD,CAAC;QAED,YAAY,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;YAC7B,IAAI,IAAI,CAAC,IAAI;gBAAE,OAAO,IAAI,CAAC,IAAI,CAAA;YAC/B,MAAM,QAAQ,GAAG,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAA;YACvD,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;YAChE,OAAO,cAAc,CAAC,YAAY,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAA;QAC7E,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Database Introspection Service
3
+ *
4
+ * Provides typed database introspection using pg-introspection.
5
+ */
6
+ import { Effect, Context } from "effect";
7
+ import { type Introspection } from "@pg-sourcerer/pg-introspection";
8
+ import { ConnectionFailed, IntrospectionFailed } from "../errors.js";
9
+ /**
10
+ * Options for introspection
11
+ */
12
+ export interface IntrospectOptions {
13
+ /** PostgreSQL connection string */
14
+ readonly connectionString: string;
15
+ /** Optional role to set before introspecting (for RLS) */
16
+ readonly role?: string;
17
+ }
18
+ /**
19
+ * Introspection service interface
20
+ */
21
+ export interface DatabaseIntrospection {
22
+ /**
23
+ * Introspect a database and return parsed results
24
+ */
25
+ readonly introspect: (options: IntrospectOptions) => Effect.Effect<Introspection, ConnectionFailed | IntrospectionFailed>;
26
+ }
27
+ declare const DatabaseIntrospectionService_base: Context.TagClass<DatabaseIntrospectionService, "DatabaseIntrospection", DatabaseIntrospection>;
28
+ /**
29
+ * Service tag for dependency injection
30
+ */
31
+ export declare class DatabaseIntrospectionService extends DatabaseIntrospectionService_base {
32
+ }
33
+ /**
34
+ * Live implementation using pg
35
+ */
36
+ export declare const DatabaseIntrospectionLive: Effect.Effect<DatabaseIntrospection, never, never>;
37
+ /**
38
+ * Create a DatabaseIntrospection implementation
39
+ */
40
+ export declare function createDatabaseIntrospection(): DatabaseIntrospection;
41
+ /**
42
+ * Convenience function for one-off introspection (e.g., scripts)
43
+ */
44
+ export declare function introspectDatabase(options: IntrospectOptions): Effect.Effect<Introspection, ConnectionFailed | IntrospectionFailed>;
45
+ export {};
46
+ //# sourceMappingURL=introspection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"introspection.d.ts","sourceRoot":"","sources":["../../src/services/introspection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAExC,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAEpE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;IACjC,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,CACnB,OAAO,EAAE,iBAAiB,KACvB,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,gBAAgB,GAAG,mBAAmB,CAAC,CAAA;CAC1E;;AAED;;GAEG;AACH,qBAAa,4BAA6B,SAAQ,iCAEM;CAAG;AAE3D;;GAEG;AACH,eAAO,MAAM,yBAAyB,oDAErC,CAAA;AAED;;GAEG;AACH,wBAAgB,2BAA2B,IAAI,qBAAqB,CAsFnE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,iBAAiB,GACzB,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,gBAAgB,GAAG,mBAAmB,CAAC,CAEtE"}