@octokit/types 2.1.0 → 2.1.1

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.
@@ -1,33 +0,0 @@
1
- // DO NOT EDIT THIS FILE
2
- import { RequestHeaders } from "../RequestHeaders";
3
- import { RequestRequestOptions } from "../RequestRequestOptions";
4
- import { Url } from "../Url";
5
-
6
- export interface Endpoints {
7
- {{#each endpointsByRoute}}
8
- "{{@key}}": [{{union this "optionsTypeName"}}, {{union this "requestOptionsTypeName"}}]
9
- {{/each}}
10
- }
11
-
12
- {{#each options}}
13
- type {{in.name}} = {
14
- {{#each in.parameters}}
15
- {{&jsdoc}}
16
- {{{name this}}}: {{{type this}}}
17
- {{/each}}
18
- }
19
- type {{out.name}} = {
20
- method: "{{out.method}}",
21
- url: Url,
22
- headers: RequestHeaders,
23
- request: RequestRequestOptions
24
- }
25
- {{/each}}
26
-
27
- {{#childParams}}
28
- export type {{paramTypeName}} = {
29
- {{#params}}
30
- {{{name this}}}: {{{type this}}}
31
- {{/params}}
32
- };
33
- {{/childParams}}
@@ -1,179 +0,0 @@
1
- const { readFileSync, writeFileSync } = require("fs");
2
- const { resolve } = require("path");
3
-
4
- const Handlebars = require("handlebars");
5
- const set = require("lodash.set");
6
- const { pascalCase } = require("pascal-case");
7
- const prettier = require("prettier");
8
- const { stringToJsdocComment } = require("string-to-jsdoc-comment");
9
- const sortKeys = require("sort-keys");
10
-
11
- const ENDPOINTS = require("./generated/Endpoints.json");
12
- const ENDPOINTS_PATH = resolve(
13
- process.cwd(),
14
- "src",
15
- "generated",
16
- "Endpoints.ts"
17
- );
18
- const ENDPOINTS_TEMPLATE_PATH = resolve(
19
- process.cwd(),
20
- "scripts",
21
- "update-endpoints",
22
- "templates",
23
- "endpoints.ts.template"
24
- );
25
-
26
- Handlebars.registerHelper("union", function(endpoints, key) {
27
- return endpoints.map(endpoint => endpoint[key]).join(" | ");
28
- });
29
- Handlebars.registerHelper("name", function(parameter) {
30
- let name = parameter.key;
31
-
32
- if (/[.\[]/.test(name)) {
33
- name = `"${name}"`;
34
- }
35
-
36
- if (parameter.required) {
37
- return name;
38
- }
39
-
40
- return `${name}?`;
41
- });
42
-
43
- Handlebars.registerHelper("type", function(parameter) {
44
- const type = typeMap[parameter.type] || parameter.type;
45
-
46
- if (parameter.allowNull) {
47
- return `${type} | null`;
48
- }
49
-
50
- return type;
51
- });
52
- const template = Handlebars.compile(
53
- readFileSync(ENDPOINTS_TEMPLATE_PATH, "utf8")
54
- );
55
-
56
- const endpointsByRoute = {};
57
-
58
- const typeMap = {
59
- integer: "number",
60
- "integer[]": "number[]"
61
- };
62
-
63
- for (const endpoint of ENDPOINTS) {
64
- const route = `${endpoint.method} ${endpoint.url.replace(
65
- /\{([^}]+)}/g,
66
- ":$1"
67
- )}`;
68
-
69
- if (!endpointsByRoute[route]) {
70
- endpointsByRoute[route] = [];
71
- }
72
-
73
- endpointsByRoute[route].push({
74
- optionsTypeName:
75
- pascalCase(`${endpoint.scope} ${endpoint.id}`) + "Endpoint",
76
- requestOptionsTypeName:
77
- pascalCase(`${endpoint.scope} ${endpoint.id}`) + "RequestOptions"
78
- });
79
- }
80
-
81
- const options = [];
82
- const childParams = {};
83
-
84
- for (const endpoint of ENDPOINTS) {
85
- const { method, parameters } = endpoint;
86
-
87
- const optionsTypeName =
88
- pascalCase(`${endpoint.scope} ${endpoint.id}`) + "Endpoint";
89
- const requestOptionsTypeName =
90
- pascalCase(`${endpoint.scope} ${endpoint.id}`) + "RequestOptions";
91
-
92
- options.push({
93
- in: {
94
- name: optionsTypeName,
95
- parameters: parameters
96
- .map(parameterize)
97
- // handle "object" & "object[]" types
98
- .map(parameter => {
99
- if (parameter.deprecated) {
100
- return;
101
- }
102
-
103
- const namespacedParamsName = pascalCase(
104
- `${endpoint.scope}.${endpoint.id}.Params`
105
- );
106
-
107
- if (parameter.type === "object" || parameter.type === "object[]") {
108
- const childParamsName = pascalCase(
109
- `${namespacedParamsName}.${parameter.key}`
110
- );
111
-
112
- parameter.type = parameter.type.replace("object", childParamsName);
113
-
114
- if (!childParams[childParamsName]) {
115
- childParams[childParamsName] = {};
116
- }
117
- }
118
-
119
- if (!/\./.test(parameter.key)) {
120
- return parameter;
121
- }
122
-
123
- const childKey = parameter.key.split(".").pop();
124
- const parentKey = parameter.key.replace(/\.[^.]+$/, "");
125
-
126
- parameter.key = childKey;
127
-
128
- const childParamsName = pascalCase(
129
- `${namespacedParamsName}.${parentKey}`
130
- );
131
- set(childParams, `${childParamsName}.${childKey}`, parameter);
132
- })
133
- .filter(Boolean)
134
- },
135
- out: {
136
- name: requestOptionsTypeName,
137
- method
138
- }
139
- });
140
- }
141
-
142
- const result = template({
143
- endpointsByRoute: sortKeys(endpointsByRoute, { deep: true }),
144
- options,
145
- childParams: Object.keys(childParams).map(key => {
146
- if (key === "GistsCreateParamsFiles") {
147
- debugger;
148
- }
149
- return {
150
- paramTypeName: key,
151
- params: Object.values(childParams[key])
152
- };
153
- })
154
- });
155
-
156
- writeFileSync(
157
- ENDPOINTS_PATH,
158
- prettier.format(result, { parser: "typescript" })
159
- );
160
- console.log(`${ENDPOINTS_PATH} updated.`);
161
-
162
- function parameterize(parameter) {
163
- const key = parameter.name;
164
- const type = typeMap[parameter.type] || parameter.type;
165
- const enums = parameter.enum
166
- ? parameter.enum.map(JSON.stringify).join("|")
167
- : null;
168
-
169
- return {
170
- name: pascalCase(key),
171
- key: key,
172
- required: parameter.required,
173
- type: enums || type,
174
- alias: parameter.alias,
175
- deprecated: parameter.deprecated,
176
- allowNull: parameter.allowNull,
177
- jsdoc: stringToJsdocComment(parameter.description)
178
- };
179
- }