@dialecte/cli 0.1.0 → 0.2.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.
@@ -0,0 +1,115 @@
1
+ // src/lib/mutation/mutation.constants.ts
2
+ var IGNORER_ERROR_TEXT = "dialecte-error-text";
3
+ var IGNORER_EXHAUSTIVE_DEFAULT = "dialecte-exhaustive-default";
4
+ var ERROR_CLASS_NAME = /Error$/;
5
+ var ERROR_WORDING_PROPERTIES = /* @__PURE__ */ new Set([
6
+ "detail",
7
+ "message",
8
+ "reason"
9
+ ]);
10
+ var ASSERT_NEVER_NAME = "assertNever";
11
+ var ERROR_TEXT_REASON = "error wording: no output depends on the text of an error";
12
+ var EXHAUSTIVE_DEFAULT_REASON = "exhaustive default: the arm is unreachable while the switch covers every case";
13
+ var STRYKER_VALIDATION_SCHEMA = {
14
+ properties: {
15
+ dialecteMutation: {
16
+ type: "object",
17
+ additionalProperties: false,
18
+ properties: { errorFactories: { type: "array", items: { type: "string" } } }
19
+ }
20
+ }
21
+ };
22
+
23
+ // src/lib/mutation/ignorers.ts
24
+ function ignoreReason(params) {
25
+ return errorTextReason(params) ?? exhaustiveDefaultReason({ path: params.path });
26
+ }
27
+ function errorTextReason(params) {
28
+ const { path, errorFactories } = params;
29
+ if (!path.isStringLiteral() && !path.isTemplateLiteral()) return void 0;
30
+ const isWording = isThrownBare({ path }) || isErrorClassArgument({ path }) || isUnderWordingProperty({ path, errorFactories });
31
+ return isWording ? ERROR_TEXT_REASON : void 0;
32
+ }
33
+ function isThrownBare(params) {
34
+ return params.path.parent.type === "ThrowStatement";
35
+ }
36
+ function isErrorClassArgument(params) {
37
+ const { path } = params;
38
+ return path.listKey === "arguments" && isErrorClassConstruction({ node: path.parent });
39
+ }
40
+ function isErrorClassConstruction(params) {
41
+ const { node } = params;
42
+ return node.type === "NewExpression" && node.callee.type === "Identifier" && ERROR_CLASS_NAME.test(node.callee.name);
43
+ }
44
+ function isUnderWordingProperty(params) {
45
+ const { path, errorFactories } = params;
46
+ const property = path.findParent(
47
+ (ancestor) => ancestor.isObjectProperty() && ERROR_WORDING_PROPERTIES.has(propertyName(ancestor))
48
+ );
49
+ return property !== null && isInsideErrorConstruction({ path: property, errorFactories });
50
+ }
51
+ function propertyName(path) {
52
+ const { node } = path;
53
+ if (node.type !== "ObjectProperty" || node.computed) return "";
54
+ if (node.key.type === "Identifier") return node.key.name;
55
+ return node.key.type === "StringLiteral" ? node.key.value : "";
56
+ }
57
+ function isInsideErrorConstruction(params) {
58
+ const { path, errorFactories } = params;
59
+ return path.findParent((ancestor) => {
60
+ const { node } = ancestor;
61
+ if (node.type === "ThrowStatement") return true;
62
+ if (isErrorClassConstruction({ node })) return true;
63
+ return node.type === "CallExpression" && node.callee.type === "Identifier" && errorFactories.includes(node.callee.name);
64
+ }) !== null;
65
+ }
66
+ function exhaustiveDefaultReason(params) {
67
+ const { path } = params;
68
+ if (!path.isSwitchCase() || path.node.test !== null) return void 0;
69
+ let exhaustive = false;
70
+ path.traverse({
71
+ Function(inner) {
72
+ inner.skip();
73
+ },
74
+ SwitchStatement(inner) {
75
+ inner.skip();
76
+ },
77
+ TSSatisfiesExpression(inner) {
78
+ if (inner.node.typeAnnotation.type === "TSNeverKeyword") {
79
+ exhaustive = true;
80
+ inner.stop();
81
+ }
82
+ },
83
+ CallExpression(inner) {
84
+ const { callee } = inner.node;
85
+ if (callee.type === "Identifier" && callee.name === ASSERT_NEVER_NAME) {
86
+ exhaustive = true;
87
+ inner.stop();
88
+ }
89
+ }
90
+ });
91
+ return exhaustive ? EXHAUSTIVE_DEFAULT_REASON : void 0;
92
+ }
93
+ function ignorerPlugin(params) {
94
+ const { name, reasonOf } = params;
95
+ const factory = Object.assign(
96
+ function createIgnorer(options) {
97
+ const errorFactories = options.dialecteMutation?.errorFactories ?? [];
98
+ return {
99
+ shouldIgnore: (path) => reasonOf({ path, errorFactories })
100
+ };
101
+ },
102
+ { inject: ["options"] }
103
+ );
104
+ return { kind: "Ignore", name, factory };
105
+ }
106
+ var strykerPlugins = [
107
+ ignorerPlugin({ name: IGNORER_ERROR_TEXT, reasonOf: errorTextReason }),
108
+ ignorerPlugin({ name: IGNORER_EXHAUSTIVE_DEFAULT, reasonOf: exhaustiveDefaultReason })
109
+ ];
110
+ var strykerValidationSchema = STRYKER_VALIDATION_SCHEMA;
111
+ export {
112
+ ignoreReason,
113
+ strykerPlugins,
114
+ strykerValidationSchema
115
+ };
@@ -0,0 +1,187 @@
1
+ import { AnyDialecteConfig } from '@dialecte/core';
2
+ import { resolveDefinition, getAttributeRules, enumeratedValues, valuePatterns, admittedXsiTypes, childOccurrences, orderByConfigSequence } from '@dialecte/core/utils';
3
+
4
+ /** The roots a method hangs from: a read on `q` (`doc.query`), a write on `tx`, the document, the project. */
5
+ declare const ROOTS: readonly ["q", "tx", "doc", "project"];
6
+
7
+ /** The root a method hangs from: a read on `doc.query`, a write on `tx`, the document or the project. */
8
+ type MethodRoot = (typeof ROOTS)[number];
9
+ /**
10
+ * One method of a package as `api.json` ships it: what `dialecte api find` and `api show` read. A method of a
11
+ * root or a function a package entry exports: `root` tells them apart, and only an export has an `entry`.
12
+ */
13
+ type ApiMethod = ApiRootMethod | ApiExportedFunction;
14
+ /** A method reached from a root (`q`, `tx`, `doc`, `project`). */
15
+ type ApiRootMethod = ApiMethodFields & {
16
+ root: MethodRoot;
17
+ entry?: undefined;
18
+ };
19
+ /** A function a package entry exports on its own (`@dialecte/core/sqlite.connectHub`). */
20
+ type ApiExportedFunction = ApiMethodFields & {
21
+ root: 'export';
22
+ /** The package entry the function comes from ('@dialecte/core/sqlite'). */
23
+ entry: string;
24
+ };
25
+ /** What every row of `api.json` holds, whatever its root. */
26
+ type ApiMethodFields = {
27
+ /** The canonical route, as a caller writes it: `doc.query.info.of`, `@dialecte/core/sqlite.connectHub`. */
28
+ path: string;
29
+ /** The same method reached from other roots. */
30
+ otherRoutes: string[];
31
+ /** As the type checker prints it, the bound query or transaction left out. */
32
+ signature: string;
33
+ summary: string | undefined;
34
+ intents: string[];
35
+ /** `src/<file>.ts:<line>`, relative to the package. */
36
+ declaredAt: string | undefined;
37
+ /** One call, from the JSDoc `@example` or from a test that calls the method. */
38
+ example: string | undefined;
39
+ };
40
+ /** `skills/<name>/references/api.json`: every public method a package defines. */
41
+ type ApiJson = {
42
+ package: string;
43
+ methods: ApiMethod[];
44
+ };
45
+
46
+ /** What a lookup command answers: the text it prints and its exit code (0 answer, 1 nothing found, 2 usage). */
47
+ type CommandOutput = {
48
+ output: string;
49
+ exitCode: 0 | 1 | 2;
50
+ };
51
+
52
+ declare function runApi(params: {
53
+ argv: readonly string[];
54
+ cwd: string;
55
+ }): CommandOutput;
56
+ declare function packagesText(indexes: readonly ApiJson[]): string;
57
+
58
+ declare function runDoctor(params: {
59
+ argv: readonly string[];
60
+ cwd: string;
61
+ dialecteRoot: string | undefined;
62
+ /** The cli's version, or how to read it: `--brief` reads it inside its guard, so a failure never shows. */
63
+ cliVersion: string | (() => string);
64
+ }): CommandOutput;
65
+
66
+ /** One public method of the q / tx / doc / project surface, with what its JSDoc says about it. */
67
+ type MethodEntry = {
68
+ /** `q.info.of`, `tx.addChild`, `project.open` */
69
+ path: string;
70
+ /** First paragraph of the JSDoc, on one line; undefined when the method has none. */
71
+ summary: string | undefined;
72
+ /** `@intent` tags, one entry per comma-separated phrase: what a caller is trying to do. */
73
+ intents: string[];
74
+ /** The call signature a caller sees (`(params: { id: string }) => string`), one line per overload. */
75
+ signature: string;
76
+ /** The first `@example` of the JSDoc, when it has one. */
77
+ example: string | undefined;
78
+ /** Declared in the package being inspected (not in a dependency such as core). */
79
+ definedInPackage: boolean;
80
+ /** Tagged `@internal`: public for TypeScript, not meant for callers (left out of the index). */
81
+ internal: boolean;
82
+ /** Where the method is declared (`file:position`): the same method reached by several routes shares it. */
83
+ declaredAt: string | undefined;
84
+ /** The package entry a standalone export comes from ('@dialecte/core/sqlite'); undefined for a route of q/tx/doc/project. */
85
+ entry?: string;
86
+ };
87
+
88
+ /** The method entries an expression is read from, or the answer that says why there are none. */
89
+ type MemberEntriesRead = {
90
+ kind: 'entries';
91
+ entries: MethodEntry[];
92
+ expression: string;
93
+ } | {
94
+ kind: 'output';
95
+ output: CommandOutput;
96
+ };
97
+
98
+ /** The method entries of the live types the expression is read from, or the answer that says why not. */
99
+ declare function readMemberEntries(params: {
100
+ argv: string[];
101
+ cwd: string;
102
+ }): MemberEntriesRead;
103
+
104
+ /** The answer, and the warning lines for stderr (an unknown or disagreeing vendor in the manifests). */
105
+ declare function runModels(params: {
106
+ argv: readonly string[];
107
+ cwd: string;
108
+ }): CommandOutput & {
109
+ warnings: string;
110
+ };
111
+
112
+ /**
113
+ * Core's own definition readers (`@dialecte/core/utils`), typed by the core the cli is built against (type-only
114
+ * imports: the cli loads at run time the core each dialecte resolves, and checks with `isCoreReaders` that it
115
+ * holds them). A dialecte on an older core may lack one: the runtime check reports which.
116
+ */
117
+ type CoreReaders = {
118
+ resolveDefinition: typeof resolveDefinition;
119
+ getAttributeRules: typeof getAttributeRules;
120
+ enumeratedValues: typeof enumeratedValues;
121
+ valuePatterns: typeof valuePatterns;
122
+ admittedXsiTypes: typeof admittedXsiTypes;
123
+ childOccurrences: typeof childOccurrences;
124
+ orderByConfigSequence: typeof orderByConfigSequence;
125
+ };
126
+ /** An installed dialecte, its config and the readers of the core it depends on. */
127
+ type LoadedDialecte = {
128
+ packageName: string;
129
+ config: AnyDialecteConfig;
130
+ readers: CoreReaders;
131
+ };
132
+ /** The dialectes found from a folder, and the packages built on core that could not be read, with why. */
133
+ type LoadedDialectes = {
134
+ dialectes: LoadedDialecte[];
135
+ skipped: {
136
+ packageName: string;
137
+ reason: string;
138
+ }[];
139
+ };
140
+
141
+ /** The dialectes a schema lookup reads, or the answer that says why there are none to read. */
142
+ type SchemaDialectesRead = {
143
+ kind: 'dialectes';
144
+ tagName: string;
145
+ /** Those the `--package` filter keeps. */
146
+ loaded: LoadedDialectes;
147
+ /** The package filter, when one was given. */
148
+ packageName: string | undefined;
149
+ /** Every dialecte installed, filter or not. */
150
+ installed: string[];
151
+ } | {
152
+ kind: 'output';
153
+ output: CommandOutput;
154
+ };
155
+
156
+ /** The dialectes (filtered by `--package`) the tag is looked up in, or the answer that says why not. */
157
+ declare function readSchemaDialectes(params: {
158
+ argv: string[];
159
+ cwd: string;
160
+ }): Promise<SchemaDialectesRead>;
161
+
162
+ declare function answerMembers(params: {
163
+ entries: readonly MethodEntry[];
164
+ expression: string;
165
+ json: boolean;
166
+ }): CommandOutput;
167
+
168
+ /**
169
+ * Every `api.json` an agent can search from `cwd`: the package's own skills (inside a dialecte repository)
170
+ * and the skills of its installed dependencies, one per package, sorted by package name.
171
+ */
172
+ declare function readApiIndexes(params: {
173
+ cwd: string;
174
+ }): ApiJson[];
175
+
176
+ /** The version of this cli: the nearest package.json above this file (dist/ in the bundle, src/lib/ in the sources). */
177
+ declare function readCliVersion(params?: {
178
+ startFolder?: string;
179
+ }): string;
180
+
181
+ declare function answerSchema(params: {
182
+ loaded: LoadedDialectes;
183
+ tagName: string;
184
+ json: boolean;
185
+ }): CommandOutput;
186
+
187
+ export { type ApiExportedFunction, type ApiJson, type ApiMethod, type ApiMethodFields, type ApiRootMethod, type CommandOutput, type MemberEntriesRead, type SchemaDialectesRead, answerMembers, answerSchema, packagesText, readApiIndexes, readCliVersion, readMemberEntries, readSchemaDialectes, runApi, runDoctor, runModels };