@apifn/core 0.0.4 → 0.1.2

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.
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/openapi/reference-context.ts
21
+ var reference_context_exports = {};
22
+ __export(reference_context_exports, {
23
+ openAPIReferenceContext: () => openAPIReferenceContext
24
+ });
25
+ module.exports = __toCommonJS(reference_context_exports);
26
+ var REFERENCE_MODES = /* @__PURE__ */ new Set(["object", "example", "link"]);
27
+ var OBJECT_MAPS = /* @__PURE__ */ new Set(["parameters", "requestBodies", "headers", "securitySchemes", "callbacks", "responses"]);
28
+ var NAME_MAPS = /* @__PURE__ */ new Set([
29
+ "properties",
30
+ "patternProperties",
31
+ "$defs",
32
+ "definitions",
33
+ "dependentSchemas",
34
+ "schemas",
35
+ "links",
36
+ "pathItems",
37
+ "paths",
38
+ "webhooks",
39
+ "content",
40
+ "encoding",
41
+ "variables"
42
+ ]);
43
+ var LITERALS = /* @__PURE__ */ new Set(["example", "default", "const", "enum"]);
44
+ function childMode(key, value) {
45
+ if (LITERALS.has(key) || key.startsWith("x-")) return "literal";
46
+ if (key === "examples") return Array.isArray(value) ? "literal" : "examples";
47
+ if (key === "components") return "components";
48
+ if (key === "links") return "links";
49
+ if (key === "paths") return "extNames";
50
+ if (key === "responses") return "extObjects";
51
+ if (key === "requestBody") return "object";
52
+ if (OBJECT_MAPS.has(key)) return "objects";
53
+ return NAME_MAPS.has(key) ? "names" : "node";
54
+ }
55
+ function entryMode(mode, key, value) {
56
+ switch (mode) {
57
+ case "names":
58
+ return "node";
59
+ case "extNames":
60
+ return key.startsWith("x-") ? "literal" : "node";
61
+ case "objects":
62
+ return "object";
63
+ case "extObjects":
64
+ return key.startsWith("x-") ? "literal" : "object";
65
+ case "components":
66
+ if (key.startsWith("x-")) return "literal";
67
+ if (key === "examples" || key === "links") return key;
68
+ return OBJECT_MAPS.has(key) ? "objects" : "names";
69
+ case "examples":
70
+ return "example";
71
+ case "links":
72
+ return "link";
73
+ case "link":
74
+ return key === "parameters" || key === "requestBody" ? "literal" : childMode(key, value);
75
+ default:
76
+ return null;
77
+ }
78
+ }
79
+ var MAP_MODES = /* @__PURE__ */ new Set(["names", "extNames", "objects", "extObjects", "components", "examples", "links"]);
80
+ var MAP_ITEMS = { names: "node", extNames: "node", objects: "object", extObjects: "object" };
81
+ var openAPIReferenceContext = Object.freeze({
82
+ childMode,
83
+ entryMode,
84
+ isReferenceObject: (mode) => REFERENCE_MODES.has(mode),
85
+ isMap: (mode) => MAP_MODES.has(mode),
86
+ arrayItemMode: (mode) => MAP_ITEMS[mode] ?? mode
87
+ });
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ openAPIReferenceContext
91
+ });
92
+ //# sourceMappingURL=openapi-reference-context.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/openapi/reference-context.ts"],"sourcesContent":["/**\n * How a value is read: `node` (an OpenAPI or schema object, whose keys are keywords), `names` (a\n * map from names to nodes, such as `properties`), `extNames` (a names map that also takes `x-`\n * extensions: Paths and Responses), `components`, `examples` (a map of Example Objects), `example`\n * (one Example Object or its `$ref`), `links` and `link` (Link Objects, whose `parameters` and\n * `requestBody` are data), `objects` and `object` (a map of, or one, OpenAPI object that may be a\n * Reference Object: a Parameter, Response, Request Body, Header, Security Scheme or Callback),\n * `extObjects` (Responses: `objects` that also take `x-` extensions) or `literal` (data). A Callback\n * Object is an `object`: its `x-` keys are data and its expressions Path Items.\n */\nexport type OpenAPIReferenceMode =\n | \"node\" | \"names\" | \"extNames\" | \"objects\" | \"extObjects\" | \"object\" | \"components\" | \"examples\" | \"example\" | \"links\" | \"link\"\n | \"literal\";\n\n/** Modes whose `$ref` is a Reference Object: only `summary` and `description` beside it apply. */\nconst REFERENCE_MODES = new Set<OpenAPIReferenceMode>([\"object\", \"example\", \"link\"]);\n/** Maps whose entries may be Reference Objects (not Schema Objects). */\nconst OBJECT_MAPS = new Set([\"parameters\", \"requestBodies\", \"headers\", \"securitySchemes\", \"callbacks\", \"responses\"]);\n\n/** Keywords whose value maps names (any string, `default` and `$ref` included) to nodes. */\nconst NAME_MAPS = new Set([\n \"properties\", \"patternProperties\", \"$defs\", \"definitions\", \"dependentSchemas\", \"schemas\", \"links\", \"pathItems\",\n \"paths\", \"webhooks\", \"content\", \"encoding\", \"variables\",\n]);\n/** Keywords whose value is data. */\nconst LITERALS = new Set([\"example\", \"default\", \"const\", \"enum\"]);\n\n/** How the value under `key` of a node is read. */\nfunction childMode(key: string, value: unknown): OpenAPIReferenceMode {\n if (LITERALS.has(key) || key.startsWith(\"x-\")) return \"literal\";\n if (key === \"examples\") return Array.isArray(value) ? \"literal\" : \"examples\";\n if (key === \"components\") return \"components\";\n if (key === \"links\") return \"links\";\n if (key === \"paths\") return \"extNames\";\n if (key === \"responses\") return \"extObjects\";\n if (key === \"requestBody\") return \"object\";\n if (OBJECT_MAPS.has(key)) return \"objects\";\n return NAME_MAPS.has(key) ? \"names\" : \"node\";\n}\n\n/** How the value under `key` of a map read in `mode` is read (null: `mode` is not a map). */\nfunction entryMode(mode: OpenAPIReferenceMode, key: string, value: unknown): OpenAPIReferenceMode | null {\n switch (mode) {\n case \"names\":\n return \"node\";\n case \"extNames\":\n return key.startsWith(\"x-\") ? \"literal\" : \"node\";\n case \"objects\":\n return \"object\";\n case \"extObjects\":\n return key.startsWith(\"x-\") ? \"literal\" : \"object\";\n case \"components\":\n if (key.startsWith(\"x-\")) return \"literal\";\n if (key === \"examples\" || key === \"links\") return key;\n return OBJECT_MAPS.has(key) ? \"objects\" : \"names\";\n case \"examples\":\n return \"example\";\n case \"links\":\n return \"link\";\n case \"link\":\n return key === \"parameters\" || key === \"requestBody\" ? \"literal\" : childMode(key, value);\n default:\n return null;\n }\n}\n\nconst MAP_MODES = new Set<OpenAPIReferenceMode>([\"names\", \"extNames\", \"objects\", \"extObjects\", \"components\", \"examples\", \"links\"]);\n/** How the items of an array read in a map mode are read. */\nconst MAP_ITEMS: Partial<Record<OpenAPIReferenceMode, OpenAPIReferenceMode>> = { names: \"node\", extNames: \"node\", objects: \"object\", extObjects: \"object\" };\n\nexport const openAPIReferenceContext = Object.freeze({\n childMode,\n entryMode,\n isReferenceObject: (mode: OpenAPIReferenceMode) => REFERENCE_MODES.has(mode),\n isMap: (mode: OpenAPIReferenceMode) => MAP_MODES.has(mode),\n arrayItemMode: (mode: OpenAPIReferenceMode) => MAP_ITEMS[mode] ?? mode,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,IAAM,kBAAkB,oBAAI,IAA0B,CAAC,UAAU,WAAW,MAAM,CAAC;AAEnF,IAAM,cAAc,oBAAI,IAAI,CAAC,cAAc,iBAAiB,WAAW,mBAAmB,aAAa,WAAW,CAAC;AAGnH,IAAM,YAAY,oBAAI,IAAI;AAAA,EACxB;AAAA,EAAc;AAAA,EAAqB;AAAA,EAAS;AAAA,EAAe;AAAA,EAAoB;AAAA,EAAW;AAAA,EAAS;AAAA,EACnG;AAAA,EAAS;AAAA,EAAY;AAAA,EAAW;AAAA,EAAY;AAC9C,CAAC;A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AAAA,EACnD;AAAA,EACA;AAAA,EACA,mBAAmB,CAAC,SAA+B,gBAAgB,IAAI,IAAI;AAAA,EAC3E,OAAO,CAAC,SAA+B,UAAU,IAAI,IAAI;AAAA,EACzD,eAAe,CAAC,SAA+B,UAAU,IAAI,KAAK;AACpE,CAAC;","names":[]}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * How a value is read: `node` (an OpenAPI or schema object, whose keys are keywords), `names` (a
3
+ * map from names to nodes, such as `properties`), `extNames` (a names map that also takes `x-`
4
+ * extensions: Paths and Responses), `components`, `examples` (a map of Example Objects), `example`
5
+ * (one Example Object or its `$ref`), `links` and `link` (Link Objects, whose `parameters` and
6
+ * `requestBody` are data), `objects` and `object` (a map of, or one, OpenAPI object that may be a
7
+ * Reference Object: a Parameter, Response, Request Body, Header, Security Scheme or Callback),
8
+ * `extObjects` (Responses: `objects` that also take `x-` extensions) or `literal` (data). A Callback
9
+ * Object is an `object`: its `x-` keys are data and its expressions Path Items.
10
+ */
11
+ type OpenAPIReferenceMode = "node" | "names" | "extNames" | "objects" | "extObjects" | "object" | "components" | "examples" | "example" | "links" | "link" | "literal";
12
+ /** How the value under `key` of a node is read. */
13
+ declare function childMode(key: string, value: unknown): OpenAPIReferenceMode;
14
+ /** How the value under `key` of a map read in `mode` is read (null: `mode` is not a map). */
15
+ declare function entryMode(mode: OpenAPIReferenceMode, key: string, value: unknown): OpenAPIReferenceMode | null;
16
+ declare const openAPIReferenceContext: Readonly<{
17
+ childMode: typeof childMode;
18
+ entryMode: typeof entryMode;
19
+ isReferenceObject: (mode: OpenAPIReferenceMode) => boolean;
20
+ isMap: (mode: OpenAPIReferenceMode) => boolean;
21
+ arrayItemMode: (mode: OpenAPIReferenceMode) => OpenAPIReferenceMode;
22
+ }>;
23
+
24
+ export { type OpenAPIReferenceMode, openAPIReferenceContext };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * How a value is read: `node` (an OpenAPI or schema object, whose keys are keywords), `names` (a
3
+ * map from names to nodes, such as `properties`), `extNames` (a names map that also takes `x-`
4
+ * extensions: Paths and Responses), `components`, `examples` (a map of Example Objects), `example`
5
+ * (one Example Object or its `$ref`), `links` and `link` (Link Objects, whose `parameters` and
6
+ * `requestBody` are data), `objects` and `object` (a map of, or one, OpenAPI object that may be a
7
+ * Reference Object: a Parameter, Response, Request Body, Header, Security Scheme or Callback),
8
+ * `extObjects` (Responses: `objects` that also take `x-` extensions) or `literal` (data). A Callback
9
+ * Object is an `object`: its `x-` keys are data and its expressions Path Items.
10
+ */
11
+ type OpenAPIReferenceMode = "node" | "names" | "extNames" | "objects" | "extObjects" | "object" | "components" | "examples" | "example" | "links" | "link" | "literal";
12
+ /** How the value under `key` of a node is read. */
13
+ declare function childMode(key: string, value: unknown): OpenAPIReferenceMode;
14
+ /** How the value under `key` of a map read in `mode` is read (null: `mode` is not a map). */
15
+ declare function entryMode(mode: OpenAPIReferenceMode, key: string, value: unknown): OpenAPIReferenceMode | null;
16
+ declare const openAPIReferenceContext: Readonly<{
17
+ childMode: typeof childMode;
18
+ entryMode: typeof entryMode;
19
+ isReferenceObject: (mode: OpenAPIReferenceMode) => boolean;
20
+ isMap: (mode: OpenAPIReferenceMode) => boolean;
21
+ arrayItemMode: (mode: OpenAPIReferenceMode) => OpenAPIReferenceMode;
22
+ }>;
23
+
24
+ export { type OpenAPIReferenceMode, openAPIReferenceContext };
@@ -0,0 +1,8 @@
1
+ import {
2
+ openAPIReferenceContext
3
+ } from "./chunk-NWH3AIKS.js";
4
+ import "./chunk-VUNV25KB.js";
5
+ export {
6
+ openAPIReferenceContext
7
+ };
8
+ //# sourceMappingURL=openapi-reference-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}