Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 5eafb39

Browse files
committed
fix(build command): remove unnecessary spaces on built documents
1 parent 9f42e80 commit 5eafb39

9 files changed

Lines changed: 1061 additions & 7 deletions

File tree

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
ignorePatterns: ['bin', 'commitlint.config.js'],
2+
ignorePatterns: ['bin', 'commitlint.config.js', 'node_modules/', 'test-typings', '.eslintrc.js'],
33
extends: [
44
'plugin:@typescript-eslint/recommended',
55
'prettier',

bin/ddoc/build/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async function build(src, opts) {
6666
return val.toString();
6767
}
6868
return val;
69-
}, 1);
69+
}, 1).replace(/ +/g, ' ');
7070
await writeFile(path_1.default.join(dest, `${filename}.json`), stringifiedDesign);
7171
}
7272
catch (error) {

main-designs.json

Lines changed: 832 additions & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"mkdirp": "~1.0.3",
3535
"require-from-string": "~2.0.2",
3636
"sade": "~1.7.3",
37-
"typescript": "~3.9.3"
37+
"typescript": "~3.9.5"
3838
},
3939
"devDependencies": {
4040
"@commitlint/cli": "~9.0.1",

src/ddoc/build/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default async function build(src: string, opts: { config: string }) {
7474
return val
7575
},
7676
1,
77-
)
77+
).replace(/ +/g, ' ')
7878
await writeFile(path.join(dest, `${filename}.json`), stringifiedDesign)
7979
} catch (error) {
8080
errors.push({ file: srcPath, error })

src/ddoc/extract/extract.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ export default async function (
109109
for (const view of Object.keys(doc.views)) {
110110
if (doc.views[view].map) {
111111
const name = `${doc._id}-${doc._rev}.views.${view}.map`
112-
methods.set(name, doc.views[view].map!)
112+
methods.set(name, doc.views[view].map!) // eslint-disable-line
113113
doc.views[view].map = name
114114
}
115115
if (doc.views[view].reduce) {
116116
const name = `${doc._id}-${doc._rev}.views.${view}.reduce`
117-
methods.set(name, doc.views[view].reduce!)
117+
methods.set(name, doc.views[view].reduce!) // eslint-disable-line
118118
doc.views[view].reduce = name
119119
}
120120
}
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
// Reference: https://docs.couchdb.org/en/latest/query-server/javascript.html#design-functions-context
2+
3+
declare namespace CouchDB {
4+
type HttpMethods = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS' | 'TRACE'
5+
interface InitResp {
6+
code?: number
7+
json?: object
8+
body?: string
9+
base64?: string
10+
headers?: any
11+
stop?: boolean
12+
}
13+
14+
interface UserCtx {
15+
db: string
16+
name: string | null
17+
roles: string[]
18+
}
19+
20+
interface SecurityObject {
21+
admins: {
22+
names: string[]
23+
roles: string[]
24+
}
25+
members: {
26+
names: string[]
27+
roles: string[]
28+
}
29+
}
30+
31+
interface DataBaseInformationObject {
32+
db_name: string
33+
committed_update_seq: number
34+
doc_count: number
35+
doc_del_count: number
36+
compact_running: boolean
37+
disk_format_version: number
38+
disk_size: number
39+
instance_start_time: string
40+
purge_seq: number
41+
update_seq: number
42+
sizes: {
43+
active: number
44+
disk: number
45+
external: number
46+
}
47+
}
48+
49+
interface RequestObject {
50+
body: string
51+
cookie: Record<string, any>
52+
form: Record<string, any>
53+
headers: Record<string, any>
54+
id: string | null
55+
info: CouchDB.DataBaseInformationObject
56+
method: HttpMethods
57+
path: string[]
58+
peer: string
59+
query: Record<string, any>
60+
raw_path: string
61+
requested_path: string[]
62+
secObj: CouchDB.SecurityObject
63+
userCtx: CouchDB.UserCtx
64+
uuid: string
65+
}
66+
67+
interface RewriteRule {
68+
method?: string
69+
from: string
70+
to: string
71+
query: Record<string, any>
72+
}
73+
74+
interface Request2Object {
75+
body: string
76+
cookie: Record<string, any>
77+
headers: Record<string, any>
78+
method: HttpMethods
79+
path: string[]
80+
peer: string
81+
query: Record<string, any>
82+
requested_path: string[]
83+
raw_path: string
84+
secObj: CouchDB.SecurityObject
85+
userCtx: CouchDB.UserCtx
86+
}
87+
88+
interface RewriteReturnObject {
89+
path: string
90+
code?: number
91+
query?: Record<string, any>
92+
headers?: any
93+
method?: HttpMethods
94+
body?: string
95+
}
96+
97+
interface ResponseObject {
98+
code?: number
99+
json?: any
100+
body?: string
101+
base64?: string
102+
headers?: any
103+
stop?: boolean
104+
}
105+
106+
interface ViewHeadInformation {
107+
total_rows: number
108+
offset: number
109+
}
110+
}
111+
// reference: https://docs.couchdb.org/en/stable/ddocs/views/collation.html
112+
type kyesBaseTypes = null | boolean | number | string | object
113+
type emitKeys = kyesBaseTypes | kyesBaseTypes[]
114+
/**
115+
* Emits a key-value pair for further processing by CouchDB after the map function is done.
116+
* @param {string} key - The view key
117+
* @param {any} value - The key’s associated value
118+
* @returns {void}
119+
*/
120+
declare function emit<T>(key: emitKeys, value?: T): void
121+
/**
122+
* @deprecated since version 2.0
123+
* Extracts the next row from a related view result.
124+
* @returns {Object} - View result row
125+
*/
126+
declare function getRow<T>(): T
127+
128+
/**
129+
* A helper function to check if the provided value is an Array.
130+
* @param {Object} obj - Any JavaScript value
131+
* @returns {boolean}
132+
*/
133+
declare function isArray<T>(obj: T): boolean
134+
135+
/**
136+
* Log a message to the CouchDB log (at the INFO level).
137+
* @param {string} message - Message to be logged
138+
* @returns {void}
139+
*/
140+
declare function log(message: string): void
141+
142+
/**
143+
* @deprecated since version 2.0
144+
* Registers callable handler for specified MIME key.
145+
* @param {string} key - MIME key previously defined by registerType()
146+
* @param {Function} value - MIME type handler
147+
* @returns {void}
148+
*/
149+
declare function provides(key: string, func: Function): string | CouchDB.ResponseObject
150+
151+
/**
152+
* @deprecated since version 2.0
153+
* Registers list of MIME types by associated key.
154+
* @param {string} key - MIME types
155+
* @param {string[]} mimes - MMIME types enumeration
156+
* @returns {void}
157+
*/
158+
declare function registerType(key: string, mimes: string[]): void
159+
160+
/**
161+
* @deprecated since version 2.0
162+
* Sends a single string chunk in response.
163+
* @param {string} chunk - Text chunk
164+
* @returns {void}
165+
*/
166+
declare function send(chunk: string): void
167+
168+
/**
169+
* @deprecated since version 2.0
170+
* Initiates chunked response. As an option, a custom response object may be sent at this point. For list-functions only!
171+
* @param {Object} init_resp - InitResp object
172+
* @returns {void}
173+
*/
174+
// eslint-disable-next-line
175+
declare function start(init_resp?: CouchDB.InitResp): void
176+
177+
/**
178+
* Sum arr’s items.
179+
* @param {number[]} arr - Array of numbers
180+
* @returns {number}
181+
*/
182+
declare function sum(arr: number[]): number
183+
184+
/**
185+
* Encodes obj to JSON string. This is an alias for the JSON.stringify method.
186+
* @param {any} obj - Array of numbers
187+
* @returns {string}
188+
*/
189+
declare function toJSON(obj: any): string
190+
191+
/**
192+
* Reduce functions take two required arguments of keys and values lists - the result of the related map function - and an optional third value which indicates if rereduce mode is active or not.
193+
* Rereduce is used for additional reduce values list, so when it is true there is no information about related keys (first argument is null).
194+
* @param {string[] | null} keys - Array of pairs of docid-key for related map function results. Always null if rereduce is running (has true value).
195+
* @returns {void}
196+
*/
197+
declare type redfun = (keys: [string, string][] | null, values: any[], rereduce?: boolean) => any

test/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import mkdirp from 'mkdirp'
44
import rimraf from 'rimraf'
55

66
import extract from '../src/ddoc/extract/extract'
7+
import build from '../src/ddoc/build/build'
78

89
const dummyData = join(__dirname, './dummy-data')
910

@@ -35,6 +36,15 @@ test('Should extract design documents from a backup', async (t: any) => {
3536
})
3637
})
3738

38-
t.tearDown(() => rimraf.sync(destinationFolder))
39+
t.test('from TypeScript', async () => {
40+
await build(destinationFolder, {
41+
config: join(__dirname, './tsconfig.build-test.json'),
42+
})
43+
})
44+
45+
t.tearDown(() => {
46+
rimraf.sync(destinationFolder)
47+
rimraf.sync(join(dummyData, 'designs'))
48+
})
3949
t.end()
4050
})

test/tsconfig.build-test.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"include": [
3+
"./dummy-data/output/main-designs"
4+
],
5+
"exclude": [
6+
"node_modules"
7+
],
8+
"compilerOptions": {
9+
"typeRoots": [
10+
"../test-typings/design-functions-context.d.ts"
11+
],
12+
"outDir": "./dummy-data/designs",
13+
"sourceMap": false
14+
}
15+
}

0 commit comments

Comments
 (0)