@fedify/vocab-tools 2.1.25 → 2.1.27

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/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/vocab-tools",
3
- "version": "2.1.25",
3
+ "version": "2.1.27",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./src/mod.ts"
package/dist/mod.cjs CHANGED
@@ -8,7 +8,7 @@ let yaml = require("yaml");
8
8
  let es_toolkit = require("es-toolkit");
9
9
  //#region deno.json
10
10
  var name = "@fedify/vocab-tools";
11
- var version = "2.1.25";
11
+ var version = "2.1.27";
12
12
  //#endregion
13
13
  //#region src/type.ts
14
14
  const HEURISTICS_CONTEXTS = [
@@ -316,7 +316,7 @@ const scalarTypes = {
316
316
  && typeof ${v}["@value"] === "string" && !("@language" in ${v})`;
317
317
  },
318
318
  decoder(v) {
319
- return `new Intl.Locale(${v}["@value"])`;
319
+ return `new Intl.Locale(normalizeLanguageTag(${v}["@value"]))`;
320
320
  }
321
321
  },
322
322
  "fedify:url": {
@@ -1215,7 +1215,7 @@ async function* generateConstructor(typeUri, types) {
1215
1215
  if (Array.isArray(values.${property.pluralName}) &&
1216
1216
  values.${property.pluralName}.every(v => ${typeGuards})) {
1217
1217
  // @ts-ignore: type is checked above.
1218
- this.${fieldName} = values.${property.pluralName};
1218
+ this.${fieldName} = values.${property.pluralName}.slice();
1219
1219
  `;
1220
1220
  if (!allScalarTypes) yield `
1221
1221
  for (let i = 0; i < values.${property.pluralName}.length; i++) {
@@ -1242,7 +1242,8 @@ async function* generateCloner(typeUri, types) {
1242
1242
  * Clones this instance, optionally updating it with the given values.
1243
1243
  * @param values The values to update the clone with.
1244
1244
  * @param options The options to use for cloning.
1245
- * @returns The cloned instance.
1245
+ * @returns The cloned instance with its own property arrays. Nested objects
1246
+ * and URLs are shared with this instance.
1246
1247
  */
1247
1248
  ${emitOverride$1(typeUri, types)} clone(
1248
1249
  values:
@@ -1276,7 +1277,7 @@ async function* generateCloner(typeUri, types) {
1276
1277
  const fieldName = await getFieldName(property.uri);
1277
1278
  const trustFieldName = await getFieldName(property.uri, "#_trust");
1278
1279
  const allScalarTypes = areAllScalarTypes(property.range, types);
1279
- yield `clone.${fieldName} = this.${fieldName};`;
1280
+ yield `clone.${fieldName} = this.${fieldName}.slice();`;
1280
1281
  if (!allScalarTypes) yield `clone.${trustFieldName} = new Set(this.${trustFieldName});`;
1281
1282
  if (hasSingularAccessor(property)) {
1282
1283
  let typeGuards = getTypeGuards(property.range, types, `values.${property.singularName}`);
@@ -1327,7 +1328,7 @@ async function* generateCloner(typeUri, types) {
1327
1328
  if (Array.isArray(values.${property.pluralName}) &&
1328
1329
  values.${property.pluralName}.every(v => ${typeGuards})) {
1329
1330
  // @ts-ignore: type is checked above.
1330
- clone.${fieldName} = values.${property.pluralName};
1331
+ clone.${fieldName} = values.${property.pluralName}.slice();
1331
1332
  `;
1332
1333
  if (!allScalarTypes) yield `
1333
1334
  clone.${trustFieldName} = new Set();
@@ -1955,6 +1956,7 @@ async function* generateClasses(types) {
1955
1956
  "importPem",
1956
1957
  "isDecimal",
1957
1958
  "LanguageString",
1959
+ "normalizeLanguageTag",
1958
1960
  "parseDecimal",
1959
1961
  "type RemoteDocument"
1960
1962
  ];
@@ -1982,7 +1984,7 @@ function decodeIri(iri: string): URL {
1982
1984
  yield `
1983
1985
  function isValidLanguageTag(language: string): boolean {
1984
1986
  try {
1985
- new Intl.Locale(language);
1987
+ new Intl.Locale(normalizeLanguageTag(language));
1986
1988
  return true;
1987
1989
  } catch (error) {
1988
1990
  if (error instanceof RangeError) return false;
package/dist/mod.js CHANGED
@@ -7,7 +7,7 @@ import { parse } from "yaml";
7
7
  import { pascalCase } from "es-toolkit";
8
8
  //#region deno.json
9
9
  var name = "@fedify/vocab-tools";
10
- var version = "2.1.25";
10
+ var version = "2.1.27";
11
11
  //#endregion
12
12
  //#region src/type.ts
13
13
  const HEURISTICS_CONTEXTS = [
@@ -315,7 +315,7 @@ const scalarTypes = {
315
315
  && typeof ${v}["@value"] === "string" && !("@language" in ${v})`;
316
316
  },
317
317
  decoder(v) {
318
- return `new Intl.Locale(${v}["@value"])`;
318
+ return `new Intl.Locale(normalizeLanguageTag(${v}["@value"]))`;
319
319
  }
320
320
  },
321
321
  "fedify:url": {
@@ -1214,7 +1214,7 @@ async function* generateConstructor(typeUri, types) {
1214
1214
  if (Array.isArray(values.${property.pluralName}) &&
1215
1215
  values.${property.pluralName}.every(v => ${typeGuards})) {
1216
1216
  // @ts-ignore: type is checked above.
1217
- this.${fieldName} = values.${property.pluralName};
1217
+ this.${fieldName} = values.${property.pluralName}.slice();
1218
1218
  `;
1219
1219
  if (!allScalarTypes) yield `
1220
1220
  for (let i = 0; i < values.${property.pluralName}.length; i++) {
@@ -1241,7 +1241,8 @@ async function* generateCloner(typeUri, types) {
1241
1241
  * Clones this instance, optionally updating it with the given values.
1242
1242
  * @param values The values to update the clone with.
1243
1243
  * @param options The options to use for cloning.
1244
- * @returns The cloned instance.
1244
+ * @returns The cloned instance with its own property arrays. Nested objects
1245
+ * and URLs are shared with this instance.
1245
1246
  */
1246
1247
  ${emitOverride$1(typeUri, types)} clone(
1247
1248
  values:
@@ -1275,7 +1276,7 @@ async function* generateCloner(typeUri, types) {
1275
1276
  const fieldName = await getFieldName(property.uri);
1276
1277
  const trustFieldName = await getFieldName(property.uri, "#_trust");
1277
1278
  const allScalarTypes = areAllScalarTypes(property.range, types);
1278
- yield `clone.${fieldName} = this.${fieldName};`;
1279
+ yield `clone.${fieldName} = this.${fieldName}.slice();`;
1279
1280
  if (!allScalarTypes) yield `clone.${trustFieldName} = new Set(this.${trustFieldName});`;
1280
1281
  if (hasSingularAccessor(property)) {
1281
1282
  let typeGuards = getTypeGuards(property.range, types, `values.${property.singularName}`);
@@ -1326,7 +1327,7 @@ async function* generateCloner(typeUri, types) {
1326
1327
  if (Array.isArray(values.${property.pluralName}) &&
1327
1328
  values.${property.pluralName}.every(v => ${typeGuards})) {
1328
1329
  // @ts-ignore: type is checked above.
1329
- clone.${fieldName} = values.${property.pluralName};
1330
+ clone.${fieldName} = values.${property.pluralName}.slice();
1330
1331
  `;
1331
1332
  if (!allScalarTypes) yield `
1332
1333
  clone.${trustFieldName} = new Set();
@@ -1954,6 +1955,7 @@ async function* generateClasses(types) {
1954
1955
  "importPem",
1955
1956
  "isDecimal",
1956
1957
  "LanguageString",
1958
+ "normalizeLanguageTag",
1957
1959
  "parseDecimal",
1958
1960
  "type RemoteDocument"
1959
1961
  ];
@@ -1981,7 +1983,7 @@ function decodeIri(iri: string): URL {
1981
1983
  yield `
1982
1984
  function isValidLanguageTag(language: string): boolean {
1983
1985
  try {
1984
- new Intl.Locale(language);
1986
+ new Intl.Locale(normalizeLanguageTag(language));
1985
1987
  return true;
1986
1988
  } catch (error) {
1987
1989
  if (error instanceof RangeError) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/vocab-tools",
3
- "version": "2.1.25",
3
+ "version": "2.1.27",
4
4
  "description": "Code generator for Activity Vocabulary APIs",
5
5
  "homepage": "https://fedify.dev/",
6
6
  "repository": {