@sqldoc/ns-postgraphile 0.0.1 → 0.0.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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@sqldoc/ns-postgraphile",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"description": "PostGraphile smart comments namespace for sqldoc -- generates COMMENT ON statements with @tag syntax",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -14,15 +14,16 @@
|
|
|
14
14
|
"types": "./src/index.ts",
|
|
15
15
|
"files": [
|
|
16
16
|
"src",
|
|
17
|
+
"!src/__tests__",
|
|
17
18
|
"package.json"
|
|
18
19
|
],
|
|
19
20
|
"peerDependencies": {
|
|
20
|
-
"@sqldoc/core": "0.0.
|
|
21
|
+
"@sqldoc/core": "0.0.2"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"typescript": "^5.9.3",
|
|
24
25
|
"vitest": "^4.1.0",
|
|
25
|
-
"@sqldoc/core": "0.0.
|
|
26
|
+
"@sqldoc/core": "0.0.2"
|
|
26
27
|
},
|
|
27
28
|
"scripts": {
|
|
28
29
|
"test": "vitest run"
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import type { TagContext } from '@sqldoc/core'
|
|
2
|
-
import { describe, expect, it } from 'vitest'
|
|
3
|
-
import plugin from '../index'
|
|
4
|
-
|
|
5
|
-
function makeCtx(overrides: Partial<TagContext> = {}): TagContext {
|
|
6
|
-
return {
|
|
7
|
-
target: 'table',
|
|
8
|
-
objectName: 'users',
|
|
9
|
-
tag: { name: 'omit', args: {} },
|
|
10
|
-
namespaceTags: [{ tag: 'omit', args: {} }],
|
|
11
|
-
siblingTags: [],
|
|
12
|
-
fileTags: [],
|
|
13
|
-
astNode: null,
|
|
14
|
-
fileStatements: [],
|
|
15
|
-
config: {},
|
|
16
|
-
filePath: 'test.sql',
|
|
17
|
-
...overrides,
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
describe('ns-postgraphile plugin', () => {
|
|
22
|
-
it('exports apiVersion === 1', () => {
|
|
23
|
-
expect(plugin.apiVersion).toBe(1)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('exports name === "pg"', () => {
|
|
27
|
-
expect(plugin.name).toBe('pg')
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('has all expected tag entries', () => {
|
|
31
|
-
expect(plugin.tags).toHaveProperty('omit')
|
|
32
|
-
expect(plugin.tags).toHaveProperty(['omit.operations'])
|
|
33
|
-
expect(plugin.tags).toHaveProperty('name')
|
|
34
|
-
expect(plugin.tags).toHaveProperty('deprecated')
|
|
35
|
-
expect(plugin.tags).toHaveProperty('simpleCollections')
|
|
36
|
-
expect(plugin.tags).toHaveProperty('behavior')
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
describe('onTag', () => {
|
|
40
|
-
it('@pg.omit on a table', () => {
|
|
41
|
-
const ctx = makeCtx()
|
|
42
|
-
const result = plugin.onTag!(ctx) as any
|
|
43
|
-
expect(result.sql).toEqual([{ sql: `COMMENT ON TABLE "users" IS E'@omit';` }])
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('@pg.omit on a column', () => {
|
|
47
|
-
const ctx = makeCtx({
|
|
48
|
-
target: 'column',
|
|
49
|
-
objectName: 'users',
|
|
50
|
-
columnName: 'secret',
|
|
51
|
-
tag: { name: 'omit', args: {} },
|
|
52
|
-
namespaceTags: [{ tag: 'omit', args: {} }],
|
|
53
|
-
})
|
|
54
|
-
const result = plugin.onTag!(ctx) as any
|
|
55
|
-
expect(result.sql).toEqual([{ sql: `COMMENT ON COLUMN "users"."secret" IS E'@omit';` }])
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('@pg.omit on a view', () => {
|
|
59
|
-
const ctx = makeCtx({
|
|
60
|
-
target: 'view',
|
|
61
|
-
objectName: 'active_users',
|
|
62
|
-
tag: { name: 'omit', args: {} },
|
|
63
|
-
namespaceTags: [{ tag: 'omit', args: {} }],
|
|
64
|
-
})
|
|
65
|
-
const result = plugin.onTag!(ctx) as any
|
|
66
|
-
expect(result.sql).toEqual([{ sql: `COMMENT ON VIEW "active_users" IS E'@omit';` }])
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('@pg.omit on a function', () => {
|
|
70
|
-
const ctx = makeCtx({
|
|
71
|
-
target: 'function',
|
|
72
|
-
objectName: 'my_func',
|
|
73
|
-
tag: { name: 'omit', args: {} },
|
|
74
|
-
namespaceTags: [{ tag: 'omit', args: {} }],
|
|
75
|
-
})
|
|
76
|
-
const result = plugin.onTag!(ctx) as any
|
|
77
|
-
expect(result.sql).toEqual([{ sql: `COMMENT ON FUNCTION "my_func" IS E'@omit';` }])
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
it('@pg.omit.operations with specific ops', () => {
|
|
81
|
-
const ctx = makeCtx({
|
|
82
|
-
tag: { name: 'omit.operations', args: { ops: ['create', 'update'] } },
|
|
83
|
-
namespaceTags: [{ tag: 'omit.operations', args: { ops: ['create', 'update'] } }],
|
|
84
|
-
})
|
|
85
|
-
const result = plugin.onTag!(ctx) as any
|
|
86
|
-
expect(result.sql).toEqual([{ sql: `COMMENT ON TABLE "users" IS E'@omit create,update';` }])
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('@pg.name renames in GraphQL', () => {
|
|
90
|
-
const ctx = makeCtx({
|
|
91
|
-
tag: { name: 'name', args: ['Person'] },
|
|
92
|
-
namespaceTags: [{ tag: 'name', args: ['Person'] }],
|
|
93
|
-
})
|
|
94
|
-
const result = plugin.onTag!(ctx) as any
|
|
95
|
-
expect(result.sql).toEqual([{ sql: `COMMENT ON TABLE "users" IS E'@name Person';` }])
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it('@pg.name on a type', () => {
|
|
99
|
-
const ctx = makeCtx({
|
|
100
|
-
target: 'type',
|
|
101
|
-
objectName: 'user_role',
|
|
102
|
-
tag: { name: 'name', args: ['UserRole'] },
|
|
103
|
-
namespaceTags: [{ tag: 'name', args: ['UserRole'] }],
|
|
104
|
-
})
|
|
105
|
-
const result = plugin.onTag!(ctx) as any
|
|
106
|
-
expect(result.sql).toEqual([{ sql: `COMMENT ON TYPE "user_role" IS E'@name UserRole';` }])
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('@pg.deprecated with reason', () => {
|
|
110
|
-
const ctx = makeCtx({
|
|
111
|
-
tag: { name: 'deprecated', args: ['Use accounts instead'] },
|
|
112
|
-
namespaceTags: [{ tag: 'deprecated', args: ['Use accounts instead'] }],
|
|
113
|
-
})
|
|
114
|
-
const result = plugin.onTag!(ctx) as any
|
|
115
|
-
expect(result.sql).toEqual([{ sql: `COMMENT ON TABLE "users" IS E'@deprecated Use accounts instead';` }])
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('@pg.deprecated with default reason', () => {
|
|
119
|
-
const ctx = makeCtx({
|
|
120
|
-
tag: { name: 'deprecated', args: [] },
|
|
121
|
-
namespaceTags: [{ tag: 'deprecated', args: [] }],
|
|
122
|
-
})
|
|
123
|
-
const result = plugin.onTag!(ctx) as any
|
|
124
|
-
expect(result.sql).toEqual([{ sql: `COMMENT ON TABLE "users" IS E'@deprecated Deprecated';` }])
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
it('@pg.simpleCollections on a table', () => {
|
|
128
|
-
const ctx = makeCtx({
|
|
129
|
-
tag: { name: 'simpleCollections', args: {} },
|
|
130
|
-
namespaceTags: [{ tag: 'simpleCollections', args: {} }],
|
|
131
|
-
})
|
|
132
|
-
const result = plugin.onTag!(ctx) as any
|
|
133
|
-
expect(result.sql).toEqual([{ sql: `COMMENT ON TABLE "users" IS E'@simpleCollections only';` }])
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
it('@pg.behavior with custom string', () => {
|
|
137
|
-
const ctx = makeCtx({
|
|
138
|
-
tag: { name: 'behavior', args: ['-query:resource:list'] },
|
|
139
|
-
namespaceTags: [{ tag: 'behavior', args: ['-query:resource:list'] }],
|
|
140
|
-
})
|
|
141
|
-
const result = plugin.onTag!(ctx) as any
|
|
142
|
-
expect(result.sql).toEqual([{ sql: `COMMENT ON TABLE "users" IS E'@behavior -query:resource:list';` }])
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
describe('multiple tags combined into one COMMENT ON', () => {
|
|
146
|
-
it('combines @pg.omit.operations and @pg.name into one statement', () => {
|
|
147
|
-
const namespaceTags = [
|
|
148
|
-
{ tag: 'omit.operations', args: { ops: ['create', 'delete'] } },
|
|
149
|
-
{ tag: 'name', args: ['Person'] },
|
|
150
|
-
]
|
|
151
|
-
// First tag generates the combined SQL
|
|
152
|
-
const ctx1 = makeCtx({
|
|
153
|
-
tag: { name: 'omit.operations', args: { ops: ['create', 'delete'] } },
|
|
154
|
-
namespaceTags,
|
|
155
|
-
})
|
|
156
|
-
const result1 = plugin.onTag!(ctx1) as any
|
|
157
|
-
expect(result1.sql).toEqual([{ sql: `COMMENT ON TABLE "users" IS E'@omit create,delete\\n@name Person';` }])
|
|
158
|
-
|
|
159
|
-
// Second tag is skipped (returns undefined)
|
|
160
|
-
const ctx2 = makeCtx({
|
|
161
|
-
tag: { name: 'name', args: ['Person'] },
|
|
162
|
-
namespaceTags,
|
|
163
|
-
})
|
|
164
|
-
const result2 = plugin.onTag!(ctx2)
|
|
165
|
-
expect(result2).toBeUndefined()
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
it('combines three tags: omit + deprecated + simpleCollections', () => {
|
|
169
|
-
const namespaceTags = [
|
|
170
|
-
{ tag: 'omit', args: {} },
|
|
171
|
-
{ tag: 'deprecated', args: ['Will be removed in v2'] },
|
|
172
|
-
{ tag: 'simpleCollections', args: {} },
|
|
173
|
-
]
|
|
174
|
-
const ctx = makeCtx({
|
|
175
|
-
tag: { name: 'omit', args: {} },
|
|
176
|
-
namespaceTags,
|
|
177
|
-
})
|
|
178
|
-
const result = plugin.onTag!(ctx) as any
|
|
179
|
-
expect(result.sql).toEqual([
|
|
180
|
-
{
|
|
181
|
-
sql: `COMMENT ON TABLE "users" IS E'@omit\\n@deprecated Will be removed in v2\\n@simpleCollections only';`,
|
|
182
|
-
},
|
|
183
|
-
])
|
|
184
|
-
})
|
|
185
|
-
})
|
|
186
|
-
})
|
|
187
|
-
})
|