@goast/core 0.4.2 → 0.5.0-beta.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.
Files changed (71) hide show
  1. package/LICENSE +21 -21
  2. package/esm/mod.d.ts +1 -0
  3. package/esm/mod.d.ts.map +1 -1
  4. package/esm/mod.js +1 -0
  5. package/esm/src/codegen/config.d.ts +11 -0
  6. package/esm/src/codegen/config.d.ts.map +1 -1
  7. package/esm/src/codegen/config.js +1 -0
  8. package/esm/src/utils/file-system.utils.d.ts +2 -0
  9. package/esm/src/utils/file-system.utils.d.ts.map +1 -1
  10. package/esm/src/utils/file-system.utils.js +11 -1
  11. package/esm/src/utils/schema.utils.d.ts +1 -0
  12. package/esm/src/utils/schema.utils.d.ts.map +1 -1
  13. package/esm/src/utils/schema.utils.js +5 -0
  14. package/package.json +2 -2
  15. package/script/mod.d.ts +1 -0
  16. package/script/mod.d.ts.map +1 -1
  17. package/script/mod.js +1 -0
  18. package/script/src/codegen/config.d.ts +11 -0
  19. package/script/src/codegen/config.d.ts.map +1 -1
  20. package/script/src/codegen/config.js +1 -0
  21. package/script/src/utils/file-system.utils.d.ts +2 -0
  22. package/script/src/utils/file-system.utils.d.ts.map +1 -1
  23. package/script/src/utils/file-system.utils.js +11 -0
  24. package/script/src/utils/schema.utils.d.ts +1 -0
  25. package/script/src/utils/schema.utils.d.ts.map +1 -1
  26. package/script/src/utils/schema.utils.js +6 -0
  27. package/src/_dnt.shims.ts +0 -69
  28. package/src/mod.ts +0 -33
  29. package/src/src/ast/node.ts +0 -46
  30. package/src/src/codegen/config.ts +0 -28
  31. package/src/src/codegen/endpoints-generator.ts +0 -72
  32. package/src/src/codegen/generator.ts +0 -181
  33. package/src/src/codegen/internal-utils.ts +0 -6
  34. package/src/src/codegen/schemas-generator.ts +0 -87
  35. package/src/src/codegen/services-generator.ts +0 -77
  36. package/src/src/codegen/types.ts +0 -37
  37. package/src/src/collect/collector.ts +0 -142
  38. package/src/src/collect/helpers.ts +0 -36
  39. package/src/src/collect/types.ts +0 -21
  40. package/src/src/internal-utils.ts +0 -5
  41. package/src/src/parse/deref-proxy.ts +0 -64
  42. package/src/src/parse/openapi-types.ts +0 -949
  43. package/src/src/parse/parser.ts +0 -220
  44. package/src/src/parse/types.ts +0 -27
  45. package/src/src/transform/api-types.ts +0 -243
  46. package/src/src/transform/helpers.ts +0 -216
  47. package/src/src/transform/transform-document.ts +0 -35
  48. package/src/src/transform/transform-endpoint.ts +0 -331
  49. package/src/src/transform/transform-schema.ts +0 -217
  50. package/src/src/transform/transformer.ts +0 -52
  51. package/src/src/transform/types.ts +0 -52
  52. package/src/src/utils/action-provider.ts +0 -58
  53. package/src/src/utils/array.utils.ts +0 -7
  54. package/src/src/utils/asset-manager.ts +0 -51
  55. package/src/src/utils/class.utils.ts +0 -40
  56. package/src/src/utils/common.utils.ts +0 -86
  57. package/src/src/utils/condition.ts +0 -7
  58. package/src/src/utils/endpoint.utils.ts +0 -10
  59. package/src/src/utils/error.utils.ts +0 -3
  60. package/src/src/utils/factory.ts +0 -42
  61. package/src/src/utils/file-system.utils.ts +0 -48
  62. package/src/src/utils/generator.utils.ts +0 -6
  63. package/src/src/utils/object.utils.ts +0 -32
  64. package/src/src/utils/schema.utils.ts +0 -142
  65. package/src/src/utils/source-builder.ts +0 -597
  66. package/src/src/utils/string-builder/options.ts +0 -19
  67. package/src/src/utils/string-builder/string-builder.ts +0 -165
  68. package/src/src/utils/string-builder/utils.ts +0 -69
  69. package/src/src/utils/string.utils.ts +0 -369
  70. package/src/src/utils/string.utils.types.ts +0 -179
  71. package/src/src/utils/type.utils.ts +0 -93
@@ -1,32 +0,0 @@
1
- export function createOverwriteProxy<T extends object>(target: T, values?: Partial<T>): T {
2
- const proxy = new Proxy(target, new OverwriteProxyHandler());
3
- if (values) {
4
- Object.assign(proxy, values);
5
- }
6
- return proxy;
7
- }
8
-
9
- export function getDeepProperty(obj: object, path: string[]): unknown {
10
- let current = obj;
11
- for (const key of path) {
12
- if (!current || typeof current !== 'object') {
13
- return undefined;
14
- }
15
- // deno-lint-ignore no-explicit-any
16
- current = (current as any)[key];
17
- }
18
- return current;
19
- }
20
-
21
- class OverwriteProxyHandler<T extends object> implements ProxyHandler<T> {
22
- private readonly _overwrittenValues: Record<PropertyKey, unknown> = {};
23
-
24
- public get(target: T, prop: PropertyKey): unknown {
25
- return this._overwrittenValues[prop] ?? (target as Record<PropertyKey, unknown>)[prop];
26
- }
27
-
28
- public set(_target: T, prop: PropertyKey, value: unknown): boolean {
29
- this._overwrittenValues[prop] = value;
30
- return true;
31
- }
32
- }
@@ -1,142 +0,0 @@
1
- import { isOpenApiObjectProperty } from '../internal-utils.js';
2
- import type { OpenApiSchema } from '../parse/openapi-types.js';
3
- import type { ApiSchema, ApiSchemaProperty, ObjectLikeApiSchema } from '../transform/api-types.js';
4
-
5
- export function resolveAnyOfAndAllOf(
6
- schema: ApiSchema<'combined' | 'object'>,
7
- ignoreNonObjectParts: boolean,
8
- ): ApiSchema<'object'> | undefined {
9
- if (!ignoreNonObjectParts && (hasInvalidSubSchema(schema.anyOf) || hasInvalidSubSchema(schema.allOf))) {
10
- return undefined;
11
- }
12
-
13
- const required = new Set(schema.required);
14
- const properties = new Map<string, ApiSchemaProperty>();
15
- if ('properties' in schema) {
16
- schema.properties.forEach((prop) => properties.set(prop.name, prop));
17
- }
18
- collectSubSchemaProperties(schema.allOf, properties, required, false);
19
- collectSubSchemaProperties(schema.anyOf, properties, required, true);
20
-
21
- const initialAdditionalProperties = schema.kind === 'object' ? schema.additionalProperties : undefined;
22
- let additionalProperties = initialAdditionalProperties;
23
- additionalProperties = combineAdditionalProperties(schema.allOf, additionalProperties);
24
- additionalProperties = combineAdditionalProperties(schema.anyOf, additionalProperties);
25
-
26
- if (properties.size === 0 && initialAdditionalProperties === additionalProperties) {
27
- return undefined;
28
- }
29
-
30
- return {
31
- ...schema,
32
- kind: 'object',
33
- type: 'object',
34
- anyOf: [],
35
- allOf: [],
36
- properties: properties,
37
- required: required,
38
- additionalProperties,
39
- };
40
- }
41
-
42
- function collectSubSchemaProperties(
43
- subSchemas: ApiSchema[],
44
- properties: Map<string, ApiSchemaProperty>,
45
- required: Set<string>,
46
- optional: boolean,
47
- ) {
48
- for (const subSchema of subSchemas) {
49
- if (subSchema.kind === 'object') {
50
- for (const prop of subSchema.properties.values()) {
51
- if (!properties.has(prop.name)) {
52
- properties.set(prop.name, prop);
53
- }
54
- }
55
- if (!optional) {
56
- for (const prop of subSchema.required) {
57
- required.add(prop);
58
- }
59
- }
60
- }
61
-
62
- if (subSchema.kind === 'object' || subSchema.kind === 'combined') {
63
- collectSubSchemaProperties(subSchema.allOf, properties, required, optional);
64
- collectSubSchemaProperties(subSchema.anyOf, properties, required, true);
65
- }
66
- }
67
- }
68
-
69
- function combineAdditionalProperties(
70
- subSchemas: ApiSchema[],
71
- current: ObjectLikeApiSchema['additionalProperties'],
72
- ): ObjectLikeApiSchema['additionalProperties'] {
73
- if (current === true) return true;
74
-
75
- for (const subSchema of subSchemas) {
76
- if (subSchema.kind === 'object' && subSchema.additionalProperties) {
77
- if (subSchema.additionalProperties === true) return true;
78
- if (!current) {
79
- current = subSchema.additionalProperties;
80
- } else if (current && current.id !== subSchema.additionalProperties.id) {
81
- if (current.kind === 'oneOf') {
82
- current.oneOf.push(subSchema.additionalProperties);
83
- } else {
84
- const id = `schema-${Math.random().toString(36).substring(2)}`;
85
- current = {
86
- $ref: undefined,
87
- $src: current.$src,
88
- id,
89
- kind: 'oneOf',
90
- name: id,
91
- isNameGenerated: true,
92
- description: undefined,
93
- deprecated: false,
94
- accessibility: 'all',
95
- enum: undefined,
96
- const: undefined,
97
- default: undefined,
98
- example: undefined,
99
- nullable: false,
100
- required: new Set(),
101
- custom: {},
102
- not: undefined,
103
- discriminator: undefined,
104
- inheritedSchemas: [],
105
- oneOf: [current, subSchema.additionalProperties],
106
- };
107
- }
108
- }
109
- }
110
-
111
- if (subSchema.kind === 'object' || subSchema.kind === 'combined') {
112
- current = combineAdditionalProperties(subSchema.allOf, current);
113
- current = combineAdditionalProperties(subSchema.anyOf, current);
114
- }
115
-
116
- if (current === true) return true;
117
- }
118
-
119
- return current;
120
- }
121
-
122
- function hasInvalidSubSchema(subSchemas: ApiSchema[]): boolean {
123
- return subSchemas.some(
124
- (x) =>
125
- x.kind !== 'object' &&
126
- (x.kind !== 'combined' || (!hasInvalidSubSchema(x.allOf) && !hasInvalidSubSchema(x.anyOf))),
127
- );
128
- }
129
-
130
- /**
131
- * Retrieves the first schema reference and the reference chain of a given schema that
132
- * defines some schema properties. (e.g. schemas with just "$ref" are skipped)
133
- * @param schema The schema to retrieve the reference from.
134
- * @param propertiesToIgnore The properties to ignore when checking for a schema definition.
135
- */
136
- export function getSchemaReference(schema: ApiSchema, propertiesToIgnore: (keyof OpenApiSchema)[]): ApiSchema {
137
- if (!schema.$ref) return schema;
138
- const hasPropertiesDefined = Object.keys(schema.$src.originalComponent).some(
139
- (key) => isOpenApiObjectProperty(key) && !propertiesToIgnore.includes(key as keyof OpenApiSchema),
140
- );
141
- return hasPropertiesDefined ? schema : getSchemaReference(schema.$ref, propertiesToIgnore);
142
- }