@sdk-it/spec 0.24.0 → 0.26.0
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/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +2 -2
- package/dist/lib/create-operation.d.ts +28 -0
- package/dist/lib/create-operation.d.ts.map +1 -0
- package/dist/lib/create-operation.js +62 -0
- package/dist/lib/create-operation.js.map +7 -0
- package/dist/lib/for-each-operation.d.ts.map +1 -1
- package/dist/lib/for-each-operation.js +0 -3
- package/dist/lib/for-each-operation.js.map +2 -2
- package/dist/lib/get-ref-usage.d.ts +1 -1
- package/dist/lib/get-ref-usage.js.map +1 -1
- package/dist/lib/guess/guess-resource.d.ts +7 -0
- package/dist/lib/guess/guess-resource.d.ts.map +1 -0
- package/dist/lib/guess/guess-resource.js +76 -0
- package/dist/lib/guess/guess-resource.js.map +7 -0
- package/dist/lib/metadata.d.ts +2 -2
- package/dist/lib/metadata.d.ts.map +1 -1
- package/dist/lib/metadata.js +17 -5
- package/dist/lib/metadata.js.map +2 -2
- package/dist/lib/metadata.test.d.ts +2 -0
- package/dist/lib/metadata.test.d.ts.map +1 -0
- package/dist/lib/metadata.test.js +359 -0
- package/dist/lib/metadata.test.js.map +7 -0
- package/dist/lib/operation.d.ts +1 -32
- package/dist/lib/operation.d.ts.map +1 -1
- package/dist/lib/operation.js +32 -312
- package/dist/lib/operation.js.map +2 -2
- package/dist/lib/options.d.ts +42 -1
- package/dist/lib/options.d.ts.map +1 -1
- package/dist/lib/options.js +23 -8
- package/dist/lib/options.js.map +2 -2
- package/dist/lib/pagination/guess-pagination.d.ts +50 -0
- package/dist/lib/pagination/guess-pagination.d.ts.map +1 -0
- package/dist/lib/pagination/guess-pagination.js +222 -0
- package/dist/lib/pagination/guess-pagination.js.map +7 -0
- package/dist/lib/pagination/pagination.d.ts +2 -49
- package/dist/lib/pagination/pagination.d.ts.map +1 -1
- package/dist/lib/pagination/pagination.js +43 -209
- package/dist/lib/pagination/pagination.js.map +2 -2
- package/dist/lib/pagination/pagination.test.js +2 -1
- package/dist/lib/pagination/pagination.test.js.map +2 -2
- package/dist/lib/security.d.ts +1 -1
- package/dist/lib/security.js.map +1 -1
- package/dist/lib/sidebar.d.ts +5 -24
- package/dist/lib/sidebar.d.ts.map +1 -1
- package/dist/lib/sidebar.js +22 -65
- package/dist/lib/sidebar.js.map +3 -3
- package/dist/lib/tune-request-body.d.ts +5 -0
- package/dist/lib/tune-request-body.d.ts.map +1 -0
- package/dist/lib/tune-request-body.js +88 -0
- package/dist/lib/tune-request-body.js.map +7 -0
- package/dist/lib/tune-response.d.ts +5 -0
- package/dist/lib/tune-response.d.ts.map +1 -0
- package/dist/lib/tune-response.js +102 -0
- package/dist/lib/tune-response.js.map +7 -0
- package/dist/lib/types.d.ts +8 -3
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './lib/create-operation.js';
|
|
1
2
|
export * from './lib/find-polymorphic-varients.js';
|
|
2
3
|
export * from './lib/find-unique-schema-name.js';
|
|
3
4
|
export * from './lib/for-each-operation.js';
|
|
@@ -15,6 +16,8 @@ export * from './lib/reserved-keywords.js';
|
|
|
15
16
|
export * from './lib/security.js';
|
|
16
17
|
export * from './lib/sidebar.js';
|
|
17
18
|
export * from './lib/tag.js';
|
|
19
|
+
export * from './lib/tune-request-body.js';
|
|
20
|
+
export * from './lib/tune-response.js';
|
|
18
21
|
export * from './lib/tune.js';
|
|
19
22
|
export * from './lib/types.js';
|
|
20
23
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from "./lib/create-operation.js";
|
|
1
2
|
export * from "./lib/find-polymorphic-varients.js";
|
|
2
3
|
export * from "./lib/find-unique-schema-name.js";
|
|
3
4
|
export * from "./lib/for-each-operation.js";
|
|
@@ -15,6 +16,8 @@ export * from "./lib/reserved-keywords.js";
|
|
|
15
16
|
export * from "./lib/security.js";
|
|
16
17
|
export * from "./lib/sidebar.js";
|
|
17
18
|
export * from "./lib/tag.js";
|
|
19
|
+
export * from "./lib/tune-request-body.js";
|
|
20
|
+
export * from "./lib/tune-response.js";
|
|
18
21
|
export * from "./lib/tune.js";
|
|
19
22
|
export * from "./lib/types.js";
|
|
20
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './lib/find-polymorphic-varients.js';\nexport * from './lib/find-unique-schema-name.js';\nexport * from './lib/for-each-operation.js';\nexport * from './lib/format-name.js';\nexport * from './lib/get-ref-usage.js';\nexport * from './lib/is-primitive-schema.js';\nexport * from './lib/is.js';\nexport * from './lib/loaders/load-spec.js';\nexport * from './lib/loaders/local-loader.js';\nexport * from './lib/loaders/remote-loader.js';\nexport * from './lib/metadata.js';\nexport * from './lib/operation.js';\nexport * from './lib/options.js';\nexport * from './lib/reserved-keywords.js';\nexport * from './lib/security.js';\nexport * from './lib/sidebar.js';\nexport * from './lib/tag.js';\nexport * from './lib/tune.js';\nexport * from './lib/types.js';\n"],
|
|
5
|
-
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
4
|
+
"sourcesContent": ["export * from './lib/create-operation.js';\nexport * from './lib/find-polymorphic-varients.js';\nexport * from './lib/find-unique-schema-name.js';\nexport * from './lib/for-each-operation.js';\nexport * from './lib/format-name.js';\nexport * from './lib/get-ref-usage.js';\nexport * from './lib/is-primitive-schema.js';\nexport * from './lib/is.js';\nexport * from './lib/loaders/load-spec.js';\nexport * from './lib/loaders/local-loader.js';\nexport * from './lib/loaders/remote-loader.js';\nexport * from './lib/metadata.js';\nexport * from './lib/operation.js';\nexport * from './lib/options.js';\nexport * from './lib/reserved-keywords.js';\nexport * from './lib/security.js';\nexport * from './lib/sidebar.js';\nexport * from './lib/tag.js';\nexport * from './lib/tune-request-body.js';\nexport * from './lib/tune-response.js';\nexport * from './lib/tune.js';\nexport * from './lib/types.js';\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ReferenceObject, SchemaObject } from 'openapi3-ts/oas31';
|
|
2
|
+
import type { TunedOperationObject } from './types.js';
|
|
3
|
+
export declare function createOperation(options: {
|
|
4
|
+
name: string;
|
|
5
|
+
group: string;
|
|
6
|
+
security?: string[];
|
|
7
|
+
parameters?: {
|
|
8
|
+
query?: Record<string, {
|
|
9
|
+
schema: SchemaObject;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
}>;
|
|
12
|
+
path?: Record<string, {
|
|
13
|
+
schema: SchemaObject;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
header?: Record<string, {
|
|
17
|
+
schema: SchemaObject;
|
|
18
|
+
required?: boolean;
|
|
19
|
+
}>;
|
|
20
|
+
cookie?: Record<string, {
|
|
21
|
+
schema: SchemaObject;
|
|
22
|
+
required?: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
};
|
|
25
|
+
response: Record<string, SchemaObject | Record<string, SchemaObject>>;
|
|
26
|
+
request?: Record<string, ReferenceObject>;
|
|
27
|
+
}): TunedOperationObject;
|
|
28
|
+
//# sourceMappingURL=create-operation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-operation.d.ts","sourceRoot":"","sources":["../../src/lib/create-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEf,YAAY,EACb,MAAM,mBAAmB,CAAC;AAI3B,OAAO,KAAK,EAAwB,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE7E,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE;QACX,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,MAAM,EAAE,YAAY,CAAC;YAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE,CAAC,CAAC;QACrE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,MAAM,EAAE,YAAY,CAAC;YAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE,CAAC,CAAC;QACpE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,MAAM,EAAE,YAAY,CAAC;YAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE,CAAC,CAAC;QACtE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,MAAM,EAAE,YAAY,CAAC;YAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE,CAAC,CAAC;KACvE,CAAC;IACF,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAC3C,GAAG,oBAAoB,CA8DvB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { isEmpty } from "@sdk-it/core/utils.js";
|
|
2
|
+
function createOperation(options) {
|
|
3
|
+
const parameters = [];
|
|
4
|
+
if (!isEmpty(options.parameters)) {
|
|
5
|
+
const locations = ["query", "path", "header", "cookie"];
|
|
6
|
+
for (const location of locations) {
|
|
7
|
+
const locationParams = options.parameters[location];
|
|
8
|
+
if (locationParams) {
|
|
9
|
+
for (const [name, param] of Object.entries(locationParams)) {
|
|
10
|
+
parameters.push({
|
|
11
|
+
name,
|
|
12
|
+
in: location,
|
|
13
|
+
required: param.required ?? false,
|
|
14
|
+
schema: param.schema
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const responses = {};
|
|
21
|
+
for (const [key, schema] of Object.entries(options.response)) {
|
|
22
|
+
const [statusCode, contentType] = key.split(/-(.*)/);
|
|
23
|
+
if (!contentType) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Response key "${key}" must be in the format "statusCode-contentType"`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
responses[statusCode] ??= {
|
|
29
|
+
description: `Response for ${statusCode}`,
|
|
30
|
+
content: {}
|
|
31
|
+
};
|
|
32
|
+
if (contentType === "headers") {
|
|
33
|
+
responses[statusCode].headers = schema;
|
|
34
|
+
} else {
|
|
35
|
+
responses[statusCode].content[contentType] = {
|
|
36
|
+
schema
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
let requestBody = void 0;
|
|
41
|
+
if (options.request) {
|
|
42
|
+
requestBody = { description: "Request body", content: {} };
|
|
43
|
+
for (const [contentType, schema] of Object.entries(options.request)) {
|
|
44
|
+
requestBody.content[contentType] = { schema };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
security: (options.security ?? []).map((name) => ({
|
|
49
|
+
[name]: []
|
|
50
|
+
})),
|
|
51
|
+
"x-fn-name": options.name,
|
|
52
|
+
operationId: options.name,
|
|
53
|
+
tags: [options.group],
|
|
54
|
+
parameters,
|
|
55
|
+
responses,
|
|
56
|
+
requestBody
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
createOperation
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=create-operation.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/create-operation.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n ParameterObject,\n ReferenceObject,\n ResponsesObject,\n SchemaObject,\n} from 'openapi3-ts/oas31';\n\nimport { isEmpty } from '@sdk-it/core/utils.js';\n\nimport type { OurRequestBodyObject, TunedOperationObject } from './types.js';\n\nexport function createOperation(options: {\n name: string;\n group: string;\n security?: string[];\n parameters?: {\n query?: Record<string, { schema: SchemaObject; required?: boolean }>;\n path?: Record<string, { schema: SchemaObject; required?: boolean }>;\n header?: Record<string, { schema: SchemaObject; required?: boolean }>;\n cookie?: Record<string, { schema: SchemaObject; required?: boolean }>;\n };\n response: Record<string, SchemaObject | Record<string, SchemaObject>>; // Key is statusCode-contentType\n request?: Record<string, ReferenceObject>;\n}): TunedOperationObject {\n const parameters: ParameterObject[] = [];\n if (!isEmpty(options.parameters)) {\n const locations = ['query', 'path', 'header', 'cookie'] as const;\n for (const location of locations) {\n const locationParams = options.parameters[location];\n if (locationParams) {\n for (const [name, param] of Object.entries(locationParams)) {\n parameters.push({\n name,\n in: location,\n required: param.required ?? false,\n schema: param.schema,\n });\n }\n }\n }\n }\n const responses: ResponsesObject = {};\n\n for (const [key, schema] of Object.entries(options.response)) {\n const [statusCode, contentType] = key.split(/-(.*)/); // Split on the first dash\n if (!contentType) {\n throw new Error(\n `Response key \"${key}\" must be in the format \"statusCode-contentType\"`,\n );\n }\n responses[statusCode] ??= {\n description: `Response for ${statusCode}`,\n content: {},\n };\n\n if (contentType === 'headers') {\n responses[statusCode].headers = schema;\n } else {\n responses[statusCode].content[contentType] = {\n schema: schema,\n };\n }\n }\n\n let requestBody: OurRequestBodyObject | undefined = undefined;\n\n if (options.request) {\n requestBody = { description: 'Request body', content: {} };\n\n for (const [contentType, schema] of Object.entries(options.request)) {\n requestBody.content[contentType] = { schema: schema };\n }\n }\n\n return {\n security: (options.security ?? []).map((name) => ({\n [name]: [],\n })),\n 'x-fn-name': options.name,\n operationId: options.name,\n tags: [options.group],\n parameters,\n responses,\n requestBody: requestBody as any,\n };\n}\n"],
|
|
5
|
+
"mappings": "AAOA,SAAS,eAAe;AAIjB,SAAS,gBAAgB,SAYP;AACvB,QAAM,aAAgC,CAAC;AACvC,MAAI,CAAC,QAAQ,QAAQ,UAAU,GAAG;AAChC,UAAM,YAAY,CAAC,SAAS,QAAQ,UAAU,QAAQ;AACtD,eAAW,YAAY,WAAW;AAChC,YAAM,iBAAiB,QAAQ,WAAW,QAAQ;AAClD,UAAI,gBAAgB;AAClB,mBAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,cAAc,GAAG;AAC1D,qBAAW,KAAK;AAAA,YACd;AAAA,YACA,IAAI;AAAA,YACJ,UAAU,MAAM,YAAY;AAAA,YAC5B,QAAQ,MAAM;AAAA,UAChB,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,QAAM,YAA6B,CAAC;AAEpC,aAAW,CAAC,KAAK,MAAM,KAAK,OAAO,QAAQ,QAAQ,QAAQ,GAAG;AAC5D,UAAM,CAAC,YAAY,WAAW,IAAI,IAAI,MAAM,OAAO;AACnD,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI;AAAA,QACR,iBAAiB,GAAG;AAAA,MACtB;AAAA,IACF;AACA,cAAU,UAAU,MAAM;AAAA,MACxB,aAAa,gBAAgB,UAAU;AAAA,MACvC,SAAS,CAAC;AAAA,IACZ;AAEA,QAAI,gBAAgB,WAAW;AAC7B,gBAAU,UAAU,EAAE,UAAU;AAAA,IAClC,OAAO;AACL,gBAAU,UAAU,EAAE,QAAQ,WAAW,IAAI;AAAA,QAC3C;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,MAAI,cAAgD;AAEpD,MAAI,QAAQ,SAAS;AACnB,kBAAc,EAAE,aAAa,gBAAgB,SAAS,CAAC,EAAE;AAEzD,eAAW,CAAC,aAAa,MAAM,KAAK,OAAO,QAAQ,QAAQ,OAAO,GAAG;AACnE,kBAAY,QAAQ,WAAW,IAAI,EAAE,OAAe;AAAA,IACtD;AAAA,EACF;AAEA,SAAO;AAAA,IACL,WAAW,QAAQ,YAAY,CAAC,GAAG,IAAI,CAAC,UAAU;AAAA,MAChD,CAAC,IAAI,GAAG,CAAC;AAAA,IACX,EAAE;AAAA,IACF,aAAa,QAAQ;AAAA,IACrB,aAAa,QAAQ;AAAA,IACrB,MAAM,CAAC,QAAQ,KAAK;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"for-each-operation.d.ts","sourceRoot":"","sources":["../../src/lib/for-each-operation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEzF,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,IAAI,EAAE,gBAAgB,EACtB,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,oBAAoB,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"for-each-operation.d.ts","sourceRoot":"","sources":["../../src/lib/for-each-operation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEzF,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,IAAI,EAAE,gBAAgB,EACtB,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,oBAAoB,KAAK,CAAC,OA0BxE"}
|
|
@@ -6,15 +6,12 @@ function forEachOperation(spec, callback) {
|
|
|
6
6
|
if (!methods.includes(method)) {
|
|
7
7
|
continue;
|
|
8
8
|
}
|
|
9
|
-
const metadata = operation["x-oaiMeta"] ?? {};
|
|
10
9
|
const operationTag = operation.tags?.[0];
|
|
11
10
|
result.push(
|
|
12
11
|
callback(
|
|
13
12
|
{
|
|
14
|
-
name: metadata.name,
|
|
15
13
|
method,
|
|
16
14
|
path,
|
|
17
|
-
groupName: operationTag,
|
|
18
15
|
tag: operationTag
|
|
19
16
|
},
|
|
20
17
|
operation
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/for-each-operation.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OperationObject } from 'openapi3-ts/oas31';\n\nimport { type Method, methods } from '@sdk-it/core/paths.js';\n\nimport type { OperationEntry, OurOpenAPIObject, TunedOperationObject } from './types.js';\n\nexport function forEachOperation<T>(\n spec: OurOpenAPIObject,\n callback: (entry: OperationEntry, operation: TunedOperationObject) => T,\n) {\n const result: T[] = [];\n for (const [path, pathItem] of Object.entries(spec.paths)) {\n for (const [method, operation] of Object.entries(pathItem) as [\n Method,\n OperationObject,\n ][]) {\n if (!methods.includes(method)) {\n continue;\n }\n const
|
|
5
|
-
"mappings": "AAEA,SAAsB,eAAe;AAI9B,SAAS,iBACd,MACA,UACA;AACA,QAAM,SAAc,CAAC;AACrB,aAAW,CAAC,MAAM,QAAQ,KAAK,OAAO,QAAQ,KAAK,KAAK,GAAG;AACzD,eAAW,CAAC,QAAQ,SAAS,KAAK,OAAO,QAAQ,QAAQ,GAGpD;AACH,UAAI,CAAC,QAAQ,SAAS,MAAM,GAAG;AAC7B;AAAA,MACF;AACA,YAAM,
|
|
4
|
+
"sourcesContent": ["import type { OperationObject } from 'openapi3-ts/oas31';\n\nimport { type Method, methods } from '@sdk-it/core/paths.js';\n\nimport type { OperationEntry, OurOpenAPIObject, TunedOperationObject } from './types.js';\n\nexport function forEachOperation<T>(\n spec: OurOpenAPIObject,\n callback: (entry: OperationEntry, operation: TunedOperationObject) => T,\n) {\n const result: T[] = [];\n for (const [path, pathItem] of Object.entries(spec.paths)) {\n for (const [method, operation] of Object.entries(pathItem) as [\n Method,\n OperationObject,\n ][]) {\n if (!methods.includes(method)) {\n continue;\n }\n const operationTag = operation.tags?.[0] as string;\n\n result.push(\n callback(\n {\n method,\n path: path,\n tag: operationTag,\n },\n operation as TunedOperationObject,\n ),\n );\n }\n }\n return result;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAsB,eAAe;AAI9B,SAAS,iBACd,MACA,UACA;AACA,QAAM,SAAc,CAAC;AACrB,aAAW,CAAC,MAAM,QAAQ,KAAK,OAAO,QAAQ,KAAK,KAAK,GAAG;AACzD,eAAW,CAAC,QAAQ,SAAS,KAAK,OAAO,QAAQ,QAAQ,GAGpD;AACH,UAAI,CAAC,QAAQ,SAAS,MAAM,GAAG;AAC7B;AAAA,MACF;AACA,YAAM,eAAe,UAAU,OAAO,CAAC;AAEvC,aAAO;AAAA,QACL;AAAA,UACE;AAAA,YACE;AAAA,YACA;AAAA,YACA,KAAK;AAAA,UACP;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/get-ref-usage.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ReferenceObject, SchemaObject } from 'openapi3-ts/oas31';\n\nimport { isEmpty, isRef, parseRef, pascalcase } from '@sdk-it/core';\n\nimport type { OurOpenAPIObject } from './types.
|
|
4
|
+
"sourcesContent": ["import type { ReferenceObject, SchemaObject } from 'openapi3-ts/oas31';\n\nimport { isEmpty, isRef, parseRef, pascalcase } from '@sdk-it/core';\n\nimport type { OurOpenAPIObject } from './types.js';\n\nexport function getRefUsage(\n spec: OurOpenAPIObject,\n schemaName: string,\n list: string[] = [],\n): string[] {\n const checkSchema = (\n schema: SchemaObject | ReferenceObject,\n withRefCheck = false,\n ): any => {\n if (isRef(schema)) {\n if (!withRefCheck) return false;\n const { model } = parseRef(schema.$ref);\n return model === schemaName;\n }\n if (!isEmpty(schema.oneOf)) {\n return schema.oneOf.some((it) => checkSchema(it, true));\n }\n if (schema.type === 'array' && schema.items) {\n if (isRef(schema.items)) {\n return checkSchema(schema.items, withRefCheck);\n }\n if (schema.items.oneOf) {\n return schema.items.oneOf.some((it) => checkSchema(it, true));\n }\n return checkSchema(schema.items, withRefCheck);\n }\n\n if (schema.type === 'object') {\n const properties = schema.properties;\n if (!isEmpty(properties)) {\n let found = false;\n let propertyName = '';\n for (const [key, it] of Object.entries(properties)) {\n found = checkSchema(it, false);\n if (found) {\n propertyName = key;\n }\n }\n return propertyName;\n }\n }\n return false;\n };\n\n for (const [key, value] of Object.entries(spec.components.schemas)) {\n const thisWouldBeTheObjectPropertyKeyName = checkSchema(value);\n if (thisWouldBeTheObjectPropertyKeyName) {\n if (typeof thisWouldBeTheObjectPropertyKeyName === 'string') {\n list.push(pascalcase(`${key} ${thisWouldBeTheObjectPropertyKeyName}`));\n } else {\n list.push(pascalcase(key));\n }\n }\n }\n\n return list;\n}\n"],
|
|
5
5
|
"mappings": "AAEA,SAAS,SAAS,OAAO,UAAU,kBAAkB;AAI9C,SAAS,YACd,MACA,YACA,OAAiB,CAAC,GACR;AACV,QAAM,cAAc,CAClB,QACA,eAAe,UACP;AACR,QAAI,MAAM,MAAM,GAAG;AACjB,UAAI,CAAC,aAAc,QAAO;AAC1B,Y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'openapi3-ts/oas31';
|
|
2
|
+
import { type Method } from '@sdk-it/core/paths.js';
|
|
3
|
+
export declare function toResource(operation: OperationObject, path: string, method: Method): {
|
|
4
|
+
name: string;
|
|
5
|
+
group: string;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=guess-resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guess-resource.d.ts","sourceRoot":"","sources":["../../../src/lib/guess/guess-resource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAiHpD,wBAAgB,UAAU,CACxB,SAAS,EAAE,eAAe,EAC1B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM;UApCL,MAAM;WAAS,MAAM;EAiD/B"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { camelcase } from "stringcase";
|
|
2
|
+
import {} from "@sdk-it/core/paths.js";
|
|
3
|
+
import { cleanOperationId } from "../options.js";
|
|
4
|
+
const HTTP_METHOD_ACTIONS = {
|
|
5
|
+
get: { single: "get", collection: "list" },
|
|
6
|
+
post: { single: "create", collection: "create" },
|
|
7
|
+
put: { single: "replace", collection: "replaceAll" },
|
|
8
|
+
patch: { single: "update", collection: "updateMany" },
|
|
9
|
+
delete: { single: "delete", collection: "deleteMany" },
|
|
10
|
+
head: { single: "exists", collection: "checkList" },
|
|
11
|
+
options: { single: "options", collection: "optionsList" },
|
|
12
|
+
trace: { single: "trace", collection: "traceList" },
|
|
13
|
+
connect: { single: "connect", collection: "connectList" }
|
|
14
|
+
};
|
|
15
|
+
function extractResourceInfo(path) {
|
|
16
|
+
const pathSegments = path.split("/").filter(Boolean);
|
|
17
|
+
if (pathSegments.length === 0) {
|
|
18
|
+
return {
|
|
19
|
+
resourceName: "root",
|
|
20
|
+
isSingleResource: false,
|
|
21
|
+
resourceHierarchy: ["root"]
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const lastSegment = pathSegments[pathSegments.length - 1];
|
|
25
|
+
const isSingleResource = lastSegment?.startsWith("{") && lastSegment?.endsWith("}");
|
|
26
|
+
let resourceName;
|
|
27
|
+
let resourceHierarchy;
|
|
28
|
+
if (isSingleResource) {
|
|
29
|
+
const parentSegment = pathSegments[pathSegments.length - 2];
|
|
30
|
+
resourceName = parentSegment || "item";
|
|
31
|
+
resourceHierarchy = pathSegments.filter((segment) => !segment.startsWith("{")).map((segment) => segment.replace(/[{}]/g, ""));
|
|
32
|
+
} else {
|
|
33
|
+
resourceName = lastSegment;
|
|
34
|
+
resourceHierarchy = pathSegments.filter((segment) => !segment.startsWith("{")).map((segment) => segment.replace(/[{}]/g, ""));
|
|
35
|
+
}
|
|
36
|
+
const cleanResourceName = resourceName.replace(/[{}]/g, "").replace(/[-_]/g, " ").replace(/[^a-zA-Z0-9\s]/g, "");
|
|
37
|
+
const hierarchicalName = resourceHierarchy.length > 1 ? resourceHierarchy.join(" ") : cleanResourceName;
|
|
38
|
+
return {
|
|
39
|
+
resourceName: cleanResourceName || "resource",
|
|
40
|
+
isSingleResource,
|
|
41
|
+
resourceHierarchy: [hierarchicalName]
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function guessOperationName(method, {
|
|
45
|
+
isSingleResource,
|
|
46
|
+
resourceHierarchy
|
|
47
|
+
}) {
|
|
48
|
+
const methodAction = HTTP_METHOD_ACTIONS[method.toLowerCase()];
|
|
49
|
+
if (!methodAction) {
|
|
50
|
+
const fallbackAction = isSingleResource ? method.toLowerCase() : `${method.toLowerCase()}All`;
|
|
51
|
+
return {
|
|
52
|
+
name: camelcase(fallbackAction),
|
|
53
|
+
group: camelcase(resourceHierarchy[0])
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const actionName = isSingleResource ? methodAction.single : methodAction.collection;
|
|
57
|
+
const operationName = resourceHierarchy.length > 1 && !isSingleResource ? `${actionName} ${resourceHierarchy.slice(-1)[0]}` : actionName;
|
|
58
|
+
return {
|
|
59
|
+
name: camelcase(operationName),
|
|
60
|
+
group: camelcase(resourceHierarchy[0])
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function toResource(operation, path, method) {
|
|
64
|
+
const resourceInfo = extractResourceInfo(path);
|
|
65
|
+
if (operation.operationId) {
|
|
66
|
+
return {
|
|
67
|
+
name: cleanOperationId(operation.operationId),
|
|
68
|
+
group: camelcase(resourceInfo.resourceName)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return guessOperationName(method, resourceInfo);
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
toResource
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=guess-resource.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/guess/guess-resource.ts"],
|
|
4
|
+
"sourcesContent": ["import type { OperationObject } from 'openapi3-ts/oas31';\nimport { camelcase } from 'stringcase';\n\nimport { type Method } from '@sdk-it/core/paths.js';\n\nimport { cleanOperationId } from '../options.js';\n\nconst HTTP_METHOD_ACTIONS = {\n get: { single: 'get', collection: 'list' },\n post: { single: 'create', collection: 'create' },\n put: { single: 'replace', collection: 'replaceAll' },\n patch: { single: 'update', collection: 'updateMany' },\n delete: { single: 'delete', collection: 'deleteMany' },\n head: { single: 'exists', collection: 'checkList' },\n options: { single: 'options', collection: 'optionsList' },\n trace: { single: 'trace', collection: 'traceList' },\n connect: { single: 'connect', collection: 'connectList' },\n} as const;\n\nfunction extractResourceInfo(path: string): {\n resourceName: string;\n isSingleResource: boolean;\n resourceHierarchy: string[];\n} {\n const pathSegments = path.split('/').filter(Boolean);\n\n if (pathSegments.length === 0) {\n return {\n resourceName: 'root',\n isSingleResource: false,\n resourceHierarchy: ['root'],\n };\n }\n\n const lastSegment = pathSegments[pathSegments.length - 1];\n const isSingleResource =\n lastSegment?.startsWith('{') && lastSegment?.endsWith('}');\n\n // For single resources, use the parent resource name\n // For collections, use the last segment\n let resourceName: string;\n let resourceHierarchy: string[];\n\n if (isSingleResource) {\n // Single resource: /users/{id} -> \"users\"\n const parentSegment = pathSegments[pathSegments.length - 2];\n resourceName = parentSegment || 'item';\n resourceHierarchy = pathSegments\n .filter((segment) => !segment.startsWith('{'))\n .map((segment) => segment.replace(/[{}]/g, ''));\n } else {\n // Collection: /users or /users/active -> \"users\" or \"usersActive\"\n resourceName = lastSegment;\n resourceHierarchy = pathSegments\n .filter((segment) => !segment.startsWith('{'))\n .map((segment) => segment.replace(/[{}]/g, ''));\n }\n\n // Clean and normalize resource name\n const cleanResourceName = resourceName\n .replace(/[{}]/g, '')\n .replace(/[-_]/g, ' ')\n .replace(/[^a-zA-Z0-9\\s]/g, '');\n\n // Generate a hierarchy-based group name for better conflict avoidance\n const hierarchicalName =\n resourceHierarchy.length > 1\n ? resourceHierarchy.join(' ')\n : cleanResourceName;\n\n return {\n resourceName: cleanResourceName || 'resource',\n isSingleResource,\n resourceHierarchy: [hierarchicalName],\n };\n}\n\nfunction guessOperationName(\n method: Method,\n {\n isSingleResource,\n resourceHierarchy,\n }: ReturnType<typeof extractResourceInfo>,\n): { name: string; group: string } {\n const methodAction =\n HTTP_METHOD_ACTIONS[\n method.toLowerCase() as keyof typeof HTTP_METHOD_ACTIONS\n ];\n\n if (!methodAction) {\n // Fallback for unknown HTTP methods\n const fallbackAction = isSingleResource\n ? method.toLowerCase()\n : `${method.toLowerCase()}All`;\n return {\n name: camelcase(fallbackAction),\n group: camelcase(resourceHierarchy[0]),\n };\n }\n\n const actionName = isSingleResource\n ? methodAction.single\n : methodAction.collection;\n\n // Create more descriptive names for complex paths\n const operationName =\n resourceHierarchy.length > 1 && !isSingleResource\n ? `${actionName} ${resourceHierarchy.slice(-1)[0]}` // e.g., \"list activeUsers\"\n : actionName;\n\n return {\n name: camelcase(operationName),\n group: camelcase(resourceHierarchy[0]),\n };\n}\n\nexport function toResource(\n operation: OperationObject,\n path: string,\n method: Method,\n) {\n // Priority 1: Non-guessed operationId\n const resourceInfo = extractResourceInfo(path);\n if (operation.operationId) {\n return {\n name: cleanOperationId(operation.operationId),\n group: camelcase(resourceInfo.resourceName),\n };\n }\n\n // Priority 2: CRUD operation name\n return guessOperationName(method, resourceInfo);\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,iBAAiB;AAE1B,eAA4B;AAE5B,SAAS,wBAAwB;AAEjC,MAAM,sBAAsB;AAAA,EAC1B,KAAK,EAAE,QAAQ,OAAO,YAAY,OAAO;AAAA,EACzC,MAAM,EAAE,QAAQ,UAAU,YAAY,SAAS;AAAA,EAC/C,KAAK,EAAE,QAAQ,WAAW,YAAY,aAAa;AAAA,EACnD,OAAO,EAAE,QAAQ,UAAU,YAAY,aAAa;AAAA,EACpD,QAAQ,EAAE,QAAQ,UAAU,YAAY,aAAa;AAAA,EACrD,MAAM,EAAE,QAAQ,UAAU,YAAY,YAAY;AAAA,EAClD,SAAS,EAAE,QAAQ,WAAW,YAAY,cAAc;AAAA,EACxD,OAAO,EAAE,QAAQ,SAAS,YAAY,YAAY;AAAA,EAClD,SAAS,EAAE,QAAQ,WAAW,YAAY,cAAc;AAC1D;AAEA,SAAS,oBAAoB,MAI3B;AACA,QAAM,eAAe,KAAK,MAAM,GAAG,EAAE,OAAO,OAAO;AAEnD,MAAI,aAAa,WAAW,GAAG;AAC7B,WAAO;AAAA,MACL,cAAc;AAAA,MACd,kBAAkB;AAAA,MAClB,mBAAmB,CAAC,MAAM;AAAA,IAC5B;AAAA,EACF;AAEA,QAAM,cAAc,aAAa,aAAa,SAAS,CAAC;AACxD,QAAM,mBACJ,aAAa,WAAW,GAAG,KAAK,aAAa,SAAS,GAAG;AAI3D,MAAI;AACJ,MAAI;AAEJ,MAAI,kBAAkB;AAEpB,UAAM,gBAAgB,aAAa,aAAa,SAAS,CAAC;AAC1D,mBAAe,iBAAiB;AAChC,wBAAoB,aACjB,OA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B,UAAU,WAAW;AAAA,MAC5C,OAAO,UAAU,aAAa,YAAY;AAAA,IAC5C;AAAA,EACF;AAGA,SAAO,mBAAmB,QAAQ,YAAY;AAChD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/lib/metadata.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare function readWriteJson<T = Record<string, unknown>>(path: string): Promise<{
|
|
2
2
|
content: Partial<T>;
|
|
3
|
-
write: (value?: Record<string,
|
|
3
|
+
write: (value?: Record<string, unknown>) => Promise<void>;
|
|
4
4
|
}>;
|
|
5
5
|
interface Metadata {
|
|
6
6
|
generatedFiles: string[];
|
|
@@ -8,7 +8,7 @@ interface Metadata {
|
|
|
8
8
|
}
|
|
9
9
|
export declare function readWriteMetadata(output: string, files: string[]): Promise<{
|
|
10
10
|
content: Partial<Metadata>;
|
|
11
|
-
write: (value?: Record<string,
|
|
11
|
+
write: (value?: Record<string, unknown>) => Promise<void>;
|
|
12
12
|
}>;
|
|
13
13
|
/**
|
|
14
14
|
* Must run this file before writing the index files
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/lib/metadata.ts"],"names":[],"mappings":"AAcA,wBAAsB,aAAa,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM;;oBAM1D,MAAM,CAAC,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/lib/metadata.ts"],"names":[],"mappings":"AAcA,wBAAsB,aAAa,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM;;oBAM1D,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;GAGzC;AAED,UAAU,QAAQ;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;;oBAVpD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;GAgBzC;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,EAC3B,MAAM,EAAE,MAAM,EACd,oBAAoB,GAAE,MAAM,EAAO,iBA4CpC"}
|
package/dist/lib/metadata.js
CHANGED
|
@@ -29,16 +29,28 @@ async function cleanFiles(metadata, output, alwaysAvailableFiles = []) {
|
|
|
29
29
|
const user = metadata.userFiles ?? [];
|
|
30
30
|
const keep = [...generated, ...user, ...alwaysAvailableFiles];
|
|
31
31
|
const actualFiles = (await readFolder(output, true)).map(addLeadingSlash);
|
|
32
|
-
const filesToDelete =
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
const filesToDelete = [
|
|
33
|
+
...new Set(
|
|
34
|
+
actualFiles.filter(
|
|
35
|
+
(file) => !micromatch.isMatch(file, keep, { cwd: join(process.cwd(), output) })
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
];
|
|
35
39
|
const limit = pLimit(availableParallelism());
|
|
36
40
|
await Promise.all(
|
|
37
41
|
filesToDelete.map(
|
|
38
42
|
(file) => limit(async () => {
|
|
39
43
|
const filePath = join(output, file);
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
try {
|
|
45
|
+
await unlink(filePath);
|
|
46
|
+
log(`Deleted file: ${filePath}`);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
if (error?.code === "ENOENT") {
|
|
49
|
+
log(`File already deleted or doesn't exist: ${filePath}`);
|
|
50
|
+
} else {
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
42
54
|
})
|
|
43
55
|
)
|
|
44
56
|
);
|
package/dist/lib/metadata.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/metadata.ts"],
|
|
4
|
-
"sourcesContent": ["import deubg from 'debug';\nimport { readFile, unlink, writeFile } from 'node:fs/promises';\nimport { availableParallelism } from 'node:os';\nimport { join } from 'node:path';\nimport pLimit from 'p-limit';\n\nimport {\n addLeadingSlash,\n exist,\n readFolder,\n} from '@sdk-it/core/file-system.js';\n\nconst log = deubg('sdk-it:metdata');\n\nexport async function readWriteJson<T = Record<string, unknown>>(path: string) {\n const content = (\n (await exist(path)) ? JSON.parse(await readFile(path, 'utf-8')) : {}\n ) as Partial<T>;\n return {\n content,\n write: (value: Record<string,
|
|
5
|
-
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,UAAU,QAAQ,iBAAiB;AAC5C,SAAS,4BAA4B;AACrC,SAAS,YAAY;AACrB,OAAO,YAAY;AAEnB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,MAAM,MAAM,gBAAgB;AAElC,eAAsB,cAA2C,MAAc;AAC7E,QAAM,UACH,MAAM,MAAM,IAAI,IAAK,KAAK,MAAM,MAAM,SAAS,MAAM,OAAO,CAAC,IAAI,CAAC;AAErE,SAAO;AAAA,IACL;AAAA,IACA,OAAO,CAAC,
|
|
4
|
+
"sourcesContent": ["import deubg from 'debug';\nimport { readFile, unlink, writeFile } from 'node:fs/promises';\nimport { availableParallelism } from 'node:os';\nimport { join } from 'node:path';\nimport pLimit from 'p-limit';\n\nimport {\n addLeadingSlash,\n exist,\n readFolder,\n} from '@sdk-it/core/file-system.js';\n\nconst log = deubg('sdk-it:metdata');\n\nexport async function readWriteJson<T = Record<string, unknown>>(path: string) {\n const content = (\n (await exist(path)) ? JSON.parse(await readFile(path, 'utf-8')) : {}\n ) as Partial<T>;\n return {\n content,\n write: (value: Record<string, unknown> = content) =>\n writeFile(path, JSON.stringify(value, null, 2), 'utf-8'),\n };\n}\n\ninterface Metadata {\n generatedFiles: string[];\n userFiles?: string[];\n}\n\nexport async function readWriteMetadata(output: string, files: string[]) {\n const metadata = await readWriteJson<Metadata>(join(output, 'metadata.json'));\n metadata.content.generatedFiles = files;\n metadata.content.userFiles ??= ['/dist/**', '/build/**', '/readme.md'];\n await metadata.write(metadata.content);\n return metadata;\n}\n\n/**\n * Must run this file before writing the index files\n * otherwise the index.ts file will have have references to files\n * that are deleted (old, non used generated files)\n * @param metadata\n * @param output\n */\nexport async function cleanFiles(\n metadata: Partial<Metadata>,\n output: string,\n alwaysAvailableFiles: string[] = [],\n) {\n const { default: micromatch } = await import('micromatch');\n const generated = metadata.generatedFiles ?? [];\n const user = metadata.userFiles ?? [];\n const keep = [...generated, ...user, ...alwaysAvailableFiles];\n const actualFiles = (await readFolder(output, true)).map(addLeadingSlash);\n const filesToDelete = [\n ...new Set(\n actualFiles.filter(\n (file) =>\n !micromatch.isMatch(file, keep, { cwd: join(process.cwd(), output) }),\n ),\n ),\n ];\n const limit = pLimit(availableParallelism());\n\n await Promise.all(\n filesToDelete.map((file) =>\n limit(async () => {\n const filePath = join(output, file);\n try {\n await unlink(filePath);\n log(`Deleted file: ${filePath}`);\n } catch (error: unknown) {\n // Ignore ENOENT errors - file was already deleted or doesn't exist\n if ((error as NodeJS.ErrnoException)?.code === 'ENOENT') {\n log(`File already deleted or doesn't exist: ${filePath}`);\n } else {\n throw error;\n }\n }\n }),\n ),\n );\n\n // for (const file of actualFiles) {\n // if (micromatch.isMatch(addLeadingSlash(file), keep)) {\n // continue;\n // }\n // const filePath = join(output, file);\n // await unlink(filePath);\n // log(`Deleted file: ${filePath}`);\n // }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,UAAU,QAAQ,iBAAiB;AAC5C,SAAS,4BAA4B;AACrC,SAAS,YAAY;AACrB,OAAO,YAAY;AAEnB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,MAAM,MAAM,gBAAgB;AAElC,eAAsB,cAA2C,MAAc;AAC7E,QAAM,U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