gatelight 0.19.1 → 0.19.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/.antigravity-plugin/plugin.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/skills/modular/SKILL.md +1 -0
- package/src/base/git.ts +7 -0
- package/src/wall/check.ts +25 -5
- package/src/wall/rules.ts +64 -8
- package/src/wall/session.ts +2 -2
- package/src/wall/sql.ts +5 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatelight",
|
|
3
3
|
"displayName": "gatelight",
|
|
4
|
-
"version": "0.19.
|
|
4
|
+
"version": "0.19.2",
|
|
5
5
|
"description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, standards (types, lint, format, secrets) are not quietly loosened, plus test-writing conventions and a change-triggered checklist",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "coffeecoproject"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatelight",
|
|
3
3
|
"displayName": "gatelight",
|
|
4
|
-
"version": "0.19.
|
|
4
|
+
"version": "0.19.2",
|
|
5
5
|
"description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, standards (types, lint, format, secrets) are not quietly loosened, plus test-writing conventions and a change-triggered checklist",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "coffeecoproject"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatelight",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.2",
|
|
4
4
|
"description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, standards (types, lint, format, secrets) are not quietly loosened, plus test-writing conventions and a change-triggered checklist",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "coffeecoproject"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatelight",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.2",
|
|
4
4
|
"description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, standards (types, lint, format, secrets) are not quietly loosened, plus test-writing conventions and a change-triggered checklist",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/coffeecoproject/gatelight#readme",
|
package/skills/modular/SKILL.md
CHANGED
|
@@ -38,6 +38,7 @@ modwall 的约定:默认模块化,越界由程序拦。模块边界以 `.mod
|
|
|
38
38
|
- 样式、图片、JSON 这类文件也算:不直接 import 别的模块里的。图片、JSON 和代码一样从对方入口导出;样式不能经入口导出,几个模块都用的样式搬进共享层,只该对方用的,改成用对方入口导出的组件。
|
|
39
39
|
- 入口里没有要的东西:在对方入口**新增导出**,作为单独的一小步来做,说清楚为什么要导出。不要为了省事把对方内部的东西全从入口导出:`modwall check` 会列出这次给哪些入口新增了导出。
|
|
40
40
|
- **不给别的模块的已有函数加分支**:为新功能在对方新增一个函数。改了别人已有的导出函数、同时又在自己模块里新加了对它的调用,`modwall check` 会提示(R4);正常的重构(改签名、同步更新调用处)不用管。
|
|
41
|
+
- **不在别的模块里写上自己的名字**:别的模块的名单、类型、枚举、常量、映射表、`switch`、数据库约束里,不为新功能加上它的名字、它的页面、它的来源。加了,对方就认识了用它的模块,以后每多一个用的地方都要回去改它,看引用还查不出来。改成对方收一个值(比如来源的文字由调用方给),或者由装配层把链接、实现接进来。旧代码里已经有这种写法的,不照着再加一项:顺手改成干净的写法,改动大的先告诉用户。这次新建了模块、又改了已有模块里已有的东西(声明,或它的新迁移里改、删已有的对象),`modwall check` 会提示(R4);正常的重构不用管。
|
|
41
42
|
- 模块之间**不能成环**(数据库里经入口 schema 的引用也算进去):A 用 B、B 又用 A 时,把真正通用、没有业务含义的东西下沉到共享层,或者通过参数传进来;两个模块确实分不开,就合成一个。不要为了躲开成环把业务类型、常量挪进共享层:成环说明模块要重新划分,拿不准就停下来问用户。
|
|
42
43
|
- 正式代码不引用 `outside` 里的文件(构建配置、脚本、迁移)和测试文件。
|
|
43
44
|
|
package/src/base/git.ts
CHANGED
|
@@ -233,6 +233,13 @@ export function filesAt(root: string, rev: string, dir: string): string[] {
|
|
|
233
233
|
return (out ?? '').split('\0').filter(Boolean)
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
/** 这些路径(文件或目录,相对仓库根目录)里,提交里有的那些。 */
|
|
237
|
+
export function pathsAt(root: string, rev: string, paths: readonly string[]): Set<string> {
|
|
238
|
+
if (paths.length === 0) return new Set()
|
|
239
|
+
const out = gitOr(root, ['ls-tree', '-z', '--name-only', rev, '--', ...paths.map(path => path.replace(/\/+$/, ''))])
|
|
240
|
+
return new Set((out ?? '').split('\0').filter(Boolean))
|
|
241
|
+
}
|
|
242
|
+
|
|
236
243
|
/** 工作区里这个文件现在的内容。只读普通文件(跟着软链走);目录、不存在的都是 undefined。 */
|
|
237
244
|
export function fileNow(root: string, path: string): string | undefined {
|
|
238
245
|
const full = join(root, path)
|
package/src/wall/check.ts
CHANGED
|
@@ -6,19 +6,23 @@ import { readFileSync, writeFileSync } from 'node:fs'
|
|
|
6
6
|
import { join } from 'node:path'
|
|
7
7
|
import { askUser } from '../base/confirm.ts'
|
|
8
8
|
import { EXIT } from '../base/exit.ts'
|
|
9
|
+
import { pathsAt } from '../base/git.ts'
|
|
9
10
|
import type { Repo } from '../base/repo.ts'
|
|
10
11
|
import { CONFIG_PATH } from './config.ts'
|
|
11
12
|
import { unreadSql } from './database.ts'
|
|
12
13
|
import { codeRoleSwitches, migrationViolations } from './dbrules.ts'
|
|
13
14
|
import { type ChangeFacts, type ProjectImports, readChanges, readImports } from './layermap.ts'
|
|
14
15
|
import { miniprogramRefs } from './miniprogram.ts'
|
|
15
|
-
import type { Layout } from './layout.ts'
|
|
16
|
+
import type { Layout, Module } from './layout.ts'
|
|
16
17
|
import { looseningItems } from './loosen.ts'
|
|
17
18
|
import { layoutOf, type Project } from './project.ts'
|
|
19
|
+
import { statements } from './sql.ts'
|
|
18
20
|
import {
|
|
19
21
|
BLOCKING_RULES,
|
|
20
22
|
behaviorHints,
|
|
21
23
|
entryExports,
|
|
24
|
+
existingChangeHints,
|
|
25
|
+
type MigrationAlter,
|
|
22
26
|
type Hint,
|
|
23
27
|
importViolations,
|
|
24
28
|
RULE_NAMES,
|
|
@@ -121,13 +125,14 @@ export function analyze(project: Project, repo: Repo): Report {
|
|
|
121
125
|
}
|
|
122
126
|
let changes: ChangeFacts | undefined
|
|
123
127
|
if (project.base && imports.ok) {
|
|
124
|
-
const
|
|
125
|
-
if (
|
|
126
|
-
changes =
|
|
128
|
+
const changed = readChanges(project.root, project.base.commit)
|
|
129
|
+
if (changed.ok) {
|
|
130
|
+
changes = changed.value
|
|
127
131
|
report.behavior = behaviorHints(layout, changes)
|
|
132
|
+
report.behavior.push(...existingChangeHints(layout, changes, freshModules(project.root, project.base.commit, layout), migrationAlters(project.root, project.base.commit, layout, read)))
|
|
128
133
|
report.entryExports = entryExports(layout, changes)
|
|
129
134
|
} else {
|
|
130
|
-
report.changesProblem =
|
|
135
|
+
report.changesProblem = changed.problem
|
|
131
136
|
}
|
|
132
137
|
}
|
|
133
138
|
report.unchecked = [
|
|
@@ -138,6 +143,21 @@ export function analyze(project: Project, repo: Repo): Report {
|
|
|
138
143
|
return report
|
|
139
144
|
}
|
|
140
145
|
|
|
146
|
+
/** 这次新建的模块:分叉点上还没有它的目录。 */
|
|
147
|
+
function freshModules(root: string, base: string, layout: Layout): Set<string> {
|
|
148
|
+
const existed = pathsAt(root, base, layout.modules.map(module => module.dir))
|
|
149
|
+
return new Set(layout.modules.filter(module => !existed.has(module.dir)).map(module => module.id))
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** 已有模块这次新加的迁移里,改、删已有对象的句子(函数正文里的不算)。 */
|
|
153
|
+
function migrationAlters(root: string, base: string, layout: Layout, read: (path: string) => string): MigrationAlter[] {
|
|
154
|
+
const owned = layout.databases.flatMap(database => database.migrations).filter((migration): migration is { path: string; module: Module } => migration.module !== undefined)
|
|
155
|
+
const existed = pathsAt(root, base, owned.map(migration => migration.path))
|
|
156
|
+
return owned
|
|
157
|
+
.filter(migration => !existed.has(migration.path))
|
|
158
|
+
.flatMap(({ path, module }) => statements(read(path)).filter(statement => statement.alters && !statement.inFunction).map(statement => ({ module, path, line: statement.line })))
|
|
159
|
+
}
|
|
160
|
+
|
|
141
161
|
/** R1–R3、R5、R6 都查了:配置能用、layermap imports 跑成了。只有这样的检查,越界列表才完整。 */
|
|
142
162
|
function complete(report: Report): boolean {
|
|
143
163
|
return report.configProblems.length === 0 && !report.removed && report.layermapProblem === undefined
|
package/src/wall/rules.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// R2 循环 模块之间有回环 拦
|
|
4
4
|
// R3 方向反了 共享层引用模块或装配层;模块引用装配层;被管的代码引用 outside 或测试文件; 拦
|
|
5
5
|
// 一个应用引用另一个应用的代码;外面一层的共享层引用任何应用的代码
|
|
6
|
-
// R4 改已有行为 改了 B 已有导出函数的实现,A
|
|
6
|
+
// R4 改已有行为 改了 B 已有导出函数的实现,A 在这次改动里新增了对它的调用; 只提示
|
|
7
|
+
// 这次新建了模块,同时改了已有模块里已有的声明、在它的新迁移里改删已有的对象
|
|
7
8
|
// R5 没有归属 代码文件不在模块、共享层、装配层、映射和 outside 里 拦
|
|
8
9
|
// R6 数据库越界 迁移文件那部分在 database.ts,库里的现状在 dbcheck.ts 拦
|
|
9
10
|
// R1、R2、R3、R5、R6 看项目当前的全部代码;R4 和"入口新增导出"看这次改动(和分叉点比)。
|
|
@@ -17,7 +18,7 @@ import { type App, type ExceptionRule, field, moduleId, type Scheme } from './co
|
|
|
17
18
|
import { posix } from 'node:path'
|
|
18
19
|
import { inEntryLanguage, isCode, isStylesheet, UNREAD_DIRECTORIES } from './files.ts'
|
|
19
20
|
import type { ChangeFacts, ProjectImports } from './layermap.ts'
|
|
20
|
-
import { label, type Layout, type Owner } from './layout.ts'
|
|
21
|
+
import { label, type Layout, type Module, type Owner } from './layout.ts'
|
|
21
22
|
|
|
22
23
|
export type Rule = 'R1' | 'R2' | 'R3' | 'R5' | 'R6'
|
|
23
24
|
|
|
@@ -338,19 +339,28 @@ export function unownedFiles(layout: Layout, files: readonly string[]): Violatio
|
|
|
338
339
|
})
|
|
339
340
|
}
|
|
340
341
|
|
|
342
|
+
type ChangedDeclaration = ChangeFacts['declarations'][number]
|
|
343
|
+
|
|
344
|
+
/** 这次改动里,同一个应用里别的模块新增的、对这个已有导出声明的调用(应用之间的调用另由 R3 拦)。 */
|
|
345
|
+
function newCallsFromOthers(layout: Layout, changes: ChangeFacts, declaration: ChangedDeclaration): ChangeFacts['calls'] {
|
|
346
|
+
const owner = layout.owner(declaration.path)
|
|
347
|
+
if (!declaration.exported || owner.kind !== 'module') return []
|
|
348
|
+
return changes.calls.filter(call => {
|
|
349
|
+
if (call.to !== declaration.path || call.declaration !== declaration.declaration) return false
|
|
350
|
+
const caller = layout.owner(call.from)
|
|
351
|
+
return caller.kind === 'module' && caller.app === owner.app && caller.name !== owner.name
|
|
352
|
+
})
|
|
353
|
+
}
|
|
354
|
+
|
|
341
355
|
/** R4:这次改了 B 模块已有的导出函数的实现,同时 A 模块在这次改动里新增了对它的调用。只提示。 */
|
|
342
356
|
export function behaviorHints(layout: Layout, changes: ChangeFacts): Hint[] {
|
|
343
357
|
const hints: Hint[] = []
|
|
344
358
|
for (const declaration of changes.declarations) {
|
|
345
|
-
if (!declaration.exported) continue
|
|
346
359
|
const owner = layout.owner(declaration.path)
|
|
347
360
|
if (owner.kind !== 'module') continue
|
|
348
361
|
const callee = moduleId(owner.app, owner.name)
|
|
349
|
-
for (const call of changes
|
|
350
|
-
|
|
351
|
-
// 只看同一个应用里别的模块:应用之间的调用另由 R3 拦
|
|
352
|
-
const caller = layout.owner(call.from)
|
|
353
|
-
if (caller.kind !== 'module' || caller.app !== owner.app || caller.name === owner.name) continue
|
|
362
|
+
for (const call of newCallsFromOthers(layout, changes, declaration)) {
|
|
363
|
+
const caller = layout.owner(call.from) as Extract<Owner, { kind: 'module' }>
|
|
354
364
|
hints.push({
|
|
355
365
|
where: `${callee} 模块的 ${declaration.declaration}(${declaration.path}:${declaration.line})这次改了实现,${moduleId(caller.app, caller.name)} 模块在 ${site(call)} 新增了对它的调用`,
|
|
356
366
|
fix: `为新功能就在 ${callee} 新增一个函数,不要给旧函数加分支;是正常的重构(比如改了签名、同时更新调用处)就不用管。`,
|
|
@@ -360,6 +370,52 @@ export function behaviorHints(layout: Layout, changes: ChangeFacts): Hint[] {
|
|
|
360
370
|
return hints
|
|
361
371
|
}
|
|
362
372
|
|
|
373
|
+
/** 新迁移里改、删已有对象的一句:所在的模块、位置。 */
|
|
374
|
+
export interface MigrationAlter {
|
|
375
|
+
module: Module
|
|
376
|
+
path: string
|
|
377
|
+
line: number
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* R4 的另一种:这次新建了模块,同一个应用里已有的模块又被改了已有的东西(声明、迁移里改删已有的对象)。
|
|
382
|
+
* 新模块要的应该在对方新增;改对方已有的,常是在对方的名单、类型、常量、约束、映射表里加上新模块的名字,
|
|
383
|
+
* 对方因此认识了用它的模块。这种依赖写在字符串里,看引用查不出来,模块之间经装配层接线时也没有调用可查,所以按"改了已有的"提示。
|
|
384
|
+
* 已经按调用提示过的(上面的 behaviorHints)不再列。
|
|
385
|
+
*/
|
|
386
|
+
export function existingChangeHints(layout: Layout, changes: ChangeFacts, fresh: ReadonlySet<string>, alters: readonly MigrationAlter[]): Hint[] {
|
|
387
|
+
const freshIn = (app: string | undefined): string[] => layout.modules.filter(module => module.app === app && fresh.has(module.id)).map(module => module.id)
|
|
388
|
+
const touched = new Map<string, { app: string | undefined; id: string; where: string[] }>()
|
|
389
|
+
// 同一处(key)只说一次,位置写第一次见到的
|
|
390
|
+
const seen = new Set<string>()
|
|
391
|
+
const add = (app: string | undefined, id: string, key: string, where: string): void => {
|
|
392
|
+
if (seen.has(key)) return
|
|
393
|
+
seen.add(key)
|
|
394
|
+
const found = touched.get(id) ?? { app, id, where: [] }
|
|
395
|
+
found.where.push(where)
|
|
396
|
+
touched.set(id, found)
|
|
397
|
+
}
|
|
398
|
+
for (const declaration of changes.declarations) {
|
|
399
|
+
const owner = layout.owner(declaration.path)
|
|
400
|
+
if (owner.kind !== 'module') continue
|
|
401
|
+
const id = moduleId(owner.app, owner.name)
|
|
402
|
+
if (fresh.has(id) || freshIn(owner.app).length === 0) continue
|
|
403
|
+
// 对象字面量的属性报成 PAGES.deposit 这样,同一个文件里按顶层的名字说一次
|
|
404
|
+
const name = declaration.declaration.split('.')[0] as string
|
|
405
|
+
if (newCallsFromOthers(layout, changes, declaration).length) continue
|
|
406
|
+
add(owner.app, id, `${declaration.path}\0${name}`, `${name}(${declaration.path}:${declaration.line})`)
|
|
407
|
+
}
|
|
408
|
+
// 一个迁移文件只说一次,位置写第一句
|
|
409
|
+
for (const alter of alters) {
|
|
410
|
+
if (fresh.has(alter.module.id) || freshIn(alter.module.app).length === 0) continue
|
|
411
|
+
add(alter.module.app, alter.module.id, alter.path, `迁移里改、删了已有的对象(${alter.path}:${alter.line})`)
|
|
412
|
+
}
|
|
413
|
+
return [...touched.values()].map(({ app, id, where }) => ({
|
|
414
|
+
where: `这次新建了 ${freshIn(app).join('、')} 模块,同时改了已有的 ${id} 模块里已有的:${where.join('、')}`,
|
|
415
|
+
fix: `新模块要的在 ${id} 新增,不改它已有的。是在 ${id} 的名单、类型、常量、约束、映射表里加上新模块的名字的(${id} 因此认识了用它的模块),改成 ${id} 收一个值,或者由装配层接进来;是正常的重构就不用管。`,
|
|
416
|
+
}))
|
|
417
|
+
}
|
|
418
|
+
|
|
363
419
|
/** 这次改动给哪些模块的入口新增了引用(转导出也算 import):不算违规,留作试点数据。 */
|
|
364
420
|
export function entryExports(layout: Layout, changes: ChangeFacts): Hint[] {
|
|
365
421
|
return changes.imports
|
package/src/wall/session.ts
CHANGED
|
@@ -121,7 +121,7 @@ function singleRules(scheme: Scheme): string[] {
|
|
|
121
121
|
return [
|
|
122
122
|
`- 模块根目录:${or(app.roots)},下面每个子目录是一个模块。新功能默认在模块根目录下新建一个模块目录,不用登记、不用问人。`,
|
|
123
123
|
`- 要别的模块的能力,只从它的入口(模块目录下第一层的 ${app.entry.join('、')})引用;入口里没有,就在对方入口新增导出,作为单独的一小步。`,
|
|
124
|
-
'-
|
|
124
|
+
'- 不给别的模块的已有函数加分支:为新功能在对方新增一个函数。不在别的模块的名单、类型、常量、映射表、数据库约束里写上新功能的名字:改成对方收一个值,或由装配层接进来。模块之间不能成环。',
|
|
125
125
|
`- 共享层(${or(app.shared)})只放真正通用的东西,不能引用模块和装配层;装配层(${or(app.app)})把各模块接起来,别人不能引用它。正式代码不引用 outside(${or(scheme.outside)})和测试文件。`,
|
|
126
126
|
...databaseLines(scheme),
|
|
127
127
|
...CHECK_LINES,
|
|
@@ -135,7 +135,7 @@ function groupedRules(scheme: Scheme): string[] {
|
|
|
135
135
|
`- 这个仓库有 ${scheme.apps.length} 个应用(${scheme.apps.map(app => app.name).join('、')}),每个应用各有一套模块,模块名只在应用内唯一,写成 应用名/模块名。应用之间不能引用代码(引用对方的模块、共享层、装配层都不行):几个应用共用的代码放进外面一层的共享层(${or(scheme.shared)}),它不能引用任何应用的代码;应用之间通过接口打交道。`,
|
|
136
136
|
`- 模块根目录(${each(app => or(app.roots))}),下面每个子目录是一个模块。新功能默认在所在应用的模块根目录下新建一个模块目录,不用登记、不用问人。`,
|
|
137
137
|
`- 要同一个应用里别的模块的能力,只从它的入口(模块目录下第一层的文件,${each(app => or(app.entry))})引用;入口里没有,就在对方入口新增导出,作为单独的一小步。`,
|
|
138
|
-
'-
|
|
138
|
+
'- 不给别的模块的已有函数加分支:为新功能在对方新增一个函数。不在别的模块的名单、类型、常量、映射表、数据库约束里写上新功能的名字:改成对方收一个值,或由装配层接进来。同一个应用里的模块之间不能成环。',
|
|
139
139
|
`- 每个应用的共享层(${each(app => or(app.shared))})只放这个应用里真正通用的东西,不能引用模块和装配层;装配层(${each(app => or(app.app))})把这个应用的各模块接起来,别人不能引用它。正式代码不引用 outside(${or(scheme.outside)})和测试文件。`,
|
|
140
140
|
...databaseLines(scheme),
|
|
141
141
|
...CHECK_LINES,
|
package/src/wall/sql.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// setsSearchPath 这句改了 search_path(SET、RESET search_path,set_config('search_path', …))
|
|
12
12
|
// switchesRole 这句切了身份(SET ROLE、RESET ROLE、SET SESSION AUTHORIZATION、set_config('role', …),也包括角色、库上设的 role;建函数、改函数时设的不算)
|
|
13
13
|
// schemas 这句建的 schema(CREATE SCHEMA)
|
|
14
|
+
// alters 这句改、删已有的对象(ALTER、DROP、CREATE OR REPLACE 开头)
|
|
14
15
|
// 不解析完整语法:切词(注释、字符串、带引号的名字、$$ 正文)后按分号分句,在句子里认几种固定的写法。
|
|
15
16
|
// 函数、DO 块的正文当成 SQL 再读一遍,得到的句子单独列出(别名只在自己的句子里起作用)。
|
|
16
17
|
// 拼出来再执行的 SQL(EXECUTE '...')是字符串,读不到。
|
|
@@ -58,6 +59,8 @@ export interface Statement {
|
|
|
58
59
|
switchesRole: boolean
|
|
59
60
|
/** CREATE SCHEMA 建的 schema。 */
|
|
60
61
|
schemas: Name[]
|
|
62
|
+
/** 改、删已有的对象:ALTER、DROP、CREATE OR REPLACE 开头的句子。 */
|
|
63
|
+
alters: boolean
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
const WORD_START = /[A-Za-z_\u0080-\uffff]/
|
|
@@ -206,11 +209,12 @@ const KINDS = new Set(['table', 'view', 'function', 'procedure', 'sequence', 'ty
|
|
|
206
209
|
const MODIFIERS = new Set(['or', 'replace', 'global', 'local', 'temp', 'temporary', 'unlogged', 'foreign', 'recursive', 'materialized', 'unique', 'concurrently'])
|
|
207
210
|
|
|
208
211
|
function statement(tokens: Token[]): Statement[] {
|
|
209
|
-
const found: Statement = { line: tokens[0]?.line ?? 0, refs: [], targets: [], writes: [], tables: [], view: false, aliases: [], relations: [], setsSearchPath: false, switchesRole: false, schemas: [], inFunction: false }
|
|
212
|
+
const found: Statement = { line: tokens[0]?.line ?? 0, refs: [], targets: [], writes: [], tables: [], view: false, aliases: [], relations: [], setsSearchPath: false, switchesRole: false, schemas: [], inFunction: false, alters: false }
|
|
210
213
|
const nested: Statement[] = []
|
|
211
214
|
const creates = isWord(tokens[0], 'create')
|
|
212
215
|
let at = 1
|
|
213
216
|
if (creates && isWord(tokens[at], 'or') && isWord(tokens[at + 1], 'replace')) at += 2
|
|
217
|
+
found.alters = isWord(tokens[0], 'alter', 'drop') || at === 3
|
|
214
218
|
const isFunction = creates && isWord(tokens[at], 'function', 'procedure')
|
|
215
219
|
// DO 块的正文是句子里第一个字符串(DO $$…$$、DO LANGUAGE x '…')
|
|
216
220
|
let doBody = isWord(tokens[0], 'do')
|