@mark1russell7/guidebook 0.1.0 → 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/README.md CHANGED
@@ -28,13 +28,14 @@ A unit has one of three uses:
28
28
  | License | `quote` | `bundle` | `summary` and `fact` | Credit line | Layer of a quote |
29
29
  | --- | --- | --- | --- | --- | --- |
30
30
  | `us-public-domain`, `public-domain`, `cc0` | yes | yes | yes | no | `main` |
31
- | `cc-by-4.0` | yes | yes | yes | yes | `main` |
31
+ | `cc-by-4.0`, `ogl-uk-3.0` | yes | yes | yes | yes | `main` |
32
32
  | `cc-by-sa-4.0`, `cc-by-sa-3.0` | yes | yes | yes | yes | `share-alike` |
33
33
  | `cc-by-nc-sa-3.0` | no | only when not commercial | yes | yes | `share-alike` |
34
34
  | `all-rights-reserved` | no | no | yes | no | `main` |
35
+ | `link-only` | no | no | no | no | `main` |
35
36
  | `invented` | only in a fixture | only in a fixture | only in a fixture | no | `main` |
36
37
 
37
- A US federal work is in the public domain under 17 USC 105. A summary and a fact are the words of the guidebook, so each real license permits them.
38
+ A US federal work is in the public domain under 17 USC 105. A summary and a fact are the words of the guidebook, so each real license permits them, but `link-only` does not. Use `link-only` when the publisher permits only a link, for example when it refuses each AI use of its text. Put the word of the publisher and its date in the field `note` of the source.
38
39
 
39
40
  ## The source gate
40
41
 
package/build/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** The licenses that the gate knows. The license `invented` is for test fixtures only. */
2
- export declare const LICENSES: readonly ["us-public-domain", "public-domain", "cc0", "cc-by-4.0", "cc-by-sa-4.0", "cc-by-sa-3.0", "cc-by-nc-sa-3.0", "all-rights-reserved", "invented"];
2
+ export declare const LICENSES: readonly ["us-public-domain", "public-domain", "cc0", "cc-by-4.0", "cc-by-sa-4.0", "cc-by-sa-3.0", "cc-by-nc-sa-3.0", "ogl-uk-3.0", "all-rights-reserved", "link-only", "invented"];
3
3
  /** A license of a source. The source gate refuses a use that the license does not permit. */
4
4
  type License = (typeof LICENSES)[number];
5
5
  /** The ways to use a source. A unit of text has one use, and an offline copy of the full source is a bundle. */
@@ -22,6 +22,8 @@ interface LicenseRule {
22
22
  readonly quote: boolean;
23
23
  /** This field is true when a guidebook can keep an offline copy of the full source. */
24
24
  readonly bundle: boolean;
25
+ /** This field is true when a guidebook can write a summary or a fact of the source. It is false when a guidebook can only link to the source. */
26
+ readonly units: boolean;
25
27
  /** This field is true when the license permits only a use that is not commercial. */
26
28
  readonly nonCommercial: boolean;
27
29
  /** The layer of a quote. A share-alike license needs its own layer, so the rest of the guidebook keeps its own license. */
@@ -38,6 +40,7 @@ interface LicenseRule {
38
40
  * - A CC BY work permits each use with a credit line. A CC BY-SA quote also needs its own layer.
39
41
  * - A CC BY-NC-SA work permits a bundle only while the guidebook is not commercial. The gate refuses a quote of it.
40
42
  * - A work with all rights reserved permits only a summary and a fact, with a citation.
43
+ * - A link-only work permits no use of its text. A guidebook can only link to it, for example when its publisher refuses each AI use.
41
44
  */
42
45
  export declare const LICENSE_RULES: Readonly<Record<License, LicenseRule>>;
43
46
  /** The context of a use. A guidebook that is sold, or that shows paid advertisements, is commercial. */
@@ -49,7 +52,7 @@ interface UseContext {
49
52
  }
50
53
  /**
51
54
  * This function tells if a license permits a use.
52
- * A summary and a fact are the words of the guidebook, so each real license permits them.
55
+ * A summary and a fact are the words of the guidebook, so each real license permits them, but a link-only license refuses them.
53
56
  * A non-commercial license refuses each use of its text in a commercial guidebook. A summary and a fact are not its text, so they stay.
54
57
  */
55
58
  export declare function permits(license: License, use: Use, context?: UseContext): boolean;
@@ -68,6 +71,8 @@ interface Source {
68
71
  readonly checked: IsoDate;
69
72
  /** The name that a credit line gives, for example the agency or the authors. The default is the title. */
70
73
  readonly by?: string;
74
+ /** A term of the publisher in addition to the license, with its date, for example "No AI ingestion (publisher, 2026-11-23)". */
75
+ readonly note?: string;
71
76
  }
72
77
  /** The use of a cited unit. A bundle is a copy of a full source, so a unit cannot have the use `bundle`. */
73
78
  type UnitUse = Exclude<Use, "bundle">;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/license.ts","../src/source.ts","../src/gate.ts"],"mappings":";qBAIa;;KAaD,kBAAkB;;qBAGjB;;;;;;KAOD,cAAc;;KAGd;;UAGK;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,OAAO;;WAEP;;WAEA;;;;;;;;;;qBAWE,eAAe,SAAS,OAAO,SAAS;;UAmEpC;;WAEN;;WAEA;;;;;;;wBAQK,QAAQ,SAAS,SAAS,KAAK,KAAK,UAAS;;KCrIjD;;KAGA;;UAGK;WACN,IAAI;WACJ;;WAEA;WACA,SAAS;;WAET,SAAS;;WAET;;;KAIC,UAAU,QAAQ;;;;UAKb;WACN;WACA,KAAK;WACL;WACA,QAAQ;;WAER;;;;;;wBAOK,SAAS,QAAQ;;qBCnCpB;;KAcD,sBAAsB;;;;;UAMjB,QAAQ,mBAAmB,aAAa;WAC9C;WACA,MAAM;;WAEN,QAAQ;;WAER;WACA;;;UAIM,oBAAoB;;WAE1B,KAAK;;WAEL;;;UAIM,WAAW,UAAU,0BAA0B;;WAErD;WACA,mBAAmB;;;wBAId,SAAS,UAAU,yBAAyB,mBAAmB,MAAM,WAAW;;wBAKhF,cAAc,cAAc,mBAAmB;;qBAMlD;;wBAIG,OAAO;;wBAeP,aAAa;;wBAKb,aAAa,kBAAkB,UAAU,UAAS,uBAA4B;;wBA8B9E,WAAW,gBAAgB,aAAa,kBAAkB,UAAU,UAAS,sBAA2B;;wBAwBxG,KAAK,gBAAgB,aAAa,kBAAkB,UAAU,UAAS,cAAmB;;wBAK1F,WAAW,gBAAgB,aAAa,kBAAkB,UAAU,UAAS;;wBAQ7E,QAAQ,MAAM,WAAW,QAAQ,SAAS"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/license.ts","../src/source.ts","../src/gate.ts"],"mappings":";qBAIa;;KAeD,kBAAkB;;qBAGjB;;;;;;KAOD,cAAc;;KAGd;;UAGK;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,OAAO;;WAEP;;WAEA;;;;;;;;;;;qBAYE,eAAe,SAAS,OAAO,SAAS;;UAqFpC;;WAEN;;WAEA;;;;;;;wBAQK,QAAQ,SAAS,SAAS,KAAK,KAAK,UAAS;;KC5JjD;;KAGA;;UAGK;WACN,IAAI;WACJ;;WAEA;WACA,SAAS;;WAET,SAAS;;WAET;;WAEA;;;KAIC,UAAU,QAAQ;;;;UAKb;WACN;WACA,KAAK;WACL;WACA,QAAQ;;WAER;;;;;;wBAOK,SAAS,QAAQ;;qBCrCpB;;KAcD,sBAAsB;;;;;UAMjB,QAAQ,mBAAmB,aAAa;WAC9C;WACA,MAAM;;WAEN,QAAQ;;WAER;WACA;;;UAIM,oBAAoB;;WAE1B,KAAK;;WAEL;;;UAIM,WAAW,UAAU,0BAA0B;;WAErD;WACA,mBAAmB;;;wBAId,SAAS,UAAU,yBAAyB,mBAAmB,MAAM,WAAW;;wBAKhF,cAAc,cAAc,mBAAmB;;qBAMlD;;wBAIG,OAAO;;wBAeP,aAAa;;wBAKb,aAAa,kBAAkB,UAAU,UAAS,uBAA4B;;wBA8B9E,WAAW,gBAAgB,aAAa,kBAAkB,UAAU,UAAS,sBAA2B;;wBAwBxG,KAAK,gBAAgB,aAAa,kBAAkB,UAAU,UAAS,cAAmB;;wBAK1F,WAAW,gBAAgB,aAAa,kBAAkB,UAAU,UAAS;;wBAQ7E,QAAQ,MAAM,WAAW,QAAQ,SAAS"}
package/build/index.js CHANGED
@@ -8,7 +8,9 @@ const LICENSES = [
8
8
  "cc-by-sa-4.0",
9
9
  "cc-by-sa-3.0",
10
10
  "cc-by-nc-sa-3.0",
11
+ "ogl-uk-3.0",
11
12
  "all-rights-reserved",
13
+ "link-only",
12
14
  "invented"
13
15
  ];
14
16
  /** The ways to use a source. A unit of text has one use, and an offline copy of the full source is a bundle. */
@@ -25,6 +27,7 @@ const USES = [
25
27
  * - A CC BY work permits each use with a credit line. A CC BY-SA quote also needs its own layer.
26
28
  * - A CC BY-NC-SA work permits a bundle only while the guidebook is not commercial. The gate refuses a quote of it.
27
29
  * - A work with all rights reserved permits only a summary and a fact, with a citation.
30
+ * - A link-only work permits no use of its text. A guidebook can only link to it, for example when its publisher refuses each AI use.
28
31
  */
29
32
  const LICENSE_RULES = {
30
33
  "us-public-domain": {
@@ -32,6 +35,7 @@ const LICENSE_RULES = {
32
35
  url: "https://www.law.cornell.edu/uscode/text/17/105",
33
36
  quote: true,
34
37
  bundle: true,
38
+ units: true,
35
39
  nonCommercial: false,
36
40
  layer: "main",
37
41
  credit: false,
@@ -42,6 +46,7 @@ const LICENSE_RULES = {
42
46
  url: "",
43
47
  quote: true,
44
48
  bundle: true,
49
+ units: true,
45
50
  nonCommercial: false,
46
51
  layer: "main",
47
52
  credit: false,
@@ -52,6 +57,7 @@ const LICENSE_RULES = {
52
57
  url: "https://creativecommons.org/publicdomain/zero/1.0/",
53
58
  quote: true,
54
59
  bundle: true,
60
+ units: true,
55
61
  nonCommercial: false,
56
62
  layer: "main",
57
63
  credit: false,
@@ -62,6 +68,7 @@ const LICENSE_RULES = {
62
68
  url: "https://creativecommons.org/licenses/by/4.0/",
63
69
  quote: true,
64
70
  bundle: true,
71
+ units: true,
65
72
  nonCommercial: false,
66
73
  layer: "main",
67
74
  credit: true,
@@ -72,6 +79,7 @@ const LICENSE_RULES = {
72
79
  url: "https://creativecommons.org/licenses/by-sa/4.0/",
73
80
  quote: true,
74
81
  bundle: true,
82
+ units: true,
75
83
  nonCommercial: false,
76
84
  layer: "share-alike",
77
85
  credit: true,
@@ -82,6 +90,7 @@ const LICENSE_RULES = {
82
90
  url: "https://creativecommons.org/licenses/by-sa/3.0/",
83
91
  quote: true,
84
92
  bundle: true,
93
+ units: true,
85
94
  nonCommercial: false,
86
95
  layer: "share-alike",
87
96
  credit: true,
@@ -92,16 +101,40 @@ const LICENSE_RULES = {
92
101
  url: "https://creativecommons.org/licenses/by-nc-sa/3.0/",
93
102
  quote: false,
94
103
  bundle: true,
104
+ units: true,
95
105
  nonCommercial: true,
96
106
  layer: "share-alike",
97
107
  credit: true,
98
108
  real: true
99
109
  },
110
+ "ogl-uk-3.0": {
111
+ title: "Open Government Licence v3.0",
112
+ url: "https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/",
113
+ quote: true,
114
+ bundle: true,
115
+ units: true,
116
+ nonCommercial: false,
117
+ layer: "main",
118
+ credit: true,
119
+ real: true
120
+ },
100
121
  "all-rights-reserved": {
101
122
  title: "All rights reserved",
102
123
  url: "",
103
124
  quote: false,
104
125
  bundle: false,
126
+ units: true,
127
+ nonCommercial: false,
128
+ layer: "main",
129
+ credit: false,
130
+ real: true
131
+ },
132
+ "link-only": {
133
+ title: "Link only",
134
+ url: "",
135
+ quote: false,
136
+ bundle: false,
137
+ units: false,
105
138
  nonCommercial: false,
106
139
  layer: "main",
107
140
  credit: false,
@@ -112,6 +145,7 @@ const LICENSE_RULES = {
112
145
  url: "",
113
146
  quote: false,
114
147
  bundle: false,
148
+ units: true,
115
149
  nonCommercial: false,
116
150
  layer: "main",
117
151
  credit: false,
@@ -120,13 +154,13 @@ const LICENSE_RULES = {
120
154
  };
121
155
  /**
122
156
  * This function tells if a license permits a use.
123
- * A summary and a fact are the words of the guidebook, so each real license permits them.
157
+ * A summary and a fact are the words of the guidebook, so each real license permits them, but a link-only license refuses them.
124
158
  * A non-commercial license refuses each use of its text in a commercial guidebook. A summary and a fact are not its text, so they stay.
125
159
  */
126
160
  function permits(license, use, context = {}) {
127
161
  const rule = LICENSE_RULES[license];
128
162
  if (!rule.real) return context.fixture === true;
129
- if (use === "summary" || use === "fact") return true;
163
+ if (use === "summary" || use === "fact") return rule.units;
130
164
  if (rule.nonCommercial && context.commercial === true) return false;
131
165
  return use === "quote" ? rule.quote : rule.bundle;
132
166
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/license.ts","../src/source.ts","../src/gate.ts"],"sourcesContent":["// The licenses of the sources, and the rule of each license.\n// The rules come from the text of each license. A rule tells what a guidebook can do with the text of a source.\n\n/** The licenses that the gate knows. The license `invented` is for test fixtures only. */\nexport const LICENSES = [\n \"us-public-domain\",\n \"public-domain\",\n \"cc0\",\n \"cc-by-4.0\",\n \"cc-by-sa-4.0\",\n \"cc-by-sa-3.0\",\n \"cc-by-nc-sa-3.0\",\n \"all-rights-reserved\",\n \"invented\",\n] as const;\n\n/** A license of a source. The source gate refuses a use that the license does not permit. */\nexport type License = (typeof LICENSES)[number];\n\n/** The ways to use a source. A unit of text has one use, and an offline copy of the full source is a bundle. */\nexport const USES = [\"quote\", \"summary\", \"fact\", \"bundle\"] as const;\n\n/**\n * A use of a source.\n * `quote` is the text word for word. `summary` is the text in the words of the guidebook. `fact` is a value with a citation.\n * `bundle` is an offline copy of the full source.\n */\nexport type Use = (typeof USES)[number];\n\n/** The layer of a printed quote. A share-alike quote prints in its own layer, with its credit and its license. */\nexport type Layer = \"main\" | \"share-alike\";\n\n/** The rule of one license. */\nexport interface LicenseRule {\n /** The name of the license that a credit line prints. */\n readonly title: string;\n /** The address of the text of the license, or an empty string when the license has no text. */\n readonly url: string;\n /** This field is true when a guidebook can print the text of the source word for word. */\n readonly quote: boolean;\n /** This field is true when a guidebook can keep an offline copy of the full source. */\n readonly bundle: boolean;\n /** This field is true when the license permits only a use that is not commercial. */\n readonly nonCommercial: boolean;\n /** The layer of a quote. A share-alike license needs its own layer, so the rest of the guidebook keeps its own license. */\n readonly layer: Layer;\n /** This field is true when a quote or a bundle must print the credit line of the source. */\n readonly credit: boolean;\n /** This field is false for the license `invented`. A real guidebook cites only real sources. */\n readonly real: boolean;\n}\n\n/**\n * The rule of each license.\n *\n * - A US federal work (17 USC 105), a work in the public domain and a CC0 work permit each use.\n * - A CC BY work permits each use with a credit line. A CC BY-SA quote also needs its own layer.\n * - A CC BY-NC-SA work permits a bundle only while the guidebook is not commercial. The gate refuses a quote of it.\n * - A work with all rights reserved permits only a summary and a fact, with a citation.\n */\nexport const LICENSE_RULES: Readonly<Record<License, LicenseRule>> = {\n \"us-public-domain\": {\n title: \"US public domain (17 USC 105)\",\n url: \"https://www.law.cornell.edu/uscode/text/17/105\",\n quote: true,\n bundle: true,\n nonCommercial: false,\n layer: \"main\",\n credit: false,\n real: true,\n },\n \"public-domain\": { title: \"Public domain\", url: \"\", quote: true, bundle: true, nonCommercial: false, layer: \"main\", credit: false, real: true },\n cc0: {\n title: \"CC0 1.0\",\n url: \"https://creativecommons.org/publicdomain/zero/1.0/\",\n quote: true,\n bundle: true,\n nonCommercial: false,\n layer: \"main\",\n credit: false,\n real: true,\n },\n \"cc-by-4.0\": {\n title: \"CC BY 4.0\",\n url: \"https://creativecommons.org/licenses/by/4.0/\",\n quote: true,\n bundle: true,\n nonCommercial: false,\n layer: \"main\",\n credit: true,\n real: true,\n },\n \"cc-by-sa-4.0\": {\n title: \"CC BY-SA 4.0\",\n url: \"https://creativecommons.org/licenses/by-sa/4.0/\",\n quote: true,\n bundle: true,\n nonCommercial: false,\n layer: \"share-alike\",\n credit: true,\n real: true,\n },\n \"cc-by-sa-3.0\": {\n title: \"CC BY-SA 3.0\",\n url: \"https://creativecommons.org/licenses/by-sa/3.0/\",\n quote: true,\n bundle: true,\n nonCommercial: false,\n layer: \"share-alike\",\n credit: true,\n real: true,\n },\n \"cc-by-nc-sa-3.0\": {\n title: \"CC BY-NC-SA 3.0\",\n url: \"https://creativecommons.org/licenses/by-nc-sa/3.0/\",\n quote: false,\n bundle: true,\n nonCommercial: true,\n layer: \"share-alike\",\n credit: true,\n real: true,\n },\n \"all-rights-reserved\": { title: \"All rights reserved\", url: \"\", quote: false, bundle: false, nonCommercial: false, layer: \"main\", credit: false, real: true },\n invented: { title: \"Invented for a test\", url: \"\", quote: false, bundle: false, nonCommercial: false, layer: \"main\", credit: false, real: false },\n};\n\n/** The context of a use. A guidebook that is sold, or that shows paid advertisements, is commercial. */\nexport interface UseContext {\n /** This field is true when the guidebook is commercial. The default is false. */\n readonly commercial?: boolean;\n /** This field is true when the guidebook is a test fixture, so the license `invented` passes. The default is false. */\n readonly fixture?: boolean;\n}\n\n/**\n * This function tells if a license permits a use.\n * A summary and a fact are the words of the guidebook, so each real license permits them.\n * A non-commercial license refuses each use of its text in a commercial guidebook. A summary and a fact are not its text, so they stay.\n */\nexport function permits(license: License, use: Use, context: UseContext = {}): boolean {\n const rule = LICENSE_RULES[license];\n if (!rule.real) return context.fixture === true;\n if (use === \"summary\" || use === \"fact\") return true;\n if (rule.nonCommercial && context.commercial === true) return false;\n return use === \"quote\" ? rule.quote : rule.bundle;\n}\n","// The records of the core: a source and a cited unit of text.\n\nimport { LICENSE_RULES } from \"./license.ts\";\nimport type { License, Use } from \"./license.ts\";\n\n/** A date as `YYYY-MM-DD`. */\nexport type IsoDate = string;\n\n/** The `id` of a source. */\nexport type SourceId = string;\n\n/** A page or a document, with its license and the date of the last check. The license `invented` is for test fixtures only. */\nexport interface Source {\n readonly id: SourceId;\n readonly title: string;\n /** The address of the source, with `https:` or `http:`. */\n readonly url: string;\n readonly license: License;\n /** The date when a person or a job last read the source and compared it with the units that cite it. */\n readonly checked: IsoDate;\n /** The name that a credit line gives, for example the agency or the authors. The default is the title. */\n readonly by?: string;\n}\n\n/** The use of a cited unit. A bundle is a copy of a full source, so a unit cannot have the use `bundle`. */\nexport type UnitUse = Exclude<Use, \"bundle\">;\n\n/**\n * A cited unit: a quote (the text word for word), a summary (the words of the guidebook) or a fact (a value with a citation).\n */\nexport interface CitedUnit {\n readonly id: string;\n readonly use: UnitUse;\n readonly text: string;\n readonly source: SourceId;\n /** The place of the text in the source, for example a section or a page. */\n readonly locator?: string;\n}\n\n/**\n * This function gives the credit line of a source: its name, its title, its address, its license and the date of the check.\n * A guidebook prints it under each quote and each bundle whose license needs a credit.\n */\nexport function creditOf(source: Source): string {\n const rule = LICENSE_RULES[source.license];\n const name = source.by === undefined || source.by === source.title ? source.title : `${source.by}: ${source.title}`;\n const license = rule.url === \"\" ? rule.title : `${rule.title} (${rule.url})`;\n return `${name}. ${source.url}. ${license}. Checked ${source.checked}.`;\n}\n","// The source gate: the checks of the sources and the cited units of a guidebook.\n// The gate gives each finding as data. A caller prints the findings, or stops with `assertGate`.\n\nimport { LICENSE_RULES, LICENSES, permits } from \"./license.ts\";\nimport type { Layer, License, UseContext } from \"./license.ts\";\nimport type { CitedUnit, IsoDate, Source, SourceId } from \"./source.ts\";\n\n/** The codes of the findings of the gate. */\nexport const FINDING_CODES = [\n \"duplicate-id\",\n \"empty-title\",\n \"empty-text\",\n \"bad-url\",\n \"bad-date\",\n \"unknown-license\",\n \"checked-in-future\",\n \"stale\",\n \"missing-source\",\n \"use-refused\",\n] as const;\n\n/** A code of a finding. */\nexport type FindingCode = (typeof FINDING_CODES)[number];\n\n/**\n * A finding of a gate. A finding with the level `error` stops the gate. A `warning` tells of a review to do.\n * An add-on gives its own codes `C` and its own kinds of record `R`.\n */\nexport interface Finding<C extends string = FindingCode, R extends string = \"source\" | \"unit\"> {\n readonly level: \"error\" | \"warning\";\n readonly code: C;\n /** The kind of the record with the finding. */\n readonly record: R;\n /** The `id` of the record with the finding. */\n readonly id: string;\n readonly message: string;\n}\n\n/** The options of the gate. */\nexport interface GateOptions extends UseContext {\n /** The date of the gate. Without it, the gate does not examine the age of the checks. */\n readonly at?: IsoDate;\n /** A source whose check is older than this number of days gets the warning `stale`. The default is 365. */\n readonly maxAgeDays?: number;\n}\n\n/** The result of a gate. */\nexport interface GateResult<F extends Finding<string, string> = Finding> {\n /** This field is true when the result has no finding with the level `error`. */\n readonly ok: boolean;\n readonly findings: readonly F[];\n}\n\n/** This function gives the result of a list of findings. */\nexport function resultOf<F extends Finding<string, string>>(findings: readonly F[]): GateResult<F> {\n return { ok: findings.every((finding) => finding.level !== \"error\"), findings };\n}\n\n/** This function throws an error with each finding of the level `error`. The name of the gate starts the message. */\nexport function throwOnErrors(name: string, findings: readonly Finding<string, string>[]): void {\n const lines = findings.filter((finding) => finding.level === \"error\").map((finding) => `- ${finding.code}: ${finding.message}`);\n if (lines.length > 0) throw new Error(`The ${name} found ${lines.length} errors:\\n${lines.join(\"\\n\")}`);\n}\n\n/** The number of milliseconds in one day. */\nexport const DAY_MS = 86_400_000;\nconst ISO_DATE = /^\\d{4}-\\d{2}-\\d{2}$/;\n\n/** This function gives the time of a date `YYYY-MM-DD` in milliseconds, or `undefined` when the date is not a real date. */\nexport function timeOf(date: string): number | undefined {\n if (!ISO_DATE.test(date)) return undefined;\n const time = Date.parse(`${date}T00:00:00Z`);\n if (Number.isNaN(time)) return undefined;\n return new Date(time).toISOString().slice(0, 10) === date ? time : undefined;\n}\n\nfunction isLicense(value: unknown): value is License {\n return typeof value === \"string\" && (LICENSES as readonly string[]).includes(value);\n}\n\n/** An address with `https:` or `http:`, a host, and no space. The core uses no platform type, so it does not use `URL`. */\nconst WEB_ADDRESS = /^https?:\\/\\/[a-z0-9.-]+(?::\\d+)?(?:[/?#]\\S*)?$/iu;\n\n/** This function tells if a text is a web address that the gate accepts. */\nexport function isWebAddress(url: string): boolean {\n return WEB_ADDRESS.test(url);\n}\n\n/** This function gives the findings of the sources: duplicate ids, empty titles, bad addresses, bad dates, unknown licenses and old checks. */\nexport function checkSources(sources: readonly Source[], options: GateOptions = {}): readonly Finding[] {\n const out: Finding[] = [];\n const error = (code: FindingCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"source\", id, message });\n };\n const at = options.at === undefined ? undefined : timeOf(options.at);\n if (options.at !== undefined && at === undefined) throw new RangeError(`checkSources: the date \"${options.at}\" of the gate is not a date YYYY-MM-DD.`);\n const maxAge = options.maxAgeDays ?? 365;\n const seen = new Set<SourceId>();\n for (const source of sources) {\n if (seen.has(source.id)) error(\"duplicate-id\", source.id, `Two sources have the id \"${source.id}\".`);\n seen.add(source.id);\n if (source.title.trim() === \"\") error(\"empty-title\", source.id, `The source \"${source.id}\" has no title.`);\n if (!isWebAddress(source.url)) error(\"bad-url\", source.id, `The source \"${source.id}\" has the address \"${source.url}\". It needs an address with https: or http:.`);\n if (!isLicense(source.license)) error(\"unknown-license\", source.id, `The source \"${source.id}\" has the unknown license \"${String(source.license)}\".`);\n const checked = timeOf(source.checked);\n if (checked === undefined) {\n error(\"bad-date\", source.id, `The source \"${source.id}\" has the check date \"${source.checked}\". It needs a date YYYY-MM-DD.`);\n } else if (at !== undefined) {\n if (checked > at) error(\"checked-in-future\", source.id, `The source \"${source.id}\" has a check date after the date of the gate.`);\n const days = (at - checked) / DAY_MS;\n if (days > maxAge) {\n out.push({ level: \"warning\", code: \"stale\", record: \"source\", id: source.id, message: `The last check of the source \"${source.id}\" is ${days} days old. Read the source again.` });\n }\n }\n }\n return out;\n}\n\n/** This function gives the findings of the units: duplicate ids, empty text, a missing source, and a use that the license refuses. */\nexport function checkUnits(units: readonly CitedUnit[], sources: readonly Source[], options: UseContext = {}): readonly Finding[] {\n const out: Finding[] = [];\n const error = (code: FindingCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"unit\", id, message });\n };\n const byId = new Map(sources.map((source) => [source.id, source] as const));\n const seen = new Set<string>();\n for (const unit of units) {\n if (seen.has(unit.id)) error(\"duplicate-id\", unit.id, `Two units have the id \"${unit.id}\".`);\n seen.add(unit.id);\n if (unit.text.trim() === \"\") error(\"empty-text\", unit.id, `The unit \"${unit.id}\" has no text.`);\n const source = byId.get(unit.source);\n if (source === undefined) {\n error(\"missing-source\", unit.id, `The unit \"${unit.id}\" cites the source \"${unit.source}\", but the list does not have it.`);\n continue;\n }\n if (isLicense(source.license) && !permits(source.license, unit.use, options)) {\n error(\"use-refused\", unit.id, `The license \"${source.license}\" of the source \"${source.id}\" refuses the use \"${unit.use}\" of the unit \"${unit.id}\".`);\n }\n }\n return out;\n}\n\n/** This function applies the gate to the sources and the units of a guidebook. */\nexport function gate(units: readonly CitedUnit[], sources: readonly Source[], options: GateOptions = {}): GateResult {\n return resultOf([...checkSources(sources, options), ...checkUnits(units, sources, options)]);\n}\n\n/** This function applies the gate, and throws an error with each finding of the level `error`. */\nexport function assertGate(units: readonly CitedUnit[], sources: readonly Source[], options: GateOptions = {}): void {\n const result = gate(units, sources, options);\n if (result.ok) return;\n const lines = result.findings.filter((finding) => finding.level === \"error\").map((finding) => `- ${finding.code}: ${finding.message}`);\n throw new Error(`The source gate found ${lines.length} errors:\\n${lines.join(\"\\n\")}`);\n}\n\n/** This function gives the layer of a printed unit. Only a quote of a share-alike source goes to the share-alike layer. */\nexport function layerOf(unit: CitedUnit, source: Source): Layer {\n return unit.use === \"quote\" ? LICENSE_RULES[source.license].layer : \"main\";\n}\n"],"mappings":";;AAIA,MAAa,WAAW;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAMA,MAAa,OAAO;CAAC;CAAS;CAAW;CAAQ;AAAQ;;;;;;;;;AAwCzD,MAAa,gBAAwD;CACnE,oBAAoB;EAClB,OAAO;EACP,KAAK;EACL,OAAO;EACP,QAAQ;EACR,eAAe;EACf,OAAO;EACP,QAAQ;EACR,MAAM;CACR;CACA,iBAAiB;EAAE,OAAO;EAAiB,KAAK;EAAI,OAAO;EAAM,QAAQ;EAAM,eAAe;EAAO,OAAO;EAAQ,QAAQ;EAAO,MAAM;CAAK;CAC9I,KAAK;EACH,OAAO;EACP,KAAK;EACL,OAAO;EACP,QAAQ;EACR,eAAe;EACf,OAAO;EACP,QAAQ;EACR,MAAM;CACR;CACA,aAAa;EACX,OAAO;EACP,KAAK;EACL,OAAO;EACP,QAAQ;EACR,eAAe;EACf,OAAO;EACP,QAAQ;EACR,MAAM;CACR;CACA,gBAAgB;EACd,OAAO;EACP,KAAK;EACL,OAAO;EACP,QAAQ;EACR,eAAe;EACf,OAAO;EACP,QAAQ;EACR,MAAM;CACR;CACA,gBAAgB;EACd,OAAO;EACP,KAAK;EACL,OAAO;EACP,QAAQ;EACR,eAAe;EACf,OAAO;EACP,QAAQ;EACR,MAAM;CACR;CACA,mBAAmB;EACjB,OAAO;E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AAK,IAAI,0BAA0B,KAAK,GAAG,GAAG;EAC3F,KAAK,IAAI,KAAK,EAAE;EAChB,IAAI,KAAK,KAAK,KAAK,MAAM,IAAI,MAAM,cAAc,KAAK,IAAI,aAAa,KAAK,GAAG,eAAe;EAC9F,MAAM,SAAS,KAAK,IAAI,KAAK,MAAM;EACnC,IAAI,WAAW,KAAA,GAAW;GACxB,MAAM,kBAAkB,KAAK,IAAI,aAAa,KAAK,GAAG,sBAAsB,KAAK,OAAO,kCAAkC;GAC1H;EACF;EACA,IAAI,UAAU,OAAO,OAAO,KAAK,CAAC,QAAQ,OAAO,SAAS,KAAK,KAAK,OAAO,GACzE,MAAM,eAAe,KAAK,IAAI,gBAAgB,OAAO,QAAQ,mBAAmB,OAAO,GAAG,qBAAqB,KAAK,IAAI,iBAAiB,KAAK,GAAG,GAAG;CAExJ;CACA,OAAO;AACT;;AAGA,SAAgB,KAAK,OAA6B,SAA4B,UAAuB,CAAC,GAAe;CACnH,OAAO,SAAS,CAAC,GAAG,aAAa,SAAS,OAAO,GAAG,GAAG,WAAW,OAAO,SAAS,OAAO,CAAC,CAAC;AAC7F;;AAGA,SAAgB,WAAW,OAA6B,SAA4B,UAAuB,CAAC,GAAS;CACnH,MAAM,SAAS,KAAK,OAAO,SAAS,OAAO;CAC3C,IAAI,OAAO,IAAI;CACf,MAAM,QAAQ,OAAO,SAAS,QAAQ,YAAY,QAAQ,UAAU,OAAO,CAAC,CAAC,KAAK,YAAY,KAAK,QAAQ,KAAK,IAAI,QAAQ,SAAS;CACrI,MAAM,IAAI,MAAM,yBAAyB,MAAM,OAAO,YAAY,MAAM,KAAK,IAAI,GAAG;AACtF;;AAGA,SAAgB,QAAQ,MAAiB,QAAuB;CAC9D,OAAO,KAAK,QAAQ,UAAU,cAAc,OAAO,QAAQ,CAAC,QAAQ;AACtE"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/license.ts","../src/source.ts","../src/gate.ts"],"sourcesContent":["// The licenses of the sources, and the rule of each license.\n// The rules come from the text of each license. A rule tells what a guidebook can do with the text of a source.\n\n/** The licenses that the gate knows. The license `invented` is for test fixtures only. */\nexport const LICENSES = [\n \"us-public-domain\",\n \"public-domain\",\n \"cc0\",\n \"cc-by-4.0\",\n \"cc-by-sa-4.0\",\n \"cc-by-sa-3.0\",\n \"cc-by-nc-sa-3.0\",\n \"ogl-uk-3.0\",\n \"all-rights-reserved\",\n \"link-only\",\n \"invented\",\n] as const;\n\n/** A license of a source. The source gate refuses a use that the license does not permit. */\nexport type License = (typeof LICENSES)[number];\n\n/** The ways to use a source. A unit of text has one use, and an offline copy of the full source is a bundle. */\nexport const USES = [\"quote\", \"summary\", \"fact\", \"bundle\"] as const;\n\n/**\n * A use of a source.\n * `quote` is the text word for word. `summary` is the text in the words of the guidebook. `fact` is a value with a citation.\n * `bundle` is an offline copy of the full source.\n */\nexport type Use = (typeof USES)[number];\n\n/** The layer of a printed quote. A share-alike quote prints in its own layer, with its credit and its license. */\nexport type Layer = \"main\" | \"share-alike\";\n\n/** The rule of one license. */\nexport interface LicenseRule {\n /** The name of the license that a credit line prints. */\n readonly title: string;\n /** The address of the text of the license, or an empty string when the license has no text. */\n readonly url: string;\n /** This field is true when a guidebook can print the text of the source word for word. */\n readonly quote: boolean;\n /** This field is true when a guidebook can keep an offline copy of the full source. */\n readonly bundle: boolean;\n /** This field is true when a guidebook can write a summary or a fact of the source. It is false when a guidebook can only link to the source. */\n readonly units: boolean;\n /** This field is true when the license permits only a use that is not commercial. */\n readonly nonCommercial: boolean;\n /** The layer of a quote. A share-alike license needs its own layer, so the rest of the guidebook keeps its own license. */\n readonly layer: Layer;\n /** This field is true when a quote or a bundle must print the credit line of the source. */\n readonly credit: boolean;\n /** This field is false for the license `invented`. A real guidebook cites only real sources. */\n readonly real: boolean;\n}\n\n/**\n * The rule of each license.\n *\n * - A US federal work (17 USC 105), a work in the public domain and a CC0 work permit each use.\n * - A CC BY work permits each use with a credit line. A CC BY-SA quote also needs its own layer.\n * - A CC BY-NC-SA work permits a bundle only while the guidebook is not commercial. The gate refuses a quote of it.\n * - A work with all rights reserved permits only a summary and a fact, with a citation.\n * - A link-only work permits no use of its text. A guidebook can only link to it, for example when its publisher refuses each AI use.\n */\nexport const LICENSE_RULES: Readonly<Record<License, LicenseRule>> = {\n \"us-public-domain\": {\n title: \"US public domain (17 USC 105)\",\n url: \"https://www.law.cornell.edu/uscode/text/17/105\",\n quote: true,\n bundle: true,\n units: true,\n nonCommercial: false,\n layer: \"main\",\n credit: false,\n real: true,\n },\n \"public-domain\": { title: \"Public domain\", url: \"\", quote: true, bundle: true, units: true, nonCommercial: false, layer: \"main\", credit: false, real: true },\n cc0: {\n title: \"CC0 1.0\",\n url: \"https://creativecommons.org/publicdomain/zero/1.0/\",\n quote: true,\n bundle: true,\n units: true,\n nonCommercial: false,\n layer: \"main\",\n credit: false,\n real: true,\n },\n \"cc-by-4.0\": {\n title: \"CC BY 4.0\",\n url: \"https://creativecommons.org/licenses/by/4.0/\",\n quote: true,\n bundle: true,\n units: true,\n nonCommercial: false,\n layer: \"main\",\n credit: true,\n real: true,\n },\n \"cc-by-sa-4.0\": {\n title: \"CC BY-SA 4.0\",\n url: \"https://creativecommons.org/licenses/by-sa/4.0/\",\n quote: true,\n bundle: true,\n units: true,\n nonCommercial: false,\n layer: \"share-alike\",\n credit: true,\n real: true,\n },\n \"cc-by-sa-3.0\": {\n title: \"CC BY-SA 3.0\",\n url: \"https://creativecommons.org/licenses/by-sa/3.0/\",\n quote: true,\n bundle: true,\n units: true,\n nonCommercial: false,\n layer: \"share-alike\",\n credit: true,\n real: true,\n },\n \"cc-by-nc-sa-3.0\": {\n title: \"CC BY-NC-SA 3.0\",\n url: \"https://creativecommons.org/licenses/by-nc-sa/3.0/\",\n quote: false,\n bundle: true,\n units: true,\n nonCommercial: true,\n layer: \"share-alike\",\n credit: true,\n real: true,\n },\n \"ogl-uk-3.0\": {\n title: \"Open Government Licence v3.0\",\n url: \"https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/\",\n quote: true,\n bundle: true,\n units: true,\n nonCommercial: false,\n layer: \"main\",\n credit: true,\n real: true,\n },\n \"all-rights-reserved\": { title: \"All rights reserved\", url: \"\", quote: false, bundle: false, units: true, nonCommercial: false, layer: \"main\", credit: false, real: true },\n \"link-only\": { title: \"Link only\", url: \"\", quote: false, bundle: false, units: false, nonCommercial: false, layer: \"main\", credit: false, real: true },\n invented: { title: \"Invented for a test\", url: \"\", quote: false, bundle: false, units: true, nonCommercial: false, layer: \"main\", credit: false, real: false },\n};\n\n/** The context of a use. A guidebook that is sold, or that shows paid advertisements, is commercial. */\nexport interface UseContext {\n /** This field is true when the guidebook is commercial. The default is false. */\n readonly commercial?: boolean;\n /** This field is true when the guidebook is a test fixture, so the license `invented` passes. The default is false. */\n readonly fixture?: boolean;\n}\n\n/**\n * This function tells if a license permits a use.\n * A summary and a fact are the words of the guidebook, so each real license permits them, but a link-only license refuses them.\n * A non-commercial license refuses each use of its text in a commercial guidebook. A summary and a fact are not its text, so they stay.\n */\nexport function permits(license: License, use: Use, context: UseContext = {}): boolean {\n const rule = LICENSE_RULES[license];\n if (!rule.real) return context.fixture === true;\n if (use === \"summary\" || use === \"fact\") return rule.units;\n if (rule.nonCommercial && context.commercial === true) return false;\n return use === \"quote\" ? rule.quote : rule.bundle;\n}\n","// The records of the core: a source and a cited unit of text.\n\nimport { LICENSE_RULES } from \"./license.ts\";\nimport type { License, Use } from \"./license.ts\";\n\n/** A date as `YYYY-MM-DD`. */\nexport type IsoDate = string;\n\n/** The `id` of a source. */\nexport type SourceId = string;\n\n/** A page or a document, with its license and the date of the last check. The license `invented` is for test fixtures only. */\nexport interface Source {\n readonly id: SourceId;\n readonly title: string;\n /** The address of the source, with `https:` or `http:`. */\n readonly url: string;\n readonly license: License;\n /** The date when a person or a job last read the source and compared it with the units that cite it. */\n readonly checked: IsoDate;\n /** The name that a credit line gives, for example the agency or the authors. The default is the title. */\n readonly by?: string;\n /** A term of the publisher in addition to the license, with its date, for example \"No AI ingestion (publisher, 2026-11-23)\". */\n readonly note?: string;\n}\n\n/** The use of a cited unit. A bundle is a copy of a full source, so a unit cannot have the use `bundle`. */\nexport type UnitUse = Exclude<Use, \"bundle\">;\n\n/**\n * A cited unit: a quote (the text word for word), a summary (the words of the guidebook) or a fact (a value with a citation).\n */\nexport interface CitedUnit {\n readonly id: string;\n readonly use: UnitUse;\n readonly text: string;\n readonly source: SourceId;\n /** The place of the text in the source, for example a section or a page. */\n readonly locator?: string;\n}\n\n/**\n * This function gives the credit line of a source: its name, its title, its address, its license and the date of the check.\n * A guidebook prints it under each quote and each bundle whose license needs a credit.\n */\nexport function creditOf(source: Source): string {\n const rule = LICENSE_RULES[source.license];\n const name = source.by === undefined || source.by === source.title ? source.title : `${source.by}: ${source.title}`;\n const license = rule.url === \"\" ? rule.title : `${rule.title} (${rule.url})`;\n return `${name}. ${source.url}. ${license}. Checked ${source.checked}.`;\n}\n","// The source gate: the checks of the sources and the cited units of a guidebook.\n// The gate gives each finding as data. A caller prints the findings, or stops with `assertGate`.\n\nimport { LICENSE_RULES, LICENSES, permits } from \"./license.ts\";\nimport type { Layer, License, UseContext } from \"./license.ts\";\nimport type { CitedUnit, IsoDate, Source, SourceId } from \"./source.ts\";\n\n/** The codes of the findings of the gate. */\nexport const FINDING_CODES = [\n \"duplicate-id\",\n \"empty-title\",\n \"empty-text\",\n \"bad-url\",\n \"bad-date\",\n \"unknown-license\",\n \"checked-in-future\",\n \"stale\",\n \"missing-source\",\n \"use-refused\",\n] as const;\n\n/** A code of a finding. */\nexport type FindingCode = (typeof FINDING_CODES)[number];\n\n/**\n * A finding of a gate. A finding with the level `error` stops the gate. A `warning` tells of a review to do.\n * An add-on gives its own codes `C` and its own kinds of record `R`.\n */\nexport interface Finding<C extends string = FindingCode, R extends string = \"source\" | \"unit\"> {\n readonly level: \"error\" | \"warning\";\n readonly code: C;\n /** The kind of the record with the finding. */\n readonly record: R;\n /** The `id` of the record with the finding. */\n readonly id: string;\n readonly message: string;\n}\n\n/** The options of the gate. */\nexport interface GateOptions extends UseContext {\n /** The date of the gate. Without it, the gate does not examine the age of the checks. */\n readonly at?: IsoDate;\n /** A source whose check is older than this number of days gets the warning `stale`. The default is 365. */\n readonly maxAgeDays?: number;\n}\n\n/** The result of a gate. */\nexport interface GateResult<F extends Finding<string, string> = Finding> {\n /** This field is true when the result has no finding with the level `error`. */\n readonly ok: boolean;\n readonly findings: readonly F[];\n}\n\n/** This function gives the result of a list of findings. */\nexport function resultOf<F extends Finding<string, string>>(findings: readonly F[]): GateResult<F> {\n return { ok: findings.every((finding) => finding.level !== \"error\"), findings };\n}\n\n/** This function throws an error with each finding of the level `error`. The name of the gate starts the message. */\nexport function throwOnErrors(name: string, findings: readonly Finding<string, string>[]): void {\n const lines = findings.filter((finding) => finding.level === \"error\").map((finding) => `- ${finding.code}: ${finding.message}`);\n if (lines.length > 0) throw new Error(`The ${name} found ${lines.length} errors:\\n${lines.join(\"\\n\")}`);\n}\n\n/** The number of milliseconds in one day. */\nexport const DAY_MS = 86_400_000;\nconst ISO_DATE = /^\\d{4}-\\d{2}-\\d{2}$/;\n\n/** This function gives the time of a date `YYYY-MM-DD` in milliseconds, or `undefined` when the date is not a real date. */\nexport function timeOf(date: string): number | undefined {\n if (!ISO_DATE.test(date)) return undefined;\n const time = Date.parse(`${date}T00:00:00Z`);\n if (Number.isNaN(time)) return undefined;\n return new Date(time).toISOString().slice(0, 10) === date ? time : undefined;\n}\n\nfunction isLicense(value: unknown): value is License {\n return typeof value === \"string\" && (LICENSES as readonly string[]).includes(value);\n}\n\n/** An address with `https:` or `http:`, a host, and no space. The core uses no platform type, so it does not use `URL`. */\nconst WEB_ADDRESS = /^https?:\\/\\/[a-z0-9.-]+(?::\\d+)?(?:[/?#]\\S*)?$/iu;\n\n/** This function tells if a text is a web address that the gate accepts. */\nexport function isWebAddress(url: string): boolean {\n return WEB_ADDRESS.test(url);\n}\n\n/** This function gives the findings of the sources: duplicate ids, empty titles, bad addresses, bad dates, unknown licenses and old checks. */\nexport function checkSources(sources: readonly Source[], options: GateOptions = {}): readonly Finding[] {\n const out: Finding[] = [];\n const error = (code: FindingCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"source\", id, message });\n };\n const at = options.at === undefined ? undefined : timeOf(options.at);\n if (options.at !== undefined && at === undefined) throw new RangeError(`checkSources: the date \"${options.at}\" of the gate is not a date YYYY-MM-DD.`);\n const maxAge = options.maxAgeDays ?? 365;\n const seen = new Set<SourceId>();\n for (const source of sources) {\n if (seen.has(source.id)) error(\"duplicate-id\", source.id, `Two sources have the id \"${source.id}\".`);\n seen.add(source.id);\n if (source.title.trim() === \"\") error(\"empty-title\", source.id, `The source \"${source.id}\" has no title.`);\n if (!isWebAddress(source.url)) error(\"bad-url\", source.id, `The source \"${source.id}\" has the address \"${source.url}\". It needs an address with https: or http:.`);\n if (!isLicense(source.license)) error(\"unknown-license\", source.id, `The source \"${source.id}\" has the unknown license \"${String(source.license)}\".`);\n const checked = timeOf(source.checked);\n if (checked === undefined) {\n error(\"bad-date\", source.id, `The source \"${source.id}\" has the check date \"${source.checked}\". It needs a date YYYY-MM-DD.`);\n } else if (at !== undefined) {\n if (checked > at) error(\"checked-in-future\", source.id, `The source \"${source.id}\" has a check date after the date of the gate.`);\n const days = (at - checked) / DAY_MS;\n if (days > maxAge) {\n out.push({ level: \"warning\", code: \"stale\", record: \"source\", id: source.id, message: `The last check of the source \"${source.id}\" is ${days} days old. Read the source again.` });\n }\n }\n }\n return out;\n}\n\n/** This function gives the findings of the units: duplicate ids, empty text, a missing source, and a use that the license refuses. */\nexport function checkUnits(units: readonly CitedUnit[], sources: readonly Source[], options: UseContext = {}): readonly Finding[] {\n const out: Finding[] = [];\n const error = (code: FindingCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"unit\", id, message });\n };\n const byId = new Map(sources.map((source) => [source.id, source] as const));\n const seen = new Set<string>();\n for (const unit of units) {\n if (seen.has(unit.id)) error(\"duplicate-id\", unit.id, `Two units have the id \"${unit.id}\".`);\n seen.add(unit.id);\n if (unit.text.trim() === \"\") error(\"empty-text\", unit.id, `The unit \"${unit.id}\" has no text.`);\n const source = byId.get(unit.source);\n if (source === undefined) {\n error(\"missing-source\", unit.id, `The unit \"${unit.id}\" cites the source \"${unit.source}\", but the list does not have it.`);\n continue;\n }\n if (isLicense(source.license) && !permits(source.license, unit.use, options)) {\n error(\"use-refused\", unit.id, `The license \"${source.license}\" of the source \"${source.id}\" refuses the use \"${unit.use}\" of the unit \"${unit.id}\".`);\n }\n }\n return out;\n}\n\n/** This function applies the gate to the sources and the units of a guidebook. */\nexport function gate(units: readonly CitedUnit[], sources: readonly Source[], options: GateOptions = {}): GateResult {\n return resultOf([...checkSources(sources, options), ...checkUnits(units, sources, options)]);\n}\n\n/** This function applies the gate, and throws an error with each finding of the level `error`. */\nexport function assertGate(units: readonly CitedUnit[], sources: readonly Source[], options: GateOptions = {}): void {\n const result = gate(units, sources, options);\n if (result.ok) return;\n const lines = result.findings.filter((finding) => finding.level === \"error\").map((finding) => `- ${finding.code}: ${finding.message}`);\n throw new Error(`The source gate found ${lines.length} errors:\\n${lines.join(\"\\n\")}`);\n}\n\n/** This function gives the layer of a printed unit. Only a quote of a share-alike source goes to the share-alike layer. */\nexport function layerOf(unit: CitedUnit, source: Source): Layer {\n return unit.use === \"quote\" ? LICENSE_RULES[source.license].layer : \"main\";\n}\n"],"mappings":";;AAIA,MAAa,WAAW;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAMA,MAAa,OAAO;CAAC;CAAS;CAAW;CAAQ;AAAQ;;;;;;;;;;AA2CzD,MAAa,gBAAwD;CACnE,oBAAoB;EAClB,OAAO;EACP,KAAK;EACL,OAAO;EACP,QAAQ;EACR,OAAO;EACP,eAAe;EACf,OAAO;EACP,QAAQ;EACR,MAAM;CACR;CACA,iBAAiB;EAAE,OAAO;EAAiB,KAAK;EAAI,OAAO;EAAM,QAAQ;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AS,KAAK,KAAK,OAAO,GACzE,MAAM,eAAe,KAAK,IAAI,gBAAgB,OAAO,QAAQ,mBAAmB,OAAO,GAAG,qBAAqB,KAAK,IAAI,iBAAiB,KAAK,GAAG,GAAG;CAExJ;CACA,OAAO;AACT;;AAGA,SAAgB,KAAK,OAA6B,SAA4B,UAAuB,CAAC,GAAe;CACnH,OAAO,SAAS,CAAC,GAAG,aAAa,SAAS,OAAO,GAAG,GAAG,WAAW,OAAO,SAAS,OAAO,CAAC,CAAC;AAC7F;;AAGA,SAAgB,WAAW,OAA6B,SAA4B,UAAuB,CAAC,GAAS;CACnH,MAAM,SAAS,KAAK,OAAO,SAAS,OAAO;CAC3C,IAAI,OAAO,IAAI;CACf,MAAM,QAAQ,OAAO,SAAS,QAAQ,YAAY,QAAQ,UAAU,OAAO,CAAC,CAAC,KAAK,YAAY,KAAK,QAAQ,KAAK,IAAI,QAAQ,SAAS;CACrI,MAAM,IAAI,MAAM,yBAAyB,MAAM,OAAO,YAAY,MAAM,KAAK,IAAI,GAAG;AACtF;;AAGA,SAAgB,QAAQ,MAAiB,QAAuB;CAC9D,OAAO,KAAK,QAAQ,UAAU,cAAc,OAAO,QAAQ,CAAC,QAAQ;AACtE"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/guidebook",
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "description": "The core of a guidebook of cited knowledge: sources with their licenses, cited units (a quote, a summary or a fact) and the source gate. The core names no topic.",
6
6
  "keywords": [
7
7
  "guidebook",
package/src/license.ts CHANGED
@@ -10,7 +10,9 @@ export const LICENSES = [
10
10
  "cc-by-sa-4.0",
11
11
  "cc-by-sa-3.0",
12
12
  "cc-by-nc-sa-3.0",
13
+ "ogl-uk-3.0",
13
14
  "all-rights-reserved",
15
+ "link-only",
14
16
  "invented",
15
17
  ] as const;
16
18
 
@@ -40,6 +42,8 @@ export interface LicenseRule {
40
42
  readonly quote: boolean;
41
43
  /** This field is true when a guidebook can keep an offline copy of the full source. */
42
44
  readonly bundle: boolean;
45
+ /** This field is true when a guidebook can write a summary or a fact of the source. It is false when a guidebook can only link to the source. */
46
+ readonly units: boolean;
43
47
  /** This field is true when the license permits only a use that is not commercial. */
44
48
  readonly nonCommercial: boolean;
45
49
  /** The layer of a quote. A share-alike license needs its own layer, so the rest of the guidebook keeps its own license. */
@@ -57,6 +61,7 @@ export interface LicenseRule {
57
61
  * - A CC BY work permits each use with a credit line. A CC BY-SA quote also needs its own layer.
58
62
  * - A CC BY-NC-SA work permits a bundle only while the guidebook is not commercial. The gate refuses a quote of it.
59
63
  * - A work with all rights reserved permits only a summary and a fact, with a citation.
64
+ * - A link-only work permits no use of its text. A guidebook can only link to it, for example when its publisher refuses each AI use.
60
65
  */
61
66
  export const LICENSE_RULES: Readonly<Record<License, LicenseRule>> = {
62
67
  "us-public-domain": {
@@ -64,17 +69,19 @@ export const LICENSE_RULES: Readonly<Record<License, LicenseRule>> = {
64
69
  url: "https://www.law.cornell.edu/uscode/text/17/105",
65
70
  quote: true,
66
71
  bundle: true,
72
+ units: true,
67
73
  nonCommercial: false,
68
74
  layer: "main",
69
75
  credit: false,
70
76
  real: true,
71
77
  },
72
- "public-domain": { title: "Public domain", url: "", quote: true, bundle: true, nonCommercial: false, layer: "main", credit: false, real: true },
78
+ "public-domain": { title: "Public domain", url: "", quote: true, bundle: true, units: true, nonCommercial: false, layer: "main", credit: false, real: true },
73
79
  cc0: {
74
80
  title: "CC0 1.0",
75
81
  url: "https://creativecommons.org/publicdomain/zero/1.0/",
76
82
  quote: true,
77
83
  bundle: true,
84
+ units: true,
78
85
  nonCommercial: false,
79
86
  layer: "main",
80
87
  credit: false,
@@ -85,6 +92,7 @@ export const LICENSE_RULES: Readonly<Record<License, LicenseRule>> = {
85
92
  url: "https://creativecommons.org/licenses/by/4.0/",
86
93
  quote: true,
87
94
  bundle: true,
95
+ units: true,
88
96
  nonCommercial: false,
89
97
  layer: "main",
90
98
  credit: true,
@@ -95,6 +103,7 @@ export const LICENSE_RULES: Readonly<Record<License, LicenseRule>> = {
95
103
  url: "https://creativecommons.org/licenses/by-sa/4.0/",
96
104
  quote: true,
97
105
  bundle: true,
106
+ units: true,
98
107
  nonCommercial: false,
99
108
  layer: "share-alike",
100
109
  credit: true,
@@ -105,6 +114,7 @@ export const LICENSE_RULES: Readonly<Record<License, LicenseRule>> = {
105
114
  url: "https://creativecommons.org/licenses/by-sa/3.0/",
106
115
  quote: true,
107
116
  bundle: true,
117
+ units: true,
108
118
  nonCommercial: false,
109
119
  layer: "share-alike",
110
120
  credit: true,
@@ -115,13 +125,26 @@ export const LICENSE_RULES: Readonly<Record<License, LicenseRule>> = {
115
125
  url: "https://creativecommons.org/licenses/by-nc-sa/3.0/",
116
126
  quote: false,
117
127
  bundle: true,
128
+ units: true,
118
129
  nonCommercial: true,
119
130
  layer: "share-alike",
120
131
  credit: true,
121
132
  real: true,
122
133
  },
123
- "all-rights-reserved": { title: "All rights reserved", url: "", quote: false, bundle: false, nonCommercial: false, layer: "main", credit: false, real: true },
124
- invented: { title: "Invented for a test", url: "", quote: false, bundle: false, nonCommercial: false, layer: "main", credit: false, real: false },
134
+ "ogl-uk-3.0": {
135
+ title: "Open Government Licence v3.0",
136
+ url: "https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/",
137
+ quote: true,
138
+ bundle: true,
139
+ units: true,
140
+ nonCommercial: false,
141
+ layer: "main",
142
+ credit: true,
143
+ real: true,
144
+ },
145
+ "all-rights-reserved": { title: "All rights reserved", url: "", quote: false, bundle: false, units: true, nonCommercial: false, layer: "main", credit: false, real: true },
146
+ "link-only": { title: "Link only", url: "", quote: false, bundle: false, units: false, nonCommercial: false, layer: "main", credit: false, real: true },
147
+ invented: { title: "Invented for a test", url: "", quote: false, bundle: false, units: true, nonCommercial: false, layer: "main", credit: false, real: false },
125
148
  };
126
149
 
127
150
  /** The context of a use. A guidebook that is sold, or that shows paid advertisements, is commercial. */
@@ -134,13 +157,13 @@ export interface UseContext {
134
157
 
135
158
  /**
136
159
  * This function tells if a license permits a use.
137
- * A summary and a fact are the words of the guidebook, so each real license permits them.
160
+ * A summary and a fact are the words of the guidebook, so each real license permits them, but a link-only license refuses them.
138
161
  * A non-commercial license refuses each use of its text in a commercial guidebook. A summary and a fact are not its text, so they stay.
139
162
  */
140
163
  export function permits(license: License, use: Use, context: UseContext = {}): boolean {
141
164
  const rule = LICENSE_RULES[license];
142
165
  if (!rule.real) return context.fixture === true;
143
- if (use === "summary" || use === "fact") return true;
166
+ if (use === "summary" || use === "fact") return rule.units;
144
167
  if (rule.nonCommercial && context.commercial === true) return false;
145
168
  return use === "quote" ? rule.quote : rule.bundle;
146
169
  }
package/src/source.ts CHANGED
@@ -20,6 +20,8 @@ export interface Source {
20
20
  readonly checked: IsoDate;
21
21
  /** The name that a credit line gives, for example the agency or the authors. The default is the title. */
22
22
  readonly by?: string;
23
+ /** A term of the publisher in addition to the license, with its date, for example "No AI ingestion (publisher, 2026-11-23)". */
24
+ readonly note?: string;
23
25
  }
24
26
 
25
27
  /** The use of a cited unit. A bundle is a copy of a full source, so a unit cannot have the use `bundle`. */