@fedify/vocab-tools 2.4.0 → 2.4.2-dev.2347

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.4.0",
3
+ "version": "2.4.2-dev.2347+09a41add",
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.4.0";
11
+ var version = "2.4.2-dev.2347+09a41add";
12
12
  //#endregion
13
13
  //#region src/type.ts
14
14
  const HEURISTICS_CONTEXTS = [
@@ -303,7 +303,7 @@ const scalarTypes = {
303
303
  && typeof ${v}["@value"] === "string" && !("@language" in ${v})`;
304
304
  },
305
305
  decoder(v) {
306
- return `new Intl.Locale(${v}["@value"])`;
306
+ return `new Intl.Locale(normalizeLanguageTag(${v}["@value"]))`;
307
307
  }
308
308
  },
309
309
  "fedify:url": {
@@ -1383,7 +1383,7 @@ async function* generateConstructor(typeUri, types) {
1383
1383
  if (Array.isArray(values.${property.pluralName}) &&
1384
1384
  values.${property.pluralName}.every(v => ${typeGuards})) {
1385
1385
  // @ts-ignore: type is checked above.
1386
- this.${fieldName} = values.${property.pluralName};
1386
+ this.${fieldName} = values.${property.pluralName}.slice();
1387
1387
  `;
1388
1388
  if (!allScalarTypes) yield `
1389
1389
  for (let i = 0; i < values.${property.pluralName}.length; i++) {
@@ -1409,6 +1409,19 @@ async function* generateCloner(typeUri, types) {
1409
1409
  /**
1410
1410
  * Clones this instance, optionally updating it with the given values.
1411
1411
  *
1412
+ * This is a shallow copy: property arrays are copied, but nested objects
1413
+ * and URLs are shared with this instance. Dereferencing accessors can cache
1414
+ * fetched objects in the instance whose accessor is called. Hydrating a
1415
+ * shared nested object through the clone can affect the original as well,
1416
+ * and can change JSON-LD output when either is embedded in another
1417
+ * object. Hydrating a top-level property of the clone does not update this
1418
+ * instance's property.
1419
+ *
1420
+ * To resolve properties without sharing nested objects, serialize and
1421
+ * re-parse the instance before hydration rather than using this method.
1422
+ * See the [vocabulary manual](https://fedify.dev/manual/vocab#immutability)
1423
+ * for details, including how cached JSON-LD affects serialization.
1424
+ *
1412
1425
  * A clone never inherits a signed JSON-LD representation retained by
1413
1426
  * \`signObject()\`: the clone may differ from the document that the proof
1414
1427
  * covers, so embedding the original secured JSON in a parent document
@@ -1417,7 +1430,8 @@ async function* generateCloner(typeUri, types) {
1417
1430
  *
1418
1431
  * @param values The values to update the clone with.
1419
1432
  * @param options The options to use for cloning.
1420
- * @returns The cloned instance.
1433
+ * @returns The cloned instance with its own property arrays. Nested objects
1434
+ * and URLs are shared with this instance.
1421
1435
  */
1422
1436
  ${emitOverride$1(typeUri, types)} clone(
1423
1437
  values:
@@ -1453,7 +1467,7 @@ async function* generateCloner(typeUri, types) {
1453
1467
  const fieldName = await getFieldName(property.uri);
1454
1468
  const trustFieldName = await getFieldName(property.uri, "#_trust");
1455
1469
  const allScalarTypes = areAllScalarTypes(property.range, types);
1456
- yield `clone.${fieldName} = this.${fieldName};`;
1470
+ yield `clone.${fieldName} = this.${fieldName}.slice();`;
1457
1471
  if (!allScalarTypes) yield `clone.${trustFieldName} = new Set(this.${trustFieldName});`;
1458
1472
  if (hasSingularAccessor(property)) {
1459
1473
  let typeGuards = getTypeGuards(property.range, types, `values.${property.singularName}`);
@@ -1504,7 +1518,7 @@ async function* generateCloner(typeUri, types) {
1504
1518
  if (Array.isArray(values.${property.pluralName}) &&
1505
1519
  values.${property.pluralName}.every(v => ${typeGuards})) {
1506
1520
  // @ts-ignore: type is checked above.
1507
- clone.${fieldName} = values.${property.pluralName};
1521
+ clone.${fieldName} = values.${property.pluralName}.slice();
1508
1522
  `;
1509
1523
  if (!allScalarTypes) yield `
1510
1524
  clone.${trustFieldName} = new Set();
@@ -2336,6 +2350,7 @@ const RUNTIME_IMPORTS = [
2336
2350
  "isDecimal",
2337
2351
  "isGatewayUrl",
2338
2352
  "LanguageString",
2353
+ "normalizeLanguageTag",
2339
2354
  "parseDecimal",
2340
2355
  "parseGatewayUrl",
2341
2356
  "parseIri",
@@ -2548,7 +2563,7 @@ function inspectIri(iri: URL): string {
2548
2563
  yield `
2549
2564
  function isValidLanguageTag(language: string): boolean {
2550
2565
  try {
2551
- new Intl.Locale(language);
2566
+ new Intl.Locale(normalizeLanguageTag(language));
2552
2567
  return true;
2553
2568
  } catch (error) {
2554
2569
  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.4.0";
10
+ var version = "2.4.2-dev.2347+09a41add";
11
11
  //#endregion
12
12
  //#region src/type.ts
13
13
  const HEURISTICS_CONTEXTS = [
@@ -302,7 +302,7 @@ const scalarTypes = {
302
302
  && typeof ${v}["@value"] === "string" && !("@language" in ${v})`;
303
303
  },
304
304
  decoder(v) {
305
- return `new Intl.Locale(${v}["@value"])`;
305
+ return `new Intl.Locale(normalizeLanguageTag(${v}["@value"]))`;
306
306
  }
307
307
  },
308
308
  "fedify:url": {
@@ -1382,7 +1382,7 @@ async function* generateConstructor(typeUri, types) {
1382
1382
  if (Array.isArray(values.${property.pluralName}) &&
1383
1383
  values.${property.pluralName}.every(v => ${typeGuards})) {
1384
1384
  // @ts-ignore: type is checked above.
1385
- this.${fieldName} = values.${property.pluralName};
1385
+ this.${fieldName} = values.${property.pluralName}.slice();
1386
1386
  `;
1387
1387
  if (!allScalarTypes) yield `
1388
1388
  for (let i = 0; i < values.${property.pluralName}.length; i++) {
@@ -1408,6 +1408,19 @@ async function* generateCloner(typeUri, types) {
1408
1408
  /**
1409
1409
  * Clones this instance, optionally updating it with the given values.
1410
1410
  *
1411
+ * This is a shallow copy: property arrays are copied, but nested objects
1412
+ * and URLs are shared with this instance. Dereferencing accessors can cache
1413
+ * fetched objects in the instance whose accessor is called. Hydrating a
1414
+ * shared nested object through the clone can affect the original as well,
1415
+ * and can change JSON-LD output when either is embedded in another
1416
+ * object. Hydrating a top-level property of the clone does not update this
1417
+ * instance's property.
1418
+ *
1419
+ * To resolve properties without sharing nested objects, serialize and
1420
+ * re-parse the instance before hydration rather than using this method.
1421
+ * See the [vocabulary manual](https://fedify.dev/manual/vocab#immutability)
1422
+ * for details, including how cached JSON-LD affects serialization.
1423
+ *
1411
1424
  * A clone never inherits a signed JSON-LD representation retained by
1412
1425
  * \`signObject()\`: the clone may differ from the document that the proof
1413
1426
  * covers, so embedding the original secured JSON in a parent document
@@ -1416,7 +1429,8 @@ async function* generateCloner(typeUri, types) {
1416
1429
  *
1417
1430
  * @param values The values to update the clone with.
1418
1431
  * @param options The options to use for cloning.
1419
- * @returns The cloned instance.
1432
+ * @returns The cloned instance with its own property arrays. Nested objects
1433
+ * and URLs are shared with this instance.
1420
1434
  */
1421
1435
  ${emitOverride$1(typeUri, types)} clone(
1422
1436
  values:
@@ -1452,7 +1466,7 @@ async function* generateCloner(typeUri, types) {
1452
1466
  const fieldName = await getFieldName(property.uri);
1453
1467
  const trustFieldName = await getFieldName(property.uri, "#_trust");
1454
1468
  const allScalarTypes = areAllScalarTypes(property.range, types);
1455
- yield `clone.${fieldName} = this.${fieldName};`;
1469
+ yield `clone.${fieldName} = this.${fieldName}.slice();`;
1456
1470
  if (!allScalarTypes) yield `clone.${trustFieldName} = new Set(this.${trustFieldName});`;
1457
1471
  if (hasSingularAccessor(property)) {
1458
1472
  let typeGuards = getTypeGuards(property.range, types, `values.${property.singularName}`);
@@ -1503,7 +1517,7 @@ async function* generateCloner(typeUri, types) {
1503
1517
  if (Array.isArray(values.${property.pluralName}) &&
1504
1518
  values.${property.pluralName}.every(v => ${typeGuards})) {
1505
1519
  // @ts-ignore: type is checked above.
1506
- clone.${fieldName} = values.${property.pluralName};
1520
+ clone.${fieldName} = values.${property.pluralName}.slice();
1507
1521
  `;
1508
1522
  if (!allScalarTypes) yield `
1509
1523
  clone.${trustFieldName} = new Set();
@@ -2335,6 +2349,7 @@ const RUNTIME_IMPORTS = [
2335
2349
  "isDecimal",
2336
2350
  "isGatewayUrl",
2337
2351
  "LanguageString",
2352
+ "normalizeLanguageTag",
2338
2353
  "parseDecimal",
2339
2354
  "parseGatewayUrl",
2340
2355
  "parseIri",
@@ -2547,7 +2562,7 @@ function inspectIri(iri: URL): string {
2547
2562
  yield `
2548
2563
  function isValidLanguageTag(language: string): boolean {
2549
2564
  try {
2550
- new Intl.Locale(language);
2565
+ new Intl.Locale(normalizeLanguageTag(language));
2551
2566
  return true;
2552
2567
  } catch (error) {
2553
2568
  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.4.0",
3
+ "version": "2.4.2-dev.2347+09a41add",
4
4
  "description": "Code generator for Activity Vocabulary APIs",
5
5
  "homepage": "https://fedify.dev/",
6
6
  "repository": {