langchain 0.0.195 → 0.0.196
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/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
- package/dist/base_language/count_tokens.cjs +5 -70
- package/dist/base_language/count_tokens.d.ts +1 -10
- package/dist/base_language/count_tokens.js +1 -65
- package/dist/base_language/index.cjs +6 -196
- package/dist/base_language/index.d.ts +1 -111
- package/dist/base_language/index.js +1 -191
- package/dist/cache/base.cjs +15 -37
- package/dist/cache/base.d.ts +1 -20
- package/dist/cache/base.js +1 -33
- package/dist/cache/index.cjs +2 -46
- package/dist/cache/index.d.ts +1 -29
- package/dist/cache/index.js +1 -45
- package/dist/callbacks/base.cjs +3 -139
- package/dist/callbacks/base.d.ts +1 -266
- package/dist/callbacks/base.js +1 -126
- package/dist/callbacks/handlers/console.cjs +14 -221
- package/dist/callbacks/handlers/console.d.ts +1 -117
- package/dist/callbacks/handlers/console.js +1 -217
- package/dist/callbacks/handlers/initialize.cjs +15 -30
- package/dist/callbacks/handlers/initialize.d.ts +1 -16
- package/dist/callbacks/handlers/initialize.js +1 -27
- package/dist/callbacks/handlers/log_stream.cjs +15 -293
- package/dist/callbacks/handlers/log_stream.d.ts +1 -100
- package/dist/callbacks/handlers/log_stream.js +1 -289
- package/dist/callbacks/handlers/run_collector.cjs +15 -48
- package/dist/callbacks/handlers/run_collector.d.ts +1 -26
- package/dist/callbacks/handlers/run_collector.js +1 -46
- package/dist/callbacks/handlers/tracer.cjs +15 -375
- package/dist/callbacks/handlers/tracer.d.ts +1 -70
- package/dist/callbacks/handlers/tracer.js +1 -373
- package/dist/callbacks/handlers/tracer_langchain.cjs +15 -104
- package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -41
- package/dist/callbacks/handlers/tracer_langchain.js +1 -102
- package/dist/callbacks/handlers/tracer_langchain_v1.cjs +15 -197
- package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -57
- package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -195
- package/dist/callbacks/manager.cjs +15 -676
- package/dist/callbacks/manager.d.ts +1 -180
- package/dist/callbacks/manager.js +1 -666
- package/dist/callbacks/promises.cjs +14 -42
- package/dist/callbacks/promises.d.ts +1 -11
- package/dist/callbacks/promises.js +1 -37
- package/dist/chains/graph_qa/prompts.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.cjs +2 -2
- package/dist/chains/openai_functions/structured_output.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.js +1 -1
- package/dist/chat_models/baiduwenxin.d.ts +1 -1
- package/dist/chat_models/base.cjs +15 -296
- package/dist/chat_models/base.d.ts +1 -122
- package/dist/chat_models/base.js +1 -292
- package/dist/chat_models/bedrock/web.d.ts +1 -1
- package/dist/chat_models/fireworks.d.ts +1 -1
- package/dist/document.cjs +2 -24
- package/dist/document.d.ts +1 -12
- package/dist/document.js +1 -23
- package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
- package/dist/document_loaders/web/s3.d.ts +1 -1
- package/dist/embeddings/base.cjs +15 -22
- package/dist/embeddings/base.d.ts +1 -33
- package/dist/embeddings/base.js +1 -20
- package/dist/embeddings/cache_backed.cjs +2 -2
- package/dist/embeddings/cache_backed.js +1 -1
- package/dist/evaluation/agents/trajectory.d.ts +1 -1
- package/dist/evaluation/criteria/prompt.d.ts +2 -2
- package/dist/evaluation/qa/prompt.d.ts +2 -2
- package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
- package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
- package/dist/llms/base.cjs +15 -278
- package/dist/llms/base.d.ts +1 -115
- package/dist/llms/base.js +1 -275
- package/dist/llms/bedrock/web.d.ts +1 -1
- package/dist/llms/fireworks.d.ts +1 -1
- package/dist/load/import_map.cjs +2 -1
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/load/index.cjs +7 -148
- package/dist/load/index.js +7 -148
- package/dist/load/map_keys.cjs +0 -24
- package/dist/load/map_keys.d.ts +0 -6
- package/dist/load/map_keys.js +1 -17
- package/dist/load/serializable.cjs +15 -178
- package/dist/load/serializable.d.ts +1 -66
- package/dist/load/serializable.js +1 -175
- package/dist/memory/base.cjs +17 -92
- package/dist/memory/base.d.ts +2 -68
- package/dist/memory/base.js +2 -87
- package/dist/output_parsers/openai_functions.cjs +2 -2
- package/dist/output_parsers/openai_functions.d.ts +1 -1
- package/dist/output_parsers/openai_functions.js +1 -1
- package/dist/output_parsers/regex.d.ts +1 -1
- package/dist/output_parsers/structured.d.ts +1 -1
- package/dist/prompts/base.cjs +8 -183
- package/dist/prompts/base.d.ts +3 -132
- package/dist/prompts/base.js +3 -178
- package/dist/prompts/chat.cjs +15 -477
- package/dist/prompts/chat.d.ts +1 -219
- package/dist/prompts/chat.js +1 -466
- package/dist/prompts/few_shot.cjs +15 -353
- package/dist/prompts/few_shot.d.ts +1 -192
- package/dist/prompts/few_shot.js +1 -350
- package/dist/prompts/index.cjs +3 -2
- package/dist/prompts/index.d.ts +2 -1
- package/dist/prompts/index.js +2 -1
- package/dist/prompts/pipeline.cjs +15 -142
- package/dist/prompts/pipeline.d.ts +1 -98
- package/dist/prompts/pipeline.js +1 -140
- package/dist/prompts/prompt.cjs +15 -146
- package/dist/prompts/prompt.d.ts +1 -92
- package/dist/prompts/prompt.js +1 -144
- package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +15 -148
- package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
- package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
- package/dist/prompts/selectors/conditional.cjs +15 -74
- package/dist/prompts/selectors/conditional.d.ts +1 -63
- package/dist/prompts/selectors/conditional.js +1 -69
- package/dist/prompts/serde.cjs +15 -0
- package/dist/prompts/serde.d.ts +1 -43
- package/dist/prompts/serde.js +1 -1
- package/dist/prompts/template.cjs +14 -88
- package/dist/prompts/template.d.ts +1 -36
- package/dist/prompts/template.js +1 -83
- package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
- package/dist/runnables/index.d.ts +1 -0
- package/dist/runnables/index.js +1 -0
- package/dist/schema/document.cjs +3 -34
- package/dist/schema/document.d.ts +2 -29
- package/dist/schema/document.js +2 -32
- package/dist/schema/index.cjs +37 -612
- package/dist/schema/index.d.ts +11 -311
- package/dist/schema/index.js +8 -583
- package/dist/schema/output_parser.cjs +15 -309
- package/dist/schema/output_parser.d.ts +1 -173
- package/dist/schema/output_parser.js +1 -301
- package/dist/schema/retriever.cjs +15 -77
- package/dist/schema/retriever.d.ts +1 -43
- package/dist/schema/retriever.js +1 -75
- package/dist/schema/runnable/base.cjs +10 -1072
- package/dist/schema/runnable/base.d.ts +1 -356
- package/dist/schema/runnable/base.js +1 -1060
- package/dist/schema/runnable/branch.cjs +2 -131
- package/dist/schema/runnable/branch.d.ts +1 -94
- package/dist/schema/runnable/branch.js +1 -130
- package/dist/schema/runnable/config.cjs +0 -6
- package/dist/schema/runnable/config.d.ts +1 -3
- package/dist/schema/runnable/config.js +1 -4
- package/dist/schema/runnable/index.cjs +15 -16
- package/dist/schema/runnable/index.d.ts +1 -5
- package/dist/schema/runnable/index.js +1 -4
- package/dist/schema/runnable/passthrough.cjs +3 -113
- package/dist/schema/runnable/passthrough.d.ts +1 -72
- package/dist/schema/runnable/passthrough.js +1 -111
- package/dist/schema/runnable/router.cjs +2 -71
- package/dist/schema/runnable/router.d.ts +1 -29
- package/dist/schema/runnable/router.js +1 -70
- package/dist/schema/storage.cjs +15 -8
- package/dist/schema/storage.d.ts +1 -57
- package/dist/schema/storage.js +1 -6
- package/dist/tools/bingserpapi.d.ts +1 -1
- package/dist/tools/searchapi.d.ts +1 -1
- package/dist/tools/serpapi.d.ts +1 -1
- package/dist/tools/serper.d.ts +1 -1
- package/dist/util/async_caller.cjs +14 -128
- package/dist/util/async_caller.d.ts +1 -45
- package/dist/util/async_caller.js +1 -124
- package/package.json +11 -5
- package/runnables.cjs +1 -0
- package/runnables.d.ts +1 -0
- package/runnables.js +1 -0
- package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/index.js +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
- package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
- package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
- package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
- package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
- package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/format.js +0 -136
- package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
- package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
- package/dist/util/@cfworker/json-schema/src/index.js +0 -8
- package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
- package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
- package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
- package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
- package/dist/util/@cfworker/json-schema/src/types.js +0 -1
- package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
- package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
- package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
- package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
- package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
- package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
- package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
- package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
- package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
- package/dist/util/fast-json-patch/index.cjs +0 -49
- package/dist/util/fast-json-patch/index.d.ts +0 -22
- package/dist/util/fast-json-patch/index.js +0 -16
- package/dist/util/fast-json-patch/src/core.cjs +0 -469
- package/dist/util/fast-json-patch/src/core.d.ts +0 -111
- package/dist/util/fast-json-patch/src/core.js +0 -459
- package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
- package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
- package/dist/util/fast-json-patch/src/duplex.js +0 -230
- package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
- package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
- package/dist/util/fast-json-patch/src/helpers.js +0 -181
- package/dist/util/js-sha1/hash.cjs +0 -358
- package/dist/util/js-sha1/hash.d.ts +0 -1
- package/dist/util/js-sha1/hash.js +0 -355
|
@@ -1,124 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import PQueueMod from "p-queue";
|
|
3
|
-
const STATUS_NO_RETRY = [
|
|
4
|
-
400,
|
|
5
|
-
401,
|
|
6
|
-
402,
|
|
7
|
-
403,
|
|
8
|
-
404,
|
|
9
|
-
405,
|
|
10
|
-
406,
|
|
11
|
-
407,
|
|
12
|
-
408,
|
|
13
|
-
409, // Conflict
|
|
14
|
-
];
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
-
const defaultFailedAttemptHandler = (error) => {
|
|
17
|
-
if (error.message.startsWith("Cancel") ||
|
|
18
|
-
error.message.startsWith("TimeoutError") ||
|
|
19
|
-
error.name === "TimeoutError" ||
|
|
20
|
-
error.message.startsWith("AbortError") ||
|
|
21
|
-
error.name === "AbortError") {
|
|
22
|
-
throw error;
|
|
23
|
-
}
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
if (error?.code === "ECONNABORTED") {
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
const status =
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
-
error?.response?.status ?? error?.status;
|
|
31
|
-
if (status && STATUS_NO_RETRY.includes(+status)) {
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
-
if (error?.error?.code === "insufficient_quota") {
|
|
36
|
-
const err = new Error(error?.message);
|
|
37
|
-
err.name = "InsufficientQuotaError";
|
|
38
|
-
throw err;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* A class that can be used to make async calls with concurrency and retry logic.
|
|
43
|
-
*
|
|
44
|
-
* This is useful for making calls to any kind of "expensive" external resource,
|
|
45
|
-
* be it because it's rate-limited, subject to network issues, etc.
|
|
46
|
-
*
|
|
47
|
-
* Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
|
|
48
|
-
* to `Infinity`. This means that by default, all calls will be made in parallel.
|
|
49
|
-
*
|
|
50
|
-
* Retries are limited by the `maxRetries` parameter, which defaults to 6. This
|
|
51
|
-
* means that by default, each call will be retried up to 6 times, with an
|
|
52
|
-
* exponential backoff between each attempt.
|
|
53
|
-
*/
|
|
54
|
-
export class AsyncCaller {
|
|
55
|
-
constructor(params) {
|
|
56
|
-
Object.defineProperty(this, "maxConcurrency", {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
configurable: true,
|
|
59
|
-
writable: true,
|
|
60
|
-
value: void 0
|
|
61
|
-
});
|
|
62
|
-
Object.defineProperty(this, "maxRetries", {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
configurable: true,
|
|
65
|
-
writable: true,
|
|
66
|
-
value: void 0
|
|
67
|
-
});
|
|
68
|
-
Object.defineProperty(this, "onFailedAttempt", {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
configurable: true,
|
|
71
|
-
writable: true,
|
|
72
|
-
value: void 0
|
|
73
|
-
});
|
|
74
|
-
Object.defineProperty(this, "queue", {
|
|
75
|
-
enumerable: true,
|
|
76
|
-
configurable: true,
|
|
77
|
-
writable: true,
|
|
78
|
-
value: void 0
|
|
79
|
-
});
|
|
80
|
-
this.maxConcurrency = params.maxConcurrency ?? Infinity;
|
|
81
|
-
this.maxRetries = params.maxRetries ?? 6;
|
|
82
|
-
this.onFailedAttempt =
|
|
83
|
-
params.onFailedAttempt ?? defaultFailedAttemptHandler;
|
|
84
|
-
const PQueue = "default" in PQueueMod ? PQueueMod.default : PQueueMod;
|
|
85
|
-
this.queue = new PQueue({ concurrency: this.maxConcurrency });
|
|
86
|
-
}
|
|
87
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
-
call(callable, ...args) {
|
|
89
|
-
return this.queue.add(() => pRetry(() => callable(...args).catch((error) => {
|
|
90
|
-
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
91
|
-
if (error instanceof Error) {
|
|
92
|
-
throw error;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
throw new Error(error);
|
|
96
|
-
}
|
|
97
|
-
}), {
|
|
98
|
-
onFailedAttempt: this.onFailedAttempt,
|
|
99
|
-
retries: this.maxRetries,
|
|
100
|
-
randomize: true,
|
|
101
|
-
// If needed we can change some of the defaults here,
|
|
102
|
-
// but they're quite sensible.
|
|
103
|
-
}), { throwOnTimeout: true });
|
|
104
|
-
}
|
|
105
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
106
|
-
callWithOptions(options, callable, ...args) {
|
|
107
|
-
// Note this doesn't cancel the underlying request,
|
|
108
|
-
// when available prefer to use the signal option of the underlying call
|
|
109
|
-
if (options.signal) {
|
|
110
|
-
return Promise.race([
|
|
111
|
-
this.call(callable, ...args),
|
|
112
|
-
new Promise((_, reject) => {
|
|
113
|
-
options.signal?.addEventListener("abort", () => {
|
|
114
|
-
reject(new Error("AbortError"));
|
|
115
|
-
});
|
|
116
|
-
}),
|
|
117
|
-
]);
|
|
118
|
-
}
|
|
119
|
-
return this.call(callable, ...args);
|
|
120
|
-
}
|
|
121
|
-
fetch(...args) {
|
|
122
|
-
return this.call(() => fetch(...args).then((res) => (res.ok ? res : Promise.reject(res))));
|
|
123
|
-
}
|
|
124
|
-
}
|
|
1
|
+
export * from "langchain-core/util/async_caller";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.196",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -805,6 +805,9 @@
|
|
|
805
805
|
"evaluation.cjs",
|
|
806
806
|
"evaluation.js",
|
|
807
807
|
"evaluation.d.ts",
|
|
808
|
+
"runnables.cjs",
|
|
809
|
+
"runnables.js",
|
|
810
|
+
"runnables.d.ts",
|
|
808
811
|
"runnables/remote.cjs",
|
|
809
812
|
"runnables/remote.js",
|
|
810
813
|
"runnables/remote.d.ts",
|
|
@@ -939,6 +942,7 @@
|
|
|
939
942
|
"jest": "^29.5.0",
|
|
940
943
|
"jest-environment-node": "^29.6.4",
|
|
941
944
|
"jsdom": "^22.1.0",
|
|
945
|
+
"langchain-core": "workspace:*",
|
|
942
946
|
"llmonitor": "^0.5.9",
|
|
943
947
|
"lodash": "^4.17.21",
|
|
944
948
|
"mammoth": "^1.5.1",
|
|
@@ -1375,21 +1379,18 @@
|
|
|
1375
1379
|
},
|
|
1376
1380
|
"dependencies": {
|
|
1377
1381
|
"@anthropic-ai/sdk": "^0.9.1",
|
|
1378
|
-
"ansi-styles": "^5.0.0",
|
|
1379
1382
|
"binary-extensions": "^2.2.0",
|
|
1380
|
-
"camelcase": "6",
|
|
1381
|
-
"decamelize": "^1.2.0",
|
|
1382
1383
|
"expr-eval": "^2.0.2",
|
|
1383
1384
|
"flat": "^5.0.2",
|
|
1384
1385
|
"js-tiktoken": "^1.0.7",
|
|
1385
1386
|
"js-yaml": "^4.1.0",
|
|
1386
1387
|
"jsonpointer": "^5.0.1",
|
|
1388
|
+
"langchain-core": "^0.0.1",
|
|
1387
1389
|
"langchainhub": "~0.0.6",
|
|
1388
1390
|
"langsmith": "~0.0.48",
|
|
1389
1391
|
"ml-distance": "^4.0.0",
|
|
1390
1392
|
"openai": "^4.19.0",
|
|
1391
1393
|
"openapi-types": "^12.1.3",
|
|
1392
|
-
"p-queue": "^6.6.2",
|
|
1393
1394
|
"p-retry": "4",
|
|
1394
1395
|
"uuid": "^9.0.0",
|
|
1395
1396
|
"yaml": "^2.2.1",
|
|
@@ -2739,6 +2740,11 @@
|
|
|
2739
2740
|
"import": "./evaluation.js",
|
|
2740
2741
|
"require": "./evaluation.cjs"
|
|
2741
2742
|
},
|
|
2743
|
+
"./runnables": {
|
|
2744
|
+
"types": "./runnables.d.ts",
|
|
2745
|
+
"import": "./runnables.js",
|
|
2746
|
+
"require": "./runnables.cjs"
|
|
2747
|
+
},
|
|
2742
2748
|
"./runnables/remote": {
|
|
2743
2749
|
"types": "./runnables/remote.d.ts",
|
|
2744
2750
|
"import": "./runnables/remote.js",
|
package/runnables.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/runnables/index.cjs');
|
package/runnables.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/runnables/index.js'
|
package/runnables.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/runnables/index.js'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index.js";
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deepCompareStrict = void 0;
|
|
4
|
-
function deepCompareStrict(a, b) {
|
|
5
|
-
const typeofa = typeof a;
|
|
6
|
-
if (typeofa !== typeof b) {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
if (Array.isArray(a)) {
|
|
10
|
-
if (!Array.isArray(b)) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
const length = a.length;
|
|
14
|
-
if (length !== b.length) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
for (let i = 0; i < length; i++) {
|
|
18
|
-
if (!deepCompareStrict(a[i], b[i])) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
if (typeofa === "object") {
|
|
25
|
-
if (!a || !b) {
|
|
26
|
-
return a === b;
|
|
27
|
-
}
|
|
28
|
-
const aKeys = Object.keys(a);
|
|
29
|
-
const bKeys = Object.keys(b);
|
|
30
|
-
const length = aKeys.length;
|
|
31
|
-
if (length !== bKeys.length) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
for (const k of aKeys) {
|
|
35
|
-
if (!deepCompareStrict(a[k], b[k])) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
return a === b;
|
|
42
|
-
}
|
|
43
|
-
exports.deepCompareStrict = deepCompareStrict;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function deepCompareStrict(a: any, b: any): boolean;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export function deepCompareStrict(a, b) {
|
|
2
|
-
const typeofa = typeof a;
|
|
3
|
-
if (typeofa !== typeof b) {
|
|
4
|
-
return false;
|
|
5
|
-
}
|
|
6
|
-
if (Array.isArray(a)) {
|
|
7
|
-
if (!Array.isArray(b)) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
const length = a.length;
|
|
11
|
-
if (length !== b.length) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
for (let i = 0; i < length; i++) {
|
|
15
|
-
if (!deepCompareStrict(a[i], b[i])) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
if (typeofa === "object") {
|
|
22
|
-
if (!a || !b) {
|
|
23
|
-
return a === b;
|
|
24
|
-
}
|
|
25
|
-
const aKeys = Object.keys(a);
|
|
26
|
-
const bKeys = Object.keys(b);
|
|
27
|
-
const length = aKeys.length;
|
|
28
|
-
if (length !== bKeys.length) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
for (const k of aKeys) {
|
|
32
|
-
if (!deepCompareStrict(a[k], b[k])) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
return a === b;
|
|
39
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dereference = exports.initialBaseURI = exports.ignoredKeyword = exports.schemaMapKeyword = exports.schemaArrayKeyword = exports.schemaKeyword = void 0;
|
|
4
|
-
const pointer_js_1 = require("./pointer.cjs");
|
|
5
|
-
exports.schemaKeyword = {
|
|
6
|
-
additionalItems: true,
|
|
7
|
-
unevaluatedItems: true,
|
|
8
|
-
items: true,
|
|
9
|
-
contains: true,
|
|
10
|
-
additionalProperties: true,
|
|
11
|
-
unevaluatedProperties: true,
|
|
12
|
-
propertyNames: true,
|
|
13
|
-
not: true,
|
|
14
|
-
if: true,
|
|
15
|
-
then: true,
|
|
16
|
-
else: true,
|
|
17
|
-
};
|
|
18
|
-
exports.schemaArrayKeyword = {
|
|
19
|
-
prefixItems: true,
|
|
20
|
-
items: true,
|
|
21
|
-
allOf: true,
|
|
22
|
-
anyOf: true,
|
|
23
|
-
oneOf: true,
|
|
24
|
-
};
|
|
25
|
-
exports.schemaMapKeyword = {
|
|
26
|
-
$defs: true,
|
|
27
|
-
definitions: true,
|
|
28
|
-
properties: true,
|
|
29
|
-
patternProperties: true,
|
|
30
|
-
dependentSchemas: true,
|
|
31
|
-
};
|
|
32
|
-
exports.ignoredKeyword = {
|
|
33
|
-
id: true,
|
|
34
|
-
$id: true,
|
|
35
|
-
$ref: true,
|
|
36
|
-
$schema: true,
|
|
37
|
-
$anchor: true,
|
|
38
|
-
$vocabulary: true,
|
|
39
|
-
$comment: true,
|
|
40
|
-
default: true,
|
|
41
|
-
enum: true,
|
|
42
|
-
const: true,
|
|
43
|
-
required: true,
|
|
44
|
-
type: true,
|
|
45
|
-
maximum: true,
|
|
46
|
-
minimum: true,
|
|
47
|
-
exclusiveMaximum: true,
|
|
48
|
-
exclusiveMinimum: true,
|
|
49
|
-
multipleOf: true,
|
|
50
|
-
maxLength: true,
|
|
51
|
-
minLength: true,
|
|
52
|
-
pattern: true,
|
|
53
|
-
format: true,
|
|
54
|
-
maxItems: true,
|
|
55
|
-
minItems: true,
|
|
56
|
-
uniqueItems: true,
|
|
57
|
-
maxProperties: true,
|
|
58
|
-
minProperties: true,
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Default base URI for schemas without an $id.
|
|
62
|
-
* https://json-schema.org/draft/2019-09/json-schema-core.html#initial-base
|
|
63
|
-
* https://tools.ietf.org/html/rfc3986#section-5.1
|
|
64
|
-
*/
|
|
65
|
-
exports.initialBaseURI =
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
typeof self !== "undefined" && self.location
|
|
68
|
-
? //@ts-ignore
|
|
69
|
-
/* #__PURE__ */ new URL(self.location.origin + self.location.pathname + location.search)
|
|
70
|
-
: /* #__PURE__ */ new URL("https://github.com/cfworker");
|
|
71
|
-
function dereference(schema, lookup = Object.create(null), baseURI = exports.initialBaseURI, basePointer = "") {
|
|
72
|
-
if (schema && typeof schema === "object" && !Array.isArray(schema)) {
|
|
73
|
-
const id = schema.$id || schema.id;
|
|
74
|
-
if (id) {
|
|
75
|
-
const url = new URL(id, baseURI.href);
|
|
76
|
-
if (url.hash.length > 1) {
|
|
77
|
-
lookup[url.href] = schema;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
url.hash = ""; // normalize hash https://url.spec.whatwg.org/#dom-url-hash
|
|
81
|
-
if (basePointer === "") {
|
|
82
|
-
baseURI = url;
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
dereference(schema, lookup, baseURI);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else if (schema !== true && schema !== false) {
|
|
91
|
-
return lookup;
|
|
92
|
-
}
|
|
93
|
-
// compute the schema's URI and add it to the mapping.
|
|
94
|
-
const schemaURI = baseURI.href + (basePointer ? "#" + basePointer : "");
|
|
95
|
-
if (lookup[schemaURI] !== undefined) {
|
|
96
|
-
throw new Error(`Duplicate schema URI "${schemaURI}".`);
|
|
97
|
-
}
|
|
98
|
-
lookup[schemaURI] = schema;
|
|
99
|
-
// exit early if this is a boolean schema.
|
|
100
|
-
if (schema === true || schema === false) {
|
|
101
|
-
return lookup;
|
|
102
|
-
}
|
|
103
|
-
// set the schema's absolute URI.
|
|
104
|
-
if (schema.__absolute_uri__ === undefined) {
|
|
105
|
-
Object.defineProperty(schema, "__absolute_uri__", {
|
|
106
|
-
enumerable: false,
|
|
107
|
-
value: schemaURI,
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
// if a $ref is found, resolve it's absolute URI.
|
|
111
|
-
if (schema.$ref && schema.__absolute_ref__ === undefined) {
|
|
112
|
-
const url = new URL(schema.$ref, baseURI.href);
|
|
113
|
-
url.hash = url.hash; // normalize hash https://url.spec.whatwg.org/#dom-url-hash
|
|
114
|
-
Object.defineProperty(schema, "__absolute_ref__", {
|
|
115
|
-
enumerable: false,
|
|
116
|
-
value: url.href,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
// if a $recursiveRef is found, resolve it's absolute URI.
|
|
120
|
-
if (schema.$recursiveRef && schema.__absolute_recursive_ref__ === undefined) {
|
|
121
|
-
const url = new URL(schema.$recursiveRef, baseURI.href);
|
|
122
|
-
url.hash = url.hash; // normalize hash https://url.spec.whatwg.org/#dom-url-hash
|
|
123
|
-
Object.defineProperty(schema, "__absolute_recursive_ref__", {
|
|
124
|
-
enumerable: false,
|
|
125
|
-
value: url.href,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
// if an $anchor is found, compute it's URI and add it to the mapping.
|
|
129
|
-
if (schema.$anchor) {
|
|
130
|
-
const url = new URL("#" + schema.$anchor, baseURI.href);
|
|
131
|
-
lookup[url.href] = schema;
|
|
132
|
-
}
|
|
133
|
-
// process subschemas.
|
|
134
|
-
for (let key in schema) {
|
|
135
|
-
if (exports.ignoredKeyword[key]) {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
const keyBase = `${basePointer}/${(0, pointer_js_1.encodePointer)(key)}`;
|
|
139
|
-
const subSchema = schema[key];
|
|
140
|
-
if (Array.isArray(subSchema)) {
|
|
141
|
-
if (exports.schemaArrayKeyword[key]) {
|
|
142
|
-
const length = subSchema.length;
|
|
143
|
-
for (let i = 0; i < length; i++) {
|
|
144
|
-
dereference(subSchema[i], lookup, baseURI, `${keyBase}/${i}`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
else if (exports.schemaMapKeyword[key]) {
|
|
149
|
-
for (let subKey in subSchema) {
|
|
150
|
-
dereference(subSchema[subKey], lookup, baseURI, `${keyBase}/${(0, pointer_js_1.encodePointer)(subKey)}`);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
dereference(subSchema, lookup, baseURI, keyBase);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return lookup;
|
|
158
|
-
}
|
|
159
|
-
exports.dereference = dereference;
|
|
160
|
-
// schema identification examples
|
|
161
|
-
// https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.appendix.A
|
|
162
|
-
// $ref delegation
|
|
163
|
-
// https://github.com/json-schema-org/json-schema-spec/issues/514
|
|
164
|
-
// output format
|
|
165
|
-
// https://json-schema.org/draft/2019-09/json-schema-core.html#output
|
|
166
|
-
// JSON pointer
|
|
167
|
-
// https://tools.ietf.org/html/rfc6901
|
|
168
|
-
// JSON relative pointer
|
|
169
|
-
// https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Schema } from "./types.js";
|
|
2
|
-
export declare const schemaKeyword: Record<string, boolean>;
|
|
3
|
-
export declare const schemaArrayKeyword: Record<string, boolean>;
|
|
4
|
-
export declare const schemaMapKeyword: Record<string, boolean>;
|
|
5
|
-
export declare const ignoredKeyword: Record<string, boolean>;
|
|
6
|
-
/**
|
|
7
|
-
* Default base URI for schemas without an $id.
|
|
8
|
-
* https://json-schema.org/draft/2019-09/json-schema-core.html#initial-base
|
|
9
|
-
* https://tools.ietf.org/html/rfc3986#section-5.1
|
|
10
|
-
*/
|
|
11
|
-
export declare let initialBaseURI: URL;
|
|
12
|
-
export declare function dereference(schema: Schema | boolean, lookup?: Record<string, Schema | boolean>, baseURI?: URL, basePointer?: string): Record<string, boolean | Schema>;
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { encodePointer } from "./pointer.js";
|
|
2
|
-
export const schemaKeyword = {
|
|
3
|
-
additionalItems: true,
|
|
4
|
-
unevaluatedItems: true,
|
|
5
|
-
items: true,
|
|
6
|
-
contains: true,
|
|
7
|
-
additionalProperties: true,
|
|
8
|
-
unevaluatedProperties: true,
|
|
9
|
-
propertyNames: true,
|
|
10
|
-
not: true,
|
|
11
|
-
if: true,
|
|
12
|
-
then: true,
|
|
13
|
-
else: true,
|
|
14
|
-
};
|
|
15
|
-
export const schemaArrayKeyword = {
|
|
16
|
-
prefixItems: true,
|
|
17
|
-
items: true,
|
|
18
|
-
allOf: true,
|
|
19
|
-
anyOf: true,
|
|
20
|
-
oneOf: true,
|
|
21
|
-
};
|
|
22
|
-
export const schemaMapKeyword = {
|
|
23
|
-
$defs: true,
|
|
24
|
-
definitions: true,
|
|
25
|
-
properties: true,
|
|
26
|
-
patternProperties: true,
|
|
27
|
-
dependentSchemas: true,
|
|
28
|
-
};
|
|
29
|
-
export const ignoredKeyword = {
|
|
30
|
-
id: true,
|
|
31
|
-
$id: true,
|
|
32
|
-
$ref: true,
|
|
33
|
-
$schema: true,
|
|
34
|
-
$anchor: true,
|
|
35
|
-
$vocabulary: true,
|
|
36
|
-
$comment: true,
|
|
37
|
-
default: true,
|
|
38
|
-
enum: true,
|
|
39
|
-
const: true,
|
|
40
|
-
required: true,
|
|
41
|
-
type: true,
|
|
42
|
-
maximum: true,
|
|
43
|
-
minimum: true,
|
|
44
|
-
exclusiveMaximum: true,
|
|
45
|
-
exclusiveMinimum: true,
|
|
46
|
-
multipleOf: true,
|
|
47
|
-
maxLength: true,
|
|
48
|
-
minLength: true,
|
|
49
|
-
pattern: true,
|
|
50
|
-
format: true,
|
|
51
|
-
maxItems: true,
|
|
52
|
-
minItems: true,
|
|
53
|
-
uniqueItems: true,
|
|
54
|
-
maxProperties: true,
|
|
55
|
-
minProperties: true,
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Default base URI for schemas without an $id.
|
|
59
|
-
* https://json-schema.org/draft/2019-09/json-schema-core.html#initial-base
|
|
60
|
-
* https://tools.ietf.org/html/rfc3986#section-5.1
|
|
61
|
-
*/
|
|
62
|
-
export let initialBaseURI =
|
|
63
|
-
// @ts-ignore
|
|
64
|
-
typeof self !== "undefined" && self.location
|
|
65
|
-
? //@ts-ignore
|
|
66
|
-
/* #__PURE__ */ new URL(self.location.origin + self.location.pathname + location.search)
|
|
67
|
-
: /* #__PURE__ */ new URL("https://github.com/cfworker");
|
|
68
|
-
export function dereference(schema, lookup = Object.create(null), baseURI = initialBaseURI, basePointer = "") {
|
|
69
|
-
if (schema && typeof schema === "object" && !Array.isArray(schema)) {
|
|
70
|
-
const id = schema.$id || schema.id;
|
|
71
|
-
if (id) {
|
|
72
|
-
const url = new URL(id, baseURI.href);
|
|
73
|
-
if (url.hash.length > 1) {
|
|
74
|
-
lookup[url.href] = schema;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
url.hash = ""; // normalize hash https://url.spec.whatwg.org/#dom-url-hash
|
|
78
|
-
if (basePointer === "") {
|
|
79
|
-
baseURI = url;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
dereference(schema, lookup, baseURI);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
else if (schema !== true && schema !== false) {
|
|
88
|
-
return lookup;
|
|
89
|
-
}
|
|
90
|
-
// compute the schema's URI and add it to the mapping.
|
|
91
|
-
const schemaURI = baseURI.href + (basePointer ? "#" + basePointer : "");
|
|
92
|
-
if (lookup[schemaURI] !== undefined) {
|
|
93
|
-
throw new Error(`Duplicate schema URI "${schemaURI}".`);
|
|
94
|
-
}
|
|
95
|
-
lookup[schemaURI] = schema;
|
|
96
|
-
// exit early if this is a boolean schema.
|
|
97
|
-
if (schema === true || schema === false) {
|
|
98
|
-
return lookup;
|
|
99
|
-
}
|
|
100
|
-
// set the schema's absolute URI.
|
|
101
|
-
if (schema.__absolute_uri__ === undefined) {
|
|
102
|
-
Object.defineProperty(schema, "__absolute_uri__", {
|
|
103
|
-
enumerable: false,
|
|
104
|
-
value: schemaURI,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
// if a $ref is found, resolve it's absolute URI.
|
|
108
|
-
if (schema.$ref && schema.__absolute_ref__ === undefined) {
|
|
109
|
-
const url = new URL(schema.$ref, baseURI.href);
|
|
110
|
-
url.hash = url.hash; // normalize hash https://url.spec.whatwg.org/#dom-url-hash
|
|
111
|
-
Object.defineProperty(schema, "__absolute_ref__", {
|
|
112
|
-
enumerable: false,
|
|
113
|
-
value: url.href,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
// if a $recursiveRef is found, resolve it's absolute URI.
|
|
117
|
-
if (schema.$recursiveRef && schema.__absolute_recursive_ref__ === undefined) {
|
|
118
|
-
const url = new URL(schema.$recursiveRef, baseURI.href);
|
|
119
|
-
url.hash = url.hash; // normalize hash https://url.spec.whatwg.org/#dom-url-hash
|
|
120
|
-
Object.defineProperty(schema, "__absolute_recursive_ref__", {
|
|
121
|
-
enumerable: false,
|
|
122
|
-
value: url.href,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
// if an $anchor is found, compute it's URI and add it to the mapping.
|
|
126
|
-
if (schema.$anchor) {
|
|
127
|
-
const url = new URL("#" + schema.$anchor, baseURI.href);
|
|
128
|
-
lookup[url.href] = schema;
|
|
129
|
-
}
|
|
130
|
-
// process subschemas.
|
|
131
|
-
for (let key in schema) {
|
|
132
|
-
if (ignoredKeyword[key]) {
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
const keyBase = `${basePointer}/${encodePointer(key)}`;
|
|
136
|
-
const subSchema = schema[key];
|
|
137
|
-
if (Array.isArray(subSchema)) {
|
|
138
|
-
if (schemaArrayKeyword[key]) {
|
|
139
|
-
const length = subSchema.length;
|
|
140
|
-
for (let i = 0; i < length; i++) {
|
|
141
|
-
dereference(subSchema[i], lookup, baseURI, `${keyBase}/${i}`);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
else if (schemaMapKeyword[key]) {
|
|
146
|
-
for (let subKey in subSchema) {
|
|
147
|
-
dereference(subSchema[subKey], lookup, baseURI, `${keyBase}/${encodePointer(subKey)}`);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
dereference(subSchema, lookup, baseURI, keyBase);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return lookup;
|
|
155
|
-
}
|
|
156
|
-
// schema identification examples
|
|
157
|
-
// https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.appendix.A
|
|
158
|
-
// $ref delegation
|
|
159
|
-
// https://github.com/json-schema-org/json-schema-spec/issues/514
|
|
160
|
-
// output format
|
|
161
|
-
// https://json-schema.org/draft/2019-09/json-schema-core.html#output
|
|
162
|
-
// JSON pointer
|
|
163
|
-
// https://tools.ietf.org/html/rfc6901
|
|
164
|
-
// JSON relative pointer
|
|
165
|
-
// https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01
|