skir 1.0.1 → 1.0.4
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 +29 -409
- package/dist/command_line_parser.d.ts +3 -0
- package/dist/command_line_parser.d.ts.map +1 -1
- package/dist/command_line_parser.js +3 -0
- package/dist/command_line_parser.js.map +1 -1
- package/dist/compatibility_checker.d.ts.map +1 -1
- package/dist/compatibility_checker.js +17 -31
- package/dist/compatibility_checker.js.map +1 -1
- package/dist/compatibility_checker.test.js +67 -7
- package/dist/compatibility_checker.test.js.map +1 -1
- package/dist/compiler.js +6 -0
- package/dist/compiler.js.map +1 -1
- package/dist/config_parser.d.ts +1 -1
- package/dist/config_parser.js +1 -0
- package/dist/config_parser.js.map +1 -1
- package/dist/definition_finder.test.js +8 -8
- package/dist/definition_finder.test.js.map +1 -1
- package/dist/formatter.test.js +4 -4
- package/dist/formatter.test.js.map +1 -1
- package/dist/literals.js +2 -2
- package/dist/literals.test.js +9 -9
- package/dist/module_set.js +2 -2
- package/dist/module_set.test.js +9 -10
- package/dist/module_set.test.js.map +1 -1
- package/dist/parser.js +8 -15
- package/dist/parser.js.map +1 -1
- package/dist/parser.test.js +9 -13
- package/dist/parser.test.js.map +1 -1
- package/package.json +2 -2
- package/src/command_line_parser.ts +8 -0
- package/src/compatibility_checker.ts +16 -36
- package/src/compiler.ts +9 -0
- package/src/config_parser.ts +9 -7
- package/src/literals.ts +2 -2
- package/src/module_set.ts +2 -2
- package/src/parser.ts +9 -15
|
@@ -22,6 +22,10 @@ export type ParsedArgs =
|
|
|
22
22
|
kind: "help";
|
|
23
23
|
root?: undefined;
|
|
24
24
|
}
|
|
25
|
+
| {
|
|
26
|
+
kind: "version";
|
|
27
|
+
root?: undefined;
|
|
28
|
+
}
|
|
25
29
|
| {
|
|
26
30
|
kind: "error";
|
|
27
31
|
root?: undefined;
|
|
@@ -46,6 +50,10 @@ export function parseCommandLine(args: string[]): ParsedArgs {
|
|
|
46
50
|
return { kind: "help" };
|
|
47
51
|
}
|
|
48
52
|
|
|
53
|
+
if (command === "version" || command === "--version" || command === "-v") {
|
|
54
|
+
return { kind: "version" };
|
|
55
|
+
}
|
|
56
|
+
|
|
49
57
|
const validCommands = ["gen", "format", "snapshot", "init"];
|
|
50
58
|
if (!command || !validCommands.includes(command)) {
|
|
51
59
|
printError(`Unknown command: ${command}`);
|
|
@@ -108,20 +108,18 @@ class BackwardCompatibilityChecker {
|
|
|
108
108
|
check(): readonly BreakingChange[] {
|
|
109
109
|
for (const moduleBefore of this.moduleSet.before.resolvedModules) {
|
|
110
110
|
for (const methodBefore of moduleBefore.methods) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
});
|
|
124
|
-
}
|
|
111
|
+
const { number } = methodBefore;
|
|
112
|
+
const methodAfter = this.moduleSet.after.findMethodByNumber(number);
|
|
113
|
+
if (methodAfter === undefined) {
|
|
114
|
+
this.breakingChanges.push({
|
|
115
|
+
kind: "missing-method",
|
|
116
|
+
method: methodBefore,
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
this.checkMethod({
|
|
120
|
+
before: methodBefore,
|
|
121
|
+
after: methodAfter,
|
|
122
|
+
});
|
|
125
123
|
}
|
|
126
124
|
}
|
|
127
125
|
for (const recordBefore of moduleBefore.records) {
|
|
@@ -439,36 +437,18 @@ function primitiveTypesAreCompatible(type: BeforeAfter<Primitive>): boolean {
|
|
|
439
437
|
type.after === "bool" ||
|
|
440
438
|
type.after === "int32" ||
|
|
441
439
|
type.after === "int64" ||
|
|
442
|
-
type.after === "
|
|
443
|
-
type.after === "float32" ||
|
|
444
|
-
type.after === "float64"
|
|
440
|
+
type.after === "hash64"
|
|
445
441
|
);
|
|
446
442
|
case "int32":
|
|
447
|
-
return
|
|
448
|
-
type.after === "int32" ||
|
|
449
|
-
type.after === "int64" ||
|
|
450
|
-
type.after === "uint64" ||
|
|
451
|
-
type.after === "float32" ||
|
|
452
|
-
type.after === "float64"
|
|
453
|
-
);
|
|
454
|
-
case "int64":
|
|
455
|
-
return (
|
|
456
|
-
type.after === "int64" ||
|
|
457
|
-
type.after === "float32" ||
|
|
458
|
-
type.after === "float64"
|
|
459
|
-
);
|
|
460
|
-
case "uint64":
|
|
461
|
-
return (
|
|
462
|
-
type.after === "uint64" ||
|
|
463
|
-
type.after === "float32" ||
|
|
464
|
-
type.after === "float64"
|
|
465
|
-
);
|
|
443
|
+
return type.after === "int32" || type.after === "int64";
|
|
466
444
|
case "float32":
|
|
467
445
|
case "float64":
|
|
468
446
|
return type.after === "float32" || type.after === "float64";
|
|
469
447
|
case "timestamp":
|
|
470
448
|
case "string":
|
|
471
449
|
case "bytes":
|
|
450
|
+
case "int64":
|
|
451
|
+
case "hash64":
|
|
472
452
|
return type.after === type.before;
|
|
473
453
|
}
|
|
474
454
|
}
|
package/src/compiler.ts
CHANGED
|
@@ -335,6 +335,15 @@ async function format(root: string, mode: "fix" | "check"): Promise<void> {
|
|
|
335
335
|
async function main(): Promise<void> {
|
|
336
336
|
const args = parseCommandLine(process.argv.slice(2));
|
|
337
337
|
|
|
338
|
+
if (args.kind === "version") {
|
|
339
|
+
const packageJsonPath = new URL("../package.json", import.meta.url);
|
|
340
|
+
const packageJson = JSON.parse(
|
|
341
|
+
await FileSystem.readFile(packageJsonPath, "utf-8"),
|
|
342
|
+
);
|
|
343
|
+
console.log(`v${packageJson.version}`);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
|
|
338
347
|
const root = args.root || ".";
|
|
339
348
|
|
|
340
349
|
if (!(await isDirectory(root))) {
|
package/src/config_parser.ts
CHANGED
|
@@ -34,7 +34,7 @@ export interface SkirConfigErrorPos {
|
|
|
34
34
|
offset: number;
|
|
35
35
|
/** 1-based */
|
|
36
36
|
lineNumber: number;
|
|
37
|
-
/**
|
|
37
|
+
/** 1-based */
|
|
38
38
|
colNumber: number;
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -277,11 +277,13 @@ async function parseSkirConfigInternalAsync(
|
|
|
277
277
|
return { skirConfig: zodResult.data!, errors: [] };
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
+
// TODO: remove the casts
|
|
280
281
|
const STATIC_GENERATORS: Record<string, CodeGenerator<unknown>> = {
|
|
281
|
-
"skir-cc-gen": CcGen.GENERATOR
|
|
282
|
-
"skir-dart-gen": DartGen.GENERATOR
|
|
283
|
-
"skir-java-gen": JavaGen.GENERATOR
|
|
284
|
-
"skir-kotlin-gen": KotlinGen.GENERATOR
|
|
285
|
-
"skir-python-gen": PythonGen.GENERATOR
|
|
286
|
-
"skir-typescript-gen":
|
|
282
|
+
"skir-cc-gen": CcGen.GENERATOR as any as CodeGenerator<unknown>,
|
|
283
|
+
"skir-dart-gen": DartGen.GENERATOR as any as CodeGenerator<unknown>,
|
|
284
|
+
"skir-java-gen": JavaGen.GENERATOR as any as CodeGenerator<unknown>,
|
|
285
|
+
"skir-kotlin-gen": KotlinGen.GENERATOR as any as CodeGenerator<unknown>,
|
|
286
|
+
"skir-python-gen": PythonGen.GENERATOR as any as CodeGenerator<unknown>,
|
|
287
|
+
"skir-typescript-gen":
|
|
288
|
+
TypescriptGen.GENERATOR as any as CodeGenerator<unknown>,
|
|
287
289
|
};
|
package/src/literals.ts
CHANGED
|
@@ -38,7 +38,7 @@ export function valueHasPrimitiveType(
|
|
|
38
38
|
BigInt("-9223372036854775808"),
|
|
39
39
|
BigInt("9223372036854775807"),
|
|
40
40
|
);
|
|
41
|
-
case "
|
|
41
|
+
case "hash64":
|
|
42
42
|
return isIntLiteral(token, BigInt(0), BigInt("18446744073709551615"));
|
|
43
43
|
case "float32":
|
|
44
44
|
case "float64": {
|
|
@@ -92,7 +92,7 @@ export function literalValueToDenseJson(
|
|
|
92
92
|
return isStringLiteral(token) ? unquoteAndUnescape(token) : Number(token);
|
|
93
93
|
}
|
|
94
94
|
case "int64":
|
|
95
|
-
case "
|
|
95
|
+
case "hash64":
|
|
96
96
|
return String(BigInt(token));
|
|
97
97
|
case "string":
|
|
98
98
|
return unquoteAndUnescape(token);
|
package/src/module_set.ts
CHANGED
|
@@ -642,7 +642,7 @@ export class ModuleSet {
|
|
|
642
642
|
: !valueJson ||
|
|
643
643
|
(Array.isArray(valueJson) && !valueJson.length) ||
|
|
644
644
|
(type.kind === "primitive" &&
|
|
645
|
-
(type.primitive === "int64" || type.primitive === "
|
|
645
|
+
(type.primitive === "int64" || type.primitive === "hash64") &&
|
|
646
646
|
valueJson === "0");
|
|
647
647
|
if (!hasDefaultValue) {
|
|
648
648
|
arrayLen = Math.max(arrayLen, field.number + 1);
|
|
@@ -774,7 +774,7 @@ export class ModuleSet {
|
|
|
774
774
|
case "bool":
|
|
775
775
|
case "int32":
|
|
776
776
|
case "int64":
|
|
777
|
-
case "
|
|
777
|
+
case "hash64":
|
|
778
778
|
case "float32":
|
|
779
779
|
case "float64":
|
|
780
780
|
case "timestamp":
|
package/src/parser.ts
CHANGED
|
@@ -27,7 +27,7 @@ import type {
|
|
|
27
27
|
UnresolvedRecordRef,
|
|
28
28
|
UnresolvedType,
|
|
29
29
|
} from "skir-internal";
|
|
30
|
-
import { convertCase
|
|
30
|
+
import { convertCase } from "skir-internal";
|
|
31
31
|
import * as Casing from "./casing.js";
|
|
32
32
|
import { mergeDocs } from "./doc_comment_parser.js";
|
|
33
33
|
import { ModuleTokens } from "./tokenizer.js";
|
|
@@ -507,7 +507,7 @@ const PRIMITIVE_TYPES: ReadonlySet<string> = new Set<Primitive>([
|
|
|
507
507
|
"bool",
|
|
508
508
|
"int32",
|
|
509
509
|
"int64",
|
|
510
|
-
"
|
|
510
|
+
"hash64",
|
|
511
511
|
"float32",
|
|
512
512
|
"float64",
|
|
513
513
|
"timestamp",
|
|
@@ -862,19 +862,14 @@ function parseMethod(it: TokenIterator, doc: Doc): MutableMethod | null {
|
|
|
862
862
|
return null;
|
|
863
863
|
}
|
|
864
864
|
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
}
|
|
872
|
-
it.expectThenNext([";"]);
|
|
873
|
-
} else {
|
|
874
|
-
const methodName = nameMatch.token.text;
|
|
875
|
-
const { modulePath } = nameMatch.token.line;
|
|
876
|
-
number = simpleHash(`${modulePath}:${methodName}`);
|
|
865
|
+
if (it.expectThenNext(["="]).case < 0) {
|
|
866
|
+
return null;
|
|
867
|
+
}
|
|
868
|
+
const number = parseUint32(it);
|
|
869
|
+
if (number < 0) {
|
|
870
|
+
return null;
|
|
877
871
|
}
|
|
872
|
+
it.expectThenNext([";"]);
|
|
878
873
|
|
|
879
874
|
return {
|
|
880
875
|
kind: "method",
|
|
@@ -887,7 +882,6 @@ function parseMethod(it: TokenIterator, doc: Doc): MutableMethod | null {
|
|
|
887
882
|
// Will be populated at a later stage.
|
|
888
883
|
responseType: undefined,
|
|
889
884
|
number: number,
|
|
890
|
-
hasExplicitNumber: explicitNumber,
|
|
891
885
|
inlineRequestRecord: requestTypeOrInlineRecord.inlineRecord,
|
|
892
886
|
inlineResponseRecord: responseTypeOrInlineRecord.inlineRecord,
|
|
893
887
|
};
|