swagger-sdk-generator 0.0.0-stage → 3.0.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/README.md +58 -2
- package/dist/cli/commands/generate.d.ts +2 -0
- package/dist/cli/commands/generate.js +196 -0
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.js +130 -0
- package/dist/cli/commands/inspect.d.ts +2 -0
- package/dist/cli/commands/inspect.js +164 -0
- package/dist/cli/commands/templates.d.ts +2 -0
- package/dist/cli/commands/templates.js +126 -0
- package/dist/cli/context.d.ts +16 -0
- package/dist/cli/context.js +85 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +25 -0
- package/dist/config/dotenv.d.ts +2 -0
- package/dist/config/dotenv.js +82 -0
- package/dist/config/interpolate.d.ts +8 -0
- package/dist/config/interpolate.js +85 -0
- package/dist/config/load.d.ts +11 -0
- package/dist/config/load.js +182 -0
- package/dist/config/migrate-v3.d.ts +5 -0
- package/dist/config/migrate-v3.js +6 -0
- package/dist/config/mode-compatibility.d.ts +9 -0
- package/dist/config/mode-compatibility.js +17 -0
- package/dist/config/modes.d.ts +13 -0
- package/dist/config/modes.js +27 -0
- package/dist/config/preset-definitions.d.ts +2 -0
- package/dist/config/preset-definitions.js +4 -0
- package/dist/config/presets.d.ts +25 -0
- package/dist/config/presets.js +36 -0
- package/dist/config/resolve.d.ts +32 -0
- package/dist/config/resolve.js +288 -0
- package/dist/config/schema.d.ts +93 -0
- package/dist/config/schema.js +173 -0
- package/dist/config/types.d.ts +42 -0
- package/dist/config/types.js +2 -0
- package/dist/config/workspace.d.ts +30 -0
- package/dist/config/workspace.js +95 -0
- package/dist/core/case-align.d.ts +5 -0
- package/dist/core/case-align.js +90 -0
- package/dist/core/deep-merge.d.ts +2 -0
- package/dist/core/deep-merge.js +21 -0
- package/dist/core/file-set.d.ts +10 -0
- package/dist/core/file-set.js +31 -0
- package/dist/core/import-module.d.ts +1 -0
- package/dist/core/import-module.js +61 -0
- package/dist/core/log.d.ts +9 -0
- package/dist/core/log.js +24 -0
- package/dist/core/manifest.d.ts +17 -0
- package/dist/core/manifest.js +195 -0
- package/dist/core/overlaps.d.ts +6 -0
- package/dist/core/overlaps.js +67 -0
- package/dist/core/package-version.d.ts +1 -0
- package/dist/core/package-version.js +44 -0
- package/dist/core/pipeline.d.ts +30 -0
- package/dist/core/pipeline.js +335 -0
- package/dist/core/plugin.d.ts +72 -0
- package/dist/core/plugin.js +2 -0
- package/dist/core/targets.d.ts +14 -0
- package/dist/core/targets.js +120 -0
- package/dist/core/unmanaged.d.ts +3 -0
- package/dist/core/unmanaged.js +101 -0
- package/dist/core/writer.d.ts +28 -0
- package/dist/core/writer.js +148 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +37 -0
- package/dist/ir/casing.d.ts +5 -0
- package/dist/ir/casing.js +22 -0
- package/dist/ir/graph.d.ts +8 -0
- package/dist/ir/graph.js +95 -0
- package/dist/ir/operations/grouping.d.ts +17 -0
- package/dist/ir/operations/grouping.js +39 -0
- package/dist/ir/operations/legacy-naming.d.ts +2 -0
- package/dist/ir/operations/legacy-naming.js +8 -0
- package/dist/ir/operations/naming.d.ts +6 -0
- package/dist/ir/operations/naming.js +54 -0
- package/dist/ir/option-errors.d.ts +3 -0
- package/dist/ir/option-errors.js +68 -0
- package/dist/ir/transforms/builtins.d.ts +2 -0
- package/dist/ir/transforms/builtins.js +4 -0
- package/dist/ir/transforms/index.d.ts +10 -0
- package/dist/ir/transforms/index.js +39 -0
- package/dist/ir/transforms/types.d.ts +9 -0
- package/dist/ir/transforms/types.js +2 -0
- package/dist/ir/types.d.ts +140 -0
- package/dist/ir/types.js +2 -0
- package/dist/runtime/axios.d.ts +28 -0
- package/dist/runtime/axios.js +132 -0
- package/dist/runtime/fetch.d.ts +6 -0
- package/dist/runtime/fetch.js +38 -0
- package/dist/runtime/index.d.ts +54 -0
- package/dist/runtime/index.js +167 -0
- package/dist/runtime/rtk.d.ts +35 -0
- package/dist/runtime/rtk.js +36 -0
- package/dist/runtime/transport.d.ts +38 -0
- package/dist/runtime/transport.js +30 -0
- package/dist/runtime/wire.d.ts +27 -0
- package/dist/runtime/wire.js +148 -0
- package/dist/spec/html-entities.d.ts +1 -0
- package/dist/spec/html-entities.js +25 -0
- package/dist/spec/load.d.ts +26 -0
- package/dist/spec/load.js +130 -0
- package/dist/spec/openapi/all-of.d.ts +3 -0
- package/dist/spec/openapi/all-of.js +9 -0
- package/dist/spec/openapi/normalize.d.ts +4 -0
- package/dist/spec/openapi/normalize.js +31 -0
- package/dist/spec/openapi/operations.d.ts +4 -0
- package/dist/spec/openapi/operations.js +173 -0
- package/dist/spec/openapi/schema.d.ts +51 -0
- package/dist/spec/openapi/schema.js +307 -0
- package/dist/targets/declarative/config.d.ts +533 -0
- package/dist/targets/declarative/config.js +280 -0
- package/dist/targets/declarative/extensions.d.ts +45 -0
- package/dist/targets/declarative/extensions.js +123 -0
- package/dist/targets/declarative/files.d.ts +13 -0
- package/dist/targets/declarative/files.js +127 -0
- package/dist/targets/declarative/format.d.ts +4 -0
- package/dist/targets/declarative/format.js +104 -0
- package/dist/targets/declarative/index.d.ts +9 -0
- package/dist/targets/declarative/index.js +170 -0
- package/dist/targets/declarative/liquid.d.ts +8 -0
- package/dist/targets/declarative/liquid.js +57 -0
- package/dist/targets/declarative/naming-case.d.ts +3 -0
- package/dist/targets/declarative/naming-case.js +31 -0
- package/dist/targets/declarative/naming.d.ts +42 -0
- package/dist/targets/declarative/naming.js +174 -0
- package/dist/targets/declarative/scaffold.d.ts +5 -0
- package/dist/targets/declarative/scaffold.js +146 -0
- package/dist/targets/declarative/types.d.ts +52 -0
- package/dist/targets/declarative/types.js +287 -0
- package/dist/targets/declarative/views.d.ts +180 -0
- package/dist/targets/declarative/views.js +447 -0
- package/dist/targets/python/extensions.js +152 -0
- package/dist/targets/python/target.json +549 -0
- package/dist/targets/python/templates/client/client.liquid +114 -0
- package/dist/targets/python/templates/client/httpx_transport.liquid +172 -0
- package/dist/targets/python/templates/client/init.liquid +20 -0
- package/dist/targets/python/templates/client/partials/operation_method.liquid +41 -0
- package/dist/targets/python/templates/client/resource.liquid +28 -0
- package/dist/targets/python/templates/client/runtime.liquid +133 -0
- package/dist/targets/python/templates/client/transport.liquid +62 -0
- package/dist/targets/python/templates/models/module.liquid +48 -0
- package/dist/targets/python/templates/models/partials/docstring.liquid +5 -0
- package/dist/targets/python/templates/models/partials/enum_class.liquid +11 -0
- package/dist/targets/python/templates/models/partials/field_line.liquid +5 -0
- package/dist/targets/python/templates/models/partials/model_class.liquid +17 -0
- package/dist/targets/typescript/compatibility-naming.d.ts +6 -0
- package/dist/targets/typescript/compatibility-naming.js +28 -0
- package/dist/targets/typescript/compatibility-options.d.ts +5 -0
- package/dist/targets/typescript/compatibility-options.js +8 -0
- package/dist/targets/typescript/compatibility-target.d.ts +5 -0
- package/dist/targets/typescript/compatibility-target.js +10 -0
- package/dist/targets/typescript/http-operations.d.ts +34 -0
- package/dist/targets/typescript/http-operations.js +155 -0
- package/dist/targets/typescript/imports.d.ts +43 -0
- package/dist/targets/typescript/imports.js +154 -0
- package/dist/targets/typescript/index.d.ts +7 -0
- package/dist/targets/typescript/index.js +52 -0
- package/dist/targets/typescript/mock-compatibility.d.ts +4 -0
- package/dist/targets/typescript/mock-compatibility.js +6 -0
- package/dist/targets/typescript/mock-hints.d.ts +13 -0
- package/dist/targets/typescript/mock-hints.js +75 -0
- package/dist/targets/typescript/mock-reachability.d.ts +12 -0
- package/dist/targets/typescript/mock-reachability.js +87 -0
- package/dist/targets/typescript/model-compatibility.d.ts +14 -0
- package/dist/targets/typescript/model-compatibility.js +16 -0
- package/dist/targets/typescript/naming.d.ts +13 -0
- package/dist/targets/typescript/naming.js +50 -0
- package/dist/targets/typescript/options.d.ts +124 -0
- package/dist/targets/typescript/options.js +90 -0
- package/dist/targets/typescript/outputs/client.d.ts +67 -0
- package/dist/targets/typescript/outputs/client.js +187 -0
- package/dist/targets/typescript/outputs/mocks.d.ts +32 -0
- package/dist/targets/typescript/outputs/mocks.js +371 -0
- package/dist/targets/typescript/outputs/models.d.ts +85 -0
- package/dist/targets/typescript/outputs/models.js +246 -0
- package/dist/targets/typescript/outputs/rtk-query.d.ts +69 -0
- package/dist/targets/typescript/outputs/rtk-query.js +266 -0
- package/dist/targets/typescript/prettier.d.ts +7 -0
- package/dist/targets/typescript/prettier.js +44 -0
- package/dist/targets/typescript/templates/client/client.liquid +30 -0
- package/dist/targets/typescript/templates/client/partials/api-member.liquid +13 -0
- package/dist/targets/typescript/templates/client/partials/jsdoc.liquid +10 -0
- package/dist/targets/typescript/templates/client/partials/method.liquid +26 -0
- package/dist/targets/typescript/templates/client/partials/query-type.liquid +10 -0
- package/dist/targets/typescript/templates/client/resource.liquid +34 -0
- package/dist/targets/typescript/templates/mocks/mock.liquid +15 -0
- package/dist/targets/typescript/templates/mocks/partials/factory.liquid +12 -0
- package/dist/targets/typescript/templates/mocks/partials/imports.liquid +7 -0
- package/dist/targets/typescript/templates/models/alias.liquid +16 -0
- package/dist/targets/typescript/templates/models/enum.liquid +27 -0
- package/dist/targets/typescript/templates/models/index.liquid +14 -0
- package/dist/targets/typescript/templates/models/model.liquid +25 -0
- package/dist/targets/typescript/templates/models/partials/const.liquid +10 -0
- package/dist/targets/typescript/templates/models/partials/imports.liquid +9 -0
- package/dist/targets/typescript/templates/models/partials/jsdoc.liquid +9 -0
- package/dist/targets/typescript/templates/models/partials/property.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/api.liquid +16 -0
- package/dist/targets/typescript/templates/rtk-query/partials/arg-types.liquid +6 -0
- package/dist/targets/typescript/templates/rtk-query/partials/endpoint-mutation.liquid +13 -0
- package/dist/targets/typescript/templates/rtk-query/partials/endpoint-query.liquid +13 -0
- package/dist/targets/typescript/templates/rtk-query/partials/file-warning.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/partials/hooks.liquid +9 -0
- package/dist/targets/typescript/templates/rtk-query/partials/imports.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/partials/request-config.liquid +9 -0
- package/dist/targets/typescript/templates/rtk-query/resource.liquid +40 -0
- package/dist/targets/typescript/ts-type.d.ts +70 -0
- package/dist/targets/typescript/ts-type.js +62 -0
- package/dist/targets/typescript/type-printer.d.ts +21 -0
- package/dist/targets/typescript/type-printer.js +115 -0
- package/dist/templates/engine.d.ts +20 -0
- package/dist/templates/engine.js +161 -0
- package/dist/templates/inspect.d.ts +27 -0
- package/dist/templates/inspect.js +331 -0
- package/package.json +65 -4
- package/schema/sdk-gen.local.schema.json +75 -0
- package/schema/sdk-gen.schema.json +980 -0
- package/schema/sdk-gen.target.schema.json +1384 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.TARGET_CONFIG_JS = exports.TARGET_JSON = exports.targetConfigSchema = exports.RESOURCE_GROUPINGS = exports.optionSpecSchema = exports.fileRuleSchema = exports.SPELLED_ELEMENTS = exports.stringLiteralSchema = exports.IMPORT_SKIPS = exports.TYPE_KEYS = exports.spellingSchema = exports.importSpecSchema = exports.NAMING_KINDS = exports.namingRuleSchema = exports.CASE_NAMES = void 0;
|
|
46
|
+
exports.isDeclarativeTargetDir = isDeclarativeTargetDir;
|
|
47
|
+
exports.loadTargetDefinition = loadTargetDefinition;
|
|
48
|
+
exports.parseTargetConfig = parseTargetConfig;
|
|
49
|
+
exports.targetConfigJsonSchema = targetConfigJsonSchema;
|
|
50
|
+
const naming_1 = require("../../ir/operations/naming");
|
|
51
|
+
const fs = __importStar(require("fs"));
|
|
52
|
+
const path = __importStar(require("path"));
|
|
53
|
+
const zod_1 = require("zod");
|
|
54
|
+
const deep_merge_1 = require("../../core/deep-merge");
|
|
55
|
+
const import_module_1 = require("../../core/import-module");
|
|
56
|
+
const option_errors_1 = require("../../ir/option-errors");
|
|
57
|
+
const extensions_1 = require("./extensions");
|
|
58
|
+
exports.CASE_NAMES = ['pascal', 'camel', 'snake', 'upper_snake', 'kebab', 'preserve'];
|
|
59
|
+
const caseSpec = zod_1.z.union([
|
|
60
|
+
zod_1.z.string().describe('A case name (pascal | camel | snake | upper_snake | kebab | preserve) or a liquid template over `name`'),
|
|
61
|
+
zod_1.z.object({ option: zod_1.z.string(), default: zod_1.z.enum(exports.CASE_NAMES).optional() }).strict().describe('Case taken from an output option'),
|
|
62
|
+
]);
|
|
63
|
+
exports.namingRuleSchema = zod_1.z.union([
|
|
64
|
+
zod_1.z.string(),
|
|
65
|
+
zod_1.z
|
|
66
|
+
.object({
|
|
67
|
+
case: caseSpec.optional(),
|
|
68
|
+
fallbackCase: zod_1.z.enum(exports.CASE_NAMES).optional(),
|
|
69
|
+
empty: zod_1.z.string().optional(),
|
|
70
|
+
identifier: zod_1.z.union([zod_1.z.string(), zod_1.z.boolean()]).optional(),
|
|
71
|
+
invalid: zod_1.z.string().optional(),
|
|
72
|
+
reserved: zod_1.z.array(zod_1.z.string()).optional(),
|
|
73
|
+
escape: zod_1.z.string().optional(),
|
|
74
|
+
after: zod_1.z.string().optional(),
|
|
75
|
+
avoid: zod_1.z.array(zod_1.z.string()).optional(),
|
|
76
|
+
unique: zod_1.z.boolean().optional(),
|
|
77
|
+
qualify: zod_1.z.literal('namespace').optional(),
|
|
78
|
+
numeric: zod_1.z.string().optional(),
|
|
79
|
+
null: zod_1.z.string().optional(),
|
|
80
|
+
})
|
|
81
|
+
.strict(),
|
|
82
|
+
]);
|
|
83
|
+
exports.NAMING_KINDS = ['type', 'property', 'enumKey', 'file', 'operation', 'param', 'resource', 'namespace'];
|
|
84
|
+
const namingSchema = zod_1.z
|
|
85
|
+
.object({
|
|
86
|
+
type: exports.namingRuleSchema.optional(),
|
|
87
|
+
property: exports.namingRuleSchema.optional(),
|
|
88
|
+
enumKey: exports.namingRuleSchema.optional(),
|
|
89
|
+
file: exports.namingRuleSchema.optional(),
|
|
90
|
+
operation: exports.namingRuleSchema.optional(),
|
|
91
|
+
param: exports.namingRuleSchema.optional(),
|
|
92
|
+
resource: exports.namingRuleSchema.optional(),
|
|
93
|
+
namespace: exports.namingRuleSchema.optional(),
|
|
94
|
+
reserved: zod_1.z.array(zod_1.z.string()).optional(),
|
|
95
|
+
escape: zod_1.z.string().optional(),
|
|
96
|
+
identifier: zod_1.z.string().optional(),
|
|
97
|
+
invalid: zod_1.z.string().optional(),
|
|
98
|
+
})
|
|
99
|
+
.strict();
|
|
100
|
+
exports.importSpecSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.object({ module: zod_1.z.string(), name: zod_1.z.string().optional() }).strict()]);
|
|
101
|
+
const spellingObject = zod_1.z
|
|
102
|
+
.object({
|
|
103
|
+
type: zod_1.z.string(),
|
|
104
|
+
imports: zod_1.z.array(exports.importSpecSchema).optional(),
|
|
105
|
+
comment: zod_1.z.string().optional(),
|
|
106
|
+
})
|
|
107
|
+
.strict();
|
|
108
|
+
exports.spellingSchema = zod_1.z.union([
|
|
109
|
+
zod_1.z.string(),
|
|
110
|
+
spellingObject.extend({ position: zod_1.z.record(zod_1.z.string(), zod_1.z.union([zod_1.z.string(), spellingObject])).optional() }).strict(),
|
|
111
|
+
]);
|
|
112
|
+
exports.TYPE_KEYS = [
|
|
113
|
+
'string', 'integer', 'number', 'boolean', 'null', 'any', 'ref', 'ref:unresolved', 'array', 'map', 'object', 'object:free',
|
|
114
|
+
'enum', 'enum:inline', 'union', 'intersection', 'literal', 'nullable', 'optional', 'fallback',
|
|
115
|
+
];
|
|
116
|
+
const PRIMITIVES = ['string', 'integer', 'number', 'boolean', 'null'];
|
|
117
|
+
const typesSchema = zod_1.z.record(zod_1.z.string(), exports.spellingSchema).superRefine((types, ctx) => {
|
|
118
|
+
for (const key of Object.keys(types)) {
|
|
119
|
+
const [base] = key.split(':');
|
|
120
|
+
const ok = exports.TYPE_KEYS.includes(key) || (PRIMITIVES.includes(base) && key.split(':').length === 2);
|
|
121
|
+
if (!ok)
|
|
122
|
+
ctx.addIssue({ code: 'custom', path: [key], message: `Unknown type-map key "${key}" (known: ${exports.TYPE_KEYS.join(', ')}, or <primitive>:<format>)` });
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
exports.IMPORT_SKIPS = ['declared', 'sameNamespace', 'inlined'];
|
|
126
|
+
const importsSchema = zod_1.z
|
|
127
|
+
.object({
|
|
128
|
+
ref: exports.importSpecSchema.optional(),
|
|
129
|
+
skip: zod_1.z.array(zod_1.z.enum(exports.IMPORT_SKIPS)).optional(),
|
|
130
|
+
order: zod_1.z.union([zod_1.z.enum(['insertion', 'alphabetical']), zod_1.z.array(zod_1.z.string())]).optional(),
|
|
131
|
+
names: zod_1.z.enum(['insertion', 'alphabetical']).optional(),
|
|
132
|
+
group: zod_1.z.string().optional(),
|
|
133
|
+
})
|
|
134
|
+
.strict();
|
|
135
|
+
exports.stringLiteralSchema = zod_1.z
|
|
136
|
+
.object({
|
|
137
|
+
quote: zod_1.z.string(),
|
|
138
|
+
close: zod_1.z.string().optional(),
|
|
139
|
+
escapes: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
|
|
140
|
+
})
|
|
141
|
+
.strict();
|
|
142
|
+
const literalsSchema = zod_1.z
|
|
143
|
+
.object({ null: zod_1.z.string(), true: zod_1.z.string(), false: zod_1.z.string(), string: zod_1.z.union([zod_1.z.string(), exports.stringLiteralSchema]), number: zod_1.z.string() })
|
|
144
|
+
.partial()
|
|
145
|
+
.strict();
|
|
146
|
+
exports.SPELLED_ELEMENTS = ['property', 'alias', 'param', 'body', 'response'];
|
|
147
|
+
const positionSchema = zod_1.z
|
|
148
|
+
.object({
|
|
149
|
+
inherits: zod_1.z.string().optional(),
|
|
150
|
+
spells: zod_1.z.array(zod_1.z.enum(exports.SPELLED_ELEMENTS)).optional(),
|
|
151
|
+
})
|
|
152
|
+
.strict();
|
|
153
|
+
const scalar = zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean(), zod_1.z.null()]);
|
|
154
|
+
exports.fileRuleSchema = zod_1.z
|
|
155
|
+
.object({
|
|
156
|
+
each: zod_1.z.enum(['model', 'resource']).optional(),
|
|
157
|
+
once: zod_1.z.boolean().optional(),
|
|
158
|
+
where: zod_1.z.record(zod_1.z.string(), zod_1.z.union([scalar, zod_1.z.array(scalar)])).optional(),
|
|
159
|
+
template: zod_1.z.string(),
|
|
160
|
+
path: zod_1.z.string(),
|
|
161
|
+
order: zod_1.z.enum(['declaration', 'dependencies']).optional(),
|
|
162
|
+
contents: zod_1.z.array(zod_1.z.enum(['models', 'resources'])).optional(),
|
|
163
|
+
format: zod_1.z.boolean().optional(),
|
|
164
|
+
})
|
|
165
|
+
.strict()
|
|
166
|
+
.refine((r) => Boolean(r.each) !== Boolean(r.once), { message: 'a file rule needs exactly one of `each` or `once: true`' });
|
|
167
|
+
exports.optionSpecSchema = zod_1.z
|
|
168
|
+
.object({
|
|
169
|
+
type: zod_1.z.enum(['string', 'number', 'boolean', 'array', 'object']),
|
|
170
|
+
default: zod_1.z.unknown().optional(),
|
|
171
|
+
enum: zod_1.z.array(scalar).optional(),
|
|
172
|
+
description: zod_1.z.string().optional(),
|
|
173
|
+
})
|
|
174
|
+
.strict();
|
|
175
|
+
const outputSchema = zod_1.z
|
|
176
|
+
.object({
|
|
177
|
+
description: zod_1.z.string().optional(),
|
|
178
|
+
files: zod_1.z.array(zod_1.z.union([zod_1.z.number().int().nonnegative(), exports.fileRuleSchema])).optional(),
|
|
179
|
+
options: zod_1.z.record(zod_1.z.string(), exports.optionSpecSchema).optional(),
|
|
180
|
+
})
|
|
181
|
+
.strict();
|
|
182
|
+
const formatSchema = zod_1.z
|
|
183
|
+
.object({
|
|
184
|
+
command: zod_1.z.string().optional(),
|
|
185
|
+
stdin: zod_1.z.boolean().optional(),
|
|
186
|
+
enabled: zod_1.z.boolean().optional(),
|
|
187
|
+
maxBlankLines: zod_1.z.number().int().nonnegative().optional(),
|
|
188
|
+
})
|
|
189
|
+
.strict();
|
|
190
|
+
exports.RESOURCE_GROUPINGS = ['path', 'tag', 'operationId'];
|
|
191
|
+
const resourcesSchema = zod_1.z
|
|
192
|
+
.object({
|
|
193
|
+
by: zod_1.z.enum(exports.RESOURCE_GROUPINGS).optional(),
|
|
194
|
+
stripPrefixes: zod_1.z.array(zod_1.z.string()).optional(),
|
|
195
|
+
folders: zod_1.z.boolean().optional(),
|
|
196
|
+
naming: zod_1.z.enum(naming_1.OPERATION_NAMING).optional(),
|
|
197
|
+
})
|
|
198
|
+
.strict();
|
|
199
|
+
exports.targetConfigSchema = zod_1.z
|
|
200
|
+
.object({
|
|
201
|
+
$schema: zod_1.z.string().optional(),
|
|
202
|
+
name: zod_1.z.string(),
|
|
203
|
+
extends: zod_1.z.string().optional(),
|
|
204
|
+
naming: namingSchema.optional(),
|
|
205
|
+
types: typesSchema.optional(),
|
|
206
|
+
positions: zod_1.z.record(zod_1.z.string(), positionSchema).optional(),
|
|
207
|
+
aliases: zod_1.z.enum(['reference', 'inline']).optional(),
|
|
208
|
+
literals: literalsSchema.optional(),
|
|
209
|
+
imports: importsSchema.optional(),
|
|
210
|
+
files: zod_1.z.array(exports.fileRuleSchema).optional(),
|
|
211
|
+
outputs: zod_1.z.record(zod_1.z.string(), outputSchema),
|
|
212
|
+
resources: resourcesSchema.optional(),
|
|
213
|
+
format: formatSchema.optional(),
|
|
214
|
+
transforms: zod_1.z.record(zod_1.z.string(), zod_1.z.union([zod_1.z.boolean(), zod_1.z.record(zod_1.z.string(), zod_1.z.unknown())])).optional(),
|
|
215
|
+
extensions: zod_1.z.string().optional(),
|
|
216
|
+
})
|
|
217
|
+
.strict();
|
|
218
|
+
exports.TARGET_JSON = 'target.json';
|
|
219
|
+
exports.TARGET_CONFIG_JS = 'target.config.js';
|
|
220
|
+
const DEFAULT_EXTENSIONS = 'extensions.js';
|
|
221
|
+
function isDeclarativeTargetDir(dir) {
|
|
222
|
+
return fs.existsSync(path.join(dir, exports.TARGET_JSON)) || fs.existsSync(path.join(dir, exports.TARGET_CONFIG_JS));
|
|
223
|
+
}
|
|
224
|
+
function loadTargetDefinition(dir_1) {
|
|
225
|
+
return __awaiter(this, arguments, void 0, function* (dir, seen = []) {
|
|
226
|
+
var _a;
|
|
227
|
+
const abs = path.resolve(dir);
|
|
228
|
+
if (seen.includes(abs))
|
|
229
|
+
throw new Error(`Config target "extends" cycle: ${[...seen, abs].join(' → ')}`);
|
|
230
|
+
const { data, inlineExtensions, file } = yield readRawConfig(abs);
|
|
231
|
+
let parent;
|
|
232
|
+
if (typeof data.extends === 'string')
|
|
233
|
+
parent = yield loadTargetDefinition(path.resolve(abs, data.extends), [...seen, abs]);
|
|
234
|
+
const merged = parent ? (0, deep_merge_1.deepMerge)(parent.config, data) : data;
|
|
235
|
+
const config = parseTargetConfig(merged, file);
|
|
236
|
+
const extensionsPath = typeof data.extensions === 'string' ? path.resolve(abs, data.extensions) : path.join(abs, DEFAULT_EXTENSIONS);
|
|
237
|
+
if (typeof data.extensions === 'string' && !fs.existsSync(extensionsPath)) {
|
|
238
|
+
throw new Error(`${file}: extensions file not found: ${data.extensions}`);
|
|
239
|
+
}
|
|
240
|
+
const own = (0, extensions_1.mergeExtensions)(fs.existsSync(extensionsPath) ? yield (0, extensions_1.loadExtensionsFile)(extensionsPath) : {}, inlineExtensions);
|
|
241
|
+
const extensions = parent ? (0, extensions_1.mergeExtensions)(parent.extensions, own) : own;
|
|
242
|
+
const templates = path.join(abs, 'templates');
|
|
243
|
+
return { dir: abs, config, extensions, templateDirs: [templates, ...((_a = parent === null || parent === void 0 ? void 0 : parent.templateDirs) !== null && _a !== void 0 ? _a : [])] };
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
function parseTargetConfig(data, file = exports.TARGET_JSON) {
|
|
247
|
+
const result = exports.targetConfigSchema.safeParse(data);
|
|
248
|
+
if (!result.success)
|
|
249
|
+
throw new Error(`Invalid config target ${file}:\n${(0, option_errors_1.formatOptionsError)(exports.targetConfigSchema, result.error, data)}`);
|
|
250
|
+
return result.data;
|
|
251
|
+
}
|
|
252
|
+
function targetConfigJsonSchema() {
|
|
253
|
+
return zod_1.z.toJSONSchema(exports.targetConfigSchema, { io: 'input', unrepresentable: 'any' });
|
|
254
|
+
}
|
|
255
|
+
function readRawConfig(dir) {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
const js = path.join(dir, exports.TARGET_CONFIG_JS);
|
|
258
|
+
if (fs.existsSync(js)) {
|
|
259
|
+
const mod = (yield (0, import_module_1.importModule)(js));
|
|
260
|
+
const exported = mod && typeof mod === 'object' && 'default' in mod && (0, deep_merge_1.isPlainObject)(mod.default) ? mod.default : mod;
|
|
261
|
+
if (!(0, deep_merge_1.isPlainObject)(exported))
|
|
262
|
+
throw new Error(`${js}: must export a config object`);
|
|
263
|
+
const { data, functions } = (0, extensions_1.splitFunctions)(exported);
|
|
264
|
+
return { data, inlineExtensions: functions, file: js };
|
|
265
|
+
}
|
|
266
|
+
const json = path.join(dir, exports.TARGET_JSON);
|
|
267
|
+
if (!fs.existsSync(json))
|
|
268
|
+
throw new Error(`No ${exports.TARGET_JSON} or ${exports.TARGET_CONFIG_JS} in ${dir}`);
|
|
269
|
+
let data;
|
|
270
|
+
try {
|
|
271
|
+
data = JSON.parse(fs.readFileSync(json, 'utf8'));
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
throw new Error(`${json}: ${error.message}`);
|
|
275
|
+
}
|
|
276
|
+
if (!(0, deep_merge_1.isPlainObject)(data))
|
|
277
|
+
throw new Error(`${json}: must contain a JSON object`);
|
|
278
|
+
return { data, inlineExtensions: {}, file: json };
|
|
279
|
+
});
|
|
280
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Logger } from '../../core/log';
|
|
2
|
+
import type { PipelineHooks, TemplateFilter } from '../../core/plugin';
|
|
3
|
+
import type { ApiSpec, EnumValue, TypeNode } from '../../ir/types';
|
|
4
|
+
import type { ImportSpec, NamingKind, NamingRuleInput } from './config';
|
|
5
|
+
export type Position = string;
|
|
6
|
+
export interface ExtensionContext {
|
|
7
|
+
api: ApiSpec;
|
|
8
|
+
options: Record<string, unknown>;
|
|
9
|
+
naming(kind: NamingKind, raw: string): string;
|
|
10
|
+
spell(node: TypeNode, position?: Position): string;
|
|
11
|
+
imports: {
|
|
12
|
+
add(spec: ImportSpec): void;
|
|
13
|
+
};
|
|
14
|
+
log: Logger;
|
|
15
|
+
}
|
|
16
|
+
export interface NamingExtensionContext extends ExtensionContext {
|
|
17
|
+
kind: NamingKind;
|
|
18
|
+
value?: EnumValue;
|
|
19
|
+
apply(raw: string, override?: Exclude<NamingRuleInput, string>): string;
|
|
20
|
+
}
|
|
21
|
+
export interface TypeExtensionContext extends ExtensionContext {
|
|
22
|
+
position: Position;
|
|
23
|
+
type?: string;
|
|
24
|
+
key: string;
|
|
25
|
+
}
|
|
26
|
+
export type ComputedFn = (view: any, ctx: ExtensionContext) => unknown;
|
|
27
|
+
export type ViewKind = 'model' | 'property' | 'resource' | 'operation' | 'file';
|
|
28
|
+
export interface TargetExtensions {
|
|
29
|
+
filters?: Record<string, TemplateFilter>;
|
|
30
|
+
computed?: Partial<Record<ViewKind, Record<string, ComputedFn>>>;
|
|
31
|
+
naming?: Partial<Record<NamingKind, (raw: string, fallback: string, ctx: NamingExtensionContext) => string>>;
|
|
32
|
+
types?: Record<string, (node: TypeNode, ctx: TypeExtensionContext, fallback: string) => string>;
|
|
33
|
+
files?: (plan: any[], ctx: ExtensionContext) => any[];
|
|
34
|
+
imports?: {
|
|
35
|
+
ref?: (model: Record<string, unknown>, ctx: ExtensionContext, fallback: ImportSpec | null) => ImportSpec | null | undefined;
|
|
36
|
+
};
|
|
37
|
+
order?: (models: any[], ctx: ExtensionContext) => any[];
|
|
38
|
+
hooks?: PipelineHooks;
|
|
39
|
+
}
|
|
40
|
+
export declare function loadExtensionsFile(file: string): Promise<TargetExtensions>;
|
|
41
|
+
export declare function mergeExtensions(parent: TargetExtensions, child: TargetExtensions): TargetExtensions;
|
|
42
|
+
export declare function splitFunctions(input: Record<string, unknown>): {
|
|
43
|
+
data: Record<string, unknown>;
|
|
44
|
+
functions: TargetExtensions;
|
|
45
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadExtensionsFile = loadExtensionsFile;
|
|
13
|
+
exports.mergeExtensions = mergeExtensions;
|
|
14
|
+
exports.splitFunctions = splitFunctions;
|
|
15
|
+
const deep_merge_1 = require("../../core/deep-merge");
|
|
16
|
+
const import_module_1 = require("../../core/import-module");
|
|
17
|
+
const SECTIONS = ['filters', 'computed', 'naming', 'types', 'files', 'order', 'hooks', 'imports'];
|
|
18
|
+
function loadExtensionsFile(file) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const mod = (yield (0, import_module_1.importModule)(file));
|
|
21
|
+
const exported = (0, deep_merge_1.isPlainObject)(mod.default) && !SECTIONS.some((k) => k in mod) ? mod.default : mod;
|
|
22
|
+
if (!exported || typeof exported !== 'object')
|
|
23
|
+
throw new Error(`${file}: must export an object`);
|
|
24
|
+
const unknown = Object.keys(exported).filter((k) => k !== 'default' && k !== '__esModule' && !SECTIONS.includes(k));
|
|
25
|
+
if (unknown.length)
|
|
26
|
+
throw new Error(`${file}: unknown extension section(s) ${unknown.join(', ')} (known: ${SECTIONS.join(', ')})`);
|
|
27
|
+
return exported;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function mergeExtensions(parent, child) {
|
|
31
|
+
var _a, _b, _c, _d, _e;
|
|
32
|
+
var _f;
|
|
33
|
+
const out = Object.assign({}, parent);
|
|
34
|
+
if (child.filters)
|
|
35
|
+
out.filters = Object.assign(Object.assign({}, parent.filters), child.filters);
|
|
36
|
+
if (child.computed) {
|
|
37
|
+
out.computed = Object.assign({}, parent.computed);
|
|
38
|
+
for (const [kind, fns] of Object.entries(child.computed)) {
|
|
39
|
+
out.computed[kind] = Object.assign(Object.assign({}, (_a = parent.computed) === null || _a === void 0 ? void 0 : _a[kind]), fns);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (child.naming) {
|
|
43
|
+
out.naming = Object.assign({}, parent.naming);
|
|
44
|
+
for (const [kind, fn] of Object.entries(child.naming)) {
|
|
45
|
+
const base = (_b = parent.naming) === null || _b === void 0 ? void 0 : _b[kind];
|
|
46
|
+
out.naming[kind] = base ? (raw, fallback, ctx) => fn(raw, base(raw, fallback, ctx), ctx) : fn;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (child.types) {
|
|
50
|
+
out.types = Object.assign({}, parent.types);
|
|
51
|
+
for (const [key, fn] of Object.entries(child.types)) {
|
|
52
|
+
const base = (_c = parent.types) === null || _c === void 0 ? void 0 : _c[key];
|
|
53
|
+
out.types[key] = base ? (node, ctx, fallback) => fn(node, ctx, base(node, ctx, fallback)) : fn;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if ((_d = child.imports) === null || _d === void 0 ? void 0 : _d.ref) {
|
|
57
|
+
const base = (_e = parent.imports) === null || _e === void 0 ? void 0 : _e.ref;
|
|
58
|
+
const fn = child.imports.ref;
|
|
59
|
+
out.imports = { ref: base ? (model, ctx, fallback) => { var _a; return fn(model, ctx, (_a = base(model, ctx, fallback)) !== null && _a !== void 0 ? _a : null); } : fn };
|
|
60
|
+
}
|
|
61
|
+
if (child.files)
|
|
62
|
+
out.files = parent.files ? (plan, ctx) => child.files(parent.files(plan, ctx), ctx) : child.files;
|
|
63
|
+
if (child.order)
|
|
64
|
+
out.order = parent.order ? (models, ctx) => child.order(parent.order(models, ctx), ctx) : child.order;
|
|
65
|
+
if (child.hooks) {
|
|
66
|
+
const p = (_f = parent.hooks) !== null && _f !== void 0 ? _f : {};
|
|
67
|
+
const c = child.hooks;
|
|
68
|
+
out.hooks = Object.assign(Object.assign(Object.assign({}, (p.ir || c.ir ? { ir: (api) => chain(api, p.ir, c.ir) } : {})), (p.view || c.view ? { view: (file, view) => chain(view, p.view && ((v) => p.view(file, v)), c.view && ((v) => c.view(file, v))) } : {})), (p.file || c.file ? { file: (file) => chain(file, p.file, c.file && ((f) => c.file(Object.assign(Object.assign({}, f), { output: file.output })))) } : {}));
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
function chain(value, ...fns) {
|
|
73
|
+
var _a;
|
|
74
|
+
let current = value;
|
|
75
|
+
for (const fn of fns)
|
|
76
|
+
if (fn)
|
|
77
|
+
current = (_a = fn(current)) !== null && _a !== void 0 ? _a : current;
|
|
78
|
+
return current;
|
|
79
|
+
}
|
|
80
|
+
function splitFunctions(input) {
|
|
81
|
+
var _a;
|
|
82
|
+
const functions = {};
|
|
83
|
+
const put = (at, fn) => {
|
|
84
|
+
var _a;
|
|
85
|
+
const pathParts = at[0] === 'extensions' ? at.slice(1) : at;
|
|
86
|
+
let node = functions;
|
|
87
|
+
for (const part of pathParts.slice(0, -1))
|
|
88
|
+
node = ((_a = node[part]) !== null && _a !== void 0 ? _a : (node[part] = {}));
|
|
89
|
+
node[pathParts[pathParts.length - 1]] = fn;
|
|
90
|
+
};
|
|
91
|
+
const walk = (value, at) => {
|
|
92
|
+
const out = {};
|
|
93
|
+
let removed = false;
|
|
94
|
+
for (const [key, v] of Object.entries(value)) {
|
|
95
|
+
if (typeof v === 'function') {
|
|
96
|
+
put([...at, key], v);
|
|
97
|
+
removed = true;
|
|
98
|
+
}
|
|
99
|
+
else if ((0, deep_merge_1.isPlainObject)(v)) {
|
|
100
|
+
const inner = walk(v, [...at, key]);
|
|
101
|
+
if (inner)
|
|
102
|
+
out[key] = inner;
|
|
103
|
+
else
|
|
104
|
+
removed = true;
|
|
105
|
+
}
|
|
106
|
+
else
|
|
107
|
+
out[key] = v;
|
|
108
|
+
}
|
|
109
|
+
return removed && Object.keys(out).length === 0 ? undefined : out;
|
|
110
|
+
};
|
|
111
|
+
const data = (_a = walk(input, [])) !== null && _a !== void 0 ? _a : {};
|
|
112
|
+
for (const section of ['filters', 'computed', 'hooks', 'order']) {
|
|
113
|
+
if (section in data) {
|
|
114
|
+
put([section], data[section]);
|
|
115
|
+
delete data[section];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if ((0, deep_merge_1.isPlainObject)(data.extensions)) {
|
|
119
|
+
Object.assign(functions, mergeExtensions(functions, data.extensions));
|
|
120
|
+
delete data.extensions;
|
|
121
|
+
}
|
|
122
|
+
return { data, functions: functions };
|
|
123
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ResourceGroup } from '../../ir/operations/grouping';
|
|
2
|
+
import type { Model } from '../../ir/types';
|
|
3
|
+
import type { FileRule, TargetConfig } from './config';
|
|
4
|
+
import { type Env, type FileView } from './views';
|
|
5
|
+
export interface PlannedFile {
|
|
6
|
+
rule: FileRule;
|
|
7
|
+
path: string;
|
|
8
|
+
model?: Model;
|
|
9
|
+
resource?: ResourceGroup;
|
|
10
|
+
}
|
|
11
|
+
export declare function outputRules(config: TargetConfig, output: string): FileRule[];
|
|
12
|
+
export declare function planFiles(env: Env, rules: FileRule[]): PlannedFile[];
|
|
13
|
+
export declare function buildFileView(env: Env, entry: PlannedFile): FileView;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.outputRules = outputRules;
|
|
4
|
+
exports.planFiles = planFiles;
|
|
5
|
+
exports.buildFileView = buildFileView;
|
|
6
|
+
const views_1 = require("./views");
|
|
7
|
+
function outputRules(config, output) {
|
|
8
|
+
var _a;
|
|
9
|
+
const def = config.outputs[output];
|
|
10
|
+
const top = (_a = config.files) !== null && _a !== void 0 ? _a : [];
|
|
11
|
+
if (!def.files)
|
|
12
|
+
return top;
|
|
13
|
+
return def.files.map((entry) => {
|
|
14
|
+
if (typeof entry !== 'number')
|
|
15
|
+
return entry;
|
|
16
|
+
if (!top[entry])
|
|
17
|
+
throw new Error(`outputs.${output}.files: no top-level file rule #${entry} (have ${top.length})`);
|
|
18
|
+
return top[entry];
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function planFiles(env, rules) {
|
|
22
|
+
const plan = [];
|
|
23
|
+
const names = rules.some((r) => r.each === 'resource') ? (0, views_1.resourceNames)(env) : undefined;
|
|
24
|
+
for (const rule of rules) {
|
|
25
|
+
if (rule.once) {
|
|
26
|
+
plan.push({ rule, path: renderPath(env, rule, {}) });
|
|
27
|
+
}
|
|
28
|
+
else if (rule.each === 'model') {
|
|
29
|
+
for (const model of env.api.models) {
|
|
30
|
+
const data = modelPathData(env, model);
|
|
31
|
+
if (matches(rule.where, data))
|
|
32
|
+
plan.push({ rule, model, path: renderPath(env, rule, Object.assign(Object.assign({}, data), { model: data })) });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
for (const group of env.resources()) {
|
|
37
|
+
const data = { name: names.get(group), wireName: group.resource, folder: group.folder, key: group.key };
|
|
38
|
+
if (matches(rule.where, data))
|
|
39
|
+
plan.push({ rule, resource: group, path: renderPath(env, rule, Object.assign(Object.assign({}, data), { resource: data })) });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return env.extensions.files ? env.extensions.files(plan, env.context()) : plan;
|
|
44
|
+
}
|
|
45
|
+
function buildFileView(env, entry) {
|
|
46
|
+
var _a;
|
|
47
|
+
const { rule } = entry;
|
|
48
|
+
let models = [];
|
|
49
|
+
if (entry.model)
|
|
50
|
+
models = [entry.model];
|
|
51
|
+
else if (rule.once) {
|
|
52
|
+
models = (rule.order === 'dependencies' ? env.dependencyOrder() : env.api.models).filter((m) => matches(rule.where, modelPathData(env, m)));
|
|
53
|
+
if (env.extensions.order)
|
|
54
|
+
models = env.extensions.order(models, env.context());
|
|
55
|
+
}
|
|
56
|
+
const scope = (0, views_1.createScope)(env, models.map((m) => m.id), (_a = entry.model) === null || _a === void 0 ? void 0 : _a.namespace);
|
|
57
|
+
return (0, views_1.inScope)(env, scope, () => {
|
|
58
|
+
var _a;
|
|
59
|
+
const view = {
|
|
60
|
+
file: { path: entry.path, dir: entry.path.includes('/') ? entry.path.slice(0, entry.path.lastIndexOf('/')) : '' },
|
|
61
|
+
imports: [],
|
|
62
|
+
options: env.options,
|
|
63
|
+
target: { name: env.config.name, naming: env.config.naming },
|
|
64
|
+
api: lazyApi(env),
|
|
65
|
+
computed: {},
|
|
66
|
+
};
|
|
67
|
+
if (entry.model)
|
|
68
|
+
view.model = (0, views_1.buildModelView)(env, entry.model);
|
|
69
|
+
else if (entry.resource)
|
|
70
|
+
view.resource = (0, views_1.buildResourceView)(env, entry.resource, (0, views_1.resourceNames)(env).get(entry.resource));
|
|
71
|
+
else {
|
|
72
|
+
const contents = (_a = rule.contents) !== null && _a !== void 0 ? _a : ['models'];
|
|
73
|
+
if (contents.includes('models'))
|
|
74
|
+
view.models = models.map((m) => (0, views_1.buildModelView)(env, m));
|
|
75
|
+
if (contents.includes('resources')) {
|
|
76
|
+
const names = (0, views_1.resourceNames)(env);
|
|
77
|
+
view.resources = env.resources().map((g) => (0, views_1.buildResourceView)(env, g, names.get(g)));
|
|
78
|
+
}
|
|
79
|
+
const inFile = new Set(models.map((m) => m.id));
|
|
80
|
+
view.cycles = env.cycles().filter((c) => c.some((id) => inFile.has(id))).map((c) => c.map((id) => env.typeNames.get(id)));
|
|
81
|
+
}
|
|
82
|
+
(0, views_1.applyComputed)(env, 'file', view);
|
|
83
|
+
view.imports = scope.imports.render(env.config.imports, env.templates);
|
|
84
|
+
return view;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function lazyApi(env) {
|
|
88
|
+
let models;
|
|
89
|
+
let resources;
|
|
90
|
+
const throwaway = () => (0, views_1.createScope)(env, env.api.models.map((m) => m.id));
|
|
91
|
+
const api = { info: env.api.info };
|
|
92
|
+
Object.defineProperty(api, 'models', {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: () => (models !== null && models !== void 0 ? models : (models = (0, views_1.inScope)(env, throwaway(), () => env.api.models.map((m) => (0, views_1.buildModelView)(env, m))))),
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(api, 'resources', {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
get: () => (resources !== null && resources !== void 0 ? resources : (resources = (0, views_1.inScope)(env, throwaway(), () => {
|
|
99
|
+
const names = (0, views_1.resourceNames)(env);
|
|
100
|
+
return env.resources().map((g) => (0, views_1.buildResourceView)(env, g, names.get(g)));
|
|
101
|
+
}))),
|
|
102
|
+
});
|
|
103
|
+
return api;
|
|
104
|
+
}
|
|
105
|
+
function modelPathData(env, model) {
|
|
106
|
+
return {
|
|
107
|
+
name: env.typeNames.get(model.id),
|
|
108
|
+
wireName: model.name,
|
|
109
|
+
id: model.id,
|
|
110
|
+
namespace: env.namespace(model.namespace),
|
|
111
|
+
wireNamespace: model.namespace,
|
|
112
|
+
kind: (0, views_1.kindOf)(model),
|
|
113
|
+
cyclic: env.cyclic().has(model.id),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function renderPath(env, rule, data) {
|
|
117
|
+
const rendered = env.templates.render(rule.path, Object.assign(Object.assign({}, data), { options: env.options }));
|
|
118
|
+
return rendered.split('/').filter((seg) => seg !== '' && seg !== '.').join('/');
|
|
119
|
+
}
|
|
120
|
+
function matches(where, data) {
|
|
121
|
+
if (!where)
|
|
122
|
+
return true;
|
|
123
|
+
return Object.entries(where).every(([key, expected]) => {
|
|
124
|
+
const actual = key.split('.').reduce((v, k) => (v && typeof v === 'object' ? v[k] : undefined), data);
|
|
125
|
+
return Array.isArray(expected) ? expected.includes(actual) : actual === expected;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Formatter } from '../../core/plugin';
|
|
2
|
+
import type { TargetConfig } from './config';
|
|
3
|
+
export declare function createCommandFormatter(format: TargetConfig['format'], targetOptions: Record<string, unknown>, targetName: string): Formatter | undefined;
|
|
4
|
+
export declare function splitCommand(command: string): string[];
|