@takeshape/schema 11.28.0 → 11.29.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.
@@ -1 +1 @@
1
- {"version":3,"file":"content-schema-transform.d.ts","sourceRoot":"","sources":["../../src/content-schema-transform.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,iBAAiB,EAAE,cAAc,EAAE,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAQnF,MAAM,MAAM,UAAU,GAAG,GAAG,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAEhG,wBAAgB,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG,UAAU,CAqBxE;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3C;AAMD,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;AAEhG,MAAM,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,KAAK,MAAM,GAAG,MAAM,EAAE,CAAC;AAE9G,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AAEhG,MAAM,MAAM,iBAAiB,GAAG;IAC9B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IACzE,OAAO,CACL,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,MAAM,EACZ,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AAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,MAAM,EAAE,CAG9E;AAED,wBAAgB,cAAc,CAC5B,SAAS,EAAE,oBAAoB,GAAG,SAAS,EAC3C,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,SAAS,GAChB,iBAAiB,GAAG,SAAS,CAQ/B;AAED,wBAAgB,mBAAmB,CAAC,EAClC,UAAU,EACV,YAAY,EACZ,YAAwB,EACxB,kBAAoC,EACpC,WAAkB,EAClB,gBAAwB,EACxB,aAAa,EACd,EAAE,sBAAsB,GAAG,gBAAgB,CA6E3C;AAgBD,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,cAAc,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,aAAa,EAAE,iBAAiB,CAAC;IACjC,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AAEF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE,CAoCrH"}
@@ -47,6 +47,20 @@ function ensureArray(value) {
47
47
  function preferKey(name, schema) {
48
48
  return (0, _schemaUtil.getStorageKey)(schema) ?? name;
49
49
  }
50
+ function getLocalizedKey(key, locale) {
51
+ return locale ? `${key}:${locale}` : key;
52
+ }
53
+ function getNonDefaultLocales(projectSchema) {
54
+ return projectSchema.locales.filter(locale => locale !== projectSchema.defaultLocale);
55
+ }
56
+ function getLocalizedSourceKeys(keys, locales) {
57
+ return keys.flatMap(key => [{
58
+ key
59
+ }, ...locales.map(locale => ({
60
+ key: `${key}:${locale}`,
61
+ locale
62
+ }))]);
63
+ }
50
64
  function preferSourceKey(name, schema) {
51
65
  const key = (0, _schemaUtil.getStorageKey)(schema);
52
66
  return key ? [key, name] : [name];
@@ -68,6 +82,7 @@ function getContentTransform({
68
82
  allowNullObjects = false,
69
83
  projectSchema
70
84
  }) {
85
+ const nonDefaultLocales = getNonDefaultLocales(projectSchema);
71
86
  const prepare = (schema, obj, name = '') => {
72
87
  const shapeName = (0, _refs.getRefShapeName)(projectSchema, schema);
73
88
  schema = (0, _refs.dereferenceSchema)(projectSchema, schema);
@@ -97,13 +112,18 @@ function getContentTransform({
97
112
  const assigned = new Set();
98
113
  (0, _forEach.default)(schema.properties, (fieldSchema, name) => {
99
114
  const sourceKeys = ensureArray(sourceKeyTransform(name, fieldSchema, obj));
100
- for (const sourceKey of sourceKeys) {
115
+ const localizedSourceKeys = getLocalizedSourceKeys(sourceKeys, nonDefaultLocales);
116
+ for (const {
117
+ key: sourceKey,
118
+ locale
119
+ } of localizedSourceKeys) {
101
120
  const value = prepare(fieldSchema, (0, _get.default)(obj, sourceKey), name);
102
121
  if (value !== undefined) {
103
122
  assigned.add(sourceKey);
104
123
  const transform = findTransforms(transforms, (0, _refs.dereferenceSchema)(projectSchema, fieldSchema), name);
105
124
  const getKey = transform?.keyTransform ? transform.keyTransform : keyTransform;
106
- result[getKey(name, fieldSchema, sourceKey)] = value;
125
+ const key = getLocalizedKey(getKey(name, fieldSchema, sourceKey), locale);
126
+ result[key] = value;
107
127
  }
108
128
  }
109
129
  });
@@ -34,6 +34,20 @@ function ensureArray(value) {
34
34
  export function preferKey(name, schema) {
35
35
  return getStorageKey(schema) ?? name;
36
36
  }
37
+ function getLocalizedKey(key, locale) {
38
+ return locale ? `${key}:${locale}` : key;
39
+ }
40
+ function getNonDefaultLocales(projectSchema) {
41
+ return projectSchema.locales.filter(locale => locale !== projectSchema.defaultLocale);
42
+ }
43
+ function getLocalizedSourceKeys(keys, locales) {
44
+ return keys.flatMap(key => [{
45
+ key
46
+ }, ...locales.map(locale => ({
47
+ key: `${key}:${locale}`,
48
+ locale
49
+ }))]);
50
+ }
37
51
  export function preferSourceKey(name, schema) {
38
52
  const key = getStorageKey(schema);
39
53
  return key ? [key, name] : [name];
@@ -55,6 +69,7 @@ export function getContentTransform({
55
69
  allowNullObjects = false,
56
70
  projectSchema
57
71
  }) {
72
+ const nonDefaultLocales = getNonDefaultLocales(projectSchema);
58
73
  const prepare = (schema, obj, name = '') => {
59
74
  const shapeName = getRefShapeName(projectSchema, schema);
60
75
  schema = dereferenceSchema(projectSchema, schema);
@@ -84,13 +99,18 @@ export function getContentTransform({
84
99
  const assigned = new Set();
85
100
  forEach(schema.properties, (fieldSchema, name) => {
86
101
  const sourceKeys = ensureArray(sourceKeyTransform(name, fieldSchema, obj));
87
- for (const sourceKey of sourceKeys) {
102
+ const localizedSourceKeys = getLocalizedSourceKeys(sourceKeys, nonDefaultLocales);
103
+ for (const {
104
+ key: sourceKey,
105
+ locale
106
+ } of localizedSourceKeys) {
88
107
  const value = prepare(fieldSchema, get(obj, sourceKey), name);
89
108
  if (value !== undefined) {
90
109
  assigned.add(sourceKey);
91
110
  const transform = findTransforms(transforms, dereferenceSchema(projectSchema, fieldSchema), name);
92
111
  const getKey = transform?.keyTransform ? transform.keyTransform : keyTransform;
93
- result[getKey(name, fieldSchema, sourceKey)] = value;
112
+ const key = getLocalizedKey(getKey(name, fieldSchema, sourceKey), locale);
113
+ result[key] = value;
94
114
  }
95
115
  }
96
116
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/schema",
3
- "version": "11.28.0",
3
+ "version": "11.29.2",
4
4
  "description": "TakeShape Schema",
5
5
  "homepage": "https://www.takeshape.io",
6
6
  "repository": {
@@ -28,9 +28,9 @@
28
28
  "p-reduce": "^2.1.0",
29
29
  "semver": "^7.3.2",
30
30
  "tiny-invariant": "^1.2.0",
31
- "@takeshape/errors": "11.28.0",
32
- "@takeshape/json-schema": "11.28.0",
33
- "@takeshape/util": "11.28.0"
31
+ "@takeshape/errors": "11.29.2",
32
+ "@takeshape/json-schema": "11.29.2",
33
+ "@takeshape/util": "11.29.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@takeshape/json-schema-to-typescript": "^11.0.0",
@@ -46,7 +46,7 @@
46
46
  "meow": "^9.0.0",
47
47
  "p-map": "^5.0.0",
48
48
  "shortid": "^2.2.15",
49
- "@takeshape/infra": "11.28.0"
49
+ "@takeshape/infra": "11.29.2"
50
50
  },
51
51
  "engines": {
52
52
  "node": ">=20"