@fedify/vocab-tools
Advanced tools
+1
-1
| { | ||
| "name": "@fedify/vocab-tools", | ||
| "version": "2.1.17", | ||
| "version": "2.1.18", | ||
| "license": "MIT", | ||
@@ -5,0 +5,0 @@ "exports": { |
+1
-1
| { | ||
| "name": "@fedify/vocab-tools", | ||
| "version": "2.1.17", | ||
| "version": "2.1.18", | ||
| "description": "Code generator for Activity Vocabulary APIs", | ||
@@ -5,0 +5,0 @@ "homepage": "https://fedify.dev/", |
+26
-0
@@ -60,2 +60,3 @@ import { generateDecoder, generateEncoder } from "./codec.ts"; | ||
| #cachedJsonLd?: unknown; | ||
| #shouldCacheJsonLd = true; | ||
| readonly id: URL | null; | ||
@@ -90,2 +91,16 @@ | ||
| } | ||
| protected get _shouldCacheJsonLd(): boolean { | ||
| return this.#shouldCacheJsonLd; | ||
| } | ||
| protected set _shouldCacheJsonLd(value: boolean) { | ||
| this.#shouldCacheJsonLd = value; | ||
| } | ||
| protected static _shouldCacheDecodedJsonLd(value: unknown): boolean { | ||
| if (value == null || typeof value !== "object") return true; | ||
| if (!("_shouldCacheJsonLd" in value)) return true; | ||
| return (value as { _shouldCacheJsonLd: boolean })._shouldCacheJsonLd; | ||
| } | ||
| `; | ||
@@ -151,2 +166,13 @@ } | ||
| } from "@fedify/vocab-runtime/temporal";\n`; | ||
| yield ` | ||
| function isValidLanguageTag(language: string): boolean { | ||
| try { | ||
| new Intl.Locale(language); | ||
| return true; | ||
| } catch (error) { | ||
| if (error instanceof RangeError) return false; | ||
| throw error; | ||
| } | ||
| } | ||
| `; | ||
| yield "\n\n"; | ||
@@ -153,0 +179,0 @@ const sorted = sortTopologically(types); |
+33
-16
@@ -403,2 +403,5 @@ import metadata from "../deno.json" with { type: "json" }; | ||
| } | ||
| yield ` | ||
| let shouldCacheJsonLd = instance._shouldCacheJsonLd; | ||
| `; | ||
| for (const property of type.properties) { | ||
@@ -443,16 +446,14 @@ const variable = await getFieldName(property.uri, ""); | ||
| } | ||
| yield ` | ||
| const decoded = | ||
| `; | ||
| if (property.range.length == 1) { | ||
| yield `${variable}.push(${ | ||
| getDecoder( | ||
| property.range[0], | ||
| types, | ||
| "v", | ||
| "options", | ||
| `(values["@id"] == null ? options.baseUrl : new URL(values["@id"]))`, | ||
| ) | ||
| })`; | ||
| yield getDecoder( | ||
| property.range[0], | ||
| types, | ||
| "v", | ||
| "options", | ||
| `(values["@id"] == null ? options.baseUrl : new URL(values["@id"]))`, | ||
| ); | ||
| } else { | ||
| yield ` | ||
| const decoded = | ||
| `; | ||
| const decoders = getDecoders( | ||
@@ -466,9 +467,21 @@ property.range, | ||
| for (const code of decoders) yield code; | ||
| } | ||
| yield ` | ||
| ; | ||
| `; | ||
| if (property.range.length > 1) { | ||
| yield ` | ||
| ; | ||
| if (typeof decoded === "undefined") continue; | ||
| ${variable}.push(decoded); | ||
| if (typeof decoded === "undefined") { | ||
| shouldCacheJsonLd = false; | ||
| continue; | ||
| } | ||
| `; | ||
| } | ||
| yield ` | ||
| if (!this._shouldCacheDecodedJsonLd(decoded)) { | ||
| shouldCacheJsonLd = false; | ||
| } | ||
| ${variable}.push(decoded); | ||
| `; | ||
| yield ` | ||
| } | ||
@@ -479,3 +492,7 @@ instance.${await getFieldName(property.uri)} = ${variable}; | ||
| yield ` | ||
| if (!("_fromSubclass" in options) || !options._fromSubclass) { | ||
| instance._shouldCacheJsonLd = shouldCacheJsonLd; | ||
| if ( | ||
| shouldCacheJsonLd && | ||
| (!("_fromSubclass" in options) || !options._fromSubclass) | ||
| ) { | ||
| try { | ||
@@ -482,0 +499,0 @@ instance._cachedJsonLd = structuredClone(json); |
+2
-1
@@ -203,3 +203,4 @@ import type { PropertySchema, TypeSchema } from "./schema.ts"; | ||
| && typeof ${v}["@language"] === "string" | ||
| && typeof ${v}["@value"] === "string"`; | ||
| && typeof ${v}["@value"] === "string" | ||
| && isValidLanguageTag(${v}["@language"])`; | ||
| }, | ||
@@ -206,0 +207,0 @@ decoder(v) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
11048475
1.53%7134
1.75%