nayota-show-sdk 1.3.82 → 1.3.83

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nayota-show-sdk",
3
- "version": "1.3.82",
3
+ "version": "1.3.83",
4
4
  "description": "nayota-show-server rest-api",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -102,6 +102,23 @@ function resolveOptionalLegacyReference(data, primaryKey, legacyKey) {
102
102
  return undefined
103
103
  }
104
104
 
105
+ function mapLegacySelectFields(select, fieldMap = {}) {
106
+ if (typeof select !== 'string') {
107
+ return select
108
+ }
109
+
110
+ const fields = select
111
+ .split(/[\s,]+/)
112
+ .map(field => field.trim())
113
+ .filter(Boolean)
114
+
115
+ if (!fields.length) {
116
+ return select
117
+ }
118
+
119
+ return [...new Set(fields.map(field => fieldMap[field] || field))].join(' ')
120
+ }
121
+
105
122
  function mapAreaToIotBody(data = {}, options = {}) {
106
123
  const isPartial = options.partial === true
107
124
  const metadata = mergeMetadata(data.metadata, {
@@ -162,6 +179,9 @@ function mapAreaClassToIotQuery(query = {}) {
162
179
  return removeUndefinedFields({
163
180
  ...omitKeys(query, ['_id', 'sort']),
164
181
  ids: Array.isArray(query.ids) ? query.ids.join(',') : (query.ids || query._id || undefined),
182
+ select: mapLegacySelectFields(query.select, {
183
+ _id: 'id'
184
+ }),
165
185
  ...parseLegacySort(query.sort)
166
186
  })
167
187
  }
@@ -677,6 +697,10 @@ function mapDeviceClassToIotQuery(query = {}) {
677
697
  ...omitKeys(query, ['_id', 'code', 'sort']),
678
698
  id: query.id || query._id,
679
699
  typeCode: query.typeCode || query.code,
700
+ select: mapLegacySelectFields(query.select, {
701
+ _id: 'id',
702
+ code: 'typeCode'
703
+ }),
680
704
  ...parseLegacySort(query.sort, {
681
705
  code: 'typeCode'
682
706
  })
@@ -202,6 +202,7 @@ describe('iotModuleSpecs departs hierarchy compatibility', () => {
202
202
 
203
203
  describe('iotModuleSpecs area space compatibility', () => {
204
204
  const area = iotModuleSpecs.area.operations
205
+ const areaClass = iotModuleSpecs.areaClass.operations
205
206
 
206
207
  test('maps legacy centerCoordinate to space centerPoint when creating areas', () => {
207
208
  const request = area.create.toRequest({
@@ -261,6 +262,33 @@ describe('iotModuleSpecs area space compatibility', () => {
261
262
 
262
263
  expect(request.data.areaClassId).toBeNull()
263
264
  })
265
+
266
+ test('maps legacy areaClass select _id to v2 id and returns legacy _id', () => {
267
+ const request = areaClass.list.toRequest({
268
+ select: '_id name'
269
+ })
270
+
271
+ expect(request.params.select).toBe('id name')
272
+
273
+ const response = areaClass.list.fromResponse({
274
+ code: 0,
275
+ data: {
276
+ total: 1,
277
+ items: [
278
+ {
279
+ id: 'space-class-1',
280
+ name: '会议室'
281
+ }
282
+ ]
283
+ }
284
+ })
285
+
286
+ expect(response.data.rows[0]).toMatchObject({
287
+ _id: 'space-class-1',
288
+ id: 'space-class-1',
289
+ name: '会议室'
290
+ })
291
+ })
264
292
  })
265
293
 
266
294
  describe('iotModuleSpecs devices write compatibility', () => {