@phis/contracts 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.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +102 -0
- package/dist/access.d.ts +115 -0
- package/dist/access.js +157 -0
- package/dist/addon-index.d.ts +6 -0
- package/dist/addon-index.js +6 -0
- package/dist/addon.d.ts +259 -0
- package/dist/addon.js +15 -0
- package/dist/capabilities.d.ts +240 -0
- package/dist/capabilities.js +37 -0
- package/dist/core.d.ts +66 -0
- package/dist/core.js +70 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/media-storage.d.ts +160 -0
- package/dist/media-storage.js +9 -0
- package/dist/queries.d.ts +171 -0
- package/dist/queries.js +16 -0
- package/dist/schema.d.ts +173 -0
- package/dist/schema.js +29 -0
- package/dist/signals.d.ts +36 -0
- package/dist/signals.js +85 -0
- package/package.json +52 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signal vocabulary phi-server and the site UI must both know.
|
|
3
|
+
*
|
|
4
|
+
* A widget declares what it emits and listens for; the Builder stores that wiring; phi-server validates
|
|
5
|
+
* it on the way in. Two sides, one list -- and when they were two lists, they drifted: `@phis/ui` had
|
|
6
|
+
* grown `date`, `time` and `length`, phi-server had not, and a length control's change signal was
|
|
7
|
+
* rejected on save with "valueType is invalid". Nothing was wrong with either list on its own.
|
|
8
|
+
*
|
|
9
|
+
* Only the closed vocabularies and the value-schema format live here. Which schemas exist is a catalogue
|
|
10
|
+
* of widget shapes that belongs to the UI: phi-server checks that a JSON signal names *a* schema, never
|
|
11
|
+
* which one, so the catalogue is not something the two must agree on.
|
|
12
|
+
*/
|
|
13
|
+
export declare const PHI_SIGNAL_SCOPES: readonly ["widget", "layout", "region", "page", "area", "site"];
|
|
14
|
+
export type PhiSignalScope = (typeof PHI_SIGNAL_SCOPES)[number];
|
|
15
|
+
export declare const PHI_SIGNAL_ACTIONS: readonly ["activate", "change", "toggle", "start", "stop", "clear", "open", "close", "reload", "flush", "filter", "drop"];
|
|
16
|
+
export type PhiSignalAction = (typeof PHI_SIGNAL_ACTIONS)[number];
|
|
17
|
+
export declare const PHI_SIGNAL_VALUE_TYPES: readonly ["none", "boolean", "string", "number", "date", "time", "enum", "color", "path", "length", "size", "image", "icon", "string[]", "number[]", "enum[]", "json"];
|
|
18
|
+
export type PhiSignalValueType = (typeof PHI_SIGNAL_VALUE_TYPES)[number];
|
|
19
|
+
export declare const PHI_SIGNAL_VALUE_SCHEMA_NAMESPACE = "signals";
|
|
20
|
+
export declare const PHI_SIGNAL_VALUE_SCHEMA_SEPARATOR = "/";
|
|
21
|
+
/** `<package name>/signals/<schema key>` -- who defined it, and which of theirs it is. */
|
|
22
|
+
export type PhiSignalValueSchema = `${string}/${typeof PHI_SIGNAL_VALUE_SCHEMA_NAMESPACE}/${string}`;
|
|
23
|
+
export declare function isPhiSignalScope(value: unknown): value is PhiSignalScope;
|
|
24
|
+
export declare function isPhiSignalAction(value: unknown): value is PhiSignalAction;
|
|
25
|
+
export declare function isPhiSignalValueType(value: unknown): value is PhiSignalValueType;
|
|
26
|
+
/**
|
|
27
|
+
* Whether a string is shaped like a value schema at all.
|
|
28
|
+
*
|
|
29
|
+
* Shape, and deliberately not membership. The site UI can ask the stricter question -- it holds the
|
|
30
|
+
* module registry and checks that the package part names a module it knows. phi-server holds no such
|
|
31
|
+
* registry and must not: refusing a schema because it had never heard of the package would refuse every
|
|
32
|
+
* third party's. So the two ask different questions, and this is the one both can ask.
|
|
33
|
+
*
|
|
34
|
+
* The last separator wins, because a scoped package name contains one too.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isPhiSignalValueSchemaShape(value: unknown): value is PhiSignalValueSchema;
|
package/dist/signals.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signal vocabulary phi-server and the site UI must both know.
|
|
3
|
+
*
|
|
4
|
+
* A widget declares what it emits and listens for; the Builder stores that wiring; phi-server validates
|
|
5
|
+
* it on the way in. Two sides, one list -- and when they were two lists, they drifted: `@phis/ui` had
|
|
6
|
+
* grown `date`, `time` and `length`, phi-server had not, and a length control's change signal was
|
|
7
|
+
* rejected on save with "valueType is invalid". Nothing was wrong with either list on its own.
|
|
8
|
+
*
|
|
9
|
+
* Only the closed vocabularies and the value-schema format live here. Which schemas exist is a catalogue
|
|
10
|
+
* of widget shapes that belongs to the UI: phi-server checks that a JSON signal names *a* schema, never
|
|
11
|
+
* which one, so the catalogue is not something the two must agree on.
|
|
12
|
+
*/
|
|
13
|
+
export const PHI_SIGNAL_SCOPES = [
|
|
14
|
+
"widget",
|
|
15
|
+
"layout",
|
|
16
|
+
"region",
|
|
17
|
+
"page",
|
|
18
|
+
"area",
|
|
19
|
+
"site",
|
|
20
|
+
];
|
|
21
|
+
export const PHI_SIGNAL_ACTIONS = [
|
|
22
|
+
"activate",
|
|
23
|
+
"change",
|
|
24
|
+
"toggle",
|
|
25
|
+
"start",
|
|
26
|
+
"stop",
|
|
27
|
+
"clear",
|
|
28
|
+
"open",
|
|
29
|
+
"close",
|
|
30
|
+
"reload",
|
|
31
|
+
"flush",
|
|
32
|
+
"filter",
|
|
33
|
+
"drop",
|
|
34
|
+
];
|
|
35
|
+
export const PHI_SIGNAL_VALUE_TYPES = [
|
|
36
|
+
"none",
|
|
37
|
+
"boolean",
|
|
38
|
+
"string",
|
|
39
|
+
"number",
|
|
40
|
+
"date",
|
|
41
|
+
"time",
|
|
42
|
+
"enum",
|
|
43
|
+
"color",
|
|
44
|
+
"path",
|
|
45
|
+
"length",
|
|
46
|
+
"size",
|
|
47
|
+
"image",
|
|
48
|
+
"icon",
|
|
49
|
+
"string[]",
|
|
50
|
+
"number[]",
|
|
51
|
+
"enum[]",
|
|
52
|
+
"json",
|
|
53
|
+
];
|
|
54
|
+
export const PHI_SIGNAL_VALUE_SCHEMA_NAMESPACE = "signals";
|
|
55
|
+
export const PHI_SIGNAL_VALUE_SCHEMA_SEPARATOR = "/";
|
|
56
|
+
export function isPhiSignalScope(value) {
|
|
57
|
+
return typeof value === "string" && PHI_SIGNAL_SCOPES.includes(value);
|
|
58
|
+
}
|
|
59
|
+
export function isPhiSignalAction(value) {
|
|
60
|
+
return typeof value === "string" && PHI_SIGNAL_ACTIONS.includes(value);
|
|
61
|
+
}
|
|
62
|
+
export function isPhiSignalValueType(value) {
|
|
63
|
+
return typeof value === "string" && PHI_SIGNAL_VALUE_TYPES.includes(value);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Whether a string is shaped like a value schema at all.
|
|
67
|
+
*
|
|
68
|
+
* Shape, and deliberately not membership. The site UI can ask the stricter question -- it holds the
|
|
69
|
+
* module registry and checks that the package part names a module it knows. phi-server holds no such
|
|
70
|
+
* registry and must not: refusing a schema because it had never heard of the package would refuse every
|
|
71
|
+
* third party's. So the two ask different questions, and this is the one both can ask.
|
|
72
|
+
*
|
|
73
|
+
* The last separator wins, because a scoped package name contains one too.
|
|
74
|
+
*/
|
|
75
|
+
export function isPhiSignalValueSchemaShape(value) {
|
|
76
|
+
if (typeof value !== "string") {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
const marker = value.lastIndexOf(`${PHI_SIGNAL_VALUE_SCHEMA_SEPARATOR}${PHI_SIGNAL_VALUE_SCHEMA_NAMESPACE}${PHI_SIGNAL_VALUE_SCHEMA_SEPARATOR}`);
|
|
80
|
+
if (marker <= 0) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const leaf = value.slice(marker + PHI_SIGNAL_VALUE_SCHEMA_NAMESPACE.length + PHI_SIGNAL_VALUE_SCHEMA_SEPARATOR.length * 2);
|
|
84
|
+
return leaf.length > 0 && !leaf.includes(PHI_SIGNAL_VALUE_SCHEMA_SEPARATOR);
|
|
85
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@phis/contracts",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"description": "The agreements phi-server keeps with what surrounds it: the Add-on ABI, and the authorization vocabulary it shares with the site UI.",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc -p tsconfig.build.json",
|
|
13
|
+
"typecheck": "tsc --noEmit",
|
|
14
|
+
"lint": "eslint src",
|
|
15
|
+
"prepack": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
"./addon": {
|
|
19
|
+
"types": "./dist/addon-index.d.ts",
|
|
20
|
+
"import": "./dist/addon-index.js",
|
|
21
|
+
"default": "./dist/addon-index.js"
|
|
22
|
+
},
|
|
23
|
+
"./access": {
|
|
24
|
+
"types": "./dist/access.d.ts",
|
|
25
|
+
"import": "./dist/access.js",
|
|
26
|
+
"default": "./dist/access.js"
|
|
27
|
+
},
|
|
28
|
+
"./signals": {
|
|
29
|
+
"types": "./dist/signals.d.ts",
|
|
30
|
+
"import": "./dist/signals.js",
|
|
31
|
+
"default": "./dist/signals.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"NOTICE"
|
|
37
|
+
],
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^24.0.0",
|
|
40
|
+
"eslint": "^10.9.1",
|
|
41
|
+
"typescript": "^6.0.3",
|
|
42
|
+
"typescript-eslint": "^8.68.0"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/phis-dev/phis-contracts.git"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/phis-dev/phis-contracts#readme",
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/phis-dev/phis-contracts/issues"
|
|
51
|
+
}
|
|
52
|
+
}
|