@reinteractive/rails-insight 1.0.2 → 1.0.4
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/package.json
CHANGED
|
@@ -18,8 +18,9 @@ export const ROUTE_PATTERNS = {
|
|
|
18
18
|
member: /^\s*member\s+do/m,
|
|
19
19
|
collection: /^\s*collection\s+do/m,
|
|
20
20
|
draw: /^\s*draw\s*\(?:?(\w+)\)?/m,
|
|
21
|
-
only: /only:\s
|
|
22
|
-
except: /except:\s
|
|
21
|
+
only: /only:\s*(?:\[([^\]]+)\]|:([\w]+))/,
|
|
22
|
+
except: /except:\s*(?:\[([^\]]+)\]|:([\w]+))/,
|
|
23
|
+
httpVerbSymbol: /^\s*(?:get|post|put|patch|delete)\s+:(\w+)/m,
|
|
23
24
|
defaults: /defaults:\s*\{([^}]+)\}/,
|
|
24
25
|
healthCheck: /^\s*get\s+['"]up['"]/m,
|
|
25
26
|
direct: /^\s*direct\s*\(:(\w+)\)/m,
|
|
@@ -10,7 +10,7 @@ export const SCHEMA_PATTERNS = {
|
|
|
10
10
|
/^\s*t\.(?:references|belongs_to)\s+['"]?:?(\w+)['"]?(?:,\s*(.+))?/m,
|
|
11
11
|
timestamps: /^\s*t\.timestamps/m,
|
|
12
12
|
index:
|
|
13
|
-
/^\s*(?:t\.index|add_index)\s+(?:\[([^\]]+)\]|['"](
|
|
13
|
+
/^\s*(?:t\.index|add_index)\s+(?:\[([^\]]+)\]|['"]([^'"]+)['"]),?\s*(.+)?/m,
|
|
14
14
|
foreignKey:
|
|
15
15
|
/^\s*add_foreign_key\s+['"](\w+)['"],\s*['"](\w+)['"](?:,\s*(.+))?/m,
|
|
16
16
|
checkConstraint:
|
package/src/extractors/routes.js
CHANGED
|
@@ -112,7 +112,8 @@ function parseRouteContent(content, result, provider, namespaceStack) {
|
|
|
112
112
|
let actions = ['show', 'new', 'create', 'edit', 'update', 'destroy']
|
|
113
113
|
const onlyMatch = options.match(ROUTE_PATTERNS.only)
|
|
114
114
|
if (onlyMatch) {
|
|
115
|
-
|
|
115
|
+
const raw = onlyMatch[1] ?? `:${onlyMatch[2]}`
|
|
116
|
+
actions = raw.match(/:(\w+)/g)?.map((a) => a.slice(1)) || []
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
const entry = {
|
|
@@ -151,12 +152,13 @@ function parseRouteContent(content, result, provider, namespaceStack) {
|
|
|
151
152
|
]
|
|
152
153
|
const onlyMatch = options.match(ROUTE_PATTERNS.only)
|
|
153
154
|
if (onlyMatch) {
|
|
154
|
-
|
|
155
|
+
const raw = onlyMatch[1] ?? `:${onlyMatch[2]}`
|
|
156
|
+
actions = raw.match(/:(\w+)/g)?.map((a) => a.slice(1)) || []
|
|
155
157
|
}
|
|
156
158
|
const exceptMatch = options.match(ROUTE_PATTERNS.except)
|
|
157
159
|
if (exceptMatch) {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
+
const raw = exceptMatch[1] ?? `:${exceptMatch[2]}`
|
|
161
|
+
const except = raw.match(/:(\w+)/g)?.map((a) => a.slice(1)) || []
|
|
160
162
|
actions = actions.filter((a) => !except.includes(a))
|
|
161
163
|
}
|
|
162
164
|
|
|
@@ -208,6 +210,20 @@ function parseRouteContent(content, result, provider, namespaceStack) {
|
|
|
208
210
|
continue
|
|
209
211
|
}
|
|
210
212
|
|
|
213
|
+
// Symbol-form verb routes inside member/collection blocks: `get :action_name`
|
|
214
|
+
if (inMember || inCollection) {
|
|
215
|
+
const symbolVerbMatch = trimmed.match(ROUTE_PATTERNS.httpVerbSymbol)
|
|
216
|
+
if (symbolVerbMatch) {
|
|
217
|
+
const action = symbolVerbMatch[1]
|
|
218
|
+
const currentResource = resourceStack[resourceStack.length - 1]
|
|
219
|
+
if (currentResource) {
|
|
220
|
+
if (inMember) currentResource.member_routes.push(action)
|
|
221
|
+
else currentResource.collection_routes.push(action)
|
|
222
|
+
}
|
|
223
|
+
continue
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
211
227
|
// HTTP verb routes
|
|
212
228
|
const verbMatch = trimmed.match(ROUTE_PATTERNS.httpVerb)
|
|
213
229
|
if (verbMatch) {
|
package/src/extractors/schema.js
CHANGED
|
@@ -149,16 +149,22 @@ export function extractSchema(provider) {
|
|
|
149
149
|
// Index
|
|
150
150
|
const indexMatch = trimmed.match(SCHEMA_PATTERNS.index)
|
|
151
151
|
if (indexMatch) {
|
|
152
|
+
const isExpression = indexMatch[1] === undefined && indexMatch[2] !== undefined && /[^a-zA-Z0-9_]/.test(indexMatch[2])
|
|
152
153
|
const columns = indexMatch[1]
|
|
153
154
|
? indexMatch[1]
|
|
154
155
|
.match(/['"](\w+)['"]/g)
|
|
155
156
|
?.map((c) => c.replace(/['"]/g, '')) || []
|
|
156
|
-
:
|
|
157
|
+
: isExpression
|
|
158
|
+
? []
|
|
159
|
+
: [indexMatch[2]]
|
|
157
160
|
const opts = indexMatch[3] || ''
|
|
158
161
|
currentTable.indexes.push({
|
|
159
162
|
columns,
|
|
163
|
+
...(isExpression ? { expression: indexMatch[2] } : {}),
|
|
160
164
|
unique: /unique:\s*true/.test(opts),
|
|
161
165
|
name: opts.match(/name:\s*['"]([^'"]+)['"]/)?.[1] || null,
|
|
166
|
+
where: opts.match(/where:\s*['"]([^'"]+)['"]/)?.[1] || null,
|
|
167
|
+
using: opts.match(/using:\s*:(\w+)/)?.[1] || null,
|
|
162
168
|
})
|
|
163
169
|
continue
|
|
164
170
|
}
|
|
@@ -15,9 +15,10 @@ export function register(server, state) {
|
|
|
15
15
|
const schema = state.index.extractions?.schema || {}
|
|
16
16
|
const models = state.index.extractions?.models || {}
|
|
17
17
|
|
|
18
|
-
// Add model ↔ table mapping
|
|
18
|
+
// Add model ↔ table mapping (concrete AR models only, not concerns/modules)
|
|
19
19
|
const modelTableMap = {}
|
|
20
20
|
for (const [modelName, modelData] of Object.entries(models)) {
|
|
21
|
+
if (modelData.type === 'concern') continue
|
|
21
22
|
const tableName = modelData.table_name || toTableName(modelName)
|
|
22
23
|
modelTableMap[modelName] = tableName
|
|
23
24
|
}
|