@faith-tools/bible-sdk 0.0.0-stage → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +535 -2
- package/dist/bible-sdk.js +261 -0
- package/dist/data/effect.js +65 -0
- package/dist/data.js +16 -0
- package/dist/index.js +946 -0
- package/dist/providers/fetch-bible.js +254 -0
- package/dist/providers/helloao.js +1 -0
- package/dist/providers/youversion.js +1 -0
- package/dist/providers-D_4UrThl.js +431 -0
- package/dist/runtime-C-BCRjZd.js +220 -0
- package/dist/scripture-inline.js +261 -0
- package/dist/types/card.d.ts +20 -0
- package/dist/types/data-effect.d.ts +184 -0
- package/dist/types/data-helpers.d.ts +21 -0
- package/dist/types/data-types.d.ts +112 -0
- package/dist/types/data.d.ts +91 -0
- package/dist/types/dom-runtime.d.ts +5 -0
- package/dist/types/find.d.ts +12 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/passage-input.d.ts +57 -0
- package/dist/types/providers/fetch-bible.d.ts +14 -0
- package/dist/types/providers/helloao.d.ts +1 -0
- package/dist/types/providers/youversion.d.ts +1 -0
- package/dist/types/providers.d.ts +62 -0
- package/dist/types/runtime.d.ts +18 -0
- package/dist/types/scan.d.ts +8 -0
- package/dist/types/scripture-passage.d.ts +61 -0
- package/dist/types/version-input.d.ts +64 -0
- package/package.json +78 -3
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { Cache as e, Context as t, Duration as n, Effect as r, Exit as i, Schedule as a, Schema as o } from "effect";
|
|
2
|
+
// src/data-types.ts
|
|
3
|
+
var s = o.Struct({
|
|
4
|
+
id: o.NonEmptyString,
|
|
5
|
+
abbreviation: o.String,
|
|
6
|
+
title: o.String,
|
|
7
|
+
language: o.optional(o.String),
|
|
8
|
+
languageName: o.optional(o.String)
|
|
9
|
+
}), c = o.Struct({
|
|
10
|
+
code: o.NonEmptyString,
|
|
11
|
+
level: o.Literals([
|
|
12
|
+
"required",
|
|
13
|
+
"recommended",
|
|
14
|
+
"notice"
|
|
15
|
+
]),
|
|
16
|
+
appliesTo: o.Literals([
|
|
17
|
+
"all",
|
|
18
|
+
"text",
|
|
19
|
+
"html"
|
|
20
|
+
]),
|
|
21
|
+
text: o.NonEmptyString,
|
|
22
|
+
urls: o.optional(o.Array(o.String))
|
|
23
|
+
}), l = o.Struct({
|
|
24
|
+
id: o.NonEmptyString,
|
|
25
|
+
title: o.String
|
|
26
|
+
}), u = o.Struct({
|
|
27
|
+
passageId: o.NonEmptyString,
|
|
28
|
+
number: o.Int.check(o.isGreaterThan(0))
|
|
29
|
+
}), d = o.Struct({
|
|
30
|
+
provider: o.NonEmptyString,
|
|
31
|
+
source: o.Struct({
|
|
32
|
+
url: o.String,
|
|
33
|
+
versionId: o.NonEmptyString
|
|
34
|
+
}),
|
|
35
|
+
requestedPassageId: o.NonEmptyString,
|
|
36
|
+
passageId: o.NonEmptyString,
|
|
37
|
+
reference: o.String,
|
|
38
|
+
text: o.String,
|
|
39
|
+
version: s.mapFields((e) => ({
|
|
40
|
+
...e,
|
|
41
|
+
sourceLanguage: o.optional(o.String)
|
|
42
|
+
})),
|
|
43
|
+
attribution: o.Struct({
|
|
44
|
+
text: o.NonEmptyString,
|
|
45
|
+
urls: o.Array(o.String)
|
|
46
|
+
}),
|
|
47
|
+
licenses: o.Array(o.Struct({
|
|
48
|
+
name: o.optional(o.String),
|
|
49
|
+
url: o.String,
|
|
50
|
+
restrictions: o.optional(o.Record(o.String, o.Union([o.Boolean, o.String])))
|
|
51
|
+
})),
|
|
52
|
+
numbering: o.Literals(["kjv", "unknown"]),
|
|
53
|
+
sourceLimitations: o.optional(o.Array(o.Struct({
|
|
54
|
+
kind: o.Literal("source-trimming"),
|
|
55
|
+
startPassageId: o.NonEmptyString,
|
|
56
|
+
endPassageId: o.NonEmptyString,
|
|
57
|
+
appliesToRequest: o.Boolean
|
|
58
|
+
}))),
|
|
59
|
+
display: o.Struct({
|
|
60
|
+
format: o.Literal("text"),
|
|
61
|
+
whitespace: o.Literal("pre-wrap"),
|
|
62
|
+
attributionPlacement: o.Literal("after-passage"),
|
|
63
|
+
direction: o.optional(o.Literals(["ltr", "rtl"])),
|
|
64
|
+
language: o.optional(o.String),
|
|
65
|
+
nativeHtml: o.optional(o.Struct({
|
|
66
|
+
containerAttributes: o.Record(o.String, o.String),
|
|
67
|
+
stylesheets: o.Array(o.Struct({
|
|
68
|
+
kind: o.Literals(["bible", "font"]),
|
|
69
|
+
href: o.String
|
|
70
|
+
}))
|
|
71
|
+
}))
|
|
72
|
+
}),
|
|
73
|
+
instructions: o.Array(c)
|
|
74
|
+
}), f = class extends t.Service()("@faith-tools/scripture-inline/data/BibleSource") {}, p = o.Literals([
|
|
75
|
+
"invalid_reference",
|
|
76
|
+
"unavailable",
|
|
77
|
+
"unsupported",
|
|
78
|
+
"authentication",
|
|
79
|
+
"rate_limit",
|
|
80
|
+
"network",
|
|
81
|
+
"timeout",
|
|
82
|
+
"invalid_response"
|
|
83
|
+
]), m = class extends o.TaggedError()("ScriptureError", {
|
|
84
|
+
code: p,
|
|
85
|
+
message: o.String,
|
|
86
|
+
cause: o.optional(o.Defect())
|
|
87
|
+
}) {
|
|
88
|
+
get retryable() {
|
|
89
|
+
return this.code === "network" || this.code === "rate_limit";
|
|
90
|
+
}
|
|
91
|
+
}, h = o.String.check(o.makeFilter((e) => {
|
|
92
|
+
try {
|
|
93
|
+
return new Intl.Locale(e), !0;
|
|
94
|
+
} catch {
|
|
95
|
+
return "Invalid source language tag.";
|
|
96
|
+
}
|
|
97
|
+
})), g = (e) => e.replace(/[&<>"']/g, (e) => ({
|
|
98
|
+
"&": "&",
|
|
99
|
+
"<": "<",
|
|
100
|
+
">": ">",
|
|
101
|
+
"\"": """,
|
|
102
|
+
"'": "'"
|
|
103
|
+
})[e]);
|
|
104
|
+
function _(e, t) {
|
|
105
|
+
let n = g(e);
|
|
106
|
+
return /^https?:\/\//i.test(t) ? `<a href="${g(t)}">${n}</a>` : n;
|
|
107
|
+
}
|
|
108
|
+
var v = o.String.check(o.isPattern(/^[1-4A-Z][A-Z0-9]{2}\.[1-9]\d*(?:\.[1-9]\d*(?:-[1-9]\d*)?)?$/)), y = o.String.check(o.isPattern(/^[1-4A-Z][A-Z0-9]{2}$/)), b = o.NumberFromString.check(o.isInt(), o.isGreaterThan(0), o.isLessThanOrEqualTo(2 ** 53 - 1)), x = o.Struct({
|
|
109
|
+
book: y,
|
|
110
|
+
chapter: b,
|
|
111
|
+
first: o.optional(b),
|
|
112
|
+
last: o.optional(b)
|
|
113
|
+
}).check(o.makeFilter((e) => e.first === void 0 || e.last >= e.first || "Range endpoints must be ascending.")), S = (e) => new m({
|
|
114
|
+
code: "invalid_reference",
|
|
115
|
+
message: "Use an uppercase USFM verse, ascending range, or chapter with positive safe integers. Ranges cannot cross chapters.",
|
|
116
|
+
cause: e
|
|
117
|
+
}), C = r.fnUntraced(function* (e) {
|
|
118
|
+
let [t, n, i] = (yield* o.decodeUnknownEffect(v)(e).pipe(r.mapError(S))).split("."), [a, s = a] = i?.split("-") ?? [];
|
|
119
|
+
return yield* o.decodeUnknownEffect(x)({
|
|
120
|
+
book: t,
|
|
121
|
+
chapter: n,
|
|
122
|
+
first: a,
|
|
123
|
+
last: s
|
|
124
|
+
}).pipe(r.mapError(S));
|
|
125
|
+
}), w = (e) => o.decodeUnknownEffect(y)(e).pipe(r.mapError(S));
|
|
126
|
+
function T(e, t, n) {
|
|
127
|
+
return !e.length || t !== void 0 && (!e.includes(t) || !e.includes(n)) ? r.fail(new m({
|
|
128
|
+
code: "unavailable",
|
|
129
|
+
message: "Passage is not available in this version."
|
|
130
|
+
})) : r.void;
|
|
131
|
+
}
|
|
132
|
+
function E() {
|
|
133
|
+
return [
|
|
134
|
+
{
|
|
135
|
+
code: "display-attribution",
|
|
136
|
+
level: "required",
|
|
137
|
+
appliesTo: "all",
|
|
138
|
+
text: "Display attribution.text after the passage, separately from Scripture. Preserve its wording and supplied source and license links."
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
code: "preserve-scripture",
|
|
142
|
+
level: "required",
|
|
143
|
+
appliesTo: "text",
|
|
144
|
+
text: "Render text as text, not HTML. Preserve wording, punctuation, meaningful line and paragraph breaks, and display.direction when supplied. Do not add notes or headings to the Scripture text."
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
code: "verify-license",
|
|
148
|
+
level: "required",
|
|
149
|
+
appliesTo: "all",
|
|
150
|
+
text: "Check the selected translation's license and provider terms for your intended use. Missing metadata is not permission for commercial use, redistribution, modifications, or offline storage."
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
code: "plain-text-limits",
|
|
154
|
+
level: "notice",
|
|
155
|
+
appliesTo: "text",
|
|
156
|
+
text: "Plain text omits verse numbers, editorial headings, notes, and rich formatting. It is not a lossless representation of the source edition."
|
|
157
|
+
}
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
function D() {
|
|
161
|
+
let t = /* @__PURE__ */ new Map(), a = r.runSync(e.makeWith((e) => r.suspend(() => t.get(e)()), {
|
|
162
|
+
capacity: 256,
|
|
163
|
+
requireServicesAt: "lookup",
|
|
164
|
+
timeToLive: (e) => i.isSuccess(e) ? n.infinity : n.zero
|
|
165
|
+
}));
|
|
166
|
+
return {
|
|
167
|
+
get(n, i) {
|
|
168
|
+
return r.suspend(() => (t.set(n, i), e.get(a, n).pipe(r.ensuring(r.sync(() => {
|
|
169
|
+
t.get(n) === i && t.delete(n);
|
|
170
|
+
})))));
|
|
171
|
+
},
|
|
172
|
+
clear: e.invalidateAll(a)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
// src/runtime.ts
|
|
176
|
+
var O = (e) => (t) => o.decodeUnknownEffect(e)(t).pipe(r.mapError((e) => new m({
|
|
177
|
+
code: "invalid_response",
|
|
178
|
+
message: "Bible provider returned invalid data.",
|
|
179
|
+
cause: e
|
|
180
|
+
}))), k = t.Reference("@faith-tools/scripture-inline/RequestPolicy", { defaultValue: () => ({
|
|
181
|
+
timeout: "15 seconds",
|
|
182
|
+
retries: 2
|
|
183
|
+
}) }), A = o.Struct({ status: o.Number }), j = o.Struct({ response: A }), M = o.decodeUnknownOption(A), N = o.decodeUnknownOption(j), P = o.decodeUnknownOption(o.Struct({ code: o.String }));
|
|
184
|
+
function F(e) {
|
|
185
|
+
if (e instanceof m) return e;
|
|
186
|
+
let t = M(e), n = N(e), r = P(e), i = t._tag === "Some" ? t.value.status : n._tag === "Some" ? n.value.response.status : Number(e instanceof Error ? /(?:Status: |^)(\d{3})\b/.exec(e.message)?.[1] : void 0), a = r._tag === "Some" && r.value.code === "missing_passage_attribution" ? "unavailable" : e instanceof SyntaxError || e instanceof Error && /^\$?ZodError$/.test(e.name) ? "invalid_response" : i === 401 || i === 403 ? "authentication" : i === 429 ? "rate_limit" : i >= 400 && i < 500 ? "unavailable" : "network";
|
|
187
|
+
return new m({
|
|
188
|
+
code: a,
|
|
189
|
+
message: `Bible provider request failed (${a}).`,
|
|
190
|
+
cause: e
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
var I = r.fn("scripture.request")(function* (e, t, n = !0) {
|
|
194
|
+
yield* r.annotateCurrentSpan({ operation: e });
|
|
195
|
+
let i = yield* k;
|
|
196
|
+
return yield* r.tryPromise({
|
|
197
|
+
try: t,
|
|
198
|
+
catch: F
|
|
199
|
+
}).pipe(r.retry({
|
|
200
|
+
times: n ? i.retries : 0,
|
|
201
|
+
schedule: a.exponential("100 millis"),
|
|
202
|
+
while: (e) => e.retryable
|
|
203
|
+
}), r.timeoutOrElse({
|
|
204
|
+
duration: i.timeout,
|
|
205
|
+
orElse: () => r.fail(new m({
|
|
206
|
+
code: "timeout",
|
|
207
|
+
message: "Bible provider request timed out."
|
|
208
|
+
}))
|
|
209
|
+
}));
|
|
210
|
+
});
|
|
211
|
+
function L(e) {
|
|
212
|
+
return {
|
|
213
|
+
id: e.id,
|
|
214
|
+
defaultVersionId: e.defaultVersionId,
|
|
215
|
+
effects: e,
|
|
216
|
+
listVersions: () => r.runPromise(e.listVersions()),
|
|
217
|
+
getPassage: (t, n) => r.runPromise(e.getPassageDisplay(t, n))
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
export { c as _, h as a, d as b, g as c, E as d, T as f, s as g, f as h, L as i, C as l, u as m, O as n, _ as o, l as p, I as r, w as s, k as t, D as u, m as v, p as y };
|