durable-actors 0.8.0 → 0.8.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.
- package/README.md +1 -1
- package/dist/actor/actor.d.ts +19 -11
- package/dist/actor/actor.d.ts.map +1 -1
- package/dist/actor/actor.js +41 -36
- package/dist/actor/actor.js.map +1 -1
- package/dist/actor/alarm.d.ts +19 -0
- package/dist/actor/alarm.d.ts.map +1 -0
- package/dist/actor/alarm.js +2 -0
- package/dist/actor/alarm.js.map +1 -0
- package/dist/actor/context.d.ts +25 -0
- package/dist/actor/context.d.ts.map +1 -0
- package/dist/actor/context.js +83 -0
- package/dist/actor/context.js.map +1 -0
- package/dist/actor/database.d.ts +5 -5
- package/dist/actor/database.d.ts.map +1 -1
- package/dist/actor/database.js +9 -37
- package/dist/actor/database.js.map +1 -1
- package/dist/actor/decorators.d.ts +7 -2
- package/dist/actor/decorators.d.ts.map +1 -1
- package/dist/actor/decorators.js +11 -2
- package/dist/actor/decorators.js.map +1 -1
- package/dist/actor/resource.d.ts +9 -0
- package/dist/actor/resource.d.ts.map +1 -0
- package/dist/actor/resource.js +2 -0
- package/dist/actor/resource.js.map +1 -0
- package/dist/actor/schema.d.ts +3 -1
- package/dist/actor/schema.d.ts.map +1 -1
- package/dist/actor/schema.js.map +1 -1
- package/dist/actor/unchecked.d.ts +12 -0
- package/dist/actor/unchecked.d.ts.map +1 -0
- package/dist/actor/unchecked.js +8 -0
- package/dist/actor/unchecked.js.map +1 -0
- package/dist/cli/inspect.d.ts +73 -0
- package/dist/cli/inspect.d.ts.map +1 -0
- package/dist/cli/inspect.js +132 -0
- package/dist/cli/inspect.js.map +1 -0
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/client-runtime/http.d.ts +1 -1
- package/dist/client-runtime/http.d.ts.map +1 -1
- package/dist/client-runtime/http.js +1 -1
- package/dist/client-runtime/http.js.map +1 -1
- package/dist/client-runtime/stub.d.ts.map +1 -1
- package/dist/client-runtime/stub.js +11 -1
- package/dist/client-runtime/stub.js.map +1 -1
- package/dist/compiler/actor-compiler.d.ts +4 -2
- package/dist/compiler/actor-compiler.d.ts.map +1 -1
- package/dist/compiler/actor-compiler.js +48 -13
- package/dist/compiler/actor-compiler.js.map +1 -1
- package/dist/compiler/declarations.d.ts.map +1 -1
- package/dist/compiler/declarations.js +31 -1
- package/dist/compiler/declarations.js.map +2 -2
- package/dist/compiler/features/atomicity.d.ts +9 -0
- package/dist/compiler/features/atomicity.d.ts.map +1 -0
- package/dist/compiler/features/atomicity.js +44 -0
- package/dist/compiler/features/atomicity.js.map +1 -0
- package/dist/compiler/features/interleave.d.ts +9 -0
- package/dist/compiler/features/{reentrancy.d.ts.map → interleave.d.ts.map} +1 -1
- package/dist/compiler/features/{reentrancy.js → interleave.js} +13 -13
- package/dist/compiler/features/{reentrancy.js.map → interleave.js.map} +1 -1
- package/dist/compiler/features/persistence.d.ts +2 -5
- package/dist/compiler/features/persistence.d.ts.map +1 -1
- package/dist/compiler/features/persistence.js +5 -83
- package/dist/compiler/features/persistence.js.map +1 -1
- package/dist/compiler/features/resource.d.ts +5 -0
- package/dist/compiler/features/resource.d.ts.map +1 -0
- package/dist/compiler/features/resource.js +18 -0
- package/dist/compiler/features/resource.js.map +1 -0
- package/dist/compiler/fieldParsing.d.ts +12 -0
- package/dist/compiler/fieldParsing.d.ts.map +1 -0
- package/dist/compiler/fieldParsing.js +106 -0
- package/dist/compiler/fieldParsing.js.map +1 -0
- package/dist/compiler/json-schema.d.ts +2 -2
- package/dist/compiler/json-schema.d.ts.map +1 -1
- package/dist/compiler/json-schema.js +22 -14
- package/dist/compiler/json-schema.js.map +1 -1
- package/dist/compiler/rpc-contract.d.ts +1 -1
- package/dist/compiler/rpc-contract.d.ts.map +1 -1
- package/dist/compiler/rpc-contract.js +21 -11
- package/dist/compiler/rpc-contract.js.map +1 -1
- package/dist/compiler/socket-contract.d.ts +1 -1
- package/dist/compiler/socket-contract.d.ts.map +1 -1
- package/dist/compiler/socket-contract.js +3 -3
- package/dist/compiler/socket-contract.js.map +1 -1
- package/dist/compiler/types.d.ts +13 -3
- package/dist/compiler/types.d.ts.map +1 -1
- package/dist/compiler/types.js +3 -1
- package/dist/compiler/types.js.map +1 -1
- package/dist/compiler/validate-public-contract.d.ts.map +1 -1
- package/dist/compiler/validate-public-contract.js +12 -1
- package/dist/compiler/validate-public-contract.js.map +1 -1
- package/dist/generated/client-runtime.d.ts.map +1 -1
- package/dist/generated/client-runtime.js +1 -1
- package/dist/generated/client-runtime.js.map +1 -1
- package/dist/host/actor-host.d.ts.map +1 -1
- package/dist/host/actor-host.js +44 -50
- package/dist/host/actor-host.js.map +1 -1
- package/dist/host/actor-runtime.d.ts +7 -8
- package/dist/host/actor-runtime.d.ts.map +1 -1
- package/dist/host/actor-runtime.js +80 -78
- package/dist/host/actor-runtime.js.map +1 -1
- package/dist/host/actor-worker.js +10 -27
- package/dist/host/actor-worker.js.map +1 -1
- package/dist/host/database-bridge.d.ts +16 -0
- package/dist/host/database-bridge.d.ts.map +1 -0
- package/dist/host/database-bridge.js +29 -0
- package/dist/host/database-bridge.js.map +1 -0
- package/dist/host/database.d.ts +86 -0
- package/dist/host/database.d.ts.map +1 -0
- package/dist/host/database.js +87 -0
- package/dist/host/database.js.map +1 -0
- package/dist/host/generic-host.js +1 -1
- package/dist/host/persisted-fields.d.ts +7 -0
- package/dist/host/persisted-fields.d.ts.map +1 -0
- package/dist/host/persisted-fields.js +29 -0
- package/dist/host/persisted-fields.js.map +1 -0
- package/dist/host/protocol.d.ts +55 -131
- package/dist/host/protocol.d.ts.map +1 -1
- package/dist/host/protocol.js +28 -28
- package/dist/host/protocol.js.map +1 -1
- package/dist/host/types.d.ts +8 -9
- package/dist/host/types.d.ts.map +1 -1
- package/dist/host/worker-supervisor.d.ts +32 -30
- package/dist/host/worker-supervisor.d.ts.map +1 -1
- package/dist/host/worker-supervisor.js +246 -230
- package/dist/host/worker-supervisor.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/templates/actor/package.json +1 -1
- package/dist/templates/ai-chat/package.json +1 -1
- package/dist/templates/ai-chat/src/actors.ts +1 -1
- package/dist/templates/chat/package.json +1 -1
- package/dist/templates/chat/src/actors.ts +1 -1
- package/dist/templates/documents/package.json +1 -1
- package/dist/templates/documents/src/actors.ts +1 -1
- package/package.json +2 -2
- package/dist/compiler/features/reentrancy.d.ts +0 -9
- package/dist/host/sqlite.d.ts +0 -49
- package/dist/host/sqlite.d.ts.map +0 -1
- package/dist/host/sqlite.js +0 -161
- package/dist/host/sqlite.js.map +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import type { DecoratorResult, DecoratorUse, ParsedActor } from "../types.js";
|
|
3
|
+
declare function readAtomicity(use: DecoratorUse): DecoratorResult;
|
|
4
|
+
declare function validateAtomicity(actor: ParsedActor): {
|
|
5
|
+
methods: string[];
|
|
6
|
+
diagnostics: ts.Diagnostic[];
|
|
7
|
+
};
|
|
8
|
+
export { readAtomicity, validateAtomicity };
|
|
9
|
+
//# sourceMappingURL=atomicity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atomicity.d.ts","sourceRoot":"","sources":["../../../src/compiler/features/atomicity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAI3B,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE7E,iBAAS,aAAa,CAAC,GAAG,EAAE,YAAY,GAAG,eAAe,CAWzD;AAED,iBAAS,iBAAiB,CAAC,KAAK,EAAE,WAAW;;;EAS5C;AAkBD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { definitionDiagnostic } from "../actor-compiler.js";
|
|
3
|
+
import { AnnotationKind } from "../types.js";
|
|
4
|
+
function readAtomicity(use) {
|
|
5
|
+
const node = use.target;
|
|
6
|
+
if (use.called)
|
|
7
|
+
return invalidAtomicity(use);
|
|
8
|
+
if (!ts.isMethodDeclaration(node) || !node.body)
|
|
9
|
+
return invalidAtomicity(use);
|
|
10
|
+
if (!hasModifier(node, ts.SyntaxKind.AsyncKeyword))
|
|
11
|
+
return invalidAtomicity(use);
|
|
12
|
+
if (hasModifier(node, ts.SyntaxKind.StaticKeyword))
|
|
13
|
+
return invalidAtomicity(use);
|
|
14
|
+
if (hasModifier(node, ts.SyntaxKind.PrivateKeyword) || hasModifier(node, ts.SyntaxKind.ProtectedKeyword))
|
|
15
|
+
return invalidAtomicity(use);
|
|
16
|
+
if (!ts.isIdentifier(node.name) && !ts.isStringLiteral(node.name))
|
|
17
|
+
return invalidAtomicity(use);
|
|
18
|
+
return { annotations: [{ kind: AnnotationKind.Atomicity, node: use.node }], diagnostics: [] };
|
|
19
|
+
}
|
|
20
|
+
function validateAtomicity(actor) {
|
|
21
|
+
const methods = [];
|
|
22
|
+
const diagnostics = [];
|
|
23
|
+
for (const member of actor.members) {
|
|
24
|
+
const annotations = member.annotations.filter(annotation => annotation.kind === AnnotationKind.Atomicity);
|
|
25
|
+
if (annotations.length > 1)
|
|
26
|
+
diagnostics.push(definitionDiagnostic(member.node, "@Atomic cannot be repeated"));
|
|
27
|
+
if (annotations.length === 1)
|
|
28
|
+
methods.push(member.node.name.text);
|
|
29
|
+
}
|
|
30
|
+
return { methods, diagnostics };
|
|
31
|
+
}
|
|
32
|
+
function hasModifier(node, kind) {
|
|
33
|
+
return ts.getModifiers(node)?.some(modifier => modifier.kind === kind) ?? false;
|
|
34
|
+
}
|
|
35
|
+
function invalidAtomicity(use) {
|
|
36
|
+
return {
|
|
37
|
+
annotations: [],
|
|
38
|
+
diagnostics: [
|
|
39
|
+
definitionDiagnostic(use.target, "@Atomic requires a public instance async method; use it without parentheses")
|
|
40
|
+
]
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export { readAtomicity, validateAtomicity };
|
|
44
|
+
//# sourceMappingURL=atomicity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atomicity.js","sourceRoot":"","sources":["../../../src/compiler/features/atomicity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAG5C,SAAS,aAAa,CAAC,GAAiB;IACpC,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAA;IACvB,IAAI,GAAG,CAAC,MAAM;QAAE,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAA;IAC5C,IAAI,CAAC,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;QAAE,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAA;IAC7E,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC;QAAE,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAA;IAChF,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC;QAAE,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAA;IAChF,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC;QACpG,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAA;IAChC,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,O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,EAAE,aAAa,EAAE,iBAAiB,EAAE,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import type { DecoratorResult, DecoratorUse, ParsedActor } from "../types.js";
|
|
3
|
+
declare function readInterleave(use: DecoratorUse): DecoratorResult;
|
|
4
|
+
declare function validateInterleave(actor: ParsedActor): {
|
|
5
|
+
methods: string[];
|
|
6
|
+
diagnostics: ts.Diagnostic[];
|
|
7
|
+
};
|
|
8
|
+
export { readInterleave, validateInterleave };
|
|
9
|
+
//# sourceMappingURL=interleave.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"interleave.d.ts","sourceRoot":"","sources":["../../../src/compiler/features/interleave.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAI3B,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE7E,iBAAS,cAAc,CAAC,GAAG,EAAE,YAAY,GAAG,eAAe,CAW1D;AAED,iBAAS,kBAAkB,CAAC,KAAK,EAAE,WAAW;;;EAU7C;AAkBD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAA"}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { definitionDiagnostic } from "../actor-compiler.js";
|
|
3
3
|
import { AnnotationKind } from "../types.js";
|
|
4
|
-
function
|
|
4
|
+
function readInterleave(use) {
|
|
5
5
|
const node = use.target;
|
|
6
6
|
if (use.called)
|
|
7
|
-
return
|
|
7
|
+
return invalidInterleave(use);
|
|
8
8
|
if (!ts.isMethodDeclaration(node) || !node.body)
|
|
9
|
-
return
|
|
9
|
+
return invalidInterleave(use);
|
|
10
10
|
if (!hasModifier(node, ts.SyntaxKind.AsyncKeyword))
|
|
11
|
-
return
|
|
11
|
+
return invalidInterleave(use);
|
|
12
12
|
if (hasModifier(node, ts.SyntaxKind.StaticKeyword))
|
|
13
|
-
return
|
|
13
|
+
return invalidInterleave(use);
|
|
14
14
|
if (hasModifier(node, ts.SyntaxKind.PrivateKeyword) || hasModifier(node, ts.SyntaxKind.ProtectedKeyword))
|
|
15
|
-
return
|
|
15
|
+
return invalidInterleave(use);
|
|
16
16
|
if (!ts.isIdentifier(node.name) && !ts.isStringLiteral(node.name))
|
|
17
|
-
return
|
|
18
|
-
return { annotations: [{ kind: AnnotationKind.
|
|
17
|
+
return invalidInterleave(use);
|
|
18
|
+
return { annotations: [{ kind: AnnotationKind.Interleave, node: use.node }], diagnostics: [] };
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function validateInterleave(actor) {
|
|
21
21
|
const methods = [];
|
|
22
22
|
const diagnostics = [];
|
|
23
23
|
for (const member of actor.members) {
|
|
24
|
-
const annotations = member.annotations.filter(annotation => annotation.kind === AnnotationKind.
|
|
24
|
+
const annotations = member.annotations.filter(annotation => annotation.kind === AnnotationKind.Interleave);
|
|
25
25
|
if (annotations.length > 1)
|
|
26
26
|
diagnostics.push(definitionDiagnostic(member.node, "@Interleave cannot be repeated"));
|
|
27
27
|
if (annotations.length === 1)
|
|
@@ -32,7 +32,7 @@ function validateReentrancy(actor) {
|
|
|
32
32
|
function hasModifier(node, kind) {
|
|
33
33
|
return ts.getModifiers(node)?.some(modifier => modifier.kind === kind) ?? false;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function invalidInterleave(use) {
|
|
36
36
|
return {
|
|
37
37
|
annotations: [],
|
|
38
38
|
diagnostics: [
|
|
@@ -40,5 +40,5 @@ function invalidReentrancy(use) {
|
|
|
40
40
|
]
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
-
export {
|
|
44
|
-
//# sourceMappingURL=
|
|
43
|
+
export { readInterleave, validateInterleave };
|
|
44
|
+
//# sourceMappingURL=interleave.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
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.js";
|
|
2
|
+
import type { ActorFieldSchema, ParsedActor } from "../types.js";
|
|
4
3
|
declare function validatePersistence(actor: ParsedActor): {
|
|
5
4
|
fields: ActorFieldSchema[];
|
|
6
5
|
diagnostics: ts.Diagnostic[];
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
declare function readEmission(use: DecoratorUse): DecoratorResult;
|
|
10
|
-
export { readEmission, readPersistence, validatePersistence };
|
|
7
|
+
export { validatePersistence };
|
|
11
8
|
//# sourceMappingURL=persistence.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../../src/compiler/features/persistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../../src/compiler/features/persistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAI3B,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEhE,iBAAS,mBAAmB,CAAC,KAAK,EAAE,WAAW;;;EAsB9C;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { definitionDiagnostic } from "../actor-compiler.js";
|
|
3
|
-
import {
|
|
3
|
+
import { hasModifier, validateField } from "../fieldParsing.js";
|
|
4
4
|
function validatePersistence(actor) {
|
|
5
5
|
const fields = [];
|
|
6
6
|
const diagnostics = [];
|
|
@@ -15,90 +15,12 @@ function validatePersistence(actor) {
|
|
|
15
15
|
if (!ts.isPropertyDeclaration(node) || hasModifier(node, ts.SyntaxKind.StaticKeyword))
|
|
16
16
|
continue;
|
|
17
17
|
const result = validateField(actor.name, member);
|
|
18
|
-
|
|
19
|
-
if (result.field !== undefined)
|
|
18
|
+
if ("field" in result)
|
|
20
19
|
fields.push(result.field);
|
|
20
|
+
else
|
|
21
|
+
diagnostics.push(...result.diagnostics);
|
|
21
22
|
}
|
|
22
23
|
return { fields, diagnostics };
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
const name = mode === Persistence.Persisted ? "Persisted" : "Ephemeral";
|
|
26
|
-
const node = use.target;
|
|
27
|
-
if (!ts.isPropertyDeclaration(node) ||
|
|
28
|
-
hasModifier(node, ts.SyntaxKind.StaticKeyword) ||
|
|
29
|
-
hasModifier(node, ts.SyntaxKind.AccessorKeyword))
|
|
30
|
-
return invalid(use, `@${name} requires an instance field`);
|
|
31
|
-
if (use.called)
|
|
32
|
-
return invalid(use, `use @${name} without parentheses or arguments`);
|
|
33
|
-
if (hasModifier(node, ts.SyntaxKind.DeclareKeyword))
|
|
34
|
-
return invalid(use, `@${name} requires a runtime field, not a declare field`);
|
|
35
|
-
if (fieldName(node.name) === undefined)
|
|
36
|
-
return invalid(use, `@${name} requires a field with a literal string name`);
|
|
37
|
-
if (mode === Persistence.Persisted && ts.isPrivateIdentifier(node.name))
|
|
38
|
-
return invalid(use, "@Persisted cannot decorate a JavaScript private field; use @Ephemeral");
|
|
39
|
-
return { annotations: [{ kind: AnnotationKind.Persistence, mode, node: use.node }], diagnostics: [] };
|
|
40
|
-
}
|
|
41
|
-
function readEmission(use) {
|
|
42
|
-
const node = use.target;
|
|
43
|
-
if (!ts.isPropertyDeclaration(node) ||
|
|
44
|
-
hasModifier(node, ts.SyntaxKind.StaticKeyword) ||
|
|
45
|
-
hasModifier(node, ts.SyntaxKind.AccessorKeyword))
|
|
46
|
-
return invalid(use, "@Emittable requires an instance field");
|
|
47
|
-
if (use.called)
|
|
48
|
-
return invalid(use, "use @Emittable without parentheses or arguments");
|
|
49
|
-
if (ts.isPrivateIdentifier(node.name) ||
|
|
50
|
-
hasModifier(node, ts.SyntaxKind.PrivateKeyword) ||
|
|
51
|
-
hasModifier(node, ts.SyntaxKind.ProtectedKeyword))
|
|
52
|
-
return invalid(use, "@Emittable requires a public persisted field");
|
|
53
|
-
return { annotations: [{ kind: AnnotationKind.Emission, node: use.node }], diagnostics: [] };
|
|
54
|
-
}
|
|
55
|
-
function validateField(actorName, member) {
|
|
56
|
-
const node = member.node;
|
|
57
|
-
if (fieldName(node.name) === "db")
|
|
58
|
-
return { diagnostics: [definitionDiagnostic(node.name, "actor field db is reserved for SQLite")] };
|
|
59
|
-
if (member.diagnostics.length > 0)
|
|
60
|
-
return { diagnostics: [] };
|
|
61
|
-
const annotations = member.annotations.filter(annotation => annotation.kind === AnnotationKind.Persistence);
|
|
62
|
-
const emission = member.annotations.filter(annotation => annotation.kind === AnnotationKind.Emission);
|
|
63
|
-
if (annotations.length !== 1)
|
|
64
|
-
return {
|
|
65
|
-
diagnostics: [
|
|
66
|
-
definitionDiagnostic(node.name, `actor field ${actorName}.${node.name.getText()} must declare exactly one of @Persisted or @Ephemeral`, annotations.map(annotation => annotation.node))
|
|
67
|
-
]
|
|
68
|
-
};
|
|
69
|
-
if (emission.length > 1 || (emission.length === 1 && annotations[0].mode !== Persistence.Persisted))
|
|
70
|
-
return {
|
|
71
|
-
diagnostics: [
|
|
72
|
-
definitionDiagnostic(node, "@Emittable requires a public @Persisted field and cannot be repeated")
|
|
73
|
-
]
|
|
74
|
-
};
|
|
75
|
-
return {
|
|
76
|
-
field: {
|
|
77
|
-
name: fieldName(node.name),
|
|
78
|
-
persistence: annotations[0].mode,
|
|
79
|
-
...(ts.isPrivateIdentifier(node.name) ? { private: true } : {}),
|
|
80
|
-
...(hasModifier(node, ts.SyntaxKind.PrivateKeyword)
|
|
81
|
-
? { visibility: "private" }
|
|
82
|
-
: hasModifier(node, ts.SyntaxKind.ProtectedKeyword)
|
|
83
|
-
? { visibility: "protected" }
|
|
84
|
-
: {}),
|
|
85
|
-
...(emission.length === 1 ? { emittable: true } : {})
|
|
86
|
-
},
|
|
87
|
-
diagnostics: []
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function fieldName(name) {
|
|
91
|
-
if (ts.isIdentifier(name) || ts.isPrivateIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name))
|
|
92
|
-
return name.text;
|
|
93
|
-
if (ts.isComputedPropertyName(name) &&
|
|
94
|
-
(ts.isStringLiteral(name.expression) || ts.isNumericLiteral(name.expression)))
|
|
95
|
-
return name.expression.text;
|
|
96
|
-
}
|
|
97
|
-
function hasModifier(node, kind) {
|
|
98
|
-
return ts.canHaveModifiers(node) && (ts.getModifiers(node)?.some(modifier => modifier.kind === kind) ?? false);
|
|
99
|
-
}
|
|
100
|
-
function invalid(use, message) {
|
|
101
|
-
return { annotations: [], diagnostics: [definitionDiagnostic(use.node, message)] };
|
|
102
|
-
}
|
|
103
|
-
export { readEmission, readPersistence, validatePersistence };
|
|
25
|
+
export { validatePersistence };
|
|
104
26
|
//# sourceMappingURL=persistence.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistence.js","sourceRoot":"","sources":["../../../src/compiler/features/persistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"persistence.js","sourceRoot":"","sources":["../../../src/compiler/features/persistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAG/D,SAAS,mBAAmB,CAAC,KAAkB;IAC3C,MAAM,MAAM,GAAuB,EAAE,CAAA;IACrC,MAAM,WAAW,GAAoB,EAAE,CAAA;IACvC,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;QACxB,IAAI,EAAE,CAAC,wBAAwB,CAAC,IAAI,CAAC,EAAE,CAAC;YACpC,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACtC,IAAI,EAAE,CAAC,8BAA8B,CAAC,SAAS,EAAE,IAAI,CAAC;oBAClD,WAAW,CAAC,IAAI,CACZ,oBAAoB,CAChB,SAAS,EACT,0EAA0E,CAC7E,CACJ,CAAA;YACT,CAAC;QACL,CAAC;QACD,IAAI,CAAC,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC;YAAE,SAAQ;QAC/F,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAChD,IAAI,OAAO,IAAI,MAAM;YAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;;YAC3C,WAAW,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;IAChD,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAA;AAClC,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { DecoratorResult, DecoratorUse, SdkSymbols } from "../types.js";
|
|
3
|
+
declare function readResource(use: DecoratorUse, sdk: SdkSymbols, checker: ts.TypeChecker): DecoratorResult;
|
|
4
|
+
export { readResource };
|
|
5
|
+
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/compiler/features/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3B,OAAO,EAAkB,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAEvF,iBAAS,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC,WAAW,GAAG,eAAe,CAgBlG;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { definitionDiagnostic } from "../actor-compiler.js";
|
|
2
|
+
import { AnnotationKind } from "../types.js";
|
|
3
|
+
function readResource(use, sdk, checker) {
|
|
4
|
+
if (sdk.ActorResource === undefined) {
|
|
5
|
+
return { annotations: [], diagnostics: [definitionDiagnostic(use.node, "@Resource requires a resource field")] };
|
|
6
|
+
}
|
|
7
|
+
const fieldType = checker.getTypeAtLocation(use.target);
|
|
8
|
+
const resourceType = checker.getDeclaredTypeOfSymbol(sdk.ActorResource);
|
|
9
|
+
if (!checker.isTypeAssignableTo(fieldType, resourceType)) {
|
|
10
|
+
return {
|
|
11
|
+
annotations: [],
|
|
12
|
+
diagnostics: [definitionDiagnostic(use.node, "@Resource fields must implement ActorResource")]
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return { annotations: [{ kind: AnnotationKind.Resource, node: use.node }], diagnostics: [] };
|
|
16
|
+
}
|
|
17
|
+
export { readResource };
|
|
18
|
+
//# sourceMappingURL=resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../src/compiler/features/resource.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,cAAc,EAA6C,MAAM,aAAa,CAAA;AAEvF,SAAS,YAAY,CAAC,GAAiB,EAAE,GAAe,EAAE,OAAuB;IAC7E,IAAI,GAAG,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,oBAAoB,CAAC,GAAG,CAAC,IAAI,EAAE,qCAAqC,CAAC,CAAC,EAAE,CAAA;IACpH,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACvD,MAAM,YAAY,GAAG,OAAO,CAAC,uBAAuB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IAEvE,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,SAAS,EAAE,YAAY,CAAC,EAAE,CAAC;QACvD,OAAO;YACH,WAAW,EAAE,EAAE;YACf,WAAW,EAAE,CAAC,oBAAoB,CAAC,GAAG,CAAC,IAAI,EAAE,+CAA+C,CAAC,CAAC;SACjG,CAAA;IACL,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAA;AAChG,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { ActorFieldSchema, DecoratorResult, DecoratorUse, ParsedMember, Persistence } from "./types.js";
|
|
3
|
+
export type FieldValidation = {
|
|
4
|
+
readonly field: ActorFieldSchema;
|
|
5
|
+
} | {
|
|
6
|
+
readonly diagnostics: readonly ts.Diagnostic[];
|
|
7
|
+
};
|
|
8
|
+
export declare function validateField(actorName: string, member: ParsedMember): FieldValidation;
|
|
9
|
+
export declare function readPersistence(use: DecoratorUse, mode: Persistence): DecoratorResult;
|
|
10
|
+
export declare function readEmission(use: DecoratorUse): DecoratorResult;
|
|
11
|
+
export declare function hasModifier(node: ts.Node, kind: ts.SyntaxKind): boolean;
|
|
12
|
+
//# sourceMappingURL=fieldParsing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldParsing.d.ts","sourceRoot":"","sources":["../../src/compiler/fieldParsing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3B,OAAO,EAAE,gBAAgB,EAAkB,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAEvH,MAAM,MAAM,eAAe,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,UAAU,EAAE,CAAA;CAAE,CAAA;AAEvH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,eAAe,CA2EtF;AAID,wBAAgB,eAAe,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,GAAG,eAAe,CAgBrF;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,GAAG,eAAe,CAgB/D;AAYD,wBAAgB,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,GAAG,OAAO,CAEvE"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { definitionDiagnostic } from "./actor-compiler.js";
|
|
3
|
+
import { AnnotationKind, Persistence } from "./types.js";
|
|
4
|
+
export function validateField(actorName, member) {
|
|
5
|
+
if (!ts.isPropertyDeclaration(member.node))
|
|
6
|
+
return { diagnostics: [] };
|
|
7
|
+
const node = member.node;
|
|
8
|
+
const nodeName = fieldName(node.name);
|
|
9
|
+
if (nodeName === undefined)
|
|
10
|
+
return {
|
|
11
|
+
diagnostics: [
|
|
12
|
+
definitionDiagnostic(node.name, `actor field ${actorName}.${node.name.getText()} must have a literal string name`)
|
|
13
|
+
]
|
|
14
|
+
};
|
|
15
|
+
if (fieldDenyList.includes(nodeName))
|
|
16
|
+
return { diagnostics: [definitionDiagnostic(node.name, `actor field ${nodeName} is reserved.`)] };
|
|
17
|
+
if (member.diagnostics.length > 0)
|
|
18
|
+
return { diagnostics: [...member.diagnostics] };
|
|
19
|
+
const annotations = member.annotations.filter(annotation => annotation.kind === AnnotationKind.Persistence);
|
|
20
|
+
const emission = member.annotations.filter(annotation => annotation.kind === AnnotationKind.Emission);
|
|
21
|
+
const resource = member.annotations.filter(annotation => annotation.kind === AnnotationKind.Resource);
|
|
22
|
+
const isResource = resource.length === 1 || (resource.length === 0 && member.resource);
|
|
23
|
+
const persistence = annotations.length === 0 ? Persistence.Ephemeral : annotations[0]?.mode;
|
|
24
|
+
const isPersistenceValid = (persistence !== undefined && annotations.length === 1) || isResource;
|
|
25
|
+
const isEmissionValid = emission.length <= 1 && (emission.length === 0 || persistence === Persistence.Persisted);
|
|
26
|
+
const isResourceValid = resource.length <= 1 && (!isResource || (persistence !== Persistence.Persisted && emission.length === 0));
|
|
27
|
+
if (!isPersistenceValid) {
|
|
28
|
+
return {
|
|
29
|
+
diagnostics: [
|
|
30
|
+
definitionDiagnostic(node.name, `actor field ${actorName}.${node.name.getText()} must declare exactly one of @Persisted or @Ephemeral`, annotations.map(annotation => annotation.node))
|
|
31
|
+
]
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (!isEmissionValid) {
|
|
35
|
+
return {
|
|
36
|
+
diagnostics: [
|
|
37
|
+
definitionDiagnostic(node, "@Emittable requires a public @Persisted field and cannot be repeated")
|
|
38
|
+
]
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (!isResourceValid) {
|
|
42
|
+
return {
|
|
43
|
+
diagnostics: [definitionDiagnostic(node, "@Resource cannot be @Persisted or @Emittable")]
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// if the field is a resource, it must be ephemeral
|
|
47
|
+
const finalPersistence = isResource ? Persistence.Ephemeral : persistence;
|
|
48
|
+
const isPrivate = hasModifier(node, ts.SyntaxKind.PrivateKeyword);
|
|
49
|
+
const isProtected = hasModifier(node, ts.SyntaxKind.ProtectedKeyword);
|
|
50
|
+
const field = {
|
|
51
|
+
name: nodeName,
|
|
52
|
+
persistence: finalPersistence,
|
|
53
|
+
private: ts.isPrivateIdentifier(node.name),
|
|
54
|
+
visibility: isPrivate ? "private" : isProtected ? "protected" : undefined,
|
|
55
|
+
emittable: emission.length === 1,
|
|
56
|
+
resource: isResource
|
|
57
|
+
};
|
|
58
|
+
return { field };
|
|
59
|
+
}
|
|
60
|
+
const fieldDenyList = ["db", "alarm"];
|
|
61
|
+
export function readPersistence(use, mode) {
|
|
62
|
+
const name = mode === Persistence.Persisted ? "Persisted" : "Ephemeral";
|
|
63
|
+
const node = use.target;
|
|
64
|
+
if (!ts.isPropertyDeclaration(node) ||
|
|
65
|
+
hasModifier(node, ts.SyntaxKind.StaticKeyword) ||
|
|
66
|
+
hasModifier(node, ts.SyntaxKind.AccessorKeyword))
|
|
67
|
+
return invalid(use, `@${name} requires an instance field`);
|
|
68
|
+
if (use.called)
|
|
69
|
+
return invalid(use, `use @${name} without parentheses or arguments`);
|
|
70
|
+
if (hasModifier(node, ts.SyntaxKind.DeclareKeyword))
|
|
71
|
+
return invalid(use, `@${name} requires a runtime field, not a declare field`);
|
|
72
|
+
if (fieldName(node.name) === undefined)
|
|
73
|
+
return invalid(use, `@${name} requires a field with a literal string name`);
|
|
74
|
+
if (mode === Persistence.Persisted && ts.isPrivateIdentifier(node.name))
|
|
75
|
+
return invalid(use, "@Persisted cannot decorate a JavaScript private field; use @Ephemeral");
|
|
76
|
+
return { annotations: [{ kind: AnnotationKind.Persistence, mode, node: use.node }], diagnostics: [] };
|
|
77
|
+
}
|
|
78
|
+
export function readEmission(use) {
|
|
79
|
+
const node = use.target;
|
|
80
|
+
if (!ts.isPropertyDeclaration(node) ||
|
|
81
|
+
hasModifier(node, ts.SyntaxKind.StaticKeyword) ||
|
|
82
|
+
hasModifier(node, ts.SyntaxKind.AccessorKeyword))
|
|
83
|
+
return invalid(use, "@Emittable requires an instance field");
|
|
84
|
+
if (use.called)
|
|
85
|
+
return invalid(use, "use @Emittable without parentheses or arguments");
|
|
86
|
+
if (ts.isPrivateIdentifier(node.name) ||
|
|
87
|
+
hasModifier(node, ts.SyntaxKind.PrivateKeyword) ||
|
|
88
|
+
hasModifier(node, ts.SyntaxKind.ProtectedKeyword))
|
|
89
|
+
return invalid(use, "@Emittable requires a public persisted field");
|
|
90
|
+
return { annotations: [{ kind: AnnotationKind.Emission, node: use.node }], diagnostics: [] };
|
|
91
|
+
}
|
|
92
|
+
function fieldName(name) {
|
|
93
|
+
const isLiteralName = ts.isIdentifier(name) || ts.isPrivateIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name);
|
|
94
|
+
if (isLiteralName)
|
|
95
|
+
return name.text;
|
|
96
|
+
const isComputedLiteralName = ts.isComputedPropertyName(name) && (ts.isStringLiteral(name.expression) || ts.isNumericLiteral(name.expression));
|
|
97
|
+
if (isComputedLiteralName)
|
|
98
|
+
return name.expression.text;
|
|
99
|
+
}
|
|
100
|
+
export function hasModifier(node, kind) {
|
|
101
|
+
return ts.canHaveModifiers(node) && (ts.getModifiers(node)?.some(modifier => modifier.kind === kind) ?? false);
|
|
102
|
+
}
|
|
103
|
+
function invalid(use, message) {
|
|
104
|
+
return { annotations: [], diagnostics: [definitionDiagnostic(use.node, message)] };
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=fieldParsing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldParsing.js","sourceRoot":"","sources":["../../src/compiler/fieldParsing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAoB,cAAc,EAA+C,WAAW,EAAE,MAAM,YAAY,CAAA;AAIvH,MAAM,UAAU,aAAa,CAAC,SAAiB,EAAE,MAAoB;IACjE,IAAI,CAAC,EAAE,CAAC,qBAAqB,CAAC,MAAM,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,CAAA;IAEtE,MAAM,I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
|
import ts from "typescript";
|
|
3
|
-
declare function jsonSchema(checker: ts.TypeChecker, types: Record<string, ts.Type>): JSONSchema7;
|
|
3
|
+
declare function jsonSchema(checker: ts.TypeChecker, unchecked: ts.Symbol | undefined, types: Record<string, ts.Type>): JSONSchema7;
|
|
4
4
|
declare function sourceTypeName(type: ts.Type): string | undefined;
|
|
5
|
-
declare function assertJsonType(checker: ts.TypeChecker, type: ts.Type, label: string, optional?: boolean, seen?: Set<ts.Type>): void;
|
|
5
|
+
declare function assertJsonType(checker: ts.TypeChecker, unchecked: ts.Symbol | undefined, type: ts.Type, label: string, optional?: boolean, seen?: Set<ts.Type>): void;
|
|
6
6
|
export { assertJsonType, jsonSchema, sourceTypeName };
|
|
7
7
|
//# sourceMappingURL=json-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../src/compiler/json-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAyB,MAAM,aAAa,CAAA;AACrE,OAAO,EAAE,MAAM,YAAY,CAAA;AAK3B,iBAAS,UAAU,
|
|
1
|
+
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../src/compiler/json-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAyB,MAAM,aAAa,CAAA;AACrE,OAAO,EAAE,MAAM,YAAY,CAAA;AAK3B,iBAAS,UAAU,CACf,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,SAAS,EAAE,EAAE,CAAC,MAAM,GAAG,SAAS,EAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,GAC/B,WAAW,CAyBb;AAsHD,iBAAS,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,GAAG,SAAS,CAWzD;AAED,iBAAS,cAAc,CACnB,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,SAAS,EAAE,EAAE,CAAC,MAAM,GAAG,SAAS,EAChC,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,KAAK,EAAE,MAAM,EACb,QAAQ,UAAQ,EAChB,IAAI,eAAqB,GAC1B,IAAI,CAoDN;AAMD,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { JsonSchemaGenerator, getDefaultArgs } from "typescript-json-schema";
|
|
3
3
|
import { ActorDefinitionError } from "../errors.js";
|
|
4
|
-
function jsonSchema(checker, types) {
|
|
5
|
-
const { allTypes, namesByType } = collectSchemaTypes(checker, types);
|
|
4
|
+
function jsonSchema(checker, unchecked, types) {
|
|
5
|
+
const { allTypes, namesByType } = collectSchemaTypes(checker, unchecked, types);
|
|
6
6
|
const generator = new JsonSchemaGenerator([], allTypes, {}, {}, checker, {
|
|
7
7
|
...getDefaultArgs(),
|
|
8
8
|
required: true,
|
|
@@ -24,10 +24,10 @@ function jsonSchema(checker, types) {
|
|
|
24
24
|
}
|
|
25
25
|
const seen = new Set();
|
|
26
26
|
for (const [name, type] of Object.entries(allTypes))
|
|
27
|
-
preserveTypes(checker, type, definitions[name], definitions, namesByType, seen);
|
|
27
|
+
preserveTypes(checker, unchecked, type, definitions[name], definitions, namesByType, seen);
|
|
28
28
|
return { $schema: "http://json-schema.org/draft-07/schema#", definitions };
|
|
29
29
|
}
|
|
30
|
-
function collectSchemaTypes(checker, roots) {
|
|
30
|
+
function collectSchemaTypes(checker, unchecked, roots) {
|
|
31
31
|
const allTypes = { ...roots };
|
|
32
32
|
const namesByType = new Map(Object.entries(roots).map(([name, type]) => [type, name]));
|
|
33
33
|
const seen = new Set();
|
|
@@ -40,7 +40,7 @@ function collectSchemaTypes(checker, roots) {
|
|
|
40
40
|
visit(type);
|
|
41
41
|
};
|
|
42
42
|
const visit = (type) => {
|
|
43
|
-
if (seen.has(type))
|
|
43
|
+
if (seen.has(type) || isUnchecked(type, unchecked))
|
|
44
44
|
return;
|
|
45
45
|
seen.add(type);
|
|
46
46
|
if (type.isUnionOrIntersection()) {
|
|
@@ -65,10 +65,15 @@ function collectSchemaTypes(checker, roots) {
|
|
|
65
65
|
Object.values(roots).forEach(visit);
|
|
66
66
|
return { allTypes, namesByType };
|
|
67
67
|
}
|
|
68
|
-
function preserveTypes(checker, type, schema, definitions, namesByType, seen) {
|
|
68
|
+
function preserveTypes(checker, unchecked, type, schema, definitions, namesByType, seen) {
|
|
69
69
|
if (!schema || typeof schema === "boolean" || seen.has(schema))
|
|
70
70
|
return;
|
|
71
71
|
seen.add(schema);
|
|
72
|
+
if (isUnchecked(type, unchecked)) {
|
|
73
|
+
for (const key of Object.keys(schema))
|
|
74
|
+
delete schema[key];
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
72
77
|
const reference = (child) => ({
|
|
73
78
|
$ref: `#/definitions/${namesByType.get(child).replaceAll("~", "~0").replaceAll("/", "~1")}`
|
|
74
79
|
});
|
|
@@ -87,7 +92,7 @@ function preserveTypes(checker, type, schema, definitions, namesByType, seen) {
|
|
|
87
92
|
const key = decodeURIComponent(schema.$ref.slice("#/definitions/".length))
|
|
88
93
|
.replaceAll("~1", "/")
|
|
89
94
|
.replaceAll("~0", "~");
|
|
90
|
-
preserveTypes(checker, type, definitions[key], definitions, namesByType, seen);
|
|
95
|
+
preserveTypes(checker, unchecked, type, definitions[key], definitions, namesByType, seen);
|
|
91
96
|
return;
|
|
92
97
|
}
|
|
93
98
|
const title = sourceTypeName(type);
|
|
@@ -99,7 +104,7 @@ function preserveTypes(checker, type, schema, definitions, namesByType, seen) {
|
|
|
99
104
|
schema.allOf = type.types.map(reference);
|
|
100
105
|
return;
|
|
101
106
|
}
|
|
102
|
-
preserveChildren(checker, type, schema, (child, definition) => preserveTypes(checker, child, definition, definitions, namesByType, seen));
|
|
107
|
+
preserveChildren(checker, type, schema, (child, definition) => preserveTypes(checker, unchecked, child, definition, definitions, namesByType, seen));
|
|
103
108
|
const indexType = checker.getIndexTypeOfType(type, ts.IndexKind.String);
|
|
104
109
|
if (indexType && type.flags & ts.TypeFlags.Object && !isArray(checker, type))
|
|
105
110
|
schema.additionalProperties = reference(indexType);
|
|
@@ -137,7 +142,7 @@ function sourceTypeName(type) {
|
|
|
137
142
|
? symbol.name
|
|
138
143
|
: undefined;
|
|
139
144
|
}
|
|
140
|
-
function assertJsonType(checker, type, label, optional = false, seen = new Set()) {
|
|
145
|
+
function assertJsonType(checker, unchecked, type, label, optional = false, seen = new Set()) {
|
|
141
146
|
if (type.flags & ts.TypeFlags.Undefined) {
|
|
142
147
|
if (optional)
|
|
143
148
|
return;
|
|
@@ -145,10 +150,10 @@ function assertJsonType(checker, type, label, optional = false, seen = new Set()
|
|
|
145
150
|
}
|
|
146
151
|
if (type.isUnionOrIntersection()) {
|
|
147
152
|
for (const member of type.types)
|
|
148
|
-
assertJsonType(checker, member, label, optional, seen);
|
|
153
|
+
assertJsonType(checker, unchecked, member, label, optional, seen);
|
|
149
154
|
return;
|
|
150
155
|
}
|
|
151
|
-
if (seen.has(type))
|
|
156
|
+
if (seen.has(type) || isUnchecked(type, unchecked))
|
|
152
157
|
return;
|
|
153
158
|
seen.add(type);
|
|
154
159
|
if (type.flags &
|
|
@@ -161,7 +166,7 @@ function assertJsonType(checker, type, label, optional = false, seen = new Set()
|
|
|
161
166
|
return;
|
|
162
167
|
if (checker.isArrayType(type) || checker.isTupleType(type) || type.getSymbol()?.name === "ReadonlyArray") {
|
|
163
168
|
for (const element of checker.getTypeArguments(type))
|
|
164
|
-
assertJsonType(checker, element, label, false, seen);
|
|
169
|
+
assertJsonType(checker, unchecked, element, label, false, seen);
|
|
165
170
|
return;
|
|
166
171
|
}
|
|
167
172
|
if (!(type.flags & ts.TypeFlags.Object) ||
|
|
@@ -173,10 +178,13 @@ function assertJsonType(checker, type, label, optional = false, seen = new Set()
|
|
|
173
178
|
const declaration = property.valueDeclaration ?? property.declarations?.[0];
|
|
174
179
|
if (!declaration || property.name.startsWith("__@"))
|
|
175
180
|
throw new ActorDefinitionError(`${label} must be JSON-compatible; symbol properties are not supported`);
|
|
176
|
-
assertJsonType(checker, checker.getTypeOfSymbolAtLocation(property, declaration), `${label}.${property.name}`, !!(property.flags & ts.SymbolFlags.Optional), seen);
|
|
181
|
+
assertJsonType(checker, unchecked, checker.getTypeOfSymbolAtLocation(property, declaration), `${label}.${property.name}`, !!(property.flags & ts.SymbolFlags.Optional), seen);
|
|
177
182
|
}
|
|
178
183
|
for (const index of checker.getIndexInfosOfType(type))
|
|
179
|
-
assertJsonType(checker, index.type, label, true, seen);
|
|
184
|
+
assertJsonType(checker, unchecked, index.type, label, true, seen);
|
|
185
|
+
}
|
|
186
|
+
function isUnchecked(type, unchecked) {
|
|
187
|
+
return unchecked !== undefined && type.getSymbol() === unchecked;
|
|
180
188
|
}
|
|
181
189
|
export { assertJsonType, jsonSchema, sourceTypeName };
|
|
182
190
|
//# sourceMappingURL=json-schema.js.map
|