@clegra/sdk 0.0.0-stage → 0.1.0-next.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/CHANGELOG.md +152 -0
- package/LICENSE +21 -0
- package/NOTICE.md +25 -0
- package/README.md +258 -2
- package/dist/spec/kinds.json +211 -0
- package/dist/spec/schema/clegra.schema.json +1249 -0
- package/dist/spec/src/cli.d.ts +2 -0
- package/dist/spec/src/cli.js +21 -0
- package/dist/spec/src/cli.js.map +1 -0
- package/dist/spec/src/conformance.d.ts +34 -0
- package/dist/spec/src/conformance.js +703 -0
- package/dist/spec/src/conformance.js.map +1 -0
- package/dist/spec/src/init/index.d.ts +31 -0
- package/dist/spec/src/init/index.js +151 -0
- package/dist/spec/src/init/index.js.map +1 -0
- package/dist/spec/src/init/next-config.d.ts +19 -0
- package/dist/spec/src/init/next-config.js +77 -0
- package/dist/spec/src/init/next-config.js.map +1 -0
- package/dist/spec/src/init/project.d.ts +44 -0
- package/dist/spec/src/init/project.js +141 -0
- package/dist/spec/src/init/project.js.map +1 -0
- package/dist/spec/src/init/templates.d.ts +20 -0
- package/dist/spec/src/init/templates.js +166 -0
- package/dist/spec/src/init/templates.js.map +1 -0
- package/dist/spec/src/init/ui.d.ts +30 -0
- package/dist/spec/src/init/ui.js +82 -0
- package/dist/spec/src/init/ui.js.map +1 -0
- package/dist/spec/src/kinds.d.ts +89 -0
- package/dist/spec/src/kinds.js +319 -0
- package/dist/spec/src/kinds.js.map +1 -0
- package/dist/spec/src/protocol.d.ts +50 -0
- package/dist/spec/src/protocol.js +52 -0
- package/dist/spec/src/protocol.js.map +1 -0
- package/dist/spec/src/rules.d.ts +132 -0
- package/dist/spec/src/rules.js +282 -0
- package/dist/spec/src/rules.js.map +1 -0
- package/dist/src/auth.d.ts +371 -0
- package/dist/src/auth.js +964 -0
- package/dist/src/auth.js.map +1 -0
- package/dist/src/define.d.ts +249 -0
- package/dist/src/define.js +83 -0
- package/dist/src/define.js.map +1 -0
- package/dist/src/embed.d.ts +98 -0
- package/dist/src/embed.js +256 -0
- package/dist/src/embed.js.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +11 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/labels.d.ts +10 -0
- package/dist/src/labels.js +22 -0
- package/dist/src/labels.js.map +1 -0
- package/dist/src/manifest.d.ts +499 -0
- package/dist/src/manifest.js +188 -0
- package/dist/src/manifest.js.map +1 -0
- package/dist/src/meaning.d.ts +64 -0
- package/dist/src/meaning.js +116 -0
- package/dist/src/meaning.js.map +1 -0
- package/dist/src/next/index.d.ts +101 -0
- package/dist/src/next/index.js +187 -0
- package/dist/src/next/index.js.map +1 -0
- package/dist/src/node.d.ts +14 -0
- package/dist/src/node.js +64 -0
- package/dist/src/node.js.map +1 -0
- package/dist/src/server.d.ts +229 -0
- package/dist/src/server.js +2256 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/store.d.ts +129 -0
- package/dist/src/store.js +213 -0
- package/dist/src/store.js.map +1 -0
- package/dist/src/testing.d.ts +133 -0
- package/dist/src/testing.js +81 -0
- package/dist/src/testing.js.map +1 -0
- package/dist/src/types.d.ts +352 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/view.d.ts +35 -0
- package/dist/src/view.js +442 -0
- package/dist/src/view.js.map +1 -0
- package/docs/quickstart.md +350 -0
- package/docs/spec.md +997 -0
- package/package.json +89 -4
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KINDS (spec §3.1): what an entity is, the same in every app. The vocabulary
|
|
3
|
+
* of this spec version (published as `spec/kinds.json`, written from this file
|
|
4
|
+
* by `npm run schema`) and the rules every manifest is checked against. The SDK
|
|
5
|
+
* (at definition time) and the conformance checks (from outside) use the same
|
|
6
|
+
* functions, so the two never disagree. No dependencies.
|
|
7
|
+
*/
|
|
8
|
+
/** What a property holds. `date`: an RFC 3339 date or date-time string; `address`: a string or a schema.org PostalAddress object; `money`: a number whose field names its `currency`. */
|
|
9
|
+
export declare const PROPERTY_TYPES: readonly ["string", "number", "boolean", "date", "address", "money"];
|
|
10
|
+
export type PropertyType = (typeof PROPERTY_TYPES)[number];
|
|
11
|
+
/** How a key's values are compared (spec §3.1 rule 5). */
|
|
12
|
+
export type Normalisation = "lowercase" | "uppercase-no-spaces" | "digits" | "exact";
|
|
13
|
+
export type PropertyDef = {
|
|
14
|
+
type: PropertyType;
|
|
15
|
+
many?: boolean;
|
|
16
|
+
key?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type StandardProperty = PropertyDef & {
|
|
19
|
+
normalise?: Normalisation;
|
|
20
|
+
};
|
|
21
|
+
export type KindDef = {
|
|
22
|
+
label: Record<string, string>;
|
|
23
|
+
properties: Record<string, PropertyDef>;
|
|
24
|
+
};
|
|
25
|
+
export type StandardKind = {
|
|
26
|
+
label: Record<string, string>;
|
|
27
|
+
properties: Record<string, StandardProperty>;
|
|
28
|
+
required: string[];
|
|
29
|
+
};
|
|
30
|
+
/** The seven kinds of 1.0. Property names are schema.org's, verbatim (JSCalendar's where schema.org has none: `due`, `uid`). */
|
|
31
|
+
export declare const KINDS: Record<string, StandardKind>;
|
|
32
|
+
/** Properties any entity MAY mark, with or without a kind. On a kind that defines the same name (`url` of organization and document), the kind's meaning applies. */
|
|
33
|
+
export declare const UNIVERSAL: Record<string, PropertyDef>;
|
|
34
|
+
/** Reserved for later versions: not kinds of 1.0, and no app may use them. */
|
|
35
|
+
export declare const RESERVED_KINDS: readonly ["message", "place", "invoice", "project"];
|
|
36
|
+
/** A third party's kind: reverse-DNS under a domain it controls, at least one dot (`com.acme.shipment`). */
|
|
37
|
+
export declare const NAMESPACED_KIND: RegExp;
|
|
38
|
+
/** A property name of a namespaced kind. */
|
|
39
|
+
export declare const PROPERTY_NAME: RegExp;
|
|
40
|
+
/** A record URI, `clegra://<app>/<entity>/<id>` (spec §3): what a cross-app reference holds. */
|
|
41
|
+
export declare const RECORD_URI: RegExp;
|
|
42
|
+
/** The published vocabulary (`spec/kinds.json`). */
|
|
43
|
+
export declare function kindsDocument(specVersion: string): {
|
|
44
|
+
specVersion: string;
|
|
45
|
+
kinds: Record<string, StandardKind>;
|
|
46
|
+
universal: Record<string, PropertyDef>;
|
|
47
|
+
reserved: ("message" | "place" | "invoice" | "project")[];
|
|
48
|
+
};
|
|
49
|
+
export type EntityKind = string | {
|
|
50
|
+
by: string;
|
|
51
|
+
map: Record<string, string>;
|
|
52
|
+
};
|
|
53
|
+
/** The kinds an entity's records can have, in declaration order, without repeats. */
|
|
54
|
+
export declare function kindsOf(kind: EntityKind | undefined): string[];
|
|
55
|
+
/** The kind of one record (null: the record has none, e.g. an unmapped value). */
|
|
56
|
+
export declare function kindOfRecord(kind: EntityKind | undefined, row: Record<string, unknown>): string | null;
|
|
57
|
+
/** The fixed sentence that ends an entity tool's description (spec §6): `Kind: person.`, `Kind: organization or person (by type).` */
|
|
58
|
+
export declare function kindSentence(kind: EntityKind): string;
|
|
59
|
+
/** What is wrong with a kind name (null: nothing). */
|
|
60
|
+
export declare function kindNameProblem(name: unknown): string | null;
|
|
61
|
+
/** The definition of a property on any of these kinds, or a universal one (undefined: none). */
|
|
62
|
+
export declare function propertyOf(property: string, kinds: string[], own?: Record<string, KindDef>): PropertyDef | undefined;
|
|
63
|
+
/** What is wrong with one value of a property (null: nothing). `email` an addr-spec; `vatID` the country prefix and number, no spaces; `gtin` 8, 12, 13 or 14 digits; dates RFC 3339; `address` a string or a PostalAddress. */
|
|
64
|
+
export declare function valueProblem(property: string, def: PropertyDef, value: unknown): string | null;
|
|
65
|
+
/** How a key property's values are compared; null when the property is not a key of any of these kinds. */
|
|
66
|
+
export declare function keyOf(property: string, kinds: string[], own?: Record<string, KindDef>): Normalisation | null;
|
|
67
|
+
/** A key value as it is compared (spec §3.1 rule 5); null when it can't be one (a gtin with letters). */
|
|
68
|
+
export declare function normaliseKey(value: string, how: Normalisation): string | null;
|
|
69
|
+
/** A field as the rules need it: the manifest's keys, and the item type of an array (from the entity's JSON Schema). */
|
|
70
|
+
export type KindField = {
|
|
71
|
+
name: string;
|
|
72
|
+
type: string;
|
|
73
|
+
required: boolean;
|
|
74
|
+
enum?: string[];
|
|
75
|
+
permission?: string;
|
|
76
|
+
as?: string;
|
|
77
|
+
filter?: boolean;
|
|
78
|
+
currency?: string;
|
|
79
|
+
itemType?: string;
|
|
80
|
+
};
|
|
81
|
+
/** What is wrong with an app's own kind definitions (`kinds` in the manifest). */
|
|
82
|
+
export declare function kindDefinitionProblems(own: Record<string, KindDef> | undefined): string[];
|
|
83
|
+
/**
|
|
84
|
+
* What is wrong with one entity's kind and its fields' `as` (spec §3.1 rules 1–5). `where` prefixes every problem.
|
|
85
|
+
* The same list is a definition error in the SDK and a failed check in conformance.
|
|
86
|
+
*/
|
|
87
|
+
export declare function entityKindProblems(where: string, kind: EntityKind | undefined, fields: KindField[], own?: Record<string, KindDef>, options?: {
|
|
88
|
+
names?: boolean;
|
|
89
|
+
}): string[];
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KINDS (spec §3.1): what an entity is, the same in every app. The vocabulary
|
|
3
|
+
* of this spec version (published as `spec/kinds.json`, written from this file
|
|
4
|
+
* by `npm run schema`) and the rules every manifest is checked against. The SDK
|
|
5
|
+
* (at definition time) and the conformance checks (from outside) use the same
|
|
6
|
+
* functions, so the two never disagree. No dependencies.
|
|
7
|
+
*/
|
|
8
|
+
import { URI_SCHEME } from "./protocol.js";
|
|
9
|
+
/** What a property holds. `date`: an RFC 3339 date or date-time string; `address`: a string or a schema.org PostalAddress object; `money`: a number whose field names its `currency`. */
|
|
10
|
+
export const PROPERTY_TYPES = ["string", "number", "boolean", "date", "address", "money"];
|
|
11
|
+
/** The seven kinds of 1.0. Property names are schema.org's, verbatim (JSCalendar's where schema.org has none: `due`, `uid`). */
|
|
12
|
+
export const KINDS = {
|
|
13
|
+
person: {
|
|
14
|
+
label: { en: "Person", it: "Persona" },
|
|
15
|
+
properties: {
|
|
16
|
+
givenName: { type: "string" },
|
|
17
|
+
familyName: { type: "string" },
|
|
18
|
+
email: { type: "string", many: true, key: true, normalise: "lowercase" },
|
|
19
|
+
telephone: { type: "string", many: true },
|
|
20
|
+
jobTitle: { type: "string" },
|
|
21
|
+
worksFor: { type: "string" },
|
|
22
|
+
address: { type: "address" },
|
|
23
|
+
image: { type: "string" },
|
|
24
|
+
},
|
|
25
|
+
required: [],
|
|
26
|
+
},
|
|
27
|
+
organization: {
|
|
28
|
+
label: { en: "Organization", it: "Organizzazione" },
|
|
29
|
+
properties: {
|
|
30
|
+
legalName: { type: "string" },
|
|
31
|
+
email: { type: "string", many: true },
|
|
32
|
+
telephone: { type: "string", many: true },
|
|
33
|
+
url: { type: "string" },
|
|
34
|
+
address: { type: "address" },
|
|
35
|
+
vatID: { type: "string", key: true, normalise: "uppercase-no-spaces" },
|
|
36
|
+
taxID: { type: "string" },
|
|
37
|
+
},
|
|
38
|
+
required: [],
|
|
39
|
+
},
|
|
40
|
+
event: {
|
|
41
|
+
label: { en: "Event", it: "Evento" },
|
|
42
|
+
properties: {
|
|
43
|
+
startDate: { type: "date" },
|
|
44
|
+
endDate: { type: "date" },
|
|
45
|
+
location: { type: "address" },
|
|
46
|
+
attendee: { type: "string", many: true },
|
|
47
|
+
organizer: { type: "string" },
|
|
48
|
+
uid: { type: "string", key: true, normalise: "exact" },
|
|
49
|
+
},
|
|
50
|
+
required: ["startDate"],
|
|
51
|
+
},
|
|
52
|
+
task: {
|
|
53
|
+
label: { en: "Task", it: "Attività" },
|
|
54
|
+
properties: {
|
|
55
|
+
due: { type: "date" },
|
|
56
|
+
startDate: { type: "date" },
|
|
57
|
+
completed: { type: "boolean" },
|
|
58
|
+
assignee: { type: "string" },
|
|
59
|
+
},
|
|
60
|
+
required: [],
|
|
61
|
+
},
|
|
62
|
+
document: {
|
|
63
|
+
label: { en: "Document", it: "Documento" },
|
|
64
|
+
properties: {
|
|
65
|
+
url: { type: "string" },
|
|
66
|
+
encodingFormat: { type: "string" },
|
|
67
|
+
author: { type: "string" },
|
|
68
|
+
contentSize: { type: "string" },
|
|
69
|
+
},
|
|
70
|
+
required: [],
|
|
71
|
+
},
|
|
72
|
+
product: {
|
|
73
|
+
label: { en: "Product", it: "Prodotto" },
|
|
74
|
+
properties: {
|
|
75
|
+
sku: { type: "string" },
|
|
76
|
+
gtin: { type: "string", key: true, normalise: "digits" },
|
|
77
|
+
brand: { type: "string" },
|
|
78
|
+
price: { type: "money" },
|
|
79
|
+
},
|
|
80
|
+
required: [],
|
|
81
|
+
},
|
|
82
|
+
order: {
|
|
83
|
+
label: { en: "Order", it: "Ordine" },
|
|
84
|
+
properties: {
|
|
85
|
+
orderNumber: { type: "string" },
|
|
86
|
+
orderDate: { type: "date" },
|
|
87
|
+
customer: { type: "string" },
|
|
88
|
+
totalPrice: { type: "money" },
|
|
89
|
+
},
|
|
90
|
+
required: [],
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
/** Properties any entity MAY mark, with or without a kind. On a kind that defines the same name (`url` of organization and document), the kind's meaning applies. */
|
|
94
|
+
export const UNIVERSAL = {
|
|
95
|
+
url: { type: "string" },
|
|
96
|
+
dateCreated: { type: "date" },
|
|
97
|
+
dateModified: { type: "date" },
|
|
98
|
+
};
|
|
99
|
+
/** Reserved for later versions: not kinds of 1.0, and no app may use them. */
|
|
100
|
+
export const RESERVED_KINDS = ["message", "place", "invoice", "project"];
|
|
101
|
+
/** A third party's kind: reverse-DNS under a domain it controls, at least one dot (`com.acme.shipment`). */
|
|
102
|
+
export const NAMESPACED_KIND = /^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/;
|
|
103
|
+
/** A property name of a namespaced kind. */
|
|
104
|
+
export const PROPERTY_NAME = /^[a-z][A-Za-z0-9]{0,63}$/;
|
|
105
|
+
/** A record URI, `clegra://<app>/<entity>/<id>` (spec §3): what a cross-app reference holds. */
|
|
106
|
+
export const RECORD_URI = new RegExp(`^${URI_SCHEME}://[a-z][a-z0-9-]{1,39}/[a-z][a-z0-9_]{0,39}/[^/?#\\s]+$`);
|
|
107
|
+
/** The published vocabulary (`spec/kinds.json`). */
|
|
108
|
+
export function kindsDocument(specVersion) {
|
|
109
|
+
return { specVersion, kinds: KINDS, universal: UNIVERSAL, reserved: [...RESERVED_KINDS] };
|
|
110
|
+
}
|
|
111
|
+
/** The kinds an entity's records can have, in declaration order, without repeats. */
|
|
112
|
+
export function kindsOf(kind) {
|
|
113
|
+
if (kind === undefined)
|
|
114
|
+
return [];
|
|
115
|
+
return typeof kind === "string" ? [kind] : [...new Set(Object.values(kind.map))];
|
|
116
|
+
}
|
|
117
|
+
/** The kind of one record (null: the record has none, e.g. an unmapped value). */
|
|
118
|
+
export function kindOfRecord(kind, row) {
|
|
119
|
+
if (kind === undefined)
|
|
120
|
+
return null;
|
|
121
|
+
if (typeof kind === "string")
|
|
122
|
+
return kind;
|
|
123
|
+
const value = row[kind.by];
|
|
124
|
+
return typeof value === "string" && Object.hasOwn(kind.map, value) ? kind.map[value] : null;
|
|
125
|
+
}
|
|
126
|
+
/** The fixed sentence that ends an entity tool's description (spec §6): `Kind: person.`, `Kind: organization or person (by type).` */
|
|
127
|
+
export function kindSentence(kind) {
|
|
128
|
+
const names = kindsOf(kind);
|
|
129
|
+
const list = names.length > 1 ? `${names.slice(0, -1).join(", ")} or ${names[names.length - 1]}` : names[0];
|
|
130
|
+
return typeof kind === "string" ? `Kind: ${list}.` : `Kind: ${list} (by ${kind.by}).`;
|
|
131
|
+
}
|
|
132
|
+
/** A kind's definition: the standard one, or the app's own for a namespaced kind (undefined: unknown). */
|
|
133
|
+
function definitionOf(name, own) {
|
|
134
|
+
if (Object.hasOwn(KINDS, name))
|
|
135
|
+
return KINDS[name];
|
|
136
|
+
if (NAMESPACED_KIND.test(name) && own && Object.hasOwn(own, name))
|
|
137
|
+
return { properties: own[name].properties, required: [] };
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
/** What is wrong with a kind name (null: nothing). */
|
|
141
|
+
export function kindNameProblem(name) {
|
|
142
|
+
if (typeof name !== "string")
|
|
143
|
+
return "a kind is a string";
|
|
144
|
+
if (RESERVED_KINDS.includes(name))
|
|
145
|
+
return `kind "${name}" is reserved, not defined in this version`;
|
|
146
|
+
if (Object.hasOwn(KINDS, name))
|
|
147
|
+
return null;
|
|
148
|
+
if (NAMESPACED_KIND.test(name))
|
|
149
|
+
return null;
|
|
150
|
+
return `kind "${name}" is not a kind of this specification (${Object.keys(KINDS).join(", ")}); a third party's kind has a dot (com.example.${name})`;
|
|
151
|
+
}
|
|
152
|
+
/** The definition of a property on any of these kinds, or a universal one (undefined: none). */
|
|
153
|
+
export function propertyOf(property, kinds, own) {
|
|
154
|
+
for (const k of kinds) {
|
|
155
|
+
const p = definitionOf(k, own)?.properties[property];
|
|
156
|
+
if (p)
|
|
157
|
+
return p;
|
|
158
|
+
}
|
|
159
|
+
return Object.hasOwn(UNIVERSAL, property) ? UNIVERSAL[property] : undefined;
|
|
160
|
+
}
|
|
161
|
+
// ------------------------------------------------------------------ values (spec §3.1 rule 4)
|
|
162
|
+
const POSTAL_ADDRESS = new Set(["@type", "streetAddress", "postOfficeBoxNumber", "addressLocality", "addressRegion", "postalCode", "addressCountry", "name"]);
|
|
163
|
+
const RFC3339 = /^\d{4}-\d{2}-\d{2}([Tt]\d{2}:\d{2}:\d{2}(\.\d+)?([Zz]|[+-]\d{2}:\d{2}))?$/;
|
|
164
|
+
/** What is wrong with one value of a property (null: nothing). `email` an addr-spec; `vatID` the country prefix and number, no spaces; `gtin` 8, 12, 13 or 14 digits; dates RFC 3339; `address` a string or a PostalAddress. */
|
|
165
|
+
export function valueProblem(property, def, value) {
|
|
166
|
+
if (value === null || value === undefined)
|
|
167
|
+
return null;
|
|
168
|
+
if (property === "email")
|
|
169
|
+
return typeof value === "string" && /^[^\s@]+@[^\s@]+$/.test(value) ? null : "not an email address";
|
|
170
|
+
if (property === "vatID")
|
|
171
|
+
return typeof value === "string" && /^[A-Za-z]{2}[0-9A-Za-z+*.]{2,13}$/.test(value) ? null : "not a VAT number (country prefix and number, no spaces)";
|
|
172
|
+
if (property === "gtin")
|
|
173
|
+
return typeof value === "string" && /^(\d{8}|\d{12}|\d{13}|\d{14})$/.test(value) ? null : "not a GTIN (8, 12, 13 or 14 digits)";
|
|
174
|
+
if (def.type === "date")
|
|
175
|
+
return typeof value === "string" && RFC3339.test(value) && !Number.isNaN(Date.parse(value.length === 10 ? `${value}T00:00:00Z` : value)) ? null : "not an RFC 3339 date or date-time";
|
|
176
|
+
if (def.type === "address")
|
|
177
|
+
return typeof value === "string" || (value && typeof value === "object" && !Array.isArray(value) && Object.keys(value).every((k) => POSTAL_ADDRESS.has(k))) ? null : "not an address (a string or a PostalAddress)";
|
|
178
|
+
if (def.type === "number" || def.type === "money")
|
|
179
|
+
return typeof value === "number" && Number.isFinite(value) ? null : "not a number";
|
|
180
|
+
if (def.type === "boolean")
|
|
181
|
+
return typeof value === "boolean" ? null : "not a boolean";
|
|
182
|
+
return typeof value === "string" ? null : "not a string";
|
|
183
|
+
}
|
|
184
|
+
/** How a key property's values are compared; null when the property is not a key of any of these kinds. */
|
|
185
|
+
export function keyOf(property, kinds, own) {
|
|
186
|
+
for (const k of kinds) {
|
|
187
|
+
const p = definitionOf(k, own)?.properties[property];
|
|
188
|
+
if (p?.key)
|
|
189
|
+
return p.normalise ?? "exact";
|
|
190
|
+
}
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
/** A key value as it is compared (spec §3.1 rule 5); null when it can't be one (a gtin with letters). */
|
|
194
|
+
export function normaliseKey(value, how) {
|
|
195
|
+
if (how === "lowercase")
|
|
196
|
+
return value.toLowerCase();
|
|
197
|
+
if (how === "uppercase-no-spaces")
|
|
198
|
+
return value.replace(/\s+/g, "").toUpperCase();
|
|
199
|
+
if (how === "digits") {
|
|
200
|
+
const digits = value.replace(/[\s-]+/g, "");
|
|
201
|
+
return /^\d+$/.test(digits) ? digits : null;
|
|
202
|
+
}
|
|
203
|
+
return value;
|
|
204
|
+
}
|
|
205
|
+
const fits = (t, field, many) => {
|
|
206
|
+
const one = (type) => {
|
|
207
|
+
if (t === "string" || t === "date")
|
|
208
|
+
return type === "string";
|
|
209
|
+
if (t === "number")
|
|
210
|
+
return type === "number" || type === "integer";
|
|
211
|
+
if (t === "money")
|
|
212
|
+
return (type === "number" || type === "integer") && typeof field.currency === "string" && field.currency.length > 0;
|
|
213
|
+
if (t === "boolean")
|
|
214
|
+
return type === "boolean";
|
|
215
|
+
return type === "string" || type === "object";
|
|
216
|
+
};
|
|
217
|
+
if (field.type === "array")
|
|
218
|
+
return many && (field.itemType === undefined ? t === "string" || t === "date" : one(field.itemType));
|
|
219
|
+
return one(field.type);
|
|
220
|
+
};
|
|
221
|
+
const typeName = (t, many) => `${t === "money" ? "a number with a currency" : t === "date" ? "a date string" : t === "address" ? "a string or an object" : `a ${t}`}${many ? " (or an array of them)" : ""}`;
|
|
222
|
+
/** What is wrong with an app's own kind definitions (`kinds` in the manifest). */
|
|
223
|
+
export function kindDefinitionProblems(own) {
|
|
224
|
+
const problems = [];
|
|
225
|
+
for (const [name, def] of Object.entries(own ?? {})) {
|
|
226
|
+
if (!NAMESPACED_KIND.test(name))
|
|
227
|
+
problems.push(`kinds: "${name}" is not a namespaced kind (com.example.thing); kinds without a dot are this specification's`);
|
|
228
|
+
if (!def || typeof def !== "object" || !def.properties || typeof def.properties !== "object") {
|
|
229
|
+
problems.push(`kinds: "${name}" needs properties`);
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
for (const [p, d] of Object.entries(def.properties)) {
|
|
233
|
+
if (!PROPERTY_NAME.test(p))
|
|
234
|
+
problems.push(`kinds: "${name}": property "${p}" is not a name ([a-z][A-Za-z0-9]*)`);
|
|
235
|
+
if (!d || !PROPERTY_TYPES.includes(d.type))
|
|
236
|
+
problems.push(`kinds: "${name}": property "${p}" needs a type, one of ${PROPERTY_TYPES.join(", ")}`);
|
|
237
|
+
else if (d.key && d.type !== "string")
|
|
238
|
+
problems.push(`kinds: "${name}": key "${p}" must be a string property`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return problems;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* What is wrong with one entity's kind and its fields' `as` (spec §3.1 rules 1–5). `where` prefixes every problem.
|
|
245
|
+
* The same list is a definition error in the SDK and a failed check in conformance.
|
|
246
|
+
*/
|
|
247
|
+
export function entityKindProblems(where, kind, fields, own, options = {}) {
|
|
248
|
+
const problems = [];
|
|
249
|
+
const kinds = [];
|
|
250
|
+
if (kind !== undefined) {
|
|
251
|
+
if (typeof kind === "string")
|
|
252
|
+
kinds.push(kind);
|
|
253
|
+
else if (!kind || typeof kind !== "object" || typeof kind.by !== "string" || !kind.map || typeof kind.map !== "object")
|
|
254
|
+
problems.push(`${where}: kind is a kind name or { by, map }`);
|
|
255
|
+
else {
|
|
256
|
+
const by = fields.find((f) => f.name === kind.by);
|
|
257
|
+
if (!by)
|
|
258
|
+
problems.push(`${where}: kind.by "${kind.by}" is not a field`);
|
|
259
|
+
else {
|
|
260
|
+
if (!by.required || !by.enum?.length)
|
|
261
|
+
problems.push(`${where}: kind.by "${kind.by}" must be a required enum field`);
|
|
262
|
+
if (by.permission)
|
|
263
|
+
problems.push(`${where}: kind.by "${kind.by}" can't have a permission (a record's kind is seen with the record)`);
|
|
264
|
+
for (const v of by.enum ?? [])
|
|
265
|
+
if (!Object.hasOwn(kind.map, v))
|
|
266
|
+
problems.push(`${where}: kind.map gives no kind for "${v}"`);
|
|
267
|
+
for (const v of Object.keys(kind.map))
|
|
268
|
+
if (by.enum && !by.enum.includes(v))
|
|
269
|
+
problems.push(`${where}: kind.map: "${v}" is not a value of ${kind.by}`);
|
|
270
|
+
}
|
|
271
|
+
kinds.push(...new Set(Object.values(kind.map)));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (options.names !== false)
|
|
275
|
+
for (const k of kinds) {
|
|
276
|
+
const p = kindNameProblem(k);
|
|
277
|
+
if (p)
|
|
278
|
+
problems.push(`${where}: ${p}`);
|
|
279
|
+
}
|
|
280
|
+
const defined = kinds.map((k) => ({ name: k, def: definitionOf(k, own) }));
|
|
281
|
+
const counts = new Map();
|
|
282
|
+
for (const f of fields) {
|
|
283
|
+
if (f.as === undefined)
|
|
284
|
+
continue;
|
|
285
|
+
const at = `${where}, field "${f.name}"`;
|
|
286
|
+
if (typeof f.as !== "string" || !f.as) {
|
|
287
|
+
problems.push(`${at}: as names a property`);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
const holders = defined.filter((d) => d.def && Object.hasOwn(d.def.properties, f.as));
|
|
291
|
+
const universal = Object.hasOwn(UNIVERSAL, f.as) ? UNIVERSAL[f.as] : undefined;
|
|
292
|
+
if (!holders.length && !universal) {
|
|
293
|
+
problems.push(kinds.length ? `${at}: as "${f.as}" is not a property of kind ${kinds.join(" or ")} (nor url, dateCreated, dateModified)` : `${at}: as "${f.as}" needs a kind on the entity (without one only url, dateCreated, dateModified)`);
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
const defs = holders.length ? holders.map((h) => h.def.properties[f.as]) : [universal];
|
|
297
|
+
for (const d of defs)
|
|
298
|
+
if (!fits(d.type, f, Boolean(d.many)))
|
|
299
|
+
problems.push(`${at}: as "${f.as}" holds ${typeName(d.type, Boolean(d.many))}; the field is ${f.type === "array" ? `an array of ${f.itemType ?? "values"}` : `a ${f.type}`}${d.type === "money" && !f.currency ? " without a currency" : ""}`);
|
|
300
|
+
if (defs.some((d) => d.key) && !f.filter)
|
|
301
|
+
problems.push(`${at}: as "${f.as}" is a key of its kind: the field needs filter: true`);
|
|
302
|
+
const list = counts.get(f.as) ?? [];
|
|
303
|
+
list.push(f.name);
|
|
304
|
+
counts.set(f.as, list);
|
|
305
|
+
}
|
|
306
|
+
for (const [property, names] of counts) {
|
|
307
|
+
if (names.length < 2)
|
|
308
|
+
continue;
|
|
309
|
+
const many = defined.some((d) => d.def?.properties[property]?.many);
|
|
310
|
+
if (!many)
|
|
311
|
+
problems.push(`${where}: as "${property}" is on ${names.join(" and ")}; it is single-valued, so at most one field holds it`);
|
|
312
|
+
}
|
|
313
|
+
for (const d of defined)
|
|
314
|
+
for (const r of d.def?.required ?? [])
|
|
315
|
+
if (!counts.has(r))
|
|
316
|
+
problems.push(`${where}: kind ${d.name} requires a field with as "${r}"`);
|
|
317
|
+
return problems;
|
|
318
|
+
}
|
|
319
|
+
//# sourceMappingURL=kinds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kinds.js","sourceRoot":"","sources":["../../../spec/src/kinds.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvC,yLAAyL;AACzL,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAU,CAAA;AAWlG,gIAAgI;AAChI,MAAM,CAAC,MAAM,KAAK,GAAiC;IACjD,MAAM,EAAE;QACN,KAAK,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE;QACtC,UAAU,EAAE;YACV,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC7B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC9B,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE;YACxE,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE;YACzC,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC5B,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC5B,OA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ACxB,CAAC;IACD,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,MAAM,EAAE,CAAC;QACvC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,SAAQ;QAC9B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,UAAU,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAA;QACnE,IAAI,CAAC,IAAI;YAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,SAAS,QAAQ,WAAW,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,sDAAsD,CAAC,CAAA;IACzI,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,OAAO;QAAE,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,QAAQ,IAAI,EAAE;YAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;gBAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,UAAU,CAAC,CAAC,IAAI,8BAA8B,CAAC,GAAG,CAAC,CAAA;IAC7J,OAAO,QAAQ,CAAA;AACjB,CAAC","sourcesContent":["/**\n * KINDS (spec §3.1): what an entity is, the same in every app. The vocabulary\n * of this spec version (published as `spec/kinds.json`, written from this file\n * by `npm run schema`) and the rules every manifest is checked against. The SDK\n * (at definition time) and the conformance checks (from outside) use the same\n * functions, so the two never disagree. No dependencies.\n */\n\nimport { URI_SCHEME } from \"./protocol\"\n\n/** What a property holds. `date`: an RFC 3339 date or date-time string; `address`: a string or a schema.org PostalAddress object; `money`: a number whose field names its `currency`. */\nexport const PROPERTY_TYPES = [\"string\", \"number\", \"boolean\", \"date\", \"address\", \"money\"] as const\nexport type PropertyType = (typeof PROPERTY_TYPES)[number]\n\n/** How a key's values are compared (spec §3.1 rule 5). */\nexport type Normalisation = \"lowercase\" | \"uppercase-no-spaces\" | \"digits\" | \"exact\"\n\nexport type PropertyDef = { type: PropertyType; many?: boolean; key?: boolean }\nexport type StandardProperty = PropertyDef & { normalise?: Normalisation }\nexport type KindDef = { label: Record<string, string>; properties: Record<string, PropertyDef> }\nexport type StandardKind = { label: Record<string, string>; properties: Record<string, StandardProperty>; required: string[] }\n\n/** The seven kinds of 1.0. Property names are schema.org's, verbatim (JSCalendar's where schema.org has none: `due`, `uid`). */\nexport const KINDS: Record<string, StandardKind> = {\n person: {\n label: { en: \"Person\", it: \"Persona\" },\n properties: {\n givenName: { type: \"string\" },\n familyName: { type: \"string\" },\n email: { type: \"string\", many: true, key: true, normalise: \"lowercase\" },\n telephone: { type: \"string\", many: true },\n jobTitle: { type: \"string\" },\n worksFor: { type: \"string\" },\n address: { type: \"address\" },\n image: { type: \"string\" },\n },\n required: [],\n },\n organization: {\n label: { en: \"Organization\", it: \"Organizzazione\" },\n properties: {\n legalName: { type: \"string\" },\n email: { type: \"string\", many: true },\n telephone: { type: \"string\", many: true },\n url: { type: \"string\" },\n address: { type: \"address\" },\n vatID: { type: \"string\", key: true, normalise: \"uppercase-no-spaces\" },\n taxID: { type: \"string\" },\n },\n required: [],\n },\n event: {\n label: { en: \"Event\", it: \"Evento\" },\n properties: {\n startDate: { type: \"date\" },\n endDate: { type: \"date\" },\n location: { type: \"address\" },\n attendee: { type: \"string\", many: true },\n organizer: { type: \"string\" },\n uid: { type: \"string\", key: true, normalise: \"exact\" },\n },\n required: [\"startDate\"],\n },\n task: {\n label: { en: \"Task\", it: \"Attività\" },\n properties: {\n due: { type: \"date\" },\n startDate: { type: \"date\" },\n completed: { type: \"boolean\" },\n assignee: { type: \"string\" },\n },\n required: [],\n },\n document: {\n label: { en: \"Document\", it: \"Documento\" },\n properties: {\n url: { type: \"string\" },\n encodingFormat: { type: \"string\" },\n author: { type: \"string\" },\n contentSize: { type: \"string\" },\n },\n required: [],\n },\n product: {\n label: { en: \"Product\", it: \"Prodotto\" },\n properties: {\n sku: { type: \"string\" },\n gtin: { type: \"string\", key: true, normalise: \"digits\" },\n brand: { type: \"string\" },\n price: { type: \"money\" },\n },\n required: [],\n },\n order: {\n label: { en: \"Order\", it: \"Ordine\" },\n properties: {\n orderNumber: { type: \"string\" },\n orderDate: { type: \"date\" },\n customer: { type: \"string\" },\n totalPrice: { type: \"money\" },\n },\n required: [],\n },\n}\n\n/** Properties any entity MAY mark, with or without a kind. On a kind that defines the same name (`url` of organization and document), the kind's meaning applies. */\nexport const UNIVERSAL: Record<string, PropertyDef> = {\n url: { type: \"string\" },\n dateCreated: { type: \"date\" },\n dateModified: { type: \"date\" },\n}\n\n/** Reserved for later versions: not kinds of 1.0, and no app may use them. */\nexport const RESERVED_KINDS = [\"message\", \"place\", \"invoice\", \"project\"] as const\n\n/** A third party's kind: reverse-DNS under a domain it controls, at least one dot (`com.acme.shipment`). */\nexport const NAMESPACED_KIND = /^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)+$/\n/** A property name of a namespaced kind. */\nexport const PROPERTY_NAME = /^[a-z][A-Za-z0-9]{0,63}$/\n/** A record URI, `clegra://<app>/<entity>/<id>` (spec §3): what a cross-app reference holds. */\nexport const RECORD_URI = new RegExp(`^${URI_SCHEME}://[a-z][a-z0-9-]{1,39}/[a-z][a-z0-9_]{0,39}/[^/?#\\\\s]+$`)\n\n/** The published vocabulary (`spec/kinds.json`). */\nexport function kindsDocument(specVersion: string) {\n return { specVersion, kinds: KINDS, universal: UNIVERSAL, reserved: [...RESERVED_KINDS] }\n}\n\n// ------------------------------------------------------------------ names and keys\n\nexport type EntityKind = string | { by: string; map: Record<string, string> }\n\n/** The kinds an entity's records can have, in declaration order, without repeats. */\nexport function kindsOf(kind: EntityKind | undefined): string[] {\n if (kind === undefined) return []\n return typeof kind === \"string\" ? [kind] : [...new Set(Object.values(kind.map))]\n}\n\n/** The kind of one record (null: the record has none, e.g. an unmapped value). */\nexport function kindOfRecord(kind: EntityKind | undefined, row: Record<string, unknown>): string | null {\n if (kind === undefined) return null\n if (typeof kind === \"string\") return kind\n const value = row[kind.by]\n return typeof value === \"string\" && Object.hasOwn(kind.map, value) ? kind.map[value]! : null\n}\n\n/** The fixed sentence that ends an entity tool's description (spec §6): `Kind: person.`, `Kind: organization or person (by type).` */\nexport function kindSentence(kind: EntityKind): string {\n const names = kindsOf(kind)\n const list = names.length > 1 ? `${names.slice(0, -1).join(\", \")} or ${names[names.length - 1]}` : names[0]\n return typeof kind === \"string\" ? `Kind: ${list}.` : `Kind: ${list} (by ${kind.by}).`\n}\n\n/** A kind's definition: the standard one, or the app's own for a namespaced kind (undefined: unknown). */\nfunction definitionOf(name: string, own: Record<string, KindDef> | undefined): { properties: Record<string, StandardProperty>; required: string[] } | undefined {\n if (Object.hasOwn(KINDS, name)) return KINDS[name]\n if (NAMESPACED_KIND.test(name) && own && Object.hasOwn(own, name)) return { properties: own[name]!.properties, required: [] }\n return undefined\n}\n\n/** What is wrong with a kind name (null: nothing). */\nexport function kindNameProblem(name: unknown): string | null {\n if (typeof name !== \"string\") return \"a kind is a string\"\n if ((RESERVED_KINDS as readonly string[]).includes(name)) return `kind \"${name}\" is reserved, not defined in this version`\n if (Object.hasOwn(KINDS, name)) return null\n if (NAMESPACED_KIND.test(name)) return null\n return `kind \"${name}\" is not a kind of this specification (${Object.keys(KINDS).join(\", \")}); a third party's kind has a dot (com.example.${name})`\n}\n\n/** The definition of a property on any of these kinds, or a universal one (undefined: none). */\nexport function propertyOf(property: string, kinds: string[], own?: Record<string, KindDef>): PropertyDef | undefined {\n for (const k of kinds) {\n const p = definitionOf(k, own)?.properties[property]\n if (p) return p\n }\n return Object.hasOwn(UNIVERSAL, property) ? UNIVERSAL[property] : undefined\n}\n\n// ------------------------------------------------------------------ values (spec §3.1 rule 4)\n\nconst POSTAL_ADDRESS = new Set([\"@type\", \"streetAddress\", \"postOfficeBoxNumber\", \"addressLocality\", \"addressRegion\", \"postalCode\", \"addressCountry\", \"name\"])\nconst RFC3339 = /^\\d{4}-\\d{2}-\\d{2}([Tt]\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?([Zz]|[+-]\\d{2}:\\d{2}))?$/\n\n/** What is wrong with one value of a property (null: nothing). `email` an addr-spec; `vatID` the country prefix and number, no spaces; `gtin` 8, 12, 13 or 14 digits; dates RFC 3339; `address` a string or a PostalAddress. */\nexport function valueProblem(property: string, def: PropertyDef, value: unknown): string | null {\n if (value === null || value === undefined) return null\n if (property === \"email\") return typeof value === \"string\" && /^[^\\s@]+@[^\\s@]+$/.test(value) ? null : \"not an email address\"\n if (property === \"vatID\") return typeof value === \"string\" && /^[A-Za-z]{2}[0-9A-Za-z+*.]{2,13}$/.test(value) ? null : \"not a VAT number (country prefix and number, no spaces)\"\n if (property === \"gtin\") return typeof value === \"string\" && /^(\\d{8}|\\d{12}|\\d{13}|\\d{14})$/.test(value) ? null : \"not a GTIN (8, 12, 13 or 14 digits)\"\n if (def.type === \"date\") return typeof value === \"string\" && RFC3339.test(value) && !Number.isNaN(Date.parse(value.length === 10 ? `${value}T00:00:00Z` : value)) ? null : \"not an RFC 3339 date or date-time\"\n if (def.type === \"address\") return typeof value === \"string\" || (value && typeof value === \"object\" && !Array.isArray(value) && Object.keys(value).every((k) => POSTAL_ADDRESS.has(k))) ? null : \"not an address (a string or a PostalAddress)\"\n if (def.type === \"number\" || def.type === \"money\") return typeof value === \"number\" && Number.isFinite(value) ? null : \"not a number\"\n if (def.type === \"boolean\") return typeof value === \"boolean\" ? null : \"not a boolean\"\n return typeof value === \"string\" ? null : \"not a string\"\n}\n\n/** How a key property's values are compared; null when the property is not a key of any of these kinds. */\nexport function keyOf(property: string, kinds: string[], own?: Record<string, KindDef>): Normalisation | null {\n for (const k of kinds) {\n const p = definitionOf(k, own)?.properties[property]\n if (p?.key) return (p as StandardProperty).normalise ?? \"exact\"\n }\n return null\n}\n\n/** A key value as it is compared (spec §3.1 rule 5); null when it can't be one (a gtin with letters). */\nexport function normaliseKey(value: string, how: Normalisation): string | null {\n if (how === \"lowercase\") return value.toLowerCase()\n if (how === \"uppercase-no-spaces\") return value.replace(/\\s+/g, \"\").toUpperCase()\n if (how === \"digits\") {\n const digits = value.replace(/[\\s-]+/g, \"\")\n return /^\\d+$/.test(digits) ? digits : null\n }\n return value\n}\n\n// ------------------------------------------------------------------ the rules of §3.1, on manifest-shaped data\n\n/** A field as the rules need it: the manifest's keys, and the item type of an array (from the entity's JSON Schema). */\nexport type KindField = { name: string; type: string; required: boolean; enum?: string[]; permission?: string; as?: string; filter?: boolean; currency?: string; itemType?: string }\n\nconst fits = (t: PropertyType, field: KindField, many: boolean): boolean => {\n const one = (type: string | undefined): boolean => {\n if (t === \"string\" || t === \"date\") return type === \"string\"\n if (t === \"number\") return type === \"number\" || type === \"integer\"\n if (t === \"money\") return (type === \"number\" || type === \"integer\") && typeof field.currency === \"string\" && field.currency.length > 0\n if (t === \"boolean\") return type === \"boolean\"\n return type === \"string\" || type === \"object\"\n }\n if (field.type === \"array\") return many && (field.itemType === undefined ? t === \"string\" || t === \"date\" : one(field.itemType))\n return one(field.type)\n}\n\nconst typeName = (t: PropertyType, many: boolean) => `${t === \"money\" ? \"a number with a currency\" : t === \"date\" ? \"a date string\" : t === \"address\" ? \"a string or an object\" : `a ${t}`}${many ? \" (or an array of them)\" : \"\"}`\n\n/** What is wrong with an app's own kind definitions (`kinds` in the manifest). */\nexport function kindDefinitionProblems(own: Record<string, KindDef> | undefined): string[] {\n const problems: string[] = []\n for (const [name, def] of Object.entries(own ?? {})) {\n if (!NAMESPACED_KIND.test(name)) problems.push(`kinds: \"${name}\" is not a namespaced kind (com.example.thing); kinds without a dot are this specification's`)\n if (!def || typeof def !== \"object\" || !def.properties || typeof def.properties !== \"object\") {\n problems.push(`kinds: \"${name}\" needs properties`)\n continue\n }\n for (const [p, d] of Object.entries(def.properties)) {\n if (!PROPERTY_NAME.test(p)) problems.push(`kinds: \"${name}\": property \"${p}\" is not a name ([a-z][A-Za-z0-9]*)`)\n if (!d || !(PROPERTY_TYPES as readonly string[]).includes(d.type)) problems.push(`kinds: \"${name}\": property \"${p}\" needs a type, one of ${PROPERTY_TYPES.join(\", \")}`)\n else if (d.key && d.type !== \"string\") problems.push(`kinds: \"${name}\": key \"${p}\" must be a string property`)\n }\n }\n return problems\n}\n\n/**\n * What is wrong with one entity's kind and its fields' `as` (spec §3.1 rules 1–5). `where` prefixes every problem.\n * The same list is a definition error in the SDK and a failed check in conformance.\n */\nexport function entityKindProblems(where: string, kind: EntityKind | undefined, fields: KindField[], own?: Record<string, KindDef>, options: { names?: boolean } = {}): string[] {\n const problems: string[] = []\n const kinds: string[] = []\n if (kind !== undefined) {\n if (typeof kind === \"string\") kinds.push(kind)\n else if (!kind || typeof kind !== \"object\" || typeof kind.by !== \"string\" || !kind.map || typeof kind.map !== \"object\") problems.push(`${where}: kind is a kind name or { by, map }`)\n else {\n const by = fields.find((f) => f.name === kind.by)\n if (!by) problems.push(`${where}: kind.by \"${kind.by}\" is not a field`)\n else {\n if (!by.required || !by.enum?.length) problems.push(`${where}: kind.by \"${kind.by}\" must be a required enum field`)\n if (by.permission) problems.push(`${where}: kind.by \"${kind.by}\" can't have a permission (a record's kind is seen with the record)`)\n for (const v of by.enum ?? []) if (!Object.hasOwn(kind.map, v)) problems.push(`${where}: kind.map gives no kind for \"${v}\"`)\n for (const v of Object.keys(kind.map)) if (by.enum && !by.enum.includes(v)) problems.push(`${where}: kind.map: \"${v}\" is not a value of ${kind.by}`)\n }\n kinds.push(...new Set(Object.values(kind.map)))\n }\n }\n if (options.names !== false)\n for (const k of kinds) {\n const p = kindNameProblem(k)\n if (p) problems.push(`${where}: ${p}`)\n }\n const defined = kinds.map((k) => ({ name: k, def: definitionOf(k, own) }))\n const counts = new Map<string, string[]>()\n for (const f of fields) {\n if (f.as === undefined) continue\n const at = `${where}, field \"${f.name}\"`\n if (typeof f.as !== \"string\" || !f.as) {\n problems.push(`${at}: as names a property`)\n continue\n }\n const holders = defined.filter((d) => d.def && Object.hasOwn(d.def.properties, f.as!))\n const universal = Object.hasOwn(UNIVERSAL, f.as) ? UNIVERSAL[f.as] : undefined\n if (!holders.length && !universal) {\n problems.push(kinds.length ? `${at}: as \"${f.as}\" is not a property of kind ${kinds.join(\" or \")} (nor url, dateCreated, dateModified)` : `${at}: as \"${f.as}\" needs a kind on the entity (without one only url, dateCreated, dateModified)`)\n continue\n }\n const defs = holders.length ? holders.map((h) => h.def!.properties[f.as!]!) : [universal!]\n for (const d of defs) if (!fits(d.type, f, Boolean(d.many))) problems.push(`${at}: as \"${f.as}\" holds ${typeName(d.type, Boolean(d.many))}; the field is ${f.type === \"array\" ? `an array of ${f.itemType ?? \"values\"}` : `a ${f.type}`}${d.type === \"money\" && !f.currency ? \" without a currency\" : \"\"}`)\n if (defs.some((d) => d.key) && !f.filter) problems.push(`${at}: as \"${f.as}\" is a key of its kind: the field needs filter: true`)\n const list = counts.get(f.as) ?? []\n list.push(f.name)\n counts.set(f.as, list)\n }\n for (const [property, names] of counts) {\n if (names.length < 2) continue\n const many = defined.some((d) => d.def?.properties[property]?.many)\n if (!many) problems.push(`${where}: as \"${property}\" is on ${names.join(\" and \")}; it is single-valued, so at most one field holds it`)\n }\n for (const d of defined) for (const r of d.def?.required ?? []) if (!counts.has(r)) problems.push(`${where}: kind ${d.name} requires a field with as \"${r}\"`)\n return problems\n}\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE NAMES CLEGRA APPS CARRY ON THE WIRE, IN ONE PLACE. Everything derives from
|
|
3
|
+
* `PROTOCOL_ID` below: the package, the conformance checks and the Clegra host
|
|
4
|
+
* import these. No dependencies.
|
|
5
|
+
*/
|
|
6
|
+
/** The technical name: the package's, the manifest's path, the URI scheme, the `_meta` key, the claim and the scope. */
|
|
7
|
+
export declare const PROTOCOL_ID = "clegra";
|
|
8
|
+
export declare const SPEC_VERSION = "1.0";
|
|
9
|
+
/** Where every app serves its manifest. */
|
|
10
|
+
export declare const MANIFEST_PATH = "/.well-known/clegra.json";
|
|
11
|
+
/** The scheme of record and fragment URIs: `clegra://<app>/<type>/<key>`; the manifest's own resource is `clegra://<app>`. */
|
|
12
|
+
export declare const URI_SCHEME = "clegra";
|
|
13
|
+
export declare const uriPrefix: (app: string) => string;
|
|
14
|
+
/** The one `_meta` key of the host protocol: `{ call, confirmation, settings }` on requests, `{ notifications, untrusted }` on results. */
|
|
15
|
+
export declare const META_KEY = "clegra";
|
|
16
|
+
/** The claim of an access token that says who calls, for which installation. */
|
|
17
|
+
export declare const TOKEN_CLAIM = "clegra";
|
|
18
|
+
/** The OAuth scope apps announce. */
|
|
19
|
+
export declare const OAUTH_SCOPE = "clegra";
|
|
20
|
+
/** The `typ` of a confirmation proof (a JWT). */
|
|
21
|
+
export declare const CONFIRMATION_TYPE = "clegra-confirm+jwt";
|
|
22
|
+
/** The tool hosts resolve record and fragment URIs with. */
|
|
23
|
+
export declare const RESOLVE_TOOL = "clegra_resolve";
|
|
24
|
+
/** The `$id` of the manifest's JSON Schema. */
|
|
25
|
+
export declare const SCHEMA_ID = "urn:clegra:manifest:1.0";
|
|
26
|
+
/** The tool a host (or the app's own view) asks for an embed ticket with (spec §5.1): app-only, hidden from models. */
|
|
27
|
+
export declare const EMBED_TOOL = "clegra_embed";
|
|
28
|
+
/** The `typ` of an embed ticket (a JWT, one minute, used once). */
|
|
29
|
+
export declare const EMBED_TICKET_TYPE = "clegra-embed+jwt";
|
|
30
|
+
/** The `typ` of the embed session a ticket is exchanged for (the cookie's value). */
|
|
31
|
+
export declare const EMBED_SESSION_TYPE = "clegra-embed-session+jwt";
|
|
32
|
+
/** The form field the ticket is posted in. */
|
|
33
|
+
export declare const EMBED_TICKET_FIELD = "ticket";
|
|
34
|
+
/** Where, under the embed path, the ticket is exchanged: a `_` segment, never a Next.js page (private folder). */
|
|
35
|
+
export declare const EMBED_EXCHANGE_SEGMENT = "_ticket";
|
|
36
|
+
/** The embed session cookie of a page is `<prefix><page>` (`__Secure-`: it is always Secure). */
|
|
37
|
+
export declare const EMBED_COOKIE_PREFIX = "__Secure-clegra-embed-";
|
|
38
|
+
/** How long a ticket lives at most, in seconds, and the clock skew allowed when it is checked. */
|
|
39
|
+
export declare const EMBED_TICKET_SECONDS = 60;
|
|
40
|
+
export declare const EMBED_SKEW_SECONDS = 5;
|
|
41
|
+
/** Runs the stored «approve now, act later» runs that are due; also the name of its schedule. */
|
|
42
|
+
export declare const LATER_TOOL = "clegra_later";
|
|
43
|
+
/** Tells the app its installation was enabled, disabled or uninstalled. */
|
|
44
|
+
export declare const INSTALLATION_TOOL = "clegra_installation";
|
|
45
|
+
/** The tenant's data, as one file. */
|
|
46
|
+
export declare const EXPORT_TOOL = "clegra_export";
|
|
47
|
+
/** Deletes everything the app keeps for the tenant. */
|
|
48
|
+
export declare const DELETE_TOOL = "clegra_delete";
|
|
49
|
+
/** Every reserved tool name of the installation-level caller. */
|
|
50
|
+
export declare const INSTALLATION_TOOLS: readonly ["clegra_later", "clegra_installation", "clegra_export", "clegra_delete"];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE NAMES CLEGRA APPS CARRY ON THE WIRE, IN ONE PLACE. Everything derives from
|
|
3
|
+
* `PROTOCOL_ID` below: the package, the conformance checks and the Clegra host
|
|
4
|
+
* import these. No dependencies.
|
|
5
|
+
*/
|
|
6
|
+
/** The technical name: the package's, the manifest's path, the URI scheme, the `_meta` key, the claim and the scope. */
|
|
7
|
+
export const PROTOCOL_ID = "clegra";
|
|
8
|
+
export const SPEC_VERSION = "1.0";
|
|
9
|
+
/** Where every app serves its manifest. */
|
|
10
|
+
export const MANIFEST_PATH = `/.well-known/${PROTOCOL_ID}.json`;
|
|
11
|
+
/** The scheme of record and fragment URIs: `clegra://<app>/<type>/<key>`; the manifest's own resource is `clegra://<app>`. */
|
|
12
|
+
export const URI_SCHEME = PROTOCOL_ID;
|
|
13
|
+
export const uriPrefix = (app) => `${URI_SCHEME}://${app}`;
|
|
14
|
+
/** The one `_meta` key of the host protocol: `{ call, confirmation, settings }` on requests, `{ notifications, untrusted }` on results. */
|
|
15
|
+
export const META_KEY = PROTOCOL_ID;
|
|
16
|
+
/** The claim of an access token that says who calls, for which installation. */
|
|
17
|
+
export const TOKEN_CLAIM = PROTOCOL_ID;
|
|
18
|
+
/** The OAuth scope apps announce. */
|
|
19
|
+
export const OAUTH_SCOPE = PROTOCOL_ID;
|
|
20
|
+
/** The `typ` of a confirmation proof (a JWT). */
|
|
21
|
+
export const CONFIRMATION_TYPE = `${PROTOCOL_ID}-confirm+jwt`;
|
|
22
|
+
/** The tool hosts resolve record and fragment URIs with. */
|
|
23
|
+
export const RESOLVE_TOOL = `${PROTOCOL_ID}_resolve`;
|
|
24
|
+
/** The `$id` of the manifest's JSON Schema. */
|
|
25
|
+
export const SCHEMA_ID = `urn:${PROTOCOL_ID}:manifest:${SPEC_VERSION}`;
|
|
26
|
+
/** The tool a host (or the app's own view) asks for an embed ticket with (spec §5.1): app-only, hidden from models. */
|
|
27
|
+
export const EMBED_TOOL = `${PROTOCOL_ID}_embed`;
|
|
28
|
+
/** The `typ` of an embed ticket (a JWT, one minute, used once). */
|
|
29
|
+
export const EMBED_TICKET_TYPE = `${PROTOCOL_ID}-embed+jwt`;
|
|
30
|
+
/** The `typ` of the embed session a ticket is exchanged for (the cookie's value). */
|
|
31
|
+
export const EMBED_SESSION_TYPE = `${PROTOCOL_ID}-embed-session+jwt`;
|
|
32
|
+
/** The form field the ticket is posted in. */
|
|
33
|
+
export const EMBED_TICKET_FIELD = "ticket";
|
|
34
|
+
/** Where, under the embed path, the ticket is exchanged: a `_` segment, never a Next.js page (private folder). */
|
|
35
|
+
export const EMBED_EXCHANGE_SEGMENT = "_ticket";
|
|
36
|
+
/** The embed session cookie of a page is `<prefix><page>` (`__Secure-`: it is always Secure). */
|
|
37
|
+
export const EMBED_COOKIE_PREFIX = `__Secure-${PROTOCOL_ID}-embed-`;
|
|
38
|
+
/** How long a ticket lives at most, in seconds, and the clock skew allowed when it is checked. */
|
|
39
|
+
export const EMBED_TICKET_SECONDS = 60;
|
|
40
|
+
export const EMBED_SKEW_SECONDS = 5;
|
|
41
|
+
// The reserved app-only tools only the installation-level caller (a workspace host's token with no person) is given.
|
|
42
|
+
/** Runs the stored «approve now, act later» runs that are due; also the name of its schedule. */
|
|
43
|
+
export const LATER_TOOL = `${PROTOCOL_ID}_later`;
|
|
44
|
+
/** Tells the app its installation was enabled, disabled or uninstalled. */
|
|
45
|
+
export const INSTALLATION_TOOL = `${PROTOCOL_ID}_installation`;
|
|
46
|
+
/** The tenant's data, as one file. */
|
|
47
|
+
export const EXPORT_TOOL = `${PROTOCOL_ID}_export`;
|
|
48
|
+
/** Deletes everything the app keeps for the tenant. */
|
|
49
|
+
export const DELETE_TOOL = `${PROTOCOL_ID}_delete`;
|
|
50
|
+
/** Every reserved tool name of the installation-level caller. */
|
|
51
|
+
export const INSTALLATION_TOOLS = [LATER_TOOL, INSTALLATION_TOOL, EXPORT_TOOL, DELETE_TOOL];
|
|
52
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../spec/src/protocol.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,wHAAwH;AACxH,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAA;AACnC,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAA;AAEjC,2CAA2C;AAC3C,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,WAAW,OAAO,CAAA;AAC/D,8HAA8H;AAC9H,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAA;AACrC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,UAAU,MAAM,GAAG,EAAE,CAAA;AAClE,2IAA2I;AAC3I,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAA;AACnC,gFAAgF;AAChF,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAA;A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GAAG,CAAC,UAAU,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW,CAAU,CAAA","sourcesContent":["/**\n * THE NAMES CLEGRA APPS CARRY ON THE WIRE, IN ONE PLACE. Everything derives from\n * `PROTOCOL_ID` below: the package, the conformance checks and the Clegra host\n * import these. No dependencies.\n */\n\n/** The technical name: the package's, the manifest's path, the URI scheme, the `_meta` key, the claim and the scope. */\nexport const PROTOCOL_ID = \"clegra\"\nexport const SPEC_VERSION = \"1.0\"\n\n/** Where every app serves its manifest. */\nexport const MANIFEST_PATH = `/.well-known/${PROTOCOL_ID}.json`\n/** The scheme of record and fragment URIs: `clegra://<app>/<type>/<key>`; the manifest's own resource is `clegra://<app>`. */\nexport const URI_SCHEME = PROTOCOL_ID\nexport const uriPrefix = (app: string) => `${URI_SCHEME}://${app}`\n/** The one `_meta` key of the host protocol: `{ call, confirmation, settings }` on requests, `{ notifications, untrusted }` on results. */\nexport const META_KEY = PROTOCOL_ID\n/** The claim of an access token that says who calls, for which installation. */\nexport const TOKEN_CLAIM = PROTOCOL_ID\n/** The OAuth scope apps announce. */\nexport const OAUTH_SCOPE = PROTOCOL_ID\n/** The `typ` of a confirmation proof (a JWT). */\nexport const CONFIRMATION_TYPE = `${PROTOCOL_ID}-confirm+jwt`\n/** The tool hosts resolve record and fragment URIs with. */\nexport const RESOLVE_TOOL = `${PROTOCOL_ID}_resolve`\n/** The `$id` of the manifest's JSON Schema. */\nexport const SCHEMA_ID = `urn:${PROTOCOL_ID}:manifest:${SPEC_VERSION}`\n\n/** The tool a host (or the app's own view) asks for an embed ticket with (spec §5.1): app-only, hidden from models. */\nexport const EMBED_TOOL = `${PROTOCOL_ID}_embed`\n/** The `typ` of an embed ticket (a JWT, one minute, used once). */\nexport const EMBED_TICKET_TYPE = `${PROTOCOL_ID}-embed+jwt`\n/** The `typ` of the embed session a ticket is exchanged for (the cookie's value). */\nexport const EMBED_SESSION_TYPE = `${PROTOCOL_ID}-embed-session+jwt`\n/** The form field the ticket is posted in. */\nexport const EMBED_TICKET_FIELD = \"ticket\"\n/** Where, under the embed path, the ticket is exchanged: a `_` segment, never a Next.js page (private folder). */\nexport const EMBED_EXCHANGE_SEGMENT = \"_ticket\"\n/** The embed session cookie of a page is `<prefix><page>` (`__Secure-`: it is always Secure). */\nexport const EMBED_COOKIE_PREFIX = `__Secure-${PROTOCOL_ID}-embed-`\n/** How long a ticket lives at most, in seconds, and the clock skew allowed when it is checked. */\nexport const EMBED_TICKET_SECONDS = 60\nexport const EMBED_SKEW_SECONDS = 5\n\n// The reserved app-only tools only the installation-level caller (a workspace host's token with no person) is given.\n\n/** Runs the stored «approve now, act later» runs that are due; also the name of its schedule. */\nexport const LATER_TOOL = `${PROTOCOL_ID}_later`\n/** Tells the app its installation was enabled, disabled or uninstalled. */\nexport const INSTALLATION_TOOL = `${PROTOCOL_ID}_installation`\n/** The tenant's data, as one file. */\nexport const EXPORT_TOOL = `${PROTOCOL_ID}_export`\n/** Deletes everything the app keeps for the tenant. */\nexport const DELETE_TOOL = `${PROTOCOL_ID}_delete`\n/** Every reserved tool name of the installation-level caller. */\nexport const INSTALLATION_TOOLS = [LATER_TOOL, INSTALLATION_TOOL, EXPORT_TOOL, DELETE_TOOL] as const\n"]}
|