@intentius/chant 0.72.0 → 0.72.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fold-import.d.ts","sourceRoot":"","sources":["../../src/discovery/fold-import.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAMjC,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAkC,KAAK,iBAAiB,EAAyB,MAAM,cAAc,CAAC;AAyC7G,OAAO,EAA6B,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,mGAAmG;AACnG,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,iBAAiB,CAAC,CAAC;AAElF,MAAM,MAAM,cAAc,GACtB;IACE,EAAE,EAAE,IAAI,CAAC;IACT;;;;;;;;OAQG;IACH,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB;;;;;;;;;;;;;OAaG;IACH,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC;;;;;;;;;;;;OAYG;IACH,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAClC,GACD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,UAAU,EAAE,SAAS,YAAY,EAAE,CAAC;IAC7C,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,cA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B;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C;AAED,iFAAiF;AACjF,MAAM,WAAW,kBAAkB;IACjC,0CAA0C;IAC1C,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC;IACjC,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,CAAC;IACnC,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,sEAAsE;IACtE,QAAQ,CAAC,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,aAAa,CAAA;KAAE,CAAC;IAC3D,mFAAmF;IACnF,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,UAAU,GAAE,SAAS,YAAY,EAAO,EACxC,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAoC1C"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { describe, test, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { foldProject } from "../index";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* chant#2442 — a host may supply the composite registration form.
|
|
9
|
+
*
|
|
10
|
+
* `findCompositeDefinition` required `Composite` to be chant's own, which is
|
|
11
|
+
* right for a chant project and is the provenance question #1082 settled: a
|
|
12
|
+
* project-local `function Composite(...)` shadowing the name is not chant's,
|
|
13
|
+
* and a call to it is not a registered composite.
|
|
14
|
+
*
|
|
15
|
+
* It had never had to consider a HOST supplying the form
|
|
16
|
+
* (`F-Host-Composite`), because a chant project's active packages are always
|
|
17
|
+
* lexicons and no lexicon exports a `Composite`. Reaching it at all requires a
|
|
18
|
+
* caller that named its own host packages
|
|
19
|
+
* (`FoldProjectOptions.lexiconPackages`, chant#2438), so nothing about a chant
|
|
20
|
+
* build changes.
|
|
21
|
+
*
|
|
22
|
+
* Two halves, and the second is the one with teeth. Recognising the form gets
|
|
23
|
+
* interpretation started; the members it produces are then the HOST's, and
|
|
24
|
+
* wrapping them in chant's `Composite` would run chant's member validation,
|
|
25
|
+
* which asks for chant's own `Declarable` and rejects an entity carrying a
|
|
26
|
+
* different marker — rejecting it for not being chant's rather than for being
|
|
27
|
+
* malformed.
|
|
28
|
+
*/
|
|
29
|
+
describe("a host's composite registration form (chant#2442)", () => {
|
|
30
|
+
let root: string;
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
root = mkdtempSync(join(tmpdir(), "chant-host-composite-"));
|
|
34
|
+
const pkg = join(root, "node_modules", "@tsad", "shapes");
|
|
35
|
+
mkdirSync(pkg, { recursive: true });
|
|
36
|
+
writeFileSync(
|
|
37
|
+
join(pkg, "package.json"),
|
|
38
|
+
JSON.stringify({ name: "@tsad/shapes", version: "0.0.0", type: "module", main: "index.js" }),
|
|
39
|
+
);
|
|
40
|
+
// An entity carrying its OWN marker, not chant's, and the host's own
|
|
41
|
+
// registration form. This is the shape the specification's `shapes` host
|
|
42
|
+
// has and the reason chant's member validation refused it.
|
|
43
|
+
writeFileSync(
|
|
44
|
+
join(pkg, "index.js"),
|
|
45
|
+
[
|
|
46
|
+
"const MARK = Symbol.for('tsad.conformance.declarable');",
|
|
47
|
+
"export class Bucket {",
|
|
48
|
+
" constructor(props = {}) {",
|
|
49
|
+
" this.entityType = 'Bucket'; this.lexicon = 'shapes'; this.props = props;",
|
|
50
|
+
" Object.defineProperty(this, MARK, { value: true, enumerable: false });",
|
|
51
|
+
" }",
|
|
52
|
+
"}",
|
|
53
|
+
"export function Composite(factory, name) {",
|
|
54
|
+
" const d = (props) => factory(props); d.compositeName = name; return d;",
|
|
55
|
+
"}",
|
|
56
|
+
].join("\n") + "\n",
|
|
57
|
+
);
|
|
58
|
+
writeFileSync(
|
|
59
|
+
join(root, "shapes.ts"),
|
|
60
|
+
'import { Bucket, Composite } from "@tsad/shapes";\n' +
|
|
61
|
+
'export const Store = Composite(({ name }) => ({ bucket: new Bucket({ name }) }), "Store");\n',
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
afterEach(() => rmSync(root, { recursive: true, force: true }));
|
|
66
|
+
|
|
67
|
+
const app = (source: string): string => {
|
|
68
|
+
const file = join(root, "app.ts");
|
|
69
|
+
writeFileSync(file, source);
|
|
70
|
+
return file;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
test("a call to the host's composite folds to the host's own members", async () => {
|
|
74
|
+
const file = app('import { Store } from "./shapes";\nexport const s = Store({ name: "a" });\n');
|
|
75
|
+
|
|
76
|
+
// `--sandbox` is what the specification calls isolated, and it is the
|
|
77
|
+
// setting that proves interpretation rather than invocation: invoking would
|
|
78
|
+
// import a project module, which the sandbox refuses.
|
|
79
|
+
const verdict = (
|
|
80
|
+
await foldProject([file], [], { lexiconPackages: ["@tsad/shapes"], sandbox: true })
|
|
81
|
+
).get(file)!;
|
|
82
|
+
|
|
83
|
+
expect(verdict.verdict).toBe("fold");
|
|
84
|
+
expect(JSON.parse(JSON.stringify(Object.fromEntries(verdict.exports!)))).toEqual({
|
|
85
|
+
s: { bucket: { entityType: "Bucket", lexicon: "shapes", props: { name: "a" } } },
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("a factory outside the subset is still refused rather than invoked", async () => {
|
|
90
|
+
// `S-FactoryParams`: two parameters is outside it, so interpretation
|
|
91
|
+
// declines and the invocation arm refuses under the sandbox.
|
|
92
|
+
writeFileSync(
|
|
93
|
+
join(root, "shapes.ts"),
|
|
94
|
+
'import { Bucket, Composite } from "@tsad/shapes";\n' +
|
|
95
|
+
'export const Two = Composite((a, b) => ({ bucket: new Bucket({ name: a.name + b }) }), "Two");\n',
|
|
96
|
+
);
|
|
97
|
+
const file = app('import { Two } from "./shapes";\nexport const s = Two({ name: "a" }, "b");\n');
|
|
98
|
+
|
|
99
|
+
const verdict = (
|
|
100
|
+
await foldProject([file], [], { lexiconPackages: ["@tsad/shapes"], sandbox: true })
|
|
101
|
+
).get(file)!;
|
|
102
|
+
|
|
103
|
+
expect(verdict.verdict).toBe("run");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("the form is only recognised when the caller named the package", async () => {
|
|
107
|
+
const file = app('import { Store } from "./shapes";\nexport const s = Store({ name: "a" });\n');
|
|
108
|
+
|
|
109
|
+
// Unnamed, the host package is not resolvable, so nothing about the
|
|
110
|
+
// registration form is reached and the sandbox refuses the invocation arm.
|
|
111
|
+
const verdict = (await foldProject([file], [], { sandbox: true })).get(file)!;
|
|
112
|
+
|
|
113
|
+
expect(verdict.verdict).toBe("run");
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -1857,6 +1857,16 @@ interface InterpretableFactory {
|
|
|
1857
1857
|
fn: ts.ArrowFunction | ts.FunctionExpression;
|
|
1858
1858
|
/** `Composite()`'s second argument, or `"anonymous"` when it has none — matching {@link Composite}'s own default. */
|
|
1859
1859
|
compositeName: string;
|
|
1860
|
+
/**
|
|
1861
|
+
* chant#2442 — the registration form came from a HOST the caller named
|
|
1862
|
+
* ({@link FoldSession.lexiconPackages}), not from chant.
|
|
1863
|
+
*
|
|
1864
|
+
* The members are then the host's own, so they are returned as the factory
|
|
1865
|
+
* produced them rather than wrapped in chant's {@link Composite}, whose
|
|
1866
|
+
* member validation asks for chant's own `Declarable` and would reject an
|
|
1867
|
+
* entity carrying a different marker. Chant's own form is untouched.
|
|
1868
|
+
*/
|
|
1869
|
+
hostForm: boolean;
|
|
1860
1870
|
}
|
|
1861
1871
|
|
|
1862
1872
|
/**
|
|
@@ -1937,7 +1947,7 @@ function findCompositeDefinition(
|
|
|
1937
1947
|
scope: FactoryModuleScope,
|
|
1938
1948
|
exportName: string,
|
|
1939
1949
|
ctx: ResolveCtx,
|
|
1940
|
-
): { fn: ts.ArrowFunction | ts.FunctionExpression; compositeName: string } | undefined {
|
|
1950
|
+
): { fn: ts.ArrowFunction | ts.FunctionExpression; compositeName: string; hostForm: boolean } | undefined {
|
|
1941
1951
|
for (const statement of scope.sourceFile.statements) {
|
|
1942
1952
|
if (!ts.isVariableStatement(statement)) continue;
|
|
1943
1953
|
if (!hasExportModifier(statement)) continue;
|
|
@@ -1955,7 +1965,16 @@ function findCompositeDefinition(
|
|
|
1955
1965
|
// call to it is not a registered composite.
|
|
1956
1966
|
const compositeBinding = scope.imports.get(init.expression.text);
|
|
1957
1967
|
if (!compositeBinding || compositeBinding.imported !== "Composite") return undefined;
|
|
1958
|
-
|
|
1968
|
+
// chant's own is the answer for every chant project, and #1082's
|
|
1969
|
+
// provenance question is why: a project-local `function Composite(...)`
|
|
1970
|
+
// shadowing the name is not chant's. chant#2442 adds the case chant had
|
|
1971
|
+
// never had to consider, a HOST supplying the form (`F-Host-Composite`),
|
|
1972
|
+
// which only a caller that named its own host packages can reach. For a
|
|
1973
|
+
// chant build the set holds only `@intentius/chant-lexicon-*`, and no
|
|
1974
|
+
// lexicon exports a `Composite`, so nothing about a chant project moves.
|
|
1975
|
+
const chantOwned = isChantOwnedHelperBinding(compositeBinding, { ...ctx, file: scope.file });
|
|
1976
|
+
const hostOwned = activeLexiconPackage(compositeBinding.specifier, ctx.lexiconPackages) !== undefined;
|
|
1977
|
+
if (!chantOwned && !hostOwned) return undefined;
|
|
1959
1978
|
|
|
1960
1979
|
const [fnArg, nameArg] = init.arguments;
|
|
1961
1980
|
if (!fnArg || (!ts.isArrowFunction(fnArg) && !ts.isFunctionExpression(fnArg))) return undefined;
|
|
@@ -1963,7 +1982,7 @@ function findCompositeDefinition(
|
|
|
1963
1982
|
// COR017 requires the literal in practice; anything that is not a plain
|
|
1964
1983
|
// string literal is not something to guess at.
|
|
1965
1984
|
if (nameArg !== undefined && !ts.isStringLiteral(nameArg)) return undefined;
|
|
1966
|
-
return { fn: fnArg, compositeName: nameArg ? nameArg.text : "anonymous" };
|
|
1985
|
+
return { fn: fnArg, compositeName: nameArg ? nameArg.text : "anonymous", hostForm: !chantOwned };
|
|
1967
1986
|
}
|
|
1968
1987
|
}
|
|
1969
1988
|
return undefined;
|
|
@@ -2011,7 +2030,7 @@ async function resolveInterpretableFactory(
|
|
|
2011
2030
|
// Rules 3-5.
|
|
2012
2031
|
if (findFactorySubsetViolation(definition.fn) !== undefined) return undefined;
|
|
2013
2032
|
|
|
2014
|
-
return { scope, fn: definition.fn, compositeName: definition.compositeName };
|
|
2033
|
+
return { scope, fn: definition.fn, compositeName: definition.compositeName, hostForm: definition.hostForm };
|
|
2015
2034
|
}
|
|
2016
2035
|
|
|
2017
2036
|
/**
|
|
@@ -2365,10 +2384,17 @@ async function interpretCompositeFactory(
|
|
|
2365
2384
|
// one per module, as the run path has) is the single visible difference:
|
|
2366
2385
|
// `_id` is a fresh symbol, which nothing outside `CompositeRegistry` — used
|
|
2367
2386
|
// only by tests — reads.
|
|
2368
|
-
|
|
2369
|
-
|
|
2387
|
+
// chant#2442 — a HOST's registration form produces the host's own members,
|
|
2388
|
+
// so they are returned as the factory built them. Wrapping them in chant's
|
|
2389
|
+
// `Composite` would run chant's member validation, which asks for chant's
|
|
2390
|
+
// own `Declarable` and rejects an entity carrying a different marker —
|
|
2391
|
+
// rejecting it for not being chant's rather than for being malformed.
|
|
2392
|
+
// Chant's own form still goes through `Composite`, unchanged.
|
|
2393
|
+
const value = factory.hostForm
|
|
2394
|
+
? members
|
|
2395
|
+
: (Composite<void, CompositeMembers>(() => members as CompositeMembers, factory.compositeName))();
|
|
2370
2396
|
executionCounts.factoryInterpretations += 1;
|
|
2371
|
-
return { value
|
|
2397
|
+
return { value };
|
|
2372
2398
|
} catch (err) {
|
|
2373
2399
|
// Every other failure here means "this body did not interpret" and the
|
|
2374
2400
|
// caller invokes instead. Exhausting the depth bound means "we stopped
|