Skip to content

Commit

Permalink
trust: generalize callable in versec printer
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed Mar 28, 2024
1 parent 4e89b5d commit c84be6f
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 37 deletions.
4 changes: 2 additions & 2 deletions integ/browser-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"@types/webpack": "^5.28.5",
"fork-ts-checker-webpack-plugin": "^9.0.2",
"html-webpack-plugin": "^5.6.0",
"puppeteer": "^22.6.0",
"puppeteer": "^22.6.1",
"ts-loader": "^9.5.1",
"tslib": "^2.6.2",
"type-fest": "^4.13.1",
"type-fest": "^4.14.0",
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4"
Expand Down
2 changes: 1 addition & 1 deletion mk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"js-yaml": "^4.1.0",
"readlink": "^3.0.0",
"split2": "^4.2.0",
"type-fest": "^4.13.1"
"type-fest": "^4.14.0"
},
"dependencies": {
"compare-versions": "6.1.0"
Expand Down
2 changes: 1 addition & 1 deletion pkg/autoconfig/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
"@types/default-gateway": "^7.2.2",
"@types/koa": "^2.15.0",
"koa": "^2.15.2",
"type-fest": "^4.13.1"
"type-fest": "^4.14.0"
}
}
2 changes: 1 addition & 1 deletion pkg/keychain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"idb-keyval": "^6.2.1",
"mnemonist": "^0.39.8",
"tslib": "^2.6.2",
"type-fest": "^4.13.1",
"type-fest": "^4.14.0",
"wait-your-turn": "^1.0.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion pkg/l3face/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"retry": "^0.13.1",
"streaming-iterables": "^8.0.1",
"tslib": "^2.6.2",
"type-fest": "^4.13.1",
"type-fest": "^4.14.0",
"typescript-event-target": "^1.1.0"
}
}
2 changes: 1 addition & 1 deletion pkg/nac/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@yoursunny/asn1": "0.0.20200718",
"mnemonist": "^0.39.8",
"tslib": "^2.6.2",
"type-fest": "^4.13.1"
"type-fest": "^4.14.0"
},
"devDependencies": {
"@ndn/l3face": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion pkg/ndncert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"nodemailer": "^6.9.13",
"p-timeout": "^6.1.2",
"tslib": "^2.6.2",
"type-fest": "^4.13.1",
"type-fest": "^4.14.0",
"typescript-event-target": "^1.1.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion pkg/nfdmgmt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"devDependencies": {
"@ndn/l3face": "workspace:*",
"@ndn/node-transport": "workspace:*",
"type-fest": "^4.13.1",
"type-fest": "^4.14.0",
"typescript-event-target": "^1.1.0"
}
}
2 changes: 1 addition & 1 deletion pkg/node-transport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"event-iterator": "^2.0.0",
"p-event": "^6.0.1",
"tslib": "^2.6.2",
"type-fest": "^4.13.1",
"type-fest": "^4.14.0",
"url-format-lax": "^2.0.0",
"url-parse-lax": "^5.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/packet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"buffer-compare": "^1.1.1",
"mnemonist": "^0.39.8",
"tslib": "^2.6.2",
"type-fest": "^4.13.1"
"type-fest": "^4.14.0"
},
"devDependencies": {
"@types/buffer-compare": "^0.0.33"
Expand Down
2 changes: 1 addition & 1 deletion pkg/pyrepo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"p-defer": "^4.0.0",
"streaming-iterables": "^8.0.1",
"tslib": "^2.6.2",
"type-fest": "^4.13.1",
"type-fest": "^4.14.0",
"typescript-event-target": "^1.1.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion pkg/repo-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
"devDependencies": {
"@ndn/node-transport": "workspace:*",
"stream-mock": "^2.0.5",
"type-fest": "^4.13.1"
"type-fest": "^4.14.0"
}
}
2 changes: 1 addition & 1 deletion pkg/repo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"memory-level": "^1.0.0",
"streaming-iterables": "^8.0.1",
"tslib": "^2.6.2",
"type-fest": "^4.13.1",
"type-fest": "^4.14.0",
"typescript-event-target": "^1.1.0",
"wait-your-turn": "^1.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/segmented-object/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"@ndn/l3face": "workspace:*",
"@ndn/repo-api": "workspace:*",
"stream-mock": "^2.0.5",
"type-fest": "^4.13.1"
"type-fest": "^4.14.0"
}
}
2 changes: 1 addition & 1 deletion pkg/svs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@ndn/util": "workspace:*",
"streaming-iterables": "^8.0.1",
"tslib": "^2.6.2",
"type-fest": "^4.13.1",
"type-fest": "^4.14.0",
"typescript-event-target": "^1.1.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion pkg/tlv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"@ndn/util": "workspace:*",
"mnemonist": "^0.39.8",
"tslib": "^2.6.2",
"type-fest": "^4.13.1"
"type-fest": "^4.14.0"
}
}
2 changes: 1 addition & 1 deletion pkg/trust-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"mnemonist": "^0.39.8",
"obliterator": "^2.0.4",
"tslib": "^2.6.2",
"type-fest": "^4.13.1"
"type-fest": "^4.14.0"
},
"devDependencies": {
"@ndn/l3face": "workspace:^",
Expand Down
4 changes: 3 additions & 1 deletion pkg/trust-schema/src/schema/versec/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ class Compiler {
}
return new VariablePattern(
callable.asVariable ? expr.func.toUpperCase() : this.makeAutoId(), {
filter: callable.makeFilter?.(...expr.args),
filter: callable.makeFilter ?
new F.FunctionFilter(expr, callable.makeFilter(...expr.args)) :
undefined,
});
}

Expand Down
17 changes: 14 additions & 3 deletions pkg/trust-schema/src/schema/versec/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export interface Callable {
}

/** A filter that matches {@link Timestamp} convention. */
export const timestamp = new VariablePattern.ConventionFilter(Timestamp);
const timestamp = new VariablePattern.ConventionFilter(Timestamp);

/** A filter that matches {@link SequenceNum} convention. */
export const seq = new VariablePattern.ConventionFilter(SequenceNum);
const seq = new VariablePattern.ConventionFilter(SequenceNum);

export const builtinFunctions: Record<string, Callable> = {
sysid: { nargs: 0, asVariable: true },
Expand All @@ -33,6 +33,17 @@ export const builtinFunctions: Record<string, Callable> = {
},
};

export class FunctionFilter implements VariablePattern.Filter {
constructor(
public readonly callExpr: A.Call,
public readonly inner: VariablePattern.Filter,
) {}

public accept(name: Name, vars: Vars) {
return this.inner.accept(name, vars);
}
}

/** A filter from a component constraint term. */
export class ConstraintTerm implements VariablePattern.Filter {
constructor(public readonly id: string, public readonly pattern: Pattern) {}
Expand Down Expand Up @@ -67,7 +78,7 @@ export function simplify(filter: VariablePattern.Filter): VariablePattern.Filter

/**
* Simplify a filter.
* @param allow - Allow set. Terms not in allow set are deleted.
* @param allow - Allow set. Terms not in allow set are deleted.
*/
export function simplify(filter: VariablePattern.Filter, allow: ReadonlySet<string> | undefined): VariablePattern.Filter | undefined;

Expand Down
29 changes: 15 additions & 14 deletions pkg/trust-schema/src/schema/versec/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class Printer {
}

private translateVariablePattern(p: VariablePattern): A.Expr {
let name: A.Name | A.Ident = new A.Ident(p.id);
const ident = new A.Ident(p.id);
let name: A.Name | A.Ident = ident;
if (p.inner) {
const inner = this.translatePattern(p.inner);
if (inner instanceof A.Name || inner instanceof A.Ident) {
Expand All @@ -58,29 +59,29 @@ class Printer {
}
}

switch (p.filter) {
case undefined: {
return name;
}
case F.timestamp: {
return new A.Call("timestamp");
}
case F.seq: {
return new A.Call("seq");
}
if (p.filter === undefined) {
return name;
}
if (!A.Ident.isRuntime(p.id) && p.filter instanceof F.FunctionFilter) {
return p.filter.callExpr;
}
return new A.Constrained(name, this.translateFilter(p.filter));
return new A.Constrained(name, this.translateFilter(p.filter, ident));
}

private translateFilter(f: VariablePattern.Filter): A.ComponentConstraintEq {
private translateFilter(f: VariablePattern.Filter, parentIdent: A.Ident): A.ComponentConstraintEq {
if (f instanceof F.FunctionFilter) {
return new A.ComponentConstraint([
new A.ComponentConstraintTerm(parentIdent, f.callExpr),
]);
}
if (f instanceof F.ConstraintTerm) {
return new A.ComponentConstraint([
new A.ComponentConstraintTerm(new A.Ident(f.id), this.translatePattern(f.pattern)),
]);
}
if (f instanceof F.And || f instanceof F.Or) {
const op = f instanceof F.And ? new T.And() : new T.Or();
return f.filters.map((sub) => this.translateFilter(sub))
return f.filters.map((sub) => this.translateFilter(sub, parentIdent))
.reduce((left, right) => new A.ComponentConstraintRel(left, op, right));
}
return new A.ComponentConstraint([
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"minimalistic-assert": "^1.0.1",
"streaming-iterables": "^8.0.1",
"tslib": "^2.6.2",
"type-fest": "^4.13.1",
"type-fest": "^4.14.0",
"wait-your-turn": "^1.0.1"
},
"devDependencies": {
Expand Down

0 comments on commit c84be6f

Please sign in to comment.